Spaces:
Sleeping
Sleeping
update_two
Browse files
app.py
CHANGED
@@ -20,26 +20,37 @@ from transformers import pipeline
|
|
20 |
#binary_labels = {0: 'healthy', 1: 'patient'}
|
21 |
|
22 |
# load the binary classification model
|
23 |
-
model_binary = tf.keras.models.load_model("densenet")
|
24 |
|
25 |
# load the multi-label classification model
|
26 |
-
model_multi = tf.keras.models.load_model("densenet")
|
27 |
|
28 |
# define the labels for the multi-label classification model
|
29 |
-
labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
|
30 |
|
31 |
|
32 |
#model = tf.keras.models.load_model('/content/drive/MyDrive/project_image_2023_NO/saved_models/saved_model/densenet')
|
33 |
#labels = ['Healthy', 'Patient']
|
34 |
#labels = {0: 'healthy', 1: 'patient'}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
def classify_image_binary(inp):
|
37 |
inp = inp.reshape((-1, 224, 224, 3))
|
38 |
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
39 |
prediction = model_binary.predict(inp)
|
40 |
confidence = float(prediction[0])
|
41 |
label = {0: 'healthy', 1: 'patient'}
|
42 |
-
return {label: confidence}
|
43 |
|
44 |
|
45 |
def classify_image_multi(inp):
|
@@ -49,21 +60,22 @@ def classify_image_multi(inp):
|
|
49 |
confidences = {labels_multi[i]: float(prediction[0][i]) for i in range(3)}
|
50 |
return confidences
|
51 |
|
52 |
-
|
53 |
-
inputs=gr.Image(shape=(224, 224)),
|
54 |
-
outputs=gr.Label(num_top_classes=2),
|
55 |
title="Binary Image Classification",
|
56 |
description="Classify an image as healthy or patient.",
|
57 |
examples=[['300104.png']]
|
58 |
)
|
59 |
|
60 |
-
|
61 |
-
inputs=gr.Image(shape=(224, 224)),
|
62 |
-
outputs=gr.Label(num_top_classes=3),
|
63 |
-
title="Multi-
|
64 |
-
description="Classify an image as healthy, mild
|
65 |
examples=[['300104.png']]
|
66 |
)
|
67 |
|
68 |
-
|
69 |
-
|
|
|
|
20 |
#binary_labels = {0: 'healthy', 1: 'patient'}
|
21 |
|
22 |
# load the binary classification model
|
23 |
+
#model_binary = tf.keras.models.load_model("densenet")
|
24 |
|
25 |
# load the multi-label classification model
|
26 |
+
#model_multi = tf.keras.models.load_model("densenet")
|
27 |
|
28 |
# define the labels for the multi-label classification model
|
29 |
+
#labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
|
30 |
|
31 |
|
32 |
#model = tf.keras.models.load_model('/content/drive/MyDrive/project_image_2023_NO/saved_models/saved_model/densenet')
|
33 |
#labels = ['Healthy', 'Patient']
|
34 |
#labels = {0: 'healthy', 1: 'patient'}
|
35 |
|
36 |
+
|
37 |
+
# load the binary classification model
|
38 |
+
model_binary = tf.keras.models.load_model("densenet")
|
39 |
+
|
40 |
+
# load the multi-label classification model
|
41 |
+
model_multi = tf.keras.models.load_model("densenet")
|
42 |
+
|
43 |
+
# define the labels for the multi-label classification model
|
44 |
+
labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
|
45 |
+
|
46 |
+
|
47 |
def classify_image_binary(inp):
|
48 |
inp = inp.reshape((-1, 224, 224, 3))
|
49 |
inp = tf.keras.applications.densenet.preprocess_input(inp)
|
50 |
prediction = model_binary.predict(inp)
|
51 |
confidence = float(prediction[0])
|
52 |
label = {0: 'healthy', 1: 'patient'}
|
53 |
+
return {label[1]: confidence}
|
54 |
|
55 |
|
56 |
def classify_image_multi(inp):
|
|
|
60 |
confidences = {labels_multi[i]: float(prediction[0][i]) for i in range(3)}
|
61 |
return confidences
|
62 |
|
63 |
+
binary_interface = gr.Interface(fn=classify_image_binary,
|
64 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
65 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
66 |
title="Binary Image Classification",
|
67 |
description="Classify an image as healthy or patient.",
|
68 |
examples=[['300104.png']]
|
69 |
)
|
70 |
|
71 |
+
multi_interface = gr.Interface(fn=classify_image_multi,
|
72 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
73 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
74 |
+
title="Multi-class Image Classification",
|
75 |
+
description="Classify an image as healthy, mild or moderate.",
|
76 |
examples=[['300104.png']]
|
77 |
)
|
78 |
|
79 |
+
binary_interface.launch()
|
80 |
+
multi_interface.launch()
|
81 |
+
|