Skip to content

Commit

Permalink
handle exceptions happening when downloading config
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed Mar 13, 2024
1 parent 85f7328 commit d3325a1
Showing 1 changed file with 9 additions and 5 deletions.
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

0 comments on commit d3325a1

Please sign in to comment.