Skip to content

Commit

Permalink
Add TorchScript-Lite export (WongKinYiu#387)
Browse files Browse the repository at this point in the history
* TorchScript-Lite export

* forgot the import
  • Loading branch information
Ian321 authored Aug 1, 2022
1 parent 0a58f6d commit 0563c70
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import torch
import torch.nn as nn
from torch.utils.mobile_optimizer import optimize_for_mobile

import models
from models.experimental import attempt_load, End2End
Expand Down Expand Up @@ -75,6 +76,17 @@
except Exception as e:
print('TorchScript export failure: %s' % e)

# TorchScript-Lite export
try:
print('\nStarting TorchScript-Lite export with torch %s...' % torch.__version__)
f = opt.weights.replace('.pt', '.torchscript.ptl') # filename
ts = torch.jit.trace(model, img, strict=False)
ts = optimize_for_mobile(ts)
ts._save_for_lite_interpreter(f)
print('TorchScript-Lite export success, saved as %s' % f)
except Exception as e:
print('TorchScript-Lite export failure: %s' % e)

# ONNX export
try:
import onnx
Expand Down

0 comments on commit 0563c70

Please sign in to comment.