Hi, I’ve trained EfficientNet model from timm and converted it into .ptl for android. Here is conversion code:
dummy_input = torch.randn(1,3,256,256)
traced_script_module = torch.jit.trace(model, dummy_input)
traced_script_module_optimized = optimize_for_mobile(traced_script_module)
traced_script_module_optimized._save_for_lite_interpreter("./models/classifier_best.ptl")
Then I try to forward Image from assets to my model but results are very different
Maybe I’m doing something wrong? Here is my Android code:
try {
module = Module.load(assetFilePath(TestModelActivity.this, "classifier_best.ptl"));
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
bitmap = BitmapFactory.decodeStream(getAssets().open("solara_cropped.jpg"));
} catch (IOException e) {
throw new RuntimeException(e);
}
Tensor inputTensor = TensorImageUtils.bitmapToFloat32Tensor(bitmap,
TensorImageUtils.TORCHVISION_NORM_MEAN_RGB,
TensorImageUtils.TORCHVISION_NORM_STD_RGB,
MemoryFormat.CHANNELS_LAST);
Tensor outputTensor = module.forward(IValue.from(inputTensor)).toTensor();
float[] scores = outputTensor.getDataAsFloatArray();