When I convert mobilenet_v2 network to torchscript model, the size increased from 13.5MB to 43.1MB. It’s too big to deploy in Android.
How can I compress the torchscript model ?
from torchvision.models import mobilenet_v2
net = mobilenet_v2()
script_module = torch.jit.script(net)
The size of models:
Are you on the latest version of PyTorch (1.3)? We made some changes to significantly decrease the size of TorchScript binaries. For
mobilenet_v2 on the nightly version of PyTorch, I get very similar sizes between eager PyTorch and TorchScript:
$ ls -la --block-size=M
-rw-------. 1 user user 15M Nov 15 13:06 net.pt
-rw-------. 1 user user 14M Nov 15 13:06 net.pth
If you are on PyTorch 1.3 and still are getting this problem, could you try using the nightly PyTorch package and see if that fixes it?
Thank you, the problem solved when I upgraded torch from 1.2 to 1.3.