🧠 Stroke Segmentation – Brain CT using Swin UPerNet + CBAM
This project provides a deep learning model for stroke lesion segmentation in brain CT images.
Unlike classification (stroke / no stroke), this model predicts pixel-wise lesion masks to localize stroke regions.
🧠 Task
Objective: Given a single axial brain CT slice, predict a binary mask:
0 → Background (No Lesion)
1 → Stroke Lesion
🧪 Dataset
Modality: Brain CT
Format: .png slices (converted from DICOM if needed)
Annotations: Binary lesion masks in .png format
Preprocessing:
Hounsfield Unit (HU) windowing & CLAHE applied if original PNG not available
Normalization parameters computed from training set:
mean ≈ 0.189
std ≈ 0.318
Source:
Dataset derived from the TEKNOFEST 2021 Medical AI Competition – Stroke CT Dataset,
shared in collaboration with the Turkish Ministry of Health.
⚠️ These anonymized images are used solely for research and educational purposes.
Public datasets can be accessed via the Ministry’s Open Data Portal
🏗️ Model
Backbone: swin_tiny_patch4_window7_224
Head: UPerNet with CBAM attention module
Pretrained Weights: Swin Transformer pretrained on ImageNet-21k
Task: Binary semantic segmentation (stroke lesion vs background)
🔗 Pretrained Model
👉 Available on Hugging Face: Sahende/teknofest_ct_stroke_segmentation
Example Usage
import torch
import numpy as np
from PIL import Image
from transformers import AutoFeatureExtractor, AutoModelForSemanticSegmentation
Load model and processor
extractor = AutoFeatureExtractor.from_pretrained("Sahende/teknofest_ct_stroke_segmentation")
model = AutoModelForSemanticSegmentation.from_pretrained("Sahende/teknofest_ct_stroke_segmentation")
Load image
image = Image.open("example_ct.png").convert("RGB")
inputs = extractor(images=image, return_tensors="pt")
Inference
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits # shape: [1, num_classes, H, W]
Convert to predicted mask (threshold 0.5 for binary mask)
mask = torch.sigmoid(logits)[0,0] > 0.5
print("🧠 Predicted mask shape:", mask.shape)
📌 Notes
This model predicts stroke lesion masks at the slice level.
Intended for research use only – not for clinical deployment.
Supports mixed-precision training (AMP) and gradient accumulation.