Spaces:
Runtime error
Runtime error
Add application file
Browse files
app.py
CHANGED
|
@@ -52,22 +52,14 @@ with open("scene_labels.json") as labels_file:
|
|
| 52 |
def classify_image(img):
|
| 53 |
img = tf.convert_to_tensor(img, dtype=tf.float32)
|
| 54 |
img = tf.expand_dims(img, axis=0)
|
| 55 |
-
# pred,idx,probs = model.predict(img)
|
| 56 |
probs = model.predict(img).flatten()
|
| 57 |
-
# vector = np.vectorize(np.float_)
|
| 58 |
-
# probs = vector(probs)
|
| 59 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 60 |
|
| 61 |
image = gr.inputs.Image(shape=(256, 256))
|
| 62 |
-
label = gr.outputs.Label(num_top_classes=45
|
| 63 |
examples = ['images/airplane_002.jpg','images/airplane_003.jpg','images/airport_020.jpg','images/airport_075.jpg','images/bridge_679.jpg','images/cloud_227.jpg','images/freeway_159.jpg','images/forest_235.jpg']
|
| 64 |
|
| 65 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, capture_session=True, interpretation="default", examples=examples)
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|
| 68 |
-
intf.launch(share=True,inline=False
|
| 69 |
-
# def classify_image(img):
|
| 70 |
-
# arr = np.expand_dims(img, axis=0)
|
| 71 |
-
# arr = tf.keras.applications.mobilenet.preprocess_input(arr)
|
| 72 |
-
# prediction = model.predict(arr).flatten()
|
| 73 |
-
# return {labels[i]: float(prediction[i]) for i in range(45)}
|
|
|
|
| 52 |
def classify_image(img):
|
| 53 |
img = tf.convert_to_tensor(img, dtype=tf.float32)
|
| 54 |
img = tf.expand_dims(img, axis=0)
|
|
|
|
| 55 |
probs = model.predict(img).flatten()
|
|
|
|
|
|
|
| 56 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 57 |
|
| 58 |
image = gr.inputs.Image(shape=(256, 256))
|
| 59 |
+
label = gr.outputs.Label(num_top_classes=5) # 45
|
| 60 |
examples = ['images/airplane_002.jpg','images/airplane_003.jpg','images/airport_020.jpg','images/airport_075.jpg','images/bridge_679.jpg','images/cloud_227.jpg','images/freeway_159.jpg','images/forest_235.jpg']
|
| 61 |
|
| 62 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, capture_session=True, interpretation="default", examples=examples)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
+
intf.launch(share=True) # ,inline=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|