Nina-HK commited on
Commit
b8fdee4
·
1 Parent(s): 9499fd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -42,24 +42,39 @@ model_efn = tf.keras.models.load_model("efficientNet_binary")
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[1][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[1][i]) for i in range(2)}
57
- return confidences
58
 
59
 
60
  binary_interface_cnn = gr.Interface(fn=classify_cnn,
61
  inputs=gr.Image(shape=(224, 224)),
62
- outputs=gr.Label(num_top_classes=2),
 
63
  title="Binary Image Classification",
64
  description="Classify an image as healthy or patient using custom CNN.",
65
  examples=[['3310277.png'],['371129.png']]
@@ -68,13 +83,17 @@ binary_interface_cnn = gr.Interface(fn=classify_cnn,
68
 
69
  binary_interface_efn = gr.Interface(fn=classify_efn,
70
  inputs=gr.Image(shape=(224, 224)),
71
- outputs=gr.Label(num_top_classes=2),
 
72
  title="Binary Image Classification",
73
  description="Classify an image as healthy or patient using EfficientNet.",
74
  examples=[['3310277.png'],['371129.png']]
75
  )
76
 
77
 
 
 
 
78
  demo = gr.TabbedInterface([binary_interface_cnn, binary_interface_efn], ["Custom CNN", "CNNs"])
79
 
80
  demo.launch()
 
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
  def classify_cnn(inp):
60
  inp = inp.reshape((-1, 224, 224, 3))
61
  inp = tf.keras.applications.densenet.preprocess_input(inp)
62
  prediction = model_cnn.predict(inp)
63
+ class_index = np.argmax(prediction, axis=-1)[0]
64
+ return labels_cnn[class_index]
65
 
66
  def classify_efn(inp):
67
  inp = inp.reshape((-1, 224, 224, 3))
68
  inp = tf.keras.applications.efficientnet.preprocess_input(inp)
69
  prediction = model_efn.predict(inp)
70
+ class_index = np.argmax(prediction, axis=-1)[0]
71
+ return labels_efn[class_index]
72
 
73
 
74
  binary_interface_cnn = gr.Interface(fn=classify_cnn,
75
  inputs=gr.Image(shape=(224, 224)),
76
+ #outputs=gr.Label(num_top_classes=2),
77
+ outputs=gr.outputs.Textbox(),
78
  title="Binary Image Classification",
79
  description="Classify an image as healthy or patient using custom CNN.",
80
  examples=[['3310277.png'],['371129.png']]
 
83
 
84
  binary_interface_efn = gr.Interface(fn=classify_efn,
85
  inputs=gr.Image(shape=(224, 224)),
86
+ #outputs=gr.Label(num_top_classes=2),
87
+ outputs=gr.outputs.Textbox(),
88
  title="Binary Image Classification",
89
  description="Classify an image as healthy or patient using EfficientNet.",
90
  examples=[['3310277.png'],['371129.png']]
91
  )
92
 
93
 
94
+
95
+
96
+
97
  demo = gr.TabbedInterface([binary_interface_cnn, binary_interface_efn], ["Custom CNN", "CNNs"])
98
 
99
  demo.launch()