Spaces:
Sleeping
Sleeping
demo_launching
Browse files
app.py
CHANGED
@@ -27,43 +27,53 @@ from tensorflow.keras.preprocessing import image as image_utils
|
|
27 |
from tensorflow.keras.applications import densenet, efficientnet
|
28 |
|
29 |
|
30 |
-
|
|
|
|
|
|
|
31 |
model_cnn = tf.keras.models.load_model("CNN_binary")
|
32 |
|
33 |
-
# define the labels for the
|
34 |
labels_cnn = {0: 'healthy', 1: 'Patients'}
|
35 |
|
36 |
-
# load the
|
37 |
-
|
38 |
|
39 |
-
# define the labels for the
|
40 |
-
|
41 |
|
42 |
-
def
|
43 |
inp = inp.reshape((-1, 224, 224, 3))
|
44 |
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
45 |
-
prediction =
|
46 |
-
|
47 |
-
return
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
title="Binary Image Classification",
|
68 |
-
description="
|
69 |
-
|
|
|
27 |
from tensorflow.keras.applications import densenet, efficientnet
|
28 |
|
29 |
|
30 |
+
import tensorflow as tf
|
31 |
+
import gradio as gr
|
32 |
+
|
33 |
+
# load the CNN binary classification model
|
34 |
model_cnn = tf.keras.models.load_model("CNN_binary")
|
35 |
|
36 |
+
# define the labels for the binary classification model
|
37 |
labels_cnn = {0: 'healthy', 1: 'Patients'}
|
38 |
|
39 |
+
# load the EfficientNet binary classification model
|
40 |
+
model_efn = tf.keras.models.load_model("efficientNet_binary")
|
41 |
|
42 |
+
# define the labels for the binary classification model
|
43 |
+
labels_efn = {0: 'healthy', 1: 'Patients'}
|
44 |
|
45 |
+
def classify_cnn(inp):
|
46 |
inp = inp.reshape((-1, 224, 224, 3))
|
47 |
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
48 |
+
prediction = model_cnn.predict(inp)
|
49 |
+
confidences = {labels_cnn[i]: float(prediction[0][i]) for i in range(2)}
|
50 |
+
return confidences
|
51 |
+
|
52 |
+
def classify_efn(inp):
|
53 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
54 |
+
inp = tf.keras.applications.efficientnet.preprocess_input(inp)
|
55 |
+
prediction = model_efn.predict(inp)
|
56 |
+
confidences = {labels_efn[i]: float(prediction[0][i]) for i in range(2)}
|
57 |
+
return confidences
|
58 |
+
|
59 |
+
binary_interface_cnn = gr.Interface(fn=classify_cnn,
|
60 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
61 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
62 |
+
title="CNN Binary Image Classification",
|
63 |
+
description="Classify an image as healthy or patient using CNN.",
|
64 |
+
examples=[['300104.png']]
|
65 |
+
)
|
66 |
+
|
67 |
+
binary_interface_efn = gr.Interface(fn=classify_efn,
|
68 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
69 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
70 |
+
title="EfficientNet Binary Image Classification",
|
71 |
+
description="Classify an image as healthy or patient using EfficientNet.",
|
72 |
+
examples=[['300104.png']]
|
73 |
+
)
|
74 |
+
|
75 |
+
demo = gr.Interface([binary_interface_cnn, binary_interface_efn],
|
76 |
+
"tab",
|
77 |
title="Binary Image Classification",
|
78 |
+
description="Classify an image as healthy or patient using either CNN or EfficientNet.")
|
79 |
+
demo.launch()
|