Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,32 @@ import gradio as gr
|
|
| 10 |
#model = tf.keras.models.load_model("./models/last_Vgg19.h5")\
|
| 11 |
model = ort.InferenceSession('./models/VGG19_32_onnx.onnx')
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
inputs_image = [
|
|
|
|
| 10 |
#model = tf.keras.models.load_model("./models/last_Vgg19.h5")\
|
| 11 |
model = ort.InferenceSession('./models/VGG19_32_onnx.onnx')
|
| 12 |
|
| 13 |
+
def show_preds_image(image_path):
|
| 14 |
+
img = cv2.imread(image_path)
|
| 15 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 16 |
+
img = cv2.resize(img, (224, 224))
|
| 17 |
+
img_array = img / 255.0
|
| 18 |
+
img_array = img_array.reshape(1, 224, 224, 3)
|
| 19 |
+
|
| 20 |
+
input_name = model.get_inputs()[0].name
|
| 21 |
+
output_name = model.get_outputs()[0].name
|
| 22 |
+
outputs = model.run(None, {input_name: img_array})
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
predicted_class_index = int(outputs[0].argmax(axis=1))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
classes = ['Ajloun Castle', 'Jerash', 'Jerash', 'Petra', 'Roman amphitheater', 'Roman amphitheater', 'Wadi Rum']
|
| 29 |
+
predicted_class = classes[predicted_class_index]
|
| 30 |
+
|
| 31 |
+
mux_value = f'{predicted_class}:{outputs[0][0][predicted_class_index]}'
|
| 32 |
+
height, width, _ = img.shape
|
| 33 |
+
text_x = int((width - len(mux_value) * 10) / 2)
|
| 34 |
+
text_y = int(height / 2)
|
| 35 |
+
font_scale = 2
|
| 36 |
+
cv2.putText(img, mux_value, (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, font_scale, (255, 0, 0), 2, cv2.LINE_AA)
|
| 37 |
+
|
| 38 |
+
return img
|
| 39 |
|
| 40 |
|
| 41 |
inputs_image = [
|