Elegbede commited on
Commit
abe5204
1 Parent(s): afa9b0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -4,24 +4,32 @@ from tensorflow.keras.models import load_model
4
  import numpy as np
5
  from tensorflow.keras.preprocessing import image
6
 
 
7
 
 
 
8
 
9
  def predict_input_image(img):
10
  # Normalize the image by cropping (center crop)
11
- h, w = img.shape[:2]
 
12
  crop_start_x = (w - 224) // 2
13
  crop_start_y = (h - 224) // 2
14
- img = img[crop_start_y:crop_start_y+224, crop_start_x:crop_start_x+224]
15
- img = tf.image.resize(img, [224,224])
16
- img = np.expand_dims(img, axis = 0)
17
-
18
- # Make predictions
19
- model = tf.keras.models.load_model('Tumor_Model.h5')
20
- prediction = model.predict(img)
21
- result = 'No Tumor Detected' if prediction[0][0] > 0.5 else 'Tumor detected'
22
-
 
 
 
23
 
24
- return prediction
 
25
 
26
 
27
 
 
4
  import numpy as np
5
  from tensorflow.keras.preprocessing import image
6
 
7
+ my_model = load_model('Brain_Tumor_Model.h5')
8
 
9
+ # Set a threshold for binary classification
10
+ threshold = 0.5
11
 
12
  def predict_input_image(img):
13
  # Normalize the image by cropping (center crop)
14
+ # Normalize the image by cropping (center crop)
15
+ h, w = img.size
16
  crop_start_x = (w - 224) // 2
17
  crop_start_y = (h - 224) // 2
18
+ img = img.crop((crop_start_x, crop_start_y, crop_start_x + 224, crop_start_y + 224))
19
+ img = img.resize((224, 224))
20
+
21
+ # Convert the image to a format suitable for model prediction
22
+ #img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]
23
+ img_array = np.expand_dims(img, axis=0)
24
+
25
+ # Make predictions using your model
26
+ predictions = my_model.predict(img_array)
27
+
28
+ # Convert predictions to binary (0 or 1) based on the threshold
29
+ binary_prediction = 'Tumor Detected' if predictions[0][0] > threshold else 'No Tumor Detected'
30
 
31
+ # Print or use the binary prediction as needed
32
+ print("Prediction:", binary_prediction)
33
 
34
 
35