0

I am loading an image into a tensor using this code snippet

var img = document.getElementById("myImage");  
var example =tf.fromPixels(img);
example = tf.image.resizeBilinear(example, [150, 150], align_corners=true);
example = example.toFloat().div(tf.scalar(255));
example = example.reshape([1, 150, 150, 3]); 
example.print()

When classifying the image with some model in tensorflow.js, I realized that I am getting slightly different softmax outputs, depending on where (e.g. my laptop vs my pixel 3 phone) I run it.

Debugging a bit further, I realized that the values in tensor I obtain from tf.fromPixels() are slightly different depending on the platform.

Is this to be expected ? Anyone has an idea why this is the case and what to be done to prevent it ?

1 Answers1

3

tf.fromPixels makes use of the HTMLCanvasElement. browsers tend to use different image processing engines, etc. therefore, similar canvas elements can produce different values depending on the system.

more info:

vabarbosa
  • 706
  • 1
  • 4
  • 9