Skip to content

Commit

Permalink
Fix TorchScript JSON string key bug
Browse files Browse the repository at this point in the history
Resolves #9011

Signed-off-by: Glenn Jocher <[email protected]>
  • Loading branch information
glenn-jocher authored Aug 18, 2022
1 parent 5c854fa commit c167b41
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ 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...')
Expand Down

0 comments on commit c167b41

Please sign in to comment.