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

update detect.py in order to support torch script #5109

Merged
merged 5 commits into from
Oct 12, 2021
Merged
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
pt, onnx, tflite, pb, saved_model = (suffix == x for x in suffixes) # backend booleans
stride, names = 64, [f'class{i}' for i in range(1000)] # assign defaults
if pt:
model = attempt_load(weights, map_location=device) # load FP32 model
if 'torchscript' in w:
# this is torchscript saved not a pickle that can be loaded with th.load
# we assume the file exist in the target folder
if Path(w).is_file():
model = torch.jit.load(w)
else:
raise ValueError('Cannot find torchscript file {}'.format(Path(w))
else:
model = attempt_load(weights, map_location=device) # load FP32 model
stride = int(model.stride.max()) # model stride
names = model.module.names if hasattr(model, 'module') else model.names # get class names
if half:
Expand Down