Downloads · 30 days
19
6% of all-time downloads
yaraa11/brain-tumor-segmentation
brain-tumor-segmentation is a image segmentation model from yaraa11. Use it for the image segmentation 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 apache-2.0.
A deep-learning model for brain tumor segmentation in MRI scans using a U-Net-based convolutional neural network. The model outputs a binary mask identifying tumor regions and is intended for research and educational…
Downloads · 30 days
19
6% of all-time downloads
All-time downloads
331
Public
Repo size
6 MB
Likes
1
Public
Click a slice to open those files.
.keras6 MB · 100%
From the Hugging Face model README
A deep-learning model for brain tumor segmentation in MRI scans using a U-Net-based convolutional neural network. The model outputs a binary mask identifying tumor regions and is intended for research and educational use only.
This model performs pixel-wise segmentation of brain tumors from MRI slices.
It was developed as part of an academic computer vision project focusing on medical image segmentation.
The architecture is a U-Net implemented in TensorFlow/Keras, trained on the Brain Tumor MRI dataset by Jun Cheng (2017), available on Figshare (DOI: 10.6084/m9.figshare.1512427.v8). The dataset contains MRI scans labeled for tumor segmentation and is commonly used in medical image analysis research.
The model can be used to:
The model must not be used for:
Users should:
You can use this model in two ways:
from tensorflow.keras.models import load_model
from keras import backend as K
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing import image
# Dice Coefficient (required for custom_objects)
def dice_coef(y_true, y_pred):
y_true = K.cast(y_true, 'float32')
y_pred = K.cast(y_pred, 'float32')
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersect = K.sum(y_true_f * y_pred_f)
return (2. * intersect + K.epsilon()) / (
K.sum(y_true_f) + K.sum(y_pred_f) + K.epsilon()
)
# Load the model from Hugging Face
model = load_model(
"yaraa11/brain-tumor-segmentation",
custom_objects={"dice_coef": dice_coef},
compile=False
)
# (Optional) Recompile
model.compile(
optimizer="adam",
loss="binary_crossentropy",
metrics=[
"accuracy",
tf.keras.metrics.Precision(),
tf.keras.metrics.Recall(),
dice_coef
]
)
# Load and preprocess input image
img = image.load_img(
"path_to_image.png",
target_size=(224, 224),
color_mode="grayscale"
)
img = image.img_to_array(img) / 255.0
img = np.expand_dims(img, axis=0)
# Predict mask
prediction = model.predict(img)
# Convert to binary mask
binary_mask = (prediction > 0.5).astype(np.float32)
from tensorflow.keras.models import load_model
import numpy as np
from tensorflow.keras.preprocessing import image
model = load_model(
"./model.keras",
custom_objects={"dice_coef": dice_coef},
compile=False
)
# Load and preprocess input image
img = image.load_img(
"path_to_image.png",
target_size=(224, 224),
color_mode="grayscale"
)
img = image.img_to_array(img) / 255.0
img = np.expand_dims(img, axis=0)
# Predict mask
prediction = model.predict(img)
# Convert to binary mask
binary_mask = (prediction > 0.5).astype(np.float32)
The model was trained on a publicly available brain MRI dataset. All images were preprocessed to ensure consistency across the dataset, including:
Before training, each MRI slice was:
The model was trained end-to-end using TensorFlow/Keras.
Evaluation was conducted on a held-out portion of the MRI dataset that was not used during training.
All preprocessing steps were identical to those used during training.
Model performance may vary depending on:
The model was evaluated using standard medical image segmentation metrics:
The model performs strongly on the provided dataset and reliably segments tumor regions.
However, performance may degrade on MRI scans from different sources or with significantly different characteristics.
The U-Net architecture uses skip connections that allow fine-grained spatial information to be preserved, improving boundary definition and tumor localization.
Performance is influenced heavily by input image quality and consistent preprocessing.
@article{Cheng2017,
author = "Jun Cheng",
title = "{brain tumor dataset}",
year = "2017",
month = "4",
url = "https://figshare.com/articles/dataset/brain_tumor_dataset/1512427",
doi = "10.6084/m9.figshare.1512427.v8"
}
Dice Coefficient:
A segmentation metric measuring overlap between predicted and ground-truth masks. Ranges from 0 (no overlap) to 1 (perfect overlap). Commonly used in medical imaging.
IoU (Intersection over Union):
A metric evaluating how well predicted regions match the true regions by dividing the intersection area by the union area.
Segmentation Mask:
A binary image where each pixel is labeled as either tumor (1) or background (0).
U-Net:
A convolutional neural network architecture with an encoder–decoder structure and skip connections, widely used for biomedical image segmentation.
For additional details, sample predictions, or troubleshooting, please refer to the repository’s README or open a discussion on the Hugging Face model page.
Created by Yara Elshehawi, as part of a medical image segmentation project focused on brain tumor detection using MRI data.
If you have any questions, encounter issues, or are interested in collaboration, feel free to reach out through any of the following channels:
Looking forward to hearing from you!