One addition here that does not solve the problem 100% as described, but it at least allows for one to train a model in python using a set of transformations and then run the model again on Android using a ‘similar’ set of transformation.
For Python I used:
transform =  transforms.Compose([
transforms.Resize((224,224)),
# transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
Note that I have commented out the CenterCrop that is not available on Pytorch for Android. Then on Android I use:
float norm_mean[] = new float[]{(float)0.485, (float)0.456, (float)0.406};
float norm_std[] = new float[]{(float)0.229, (float)0.224, (float)0.225};
Tensor inputTensor = TensorImageUtils.bitmapToFloat32Tensor(bitmap, 0,0, 224,224,
norm_mean, norm_std);
The transformations are not 100% the same because of the differences in implementation, but at least are similar enough to allow for alignment in model prediction…