azeemkhan417 commited on
Commit
0311989
·
verified ·
1 Parent(s): e519366

Upload 3 files

Browse files
Files changed (3) hide show
  1. BraintumorClassifier.h5 +3 -0
  2. app.py +49 -0
  3. model_metadata.json +58 -0
BraintumorClassifier.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1541bc63bbe75ad6a456db0c977f3d28e14eab117ee3d01149907648b4625542
3
+ size 231299440
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing import image
5
+ import numpy as np
6
+ from PIL import Image
7
+ import json
8
+
9
+ # Load the CNN model
10
+ model = load_model('BraintumorClassifier.h5')
11
+
12
+ # Load the meta data (containing class names or other metadata)
13
+ with open('meta_data.json', 'r') as f:
14
+ meta_data = json.load(f)
15
+
16
+ # Extract class names from the meta data (assuming they are stored under "class_names")
17
+ class_names = meta_data.get('classes', ['glioma', 'meningioma', 'pituitary_tumor'])
18
+
19
+ # Function to preprocess the image for prediction
20
+ def preprocess_image(img):
21
+ img = img.resize((224, 224)) # Resize to the input shape of the model
22
+ img_array = np.array(img) / 255.0 # Normalize the image
23
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
24
+ return img_array
25
+
26
+ # Streamlit UI
27
+ st.title('Brain Tumor Classification')
28
+
29
+ # Upload image
30
+ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
31
+
32
+ if uploaded_image is not None:
33
+ # Display the image
34
+ img = Image.open(uploaded_image)
35
+ st.image(img, caption="Uploaded Image", use_column_width=True)
36
+
37
+ # Preprocess the image for the model
38
+ img_array = preprocess_image(img)
39
+
40
+ # Button to classify the image
41
+ if st.button('Classify'):
42
+ prediction = model.predict(img_array)
43
+ predicted_class = np.argmax(prediction, axis=1)
44
+ class_name = class_names[predicted_class[0]]
45
+ st.write(f"Prediction: {class_name}")
46
+
47
+ # Button to clear the output
48
+ if st.button('Clear'):
49
+ st.experimental_rerun()
model_metadata.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "training_date": "20241203_163951",
3
+ "dataset_info": {
4
+ "total_images": 6000,
5
+ "real_images": 4500,
6
+ "synthetic_images": 1500,
7
+ "synthetic_ratio": 0.3,
8
+ "class_distribution": {
9
+ "glioma": 2000,
10
+ "meningioma": 2000,
11
+ "pituitary_tumor": 2000
12
+ }
13
+ },
14
+ "model_performance": {
15
+ "glioma": {
16
+ "precision": 0.9473684210526315,
17
+ "recall": 0.96,
18
+ "f1-score": 0.9536423841059603,
19
+ "support": 300
20
+ },
21
+ "meningioma": {
22
+ "precision": 0.962457337883959,
23
+ "recall": 0.94,
24
+ "f1-score": 0.9510961214165261,
25
+ "support": 300
26
+ },
27
+ "pituitary_tumor": {
28
+ "precision": 0.9867986798679867,
29
+ "recall": 0.9966666666666667,
30
+ "f1-score": 0.9917081260364843,
31
+ "support": 300
32
+ },
33
+ "accuracy": 0.9655555555555555,
34
+ "macro avg": {
35
+ "precision": 0.9655414796015257,
36
+ "recall": 0.9655555555555555,
37
+ "f1-score": 0.9654822105196569,
38
+ "support": 900
39
+ },
40
+ "weighted avg": {
41
+ "precision": 0.9655414796015258,
42
+ "recall": 0.9655555555555555,
43
+ "f1-score": 0.9654822105196569,
44
+ "support": 900
45
+ }
46
+ },
47
+ "input_shape": [
48
+ null,
49
+ 224,
50
+ 224,
51
+ 1
52
+ ],
53
+ "classes": [
54
+ "glioma",
55
+ "meningioma",
56
+ "pituitary_tumor"
57
+ ]
58
+ }