title: tensorflow.js model is not predicting correctly
body: <p>hello I'm new to this topic of ml. I trained a model in python which classifies the images in 2 classes as 'santa' and 'not santa' and it is predicting correctly. I converted this model to tensorflow.js as I need to use it in my website for classifying uploaded images but it is not classifying images correctly as in the python model. model.predict() returns 2 probabilities which of one is higher returns that class. I feel the problem lies in the preprocessing part in the javascript for testing from the model. I have attached the code below.</p>
  
  <p>below is the code snippet for testing in python </p>
  
  <pre><code>image = cv2.imread(args["image"])
  orig = image.copy()
  image = cv2.resize(image, (28, 28))
  image = image.astype("float") / 255.0
  image = img_to_array(image)
  image = np.expand_dims(image, axis=0)
  print("[INFO] loading network...")
  model = load_model(args["model"])
  x= model.predict(image)
  print(x)
  </code></pre>
  
  <p>below is javascript code for testing</p>
  
  <pre><code>function preprocess(img)
  {
  
  
  let tensor = tf.browser.fromPixels(img)
  
  const resized = tf.image.resizeBilinear(tensor, [28, 28]).toFloat()
  
  const offset = tf.scalar(255.0);
  const normalized = tf.scalar(1.0).sub(resized.div(offset));
  
  const batched = normalized.expandDims(0)
  return batched
  
  }
  
  function predict(imgData) {
  
      var class_names = ['santa','not santa']
  
      var pred = model.predict(preprocess(imgData)).dataSync()
      console.log(pred)            
      const idx = tf.argMax(pred);
  
  
  
      var indices = findIndicesOfMax(pred, 1)
      console.log(indices)
      var probs = findTopValues(pred, 1)
      var names = getClassNames(indices) 
  
  
      document.getElementById("Result").innerHTML = names
  
      console.log(names);
  
      console.log(document.getElementById("Result"));
  
    }
  </code></pre>
  
  <p>please help how can I solve this problem.
  for a sample images the python model returns the value as follows
  [[0.9940202  0.00597982]]
  [python output]<a href="https://i.stack.imgur.com/kqbxM.png" rel="nofollow noreferrer">1</a></p>
  
  <p>and for the same image tensorflowjs model returns value as follows
  Float32Array [ 0.24975205957889557, 0.7502480149269104 ]
  [tensorflowjs]<a href="https://i.stack.imgur.com/cRhYI.png" rel="nofollow noreferrer">2</a></p>