소스 검색

Default optimize_for_mobile() on TorchScript models (#2908)

Per https://pytorch.org/tutorials/recipes/script_optimized.html this should improve performance on torchscript models (and maybe coreml models also since coremltools operates on a torchscript model input, though this still requires testing).
modifyDataloader
Glenn Jocher GitHub 3 년 전
부모
커밋
28db237639
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1개의 변경된 파일2개의 추가작업 그리고 0개의 파일을 삭제
  1. +2
    -0
      models/export.py

+ 2
- 0
models/export.py 파일 보기

@@ -12,6 +12,7 @@ sys.path.append('./') # to run '$ python *.py' files in subdirectories

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

import models
from models.experimental import attempt_load
@@ -65,6 +66,7 @@ if __name__ == '__main__':
print(f'\n{prefix} starting export with torch {torch.__version__}...')
f = opt.weights.replace('.pt', '.torchscript.pt') # filename
ts = torch.jit.trace(model, img, strict=False)
ts = optimize_for_mobile(ts) # https://pytorch.org/tutorials/recipes/script_optimized.html
ts.save(f)
print(f'{prefix} export success, saved as {f}')
except Exception as e:

Loading…
취소
저장