From 529aafd737053264cf8676b29c37f5d5300460eb Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 18 Aug 2022 11:50:24 +0200 Subject: [PATCH] Fix TorchScript JSON string key bug (#9015) * Fix TorchScript JSON string key bug Resolves https://github.com/ultralytics/yolov5/issues/9011 Signed-off-by: Glenn Jocher * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: Glenn Jocher Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- models/common.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/common.py b/models/common.py index 30202ca1abd7..4f93887c55e0 100644 --- a/models/common.py +++ b/models/common.py @@ -337,8 +337,10 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False, extra_files = {'config.txt': ''} # model metadata model = torch.jit.load(w, _extra_files=extra_files) model.half() if fp16 else model.float() - if extra_files['config.txt']: - d = json.loads(extra_files['config.txt']) # extra_files dict + if extra_files['config.txt']: # load metadata dict + d = json.loads(extra_files['config.txt'], + object_hook=lambda d: {int(k) if k.isdigit() else k: v + for k, v in d.items()}) stride, names = int(d['stride']), d['names'] elif dnn: # ONNX OpenCV DNN LOGGER.info(f'Loading {w} for ONNX OpenCV DNN inference...')