Hello,I want to deploy the clip model to an Android phone and encountered a problem. Can anyone help me to solve this problem?
first save the model into ‘clip_model.pt’ file;
import torch
import clip
from PIL import Image
from tensorboardX import SummaryWriter
from torch.utils.mobile_optimizer import optimize_for_mobile
model, preprocess = clip.load("ViT-B/32")
model = list(model.children())[0]
image_path = "./image.jpg";
image = preprocess(Image.open(image_path)).unsqueeze(0)
model.eval()
traced_script_model = torch.jit.trace(model, image)
optimized_script_model = optimize_for_mobile(traced_script_model)
optimized_script_model._save_for_lite_interpreter('./clip_model.pt')
secondly, load the model in android app:
module = LiteModuleLoader.load(assetFilePath(this, "clip_model.pt"));
the build.gradle file of the android project:
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'org.pytorch:pytorch_android_lite:1.13.0'
implementation 'org.pytorch:pytorch_android_torchvision:1.9.0'
}
the runtime exception:
com.facebook.jni.CppException: Following ops cannot be found: [aten::scaled_dot_product_attention]. Please check if the operator library is included in the build. If built with selected ops, check if these ops are in the list. If you are a Meta employee, please see fburl.com/missing_ops for a fix. Or post it in https://discuss.pytorch.org/c/mobile/ ()
Exception raised from initialize_operators at /home/agunapal/pytorch/torch/csrc/jit/mobile/function.cpp:90 (most recent call first):
(no backtrace available)