DHEIVER commited on
Commit
5a2dc7d
1 Parent(s): cab105c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -5,24 +5,22 @@ import numpy as np
5
 
6
  loaded_model = tf.keras.models.load_model('kidney2.h5')
7
 
 
 
 
 
 
 
 
8
  def classify_kidney_image(img):
9
  resize = tf.image.resize(img, (224, 224))
10
  gray = tfio.experimental.color.bgr_to_rgb(resize)
11
- yhat = loaded_model.predict(np.expand_dims(gray / 255, 0))
12
- label_names = {
13
- "1": "Cyst",
14
- "2": "Normal",
15
- "3": "Stone",
16
- "4": "Tumor"
17
- }
18
- classes_x = np.argmax(yhat, axis=1)
19
- a = classes_x[0]
20
- input_value = a + 1
21
- input_str = str(input_value)
22
- predicted_label = label_names[input_str]
23
- q, w, e, r = yhat[0]
24
-
25
- return {'Cyst': str(q), 'Normal': str(w), 'Stone': str(e), 'Tumor': str(r)}
26
 
27
  image = gr.inputs.Image(shape=(224, 224))
28
  label = gr.outputs.Label()
 
5
 
6
  loaded_model = tf.keras.models.load_model('kidney2.h5')
7
 
8
+ label_names = {
9
+ "1": "Cyst",
10
+ "2": "Normal",
11
+ "3": "Stone",
12
+ "4": "Tumor"
13
+ }
14
+
15
  def classify_kidney_image(img):
16
  resize = tf.image.resize(img, (224, 224))
17
  gray = tfio.experimental.color.bgr_to_rgb(resize)
18
+ normalized_img = gray / 255.0
19
+ yhat = loaded_model.predict(np.expand_dims(normalized_img, 0))
20
+ class_index = np.argmax(yhat, axis=1)[0]
21
+ predicted_label = label_names[str(class_index + 1)]
22
+ probabilities = {label_names[str(i + 1)]: str(prob) for i, prob in enumerate(yhat[0])}
23
+ return predicted_label, probabilities
 
 
 
 
 
 
 
 
 
24
 
25
  image = gr.inputs.Image(shape=(224, 224))
26
  label = gr.outputs.Label()