From 42d1a9404184dc36a52db980c467e9a2b4b459c2 Mon Sep 17 00:00:00 2001 From: Yin Rong Date: Tue, 4 Jan 2022 12:25:48 +0800 Subject: [PATCH] Fix TorchScript on mobile export (#6183) * fix export of TorchScript on mobile * Cleanup Co-authored-by: yinrong Co-authored-by: Glenn Jocher --- export.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/export.py b/export.py index 3b677d2ca144..d169aa0de5f5 100644 --- a/export.py +++ b/export.py @@ -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() - (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: