Fix TorchScript on mobile export (#6183)
Browse files* fix export of TorchScript on mobile
* Cleanup
Co-authored-by: yinrong <[email protected]>
Co-authored-by: Glenn Jocher <[email protected]>
export.py
CHANGED
@@ -75,7 +75,10 @@ def export_torchscript(model, im, file, optimize, prefix=colorstr('TorchScript:'
|
|
75 |
ts = torch.jit.trace(model, im, strict=False)
|
76 |
d = {"shape": im.shape, "stride": int(max(model.stride)), "names": model.names}
|
77 |
extra_files = {'config.txt': json.dumps(d)} # torch._C.ExtraFilesMap()
|
78 |
-
|
|
|
|
|
|
|
79 |
|
80 |
LOGGER.info(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')
|
81 |
except Exception as e:
|
|
|
75 |
ts = torch.jit.trace(model, im, strict=False)
|
76 |
d = {"shape": im.shape, "stride": int(max(model.stride)), "names": model.names}
|
77 |
extra_files = {'config.txt': json.dumps(d)} # torch._C.ExtraFilesMap()
|
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)
|
82 |
|
83 |
LOGGER.info(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')
|
84 |
except Exception as e:
|