'How to make an image into a Pytorch Tensor without normalization on Android?

I am making an application that compares two images to find the similarity. My model has been trained without image normalization. I want convert to image to Tensor without normalization. What should I do?

    public Tensor recognize(Bitmap image){

    //        Tensor input =  TensorImageUtils.bitmapToFloat32Tensor(
    //                image,
    //                TensorImageUtils.TORCHVISION_NORM_MEAN_RGB,
    //                TensorImageUtils.TORCHVISION_NORM_STD_RGB);

    float[] a = new float[]{1.0f, 1.0f, 1.0f};
    float[] b = new float[]{1.0f, 1.0f, 1.0f};
    Tensor input =  TensorImageUtils.bitmapToFloat32Tensor(
            image, a, b);


    Tensor output = module.forward(IValue.from(input)).toTensor();

    return output;
}


Solution 1:[1]

Maybe too late to the party, but the short answer would be to use custom mean and std float arrays as follows:

float[] NO_NORM_STD = {1.0f, 1.0f, 1.0f};
float[] NO_NORM_MEAN = {0.0f, 0.0f, 0.0f};

Tensor input =  TensorImageUtils.bitmapToFloat32Tensor(image, NO_NORM_MEAN, NO_NORM_STD);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman