title: Why is my model giving different results in tensorflow.js and in Python Tensorflow?
body: <p>I'm trying to adapt the notebook &quot;<a href="https://www.kaggle.com/nageshsingh/eda-predict-artist-from-artworks-imagenet" rel="nofollow noreferrer">Predict Artist from Artworks</a>&quot; to my own dataset. The Keras model has been generated and converted to a Tensorflow model (using <code>tensorflowjs_converter --input_format keras us.keras tfjs_model/us</code>), and I now try to use it with tensorflow.js, but the predictions results are different (and wrong) when using tensorflow.js.</p>
  <p>Here is the prediction Python code which gives a correct result:</p>
  <pre><code>from keras.preprocessing import image
  from tensorflow import keras
  import numpy as np
  
  artists = ['CB', 'AT', 'TS', 'FG', 'DR']
  
  model = keras.models.load_model('us.keras')
  
  image_file = 'datasets/full/thumbnails3/fr/gb/fr_gb_0004p_001.jpg'
  test_image = image.load_img(image_file, target_size=(224, 224))
  
  # Predict artist
  test_image = image.img_to_array(test_image)
  test_image /= 255.
  test_image = np.expand_dims(test_image, axis=0)
  
  prediction = model.predict(test_image)
  prediction_probability = np.amax(prediction)
  prediction_idx = np.argmax(prediction)
  
  print(&quot;Predicted artist = {}, probability of {:.2f} %&quot;
        .format(artists[prediction_idx],  prediction_probability * 100))
  </code></pre>
  <p>The result is:</p>
  <blockquote>
  <p>Predicted artist = CB, probability of 22.62 %</p>
  </blockquote>
  <p>However, when using tensorflow.js the results are completely different:</p>
  <pre><code>const tf = require(&quot;@tensorflow/tfjs&quot;);
  const tfn = require(&quot;@tensorflow/tfjs-node&quot;);
  const sharp = require('sharp');
  
  const modelFile = tfn.io.fileSystem(&quot;tfjs_model/us/model.json&quot;);
  
  const artists = ['CB', 'AT', 'TS', 'FG', 'DR']
  
  tf.loadLayersModel(modelFile).then(model =&gt; {
      sharp('datasets/full/thumbnails3/fr/gb/fr_gb_0004p_001.jpg')
          .rotate()
          .resize(224, 224)
          .toBuffer().then(
              data =&gt; {
                  let image = tfn.node.decodeImage(data, 0)
                  image = tf.expandDims(image, 0);
                  image = tf.cast(image, 'float32').div(255)
                  const prediction = model.predict(image);
                  prediction.array().then(([predictionArray]) =&gt; {
                      const predictionProbability = Math.max(...predictionArray);
                      const predictionIndex = predictionArray.indexOf(predictionProbability);
                      console.log(`Predicted artist = ${artists[predictionIndex]}, probability of ${predictionProbability * 100}%`)
                  })
              }
          )
  })
  </code></pre>
  <p>Result:</p>
  <blockquote>
  <p>Predicted artist = DR, probability of 37.461987137794495%</p>
  </blockquote>
  <p>My assumption is that something that I do with the dimensions or the handling of the image is wrong in the JS code, but I can't figure out what.</p>