Sa-m commited on
Commit
b0e91bc
·
1 Parent(s): 948a598

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -19,15 +19,18 @@ with custom_object_scope({'Addons>F1Score': F1Score}):
19
  def classify_image(inp):
20
  np.random.seed(143)
21
 
22
- # Preprocess input
23
- inp = inp.reshape((-1, HEIGHT, WIDTH, 3))
 
24
  inp = tf.keras.applications.nasnet.preprocess_input(inp)
 
25
 
26
  # Prediction
27
  prediction = model.predict(inp)
28
- # Build a dict of label:confidence
29
  return {LABELS[i]: float(f"{prediction[0][i]:.6f}") for i in range(NUM_CLASSES)}
30
 
 
31
  # Gradio interface
32
  iface = gr.Interface(
33
  fn=classify_image,
 
19
  def classify_image(inp):
20
  np.random.seed(143)
21
 
22
+ # Ensure input is resized to expected shape
23
+ inp = tf.image.resize(inp, [HEIGHT, WIDTH])
24
+ inp = tf.cast(inp, tf.float32) # ensure correct dtype for preprocessing
25
  inp = tf.keras.applications.nasnet.preprocess_input(inp)
26
+ inp = tf.expand_dims(inp, axis=0) # make batch dimension
27
 
28
  # Prediction
29
  prediction = model.predict(inp)
30
+
31
  return {LABELS[i]: float(f"{prediction[0][i]:.6f}") for i in range(NUM_CLASSES)}
32
 
33
+
34
  # Gradio interface
35
  iface = gr.Interface(
36
  fn=classify_image,