Skip to content

Commit

Permalink
Fix TorchScript on mobile export (#6183)
Browse files Browse the repository at this point in the history
* fix export of TorchScript on mobile

* Cleanup

Co-authored-by: yinrong <[email protected]>
Co-authored-by: Glenn Jocher <[email protected]>
  • Loading branch information
3 people authored Jan 4, 2022
1 parent 5bd6a97 commit fb83929
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion export.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def export_torchscript(model, im, file, optimize, prefix=colorstr('TorchScript:'
ts = torch.jit.trace(model, im, strict=False)
d = {"shape": im.shape, "stride": int(max(model.stride)), "names": model.names}
extra_files = {'config.txt': json.dumps(d)} # torch._C.ExtraFilesMap()

This comment has been minimized.

Copy link
@3097254259

3097254259 Jan 22, 2022

000

(optimize_for_mobile(ts) if optimize else ts).save(str(f), _extra_files=extra_files)
if optimize: # https://pytorch.org/tutorials/recipes/mobile_interpreter.html
optimize_for_mobile(ts)._save_for_lite_interpreter(str(f), _extra_files=extra_files)
else:
ts.save(str(f), _extra_files=extra_files)

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

0 comments on commit fb83929

Please sign in to comment.