Spaces:
Runtime error
Runtime error
File size: 1,924 Bytes
cf37736 a3ec0e3 cf37736 93dd3e5 cf37736 9e1a7b8 cf37736 9e1a7b8 cf37736 7fd4e5e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import numpy as np
import os
import cv2
import gradio as gr
import tensorflow as tf
inception_model_path = './inceptionv3_-saved-model-97-loss-0.00.hdf5'
vggnet_model_path = './resnet50-saved-model-79-val_acc-1.00.hdf5'
resnet_model_path = './vgg_16_-saved-model-89-acc-0.93.hdf5'
efficientnet_model_path = './efficientnet-saved-model-06-val_acc-0.98.hdf5'
inception_model = tf.keras.models.load_model(inception_model_path)
vggnet_model = tf.keras.models.load_model(vggnet_model_path)
resnet_model = tf.keras.models.load_model(resnet_model_path)
efficientnet_model = tf.keras.models.load_model(efficientnet_model_path)
class_folders = ['Umm Qais', 'Jeresh', 'Petra',' Ajloun Castle', 'Wadi Rum', 'Roman amphitheater']
def classify_selected_model(image, model_name):
img = cv2.imread(image.name)
img = cv2.resize(img, (150, 150))
img = np.expand_dims(img, axis=0)
img = img / 255.0
if model_name.lower() == 'inceptionv3':
predictions = inception_model.predict(img)
elif model_name.lower() == 'vggnet':
predictions = vggnet_model.predict(img)
elif model_name.lower() == 'resnet':
predictions = resnet_model.predict(img)
elif model_name.lower() == 'efficientnet':
predictions = efficientnet_model.predict(img)
else:
return {"error": "Invalid model selection"}
class_index = np.argmax(predictions)
class_name = class_folders[class_index]
probability = predictions[0, class_index]
print(f"Class Index: {class_index}")
print(f"Class Name: {class_name}")
print(f"Probability: {probability}")
return {class_name: probability}
image_input = gr.Image()
model_selection_input = gr.Dropdown(["InceptionV3", "VGGNet", "ResNet", "EfficientNet"], value="InceptionV3")
gr.Interface(
fn=classify_selected_model,
inputs=[image_input, model_selection_input],
outputs="label",
live=True
).launch(debug=True)
|