Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,11 +15,17 @@ def load_image_with_cv2(image_path):
|
|
| 15 |
|
| 16 |
return img_array
|
| 17 |
|
| 18 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
img_array = load_image_with_cv2(input_image)
|
| 20 |
-
|
| 21 |
-
onnx.checker.check_model(onnx32)
|
| 22 |
-
ort_sess = ort.InferenceSession('./models/VGG19_32_onnx.onnx')
|
| 23 |
input_name = ort_sess.get_inputs()[0].name
|
| 24 |
output_name = ort_sess.get_outputs()[0].name
|
| 25 |
outputs = ort_sess.run(None, {input_name: img_array})
|
|
@@ -30,8 +36,8 @@ def classify_image(input_image):
|
|
| 30 |
|
| 31 |
return predicted_class, confidence
|
| 32 |
|
| 33 |
-
def show_preds_image(image_path):
|
| 34 |
-
mux_value = str(classify_image(image_path))
|
| 35 |
img = cv2.imread(image_path)
|
| 36 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 37 |
height, width, _ = img.shape
|
|
@@ -43,15 +49,14 @@ def show_preds_image(image_path):
|
|
| 43 |
return img
|
| 44 |
|
| 45 |
|
| 46 |
-
inputs_image =
|
| 47 |
-
|
| 48 |
-
]
|
| 49 |
outputs_image = [
|
| 50 |
gr.Image(type="numpy", label="Output Image"),
|
| 51 |
]
|
| 52 |
interface_image = gr.Interface(
|
| 53 |
fn=show_preds_image,
|
| 54 |
-
inputs=inputs_image,
|
| 55 |
outputs=outputs_image,
|
| 56 |
title="image classification",
|
| 57 |
)
|
|
|
|
| 15 |
|
| 16 |
return img_array
|
| 17 |
|
| 18 |
+
def open_model(model_selection):
|
| 19 |
+
if model_selection == "VGG19":
|
| 20 |
+
return './models/VGG19_32_onnx.onnx'
|
| 21 |
+
elif model_selection == "ResNet50":
|
| 22 |
+
return './models/ResNet50_32_onnx.onnx'
|
| 23 |
+
elif model_selection == "Efficientnet":
|
| 24 |
+
return './models/efficientnet_32_onnx.onnx'
|
| 25 |
+
|
| 26 |
+
def classify_image(input_image,model_selection):
|
| 27 |
img_array = load_image_with_cv2(input_image)
|
| 28 |
+
ort_sess = ort.InferenceSession(open_model(model_selection))
|
|
|
|
|
|
|
| 29 |
input_name = ort_sess.get_inputs()[0].name
|
| 30 |
output_name = ort_sess.get_outputs()[0].name
|
| 31 |
outputs = ort_sess.run(None, {input_name: img_array})
|
|
|
|
| 36 |
|
| 37 |
return predicted_class, confidence
|
| 38 |
|
| 39 |
+
def show_preds_image(image_path,model_selection):
|
| 40 |
+
mux_value = str(classify_image(image_path,model_selection)[0])
|
| 41 |
img = cv2.imread(image_path)
|
| 42 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 43 |
height, width, _ = img.shape
|
|
|
|
| 49 |
return img
|
| 50 |
|
| 51 |
|
| 52 |
+
inputs_image = gr.Image(type="filepath", label="Input Image")
|
| 53 |
+
model_selection = gr.Dropdown(["VGG19","ResNet50","Efficientnet"])
|
|
|
|
| 54 |
outputs_image = [
|
| 55 |
gr.Image(type="numpy", label="Output Image"),
|
| 56 |
]
|
| 57 |
interface_image = gr.Interface(
|
| 58 |
fn=show_preds_image,
|
| 59 |
+
inputs=[inputs_image,model_selection],
|
| 60 |
outputs=outputs_image,
|
| 61 |
title="image classification",
|
| 62 |
)
|