mirror of
https://github.com/WongKinYiu/yolov7.git
synced 2025-06-03 21:54:57 +08:00
Add TorchScript-Lite export (#387)
* TorchScript-Lite export * forgot the import
This commit is contained in:
parent
0a58f6d1cb
commit
0563c70705
12
export.py
12
export.py
@ -6,6 +6,7 @@ sys.path.append('./') # to run '$ python *.py' files in subdirectories
|
|||||||
|
|
||||||
import torch
|
import torch
|
||||||
import torch.nn as nn
|
import torch.nn as nn
|
||||||
|
from torch.utils.mobile_optimizer import optimize_for_mobile
|
||||||
|
|
||||||
import models
|
import models
|
||||||
from models.experimental import attempt_load, End2End
|
from models.experimental import attempt_load, End2End
|
||||||
@ -75,6 +76,17 @@ if __name__ == '__main__':
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('TorchScript export failure: %s' % 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
|
# ONNX export
|
||||||
try:
|
try:
|
||||||
import onnx
|
import onnx
|
||||||
|
Loading…
x
Reference in New Issue
Block a user