Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
23 |
-
inp =
|
|
|
24 |
inp = tf.keras.applications.nasnet.preprocess_input(inp)
|
|
|
25 |
|
26 |
# Prediction
|
27 |
prediction = model.predict(inp)
|
28 |
-
|
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,
|