How to make vgg pytorch's ptl size smaller on android?

import torch
# import joblib
from torch.utils.mobile_optimizer import optimize_for_mobile
from torchvision.models.vgg import vgg16
import torch, torchvision.models

# lb = joblib.load('lb.pkl')
device = torch.device('cuda:0')
#device = torch.device('cpu')#'cuda:0')
torch.backends.cudnn.benchmark = True
model = vgg16().to(device)

# model = torchvision.models.vgg16()
path = 'model-22222.pth', path) # nothing else here


scripted_module = torch.jit.script(model)
optimized_scripted_module = optimize_for_mobile(scripted_module)

The optimize_for_mobile seems does not make the ptl file smaller, it’s about 527M, too large on Android. How to make it smaller?

You first need to ** Quantized** the model (This will reduce the size) and then convert it into torch script for it to run on android.

1 Like

Is there any other solutions? For example using onnx , ncnn or transform into tensorflow lite? Thanks. Because the size only smaller 50%, how to reduce to about 5%. The size is too big yet. Not fit for the mobile phone users.