Initial Commit
Browse files- app.py +40 -0
- final/brain_tumor_fine_tune.h5 +3 -0
- tumor_detection.ipynb +0 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
model = load_model("final/brain_tumor_fine_tune.h5")
|
7 |
+
model.load_weights("final/brain_tumor_fine_tune.h5")
|
8 |
+
|
9 |
+
|
10 |
+
class_names = [
|
11 |
+
'glioma',
|
12 |
+
'meningioma',
|
13 |
+
'notumor',
|
14 |
+
'pituitary',
|
15 |
+
]
|
16 |
+
|
17 |
+
def classify_tumor(input_image):
|
18 |
+
|
19 |
+
img = Image.fromarray(input_image)
|
20 |
+
resized_img = img.resize((299, 299))
|
21 |
+
img = np.asarray(resized_img)
|
22 |
+
img = np.expand_dims(img, axis=0)
|
23 |
+
img = img / 255
|
24 |
+
prediction = model.predict(img)
|
25 |
+
|
26 |
+
confidences = {class_names[i]: float(prediction[0][i]) for i in range(len(class_names))}
|
27 |
+
|
28 |
+
return {class_name: conf for class_name, conf in sorted(confidences.items(), key=lambda x: x[1], reverse=True)}
|
29 |
+
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=classify_tumor,
|
32 |
+
inputs=gr.Image(type="numpy"),
|
33 |
+
outputs=gr.Label(num_top_classes=5),
|
34 |
+
title="Brain Tumor Classification",
|
35 |
+
description="Upload an image of a Brain to classify its tumor.",
|
36 |
+
theme=gr.themes.Soft()
|
37 |
+
)
|
38 |
+
|
39 |
+
# Launch the interface
|
40 |
+
iface.launch(share=True)
|
final/brain_tumor_fine_tune.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3287b3d7f0167cbd8f6d28d0c587eb428e5bdf239cb1518a6057697ba5eca8dd
|
3 |
+
size 227395152
|
tumor_detection.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|