Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle exceptions happening when downloading config #210

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions supervisely/export_weights/src/sly_export_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,22 @@ def export_to_core_ml(weights, img):
@sly.timeit
def export_weights(api: sly.Api, task_id, context, state, app_logger):
weights_path = download_weights(customWeightsPath)
cwp = os.path.join(Path(customWeightsPath).parents[1], 'opt.yaml')
configs_path = download_weights(cwp)
try:
cwp = os.path.join(Path(customWeightsPath).parents[1], 'opt.yaml')
configs_path = download_weights(cwp)
with open(configs_path, 'r') as stream:
cfgs_loaded = yaml.safe_load(stream)
except:
cfgs_loaded = None
model = attempt_load(weights=weights_path, map_location=device)

with open(configs_path, 'r') as stream:
cfgs_loaded = yaml.safe_load(stream)


if hasattr(model, 'module') and hasattr(model.module, 'img_size'):
imgsz = model.module.img_size[0]
elif hasattr(model, 'img_size'):
imgsz = model.img_size[0]
elif cfgs_loaded['img_size']:
elif cfgs_loaded and cfgs_loaded['img_size']:
imgsz = cfgs_loaded['img_size'][0]
else:
sly.logger.warning(f"Image size is not found in model checkpoint. Use default: {image_size}")
Expand Down
Loading