Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -15,21 +15,19 @@ def normalize_image(img):
|
|
15 |
return img
|
16 |
|
17 |
def predict_top_classes(img, num_top_classes=5):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
return dict(zip(top_classes, top_probabilities))
|
31 |
-
|
32 |
model = tf.keras.models.load_model("Xception.h5")
|
33 |
|
34 |
-
interface = gr.Interface(predict_top_classes, gr.inputs.Image(type='pil'), outputs='
|
35 |
interface.launch()
|
|
|
15 |
return img
|
16 |
|
17 |
def predict_top_classes(img, num_top_classes=5):
|
18 |
+
img = img.convert('RGB')
|
19 |
+
img_data = _normalize_img(img)
|
20 |
+
x = np.array(img_data)
|
21 |
+
x = np.expand_dims(x, axis=0)
|
22 |
+
temp = model.predict(x)
|
23 |
+
|
24 |
+
idx = np.argsort(np.squeeze(temp))[::-1]
|
25 |
+
top5_value = np.asarray([temp[0][i] for i in idx[0:5]])
|
26 |
+
top5_idx = idx[0:5]
|
27 |
+
|
28 |
+
return {CLASS_LABEL[i]:str(v) for i,v in zip(top5_idx,top5_value)}
|
29 |
+
|
|
|
|
|
30 |
model = tf.keras.models.load_model("Xception.h5")
|
31 |
|
32 |
+
interface = gr.Interface(predict_top_classes, gr.inputs.Image(type='pil'), outputs='label', args={'num_top_classes': 5})
|
33 |
interface.launch()
|