Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
12 |
crop_start_x = (w - 224) // 2
|
13 |
crop_start_y = (h - 224) // 2
|
14 |
-
img = img
|
15 |
-
img =
|
16 |
-
|
17 |
-
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
23 |
|
24 |
-
|
|
|
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 |
|