Downloads · 30 days
0
VaradPatil8815/wellscanhealthcare-brain-tumor
wellscanhealthcare-brain-tumor is a machine learning model from VaradPatil8815. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for keras. The card lists the license as mit.
Brain tumor classification + segmentation model trained on MRI scans. Part of the WellScan Healthcare project — BTech Final Year Project
Downloads · 30 days
0
Access
Public
Updated Jun 14, 2026
Repo size
176 MB
Likes
0
Public
Click a slice to open those files.
.hdf5176 MB · 100%
From the Hugging Face model README
Brain tumor classification + segmentation model trained on MRI scans.
Part of the WellScan Healthcare project — BTech Final Year Project
A custom Attention ResU-Net with Classifier — dual-output architecture that simultaneously:
Built on U-Net with ResNet skip connections and attention gates integrated into the decoder path.
| Metric | Training | Validation |
|---|---|---|
| Classification Accuracy | 98.73% | 97.18% |
| Segmentation Accuracy | 99.48% | 99.25% |
| Mean IoU | 0.7312 | 0.6397 |
| Dice Coefficient | 0.8438 | 0.7769 |
| Total Loss | 0.0523 | 0.0928 |
| Optimal Threshold | 0.38 | — |
| Label | Class |
|---|---|
| 0 | Meningioma |
| 1 | Glioma |
| 2 | Pituitary Tumor |
| 3 | No Tumor |
| Parameter | Value |
|---|---|
| Framework | TensorFlow 2.15 / Keras |
| Image size | 224 × 224 (grayscale) |
| Training samples | 3,727 MRI images |
| Train/Val/Test split | 80/10/10 |
| Optimizer | Adam |
| LR scheduler | ReduceLROnPlateau |
| Epochs | 50 |
| Batch size | 32 |
| Hardware | Kaggle GPU P100 (15GB RAM) |
from huggingface_hub import hf_hub_download
from keras.models import load_model
import tensorflow as tf
threshold = 0.38
def mean_iou(y_true, y_pred):
y_true = tf.cast(y_true, tf.float32)
y_pred = tf.cast(y_pred >= threshold, tf.float32)
intersection = tf.reduce_sum(tf.abs(y_true * y_pred))
union = tf.reduce_sum(y_true) + tf.reduce_sum(y_pred) - intersection
return intersection / union
def dice_coefficient(y_true, y_pred, smooth=1e-5):
y_true = tf.cast(y_true, tf.float32)
y_pred = tf.cast(y_pred >= threshold, tf.float32)
intersection = tf.reduce_sum(y_true * y_pred)
union = tf.reduce_sum(y_true) + tf.reduce_sum(y_pred)
return (2. * intersection + smooth) / (union + smooth)
# Download model from Hugging Face
model_path = hf_hub_download(
repo_id="varad-patil/wellscanhealthcare-brain-tumor",
filename="AT_RESu_net_all_STD_0.0927_th=0.38.hdf5"
)
# Load with custom metrics
model = load_model(model_path, custom_objects={
'mean_iou': mean_iou,
'dice_coefficient': dice_coefficient
})
import cv2
import numpy as np
def preprocess(image_path, size=224):
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, binary = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[0]
x, y, w, h = cv2.boundingRect(contours)
img = cv2.resize(img[y:y+h, x:x+w], (size, size))
img = (img - img.mean()) / img.std()
return np.expand_dims(np.expand_dims(img, axis=-1), axis=0)
class_labels = ['meningioma', 'glioma', 'pituitary tumor', 'noTumor']
img = preprocess("your_mri_scan.jpg")
classification, segmentation_mask = model.predict(img)
predicted_class = class_labels[np.argmax(classification)]
confidence = np.max(classification) * 100
print(f"Prediction: {predicted_class} ({confidence:.2f}%)")