Nina-HK commited on
Commit
28fb1f0
1 Parent(s): 02b49f6

model_update

Browse files
Files changed (1) hide show
  1. app.py +33 -26
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
- 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
  def classify_multi(inp):
45
- inp = inp.reshape((-1, 224, 224, 3))
46
- inp = tf.keras.applications.densenet.preprocess_input(inp)
47
- prediction = model_multi.predict(inp)
48
- confidences = {labels_multi[i]: float(prediction[0][i]) for i in range(len(labels_multi))}
49
- return confidences
50
 
51
  binary_interface = gr.Interface(fn=classify_binary,
52
- inputs=gr.inputs.Image(shape=(224, 224)),
53
- outputs=gr.outputs.Label(num_top_classes=2),
54
- title="Binary Image Classification",
55
- description="Classify an image as healthy or patient.",
56
- examples=[['300104.png']]
57
- )
58
 
59
  multi_interface = gr.Interface(fn=classify_multi,
60
- inputs=gr.inputs.Image(shape=(224, 224)),
61
- outputs=gr.outputs.Label(num_top_classes=3),
62
- title="Multi-class Image Classification",
63
- description="Classify an image as healthy, mild or moderate.",
64
- examples=[['300104.png']]
65
- )
66
-
67
- demo = gr.TabbedInterface([binary_interface, multi_interface], ["Binary", "Multi-class"])
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
+