Spaces:
Sleeping
Sleeping
model_update
Browse files
app.py
CHANGED
@@ -24,9 +24,13 @@ import numpy as np
|
|
24 |
import tensorflow as tf
|
25 |
from transformers import pipeline
|
26 |
|
|
|
27 |
# load the binary classification model
|
28 |
model_binary = tf.keras.models.load_model("CNN_binary")
|
29 |
|
|
|
|
|
|
|
30 |
# load the multi-label classification model
|
31 |
model_multi = tf.keras.models.load_model("CNN_multiclass")
|
32 |
|
@@ -34,37 +38,40 @@ model_multi = tf.keras.models.load_model("CNN_multiclass")
|
|
34 |
labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
|
35 |
|
36 |
def classify_binary(inp):
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
return {label: confidence}
|
43 |
|
44 |
def classify_multi(inp):
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
binary_interface = gr.Interface(fn=classify_binary,
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
multi_interface = gr.Interface(fn=classify_multi,
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
demo = gr.
|
68 |
-
|
|
|
|
|
69 |
demo.launch()
|
70 |
|
|
|
|
|
|
24 |
import tensorflow as tf
|
25 |
from transformers import pipeline
|
26 |
|
27 |
+
|
28 |
# load the binary classification model
|
29 |
model_binary = tf.keras.models.load_model("CNN_binary")
|
30 |
|
31 |
+
# define the labels for the binary classification model
|
32 |
+
labels_binary = {0: 'healthy', 1: 'Patients'}
|
33 |
+
|
34 |
# load the multi-label classification model
|
35 |
model_multi = tf.keras.models.load_model("CNN_multiclass")
|
36 |
|
|
|
38 |
labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
|
39 |
|
40 |
def classify_binary(inp):
|
41 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
42 |
+
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
43 |
+
prediction = model_binary.predict(inp)
|
44 |
+
confidence = float(prediction[0])
|
45 |
+
return {labels_binary[prediction.argmax()]: confidence}
|
|
|
46 |
|
47 |
def classify_multi(inp):
|
48 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
49 |
+
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
50 |
+
prediction = model_multi.predict(inp)
|
51 |
+
confidences = {labels_multi[i]: float(prediction[0][i]) for i in range(len(labels_multi))}
|
52 |
+
return confidences
|
53 |
|
54 |
binary_interface = gr.Interface(fn=classify_binary,
|
55 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
56 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
57 |
+
title="Binary Image Classification",
|
58 |
+
description="Classify an image as healthy or patient.",
|
59 |
+
examples=[['300104.png']]
|
60 |
+
)
|
61 |
|
62 |
multi_interface = gr.Interface(fn=classify_multi,
|
63 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
64 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
65 |
+
title="Multi-class Image Classification",
|
66 |
+
description="Classify an image as healthy, mild or moderate.",
|
67 |
+
examples=[['300104.png']]
|
68 |
+
)
|
69 |
+
|
70 |
+
demo = gr.Interface([binary_interface, multi_interface],
|
71 |
+
"tab",
|
72 |
+
title="Binary and Multi-class Image Classification",
|
73 |
+
description="Classify an image as healthy, mild or moderate.")
|
74 |
demo.launch()
|
75 |
|
76 |
+
|
77 |
+
|