Skip to content

Commit

Permalink
fix export of TorchScript on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
yinrong authored and glenn-jocher committed Jan 4, 2022
1 parent 5bd6a97 commit 5fb246d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion export.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ 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()
(optimize_for_mobile(ts) if optimize else ts).save(str(f), _extra_files=extra_files)
if optimize:
ts = optimize_for_mobile(ts)
# pytorch BETA
# https://pytorch.org/tutorials/recipes/mobile_interpreter.html
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 5fb246d

Please sign in to comment.