Nathan Segers commited on
Commit
4d461c9
·
1 Parent(s): 909a40e

fix: Updated prediction for better accuracy

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import tensorflow as tf
3
  import gradio as gr
 
4
  from huggingface_hub import hf_hub_download
5
 
6
  # 1) download your SavedModel from the Hub
@@ -15,8 +16,9 @@ model = tf.keras.models.load_model("./model")
15
  # 3) simple preprocess + predict
16
  CLASS_NAMES = ["cat","dog","panda"]
17
  def predict(image):
18
- img = tf.image.resize(image, (64,64)) / 255.0
19
- probs = model.predict(img[None,...])[0]
 
20
  return {c: float(p) for c,p in zip(CLASS_NAMES, probs)}
21
 
22
  # 4) launch Gradio
 
1
  import os
2
  import tensorflow as tf
3
  import gradio as gr
4
+ import numpy as np
5
  from huggingface_hub import hf_hub_download
6
 
7
  # 1) download your SavedModel from the Hub
 
16
  # 3) simple preprocess + predict
17
  CLASS_NAMES = ["cat","dog","panda"]
18
  def predict(image):
19
+ resized_image = tf.image.resize(image, (64,64))
20
+ images_to_predict = np.expand_dims(np.array(resized_image), axis=0)
21
+ probs = model.predict(images_to_predict)[0]
22
  return {c: float(p) for c,p in zip(CLASS_NAMES, probs)}
23
 
24
  # 4) launch Gradio