Downloads · 30 days
0
aadium/brain-tumor-detect
brain-tumor-detect is a object detection model from aadium. Use it when you need objects located in an image. It is set up for torchvision. The card lists the license as mit.
An end-to-end object detection model using Faster R-CNN (ResNet-50-FPN) trained to detect, localize, and classify brain tumors from MRI scans.
Downloads · 30 days
0
Access
Public
Updated Aug 28, 2026
Repo size
332 MB
Likes
0
Public
Click a slice to open those files.
.pth166 MB · 100%
From the Hugging Face model README
An end-to-end object detection model using Faster R-CNN (ResNet-50-FPN) trained to detect, localize, and classify brain tumors from MRI scans.
glioma, meningioma, pituitaryThe model was trained using the Brain Tumor Dataset on Roboflow Universe:
glioma (1), meningioma (2), pituitary (3)You can run inference using standard torchvision and PIL:
import torch
import torchvision
from torchvision.transforms import functional as F
from PIL import Image
# 1. Load Model Architecture
NUM_CLASSES = 4 # Background + 3 tumor classes
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(
weights=None,
min_size=800,
max_size=1333
)
in_features = model.roi_heads.box_predictor.cls_score.in_features
model.roi_heads.box_predictor = torchvision.models.detection.faster_rcnn.FastRCNNPredictor(in_features, NUM_CLASSES)
# 2. Download and Load Checkpoint from Hugging Face Hub
from huggingface_hub import hf_hub_download
checkpoint_path = hf_hub_download(repo_id="YOUR_HF_USERNAME/YOUR_MODEL_REPO", filename="fasterrcnn_best.pth")
state_dict = torch.load(checkpoint_path, map_location="cpu", weights_only=True)
model.load_state_dict(state_dict)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
model.eval()
# 3. Predict on an Image
CLASS_NAMES = {1: "glioma", 2: "meningioma", 3: "pituitary"}
img = Image.open("sample_mri.jpg").convert("RGB")
img_tensor = F.to_tensor(img).unsqueeze(0).to(device)
THRESHOLD = 0.6
with torch.no_grad():
prediction = model(img_tensor)[0]
for i in range(len(prediction["boxes"])):
score = prediction["scores"][i].item()
if score > THRESHOLD:
box = prediction["boxes"][i].cpu().numpy()
label_id = prediction["labels"][i].item()
print(f"Detected {CLASS_NAMES.get(label_id)} with {score:.2f} confidence at {box}")