psinha823 commited on
Commit
fd472ac
·
verified ·
1 Parent(s): a6468e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -4,7 +4,9 @@ from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
  # Load the trained model
7
- model = tf.keras.models.load_model('Model1_kera.h5')
 
 
8
 
9
  # Define the class names
10
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
@@ -14,11 +16,15 @@ def predict(img):
14
  img = img.resize((224, 224))
15
  img_array = tf.keras.preprocessing.image.img_to_array(img)
16
  img_array = tf.expand_dims(img_array, 0)
17
-
18
  predictions = model.predict(img_array)
19
- predicted_class = classes[np.argmax(predictions[0])]
 
 
 
 
20
 
21
- return predicted_class
22
 
23
  # Create a Gradio interface
24
  iface = gr.Interface(
 
4
  import numpy as np
5
 
6
  # Load the trained model
7
+ model = tf.keras.models.load_model('Model1_kera.h5', compile=False)
8
+ model.compile(Adamax(learning_rate= 0.001), loss= 'categorical_crossentropy', metrics= ['accuracy'])
9
+ # model = tf.keras.models.load_model('Model1_kera.h5')
10
 
11
  # Define the class names
12
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
 
16
  img = img.resize((224, 224))
17
  img_array = tf.keras.preprocessing.image.img_to_array(img)
18
  img_array = tf.expand_dims(img_array, 0)
19
+
20
  predictions = model.predict(img_array)
21
+ class_labels = classes
22
+ # predictions = model.predict(img_array)
23
+ # predicted_class = classes[np.argmax(predictions[0])]
24
+ score = tf.nn.softmax(predictions[0])
25
+ print(f"{class_labels[tf.argmax(score)]}")
26
 
27
+ return f"{class_labels[tf.argmax(score)]}
28
 
29
  # Create a Gradio interface
30
  iface = gr.Interface(