Skip to content

Commit fb83929

Browse files
yinrongyinrongglenn-jocher
authored
Fix TorchScript on mobile export (ultralytics#6183)
* fix export of TorchScript on mobile * Cleanup Co-authored-by: yinrong <[email protected]> Co-authored-by: Glenn Jocher <[email protected]>
1 parent 5bd6a97 commit fb83929

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

export.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ def export_torchscript(model, im, file, optimize, prefix=colorstr('TorchScript:'
7575
ts = torch.jit.trace(model, im, strict=False)
7676
d = {"shape": im.shape, "stride": int(max(model.stride)), "names": model.names}
7777
extra_files = {'config.txt': json.dumps(d)} # torch._C.ExtraFilesMap()
78-
(optimize_for_mobile(ts) if optimize else ts).save(str(f), _extra_files=extra_files)
78+
if optimize: # https://pytorch.org/tutorials/recipes/mobile_interpreter.html
79+
optimize_for_mobile(ts)._save_for_lite_interpreter(str(f), _extra_files=extra_files)
80+
else:
81+
ts.save(str(f), _extra_files=extra_files)
7982

8083
LOGGER.info(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')
8184
except Exception as e:

0 commit comments

Comments
 (0)