Downloads · 30 days
10
6% of all-time downloads
hoangtung386/brain-stroke-lcnn
brain-stroke-lcnn is a image segmentation model from hoangtung386. 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 pytorch. The card lists the license as mit.
<div align="center" <img src="https://img.shields.io/badge/Architecture-LCNN%20%2B%20SEAN-blue?style=for-the-badge&logo=pytorch" alt="Architecture"/ <img src="https://img.shields.io/badge/PyTorch-2.0%2B-ee4c2c?style=f…
Downloads · 30 days
10
6% of all-time downloads
All-time downloads
170
Public
Repo size
1.2 GB
Likes
1
Public
Click a slice to open those files.
.pth1.2 GB · 99%
From the Hugging Face model README
This repository hosts a trained LCNN (Local-Global Combined Neural Network) for automatic brain stroke lesion segmentation from CT scans. The model achieves high precision by combining local anatomical details with global semantic context, specifically addressing the challenge of segmenting small lesions in complex brain structures.
The model demonstrates robust performance across various stroke types and locations.
<div align="center"> <h3>Segmentation Samples</h3> <img src="overlay_sample_2.png" width="45%" alt="Sample 2" style="margin: 5px;"/> <img src="overlay_sample_4.png" width="45%" alt="Sample 4" style="margin: 5px;"/> <br/><br/> <img src="overlay_sample_5.png" width="45%" alt="Sample 5" style="margin: 5px;"/> <img src="overlay_sample_6.png" width="45%" alt="Sample 6" style="margin: 5px;"/> </div>The training process was monitored extensively to ensure stable convergence and optimal performance.
<div align="center"> <img src="training_dashboard.png" width="100%" alt="Training Dashboard"/> <p><i>Figure 2: Comprehensive training dashboard showing loss, metrics, and resource usage.</i></p> </div>The model was evaluated using strict medical imaging metrics.
<div align="center"> <img src="metrics_comparison.png" width="45%" alt="Metrics Comparison"/> <img src="confusion_matrix.png" width="45%" alt="Confusion Matrix"/> </div>Tracking the loss components and validation Dice score throughout the training epochs. The graphs below demonstrate steady convergence and learning stability.
<div align="center"> <img src="training_loss.png" width="45%" alt="Training Loss"/> <img src="validation_dice.png" width="45%" alt="Validation Dice"/> <br/><br/> <img src="learning_rate.png" width="60%" alt="Learning Rate"/> <p><i>Figure 3: Top Left: Training Loss curve. Top Right: Validation Dice Score. Bottom: Learning Rate schedule.</i></p> </div>We employ a composite loss function designed to handle class imbalance (Dice), pixel accuracy (Cross-Entropy), and symmetry enforcement (Alignment).
<div align="center"> <img src="loss_components.png" width="70%" alt="Loss Components"/> <p><i>Figure 4: Breakdown of the combined loss function components over time.</i></p> </div># Loss Composition
total_loss = 0.7 * dice_loss + 0.3 * ce_loss + 0.05 * alignment_loss
git clone https://github.com/hoangtung386/brain-stroke-segmentation.git
cd brain-stroke-segmentation
pip install -r requirements.txt
pip install huggingface_hub
import torch
import os
from models.lcnn import LCNN
from huggingface_hub import hf_hub_download
# Create checkpoints folder
os.makedirs("./checkpoints", exist_ok=True)
# Download directly to the folder without creating a complex structure
checkpoint_path = hf_hub_download(
repo_id="hoangtung386/brain-stroke-lcnn",
filename="best_model.pth",
local_dir="./checkpoints",
local_dir_use_symlinks=False
)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = LCNN(num_channels=1, num_classes=2, global_impact=0.3, local_impact=0.7, T=1).to(device)
checkpoint = torch.load(checkpoint_path, map_location=device)
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
print("\n--------------------------------------")
print("Model ready for inference")
print(f"Model path: {checkpoint_path}")
print("--------------------------------------\n")
This project is licensed under the MIT License - see LICENSE.txt for details.
Developed by Le Vu Hoang Tung (@hoangtung386).