Downloads · 30 days
8
26% of all-time downloads
szabopeter/roi-swinunetr-2d
roi-swinunetr-2d is a image segmentation model from szabopeter. 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 apache-2.0.
Per-slice 2D lung foreground segmentation for chest CT — Swin-transformer variant. Same task, same data, same eval as the SegResNet ROI model, but with a Swin encoder + CNN decoder instead of a plain residual CNN. Sma…
Downloads · 30 days
8
26% of all-time downloads
All-time downloads
31
Public
Repo size
25.4 MB
Likes
0
Public
Click a slice to open those files.
.pth25.4 MB · 100%
From the Hugging Face model README
Per-slice 2D lung foreground segmentation for chest CT — Swin-transformer variant. Same task, same data, same eval as the SegResNet ROI model, but with a Swin encoder
feature_size = 24) chosen to match the SegResNet baseline's parameter
budget for an apples-to-apples architecture comparison.(1, 256, 256) axial CT slice, intensity-normalised to [0, 1](1, 256, 256) sigmoid map; foreground = lung tissueTrained on the unified split (patient-grouped, dataset-stratified)
of a unified corpus assembled from three public sources:
Slices per split: 365 014 train / 64 097 val / — test held out. Identical split and sampling recipe as the SegResNet baseline; only the model family and LR differ.
Evaluated on 64 097 val slices (≈ 4.2 × 10⁹ pixels), micro-averaged at 0.5 threshold on sigmoid output.
| Metric | Value | Δ vs SegResNet |
|---|---|---|
| mIoU | 0.9848 | +0.0045 |
| Accuracy | 0.9964 | +0.0011 |
| Precision | 0.9858 | +0.0061 |
| Recall | 0.9876 | +0.0019 |
| Dice (F1) | 0.9867 | +0.0040 |
The largest improvement over the SegResNet baseline is in the tail of
the per-slice distribution (Dice_p05 rises from 0.00 to 0.88) —
top-/bottom-of-volume slices where the lung is nearly absent are handled
more conservatively.
import yaml, torch
from monai.networks.nets import SwinUNETR
cfg = yaml.safe_load(open("config.yaml"))["model"]
model = SwinUNETR(
in_channels = cfg["in_channels"],
out_channels = cfg["out_channels"],
feature_size = cfg["feature_size"],
depths = tuple(cfg["depths"]),
num_heads = tuple(cfg["num_heads"]),
spatial_dims = cfg["spatial_dims"],
use_checkpoint = cfg.get("use_checkpoint", False),
)
state = torch.load("model.pth", map_location="cpu", weights_only=True)
model.load_state_dict(state)
model.eval()
with torch.no_grad():
x = torch.randn(1, 1, 256, 256) # (B, C, H, W) — replace with your CT slice
prob = torch.sigmoid(model(x))
lung_mask = (prob > 0.5).to(torch.uint8)
DiceLoss(sigmoid=True, squared_pred=True)Full config is included in this repo as config.yaml.
Training code lives in an accompanying reproduction demo (published separately). Once available, reproduce with:
export DATA_ROOT=/path/to/unified # dir containing ct_2d/ and roi_sem_seg_2d/
python train.py --config config.yaml
Model weights released under Apache 2.0. Training data was public but covered by dataset-specific terms (NLST, NSCLC-Radiomics, LIDC-IDRI) — users must comply with those separately when using the model on comparable data.
Not a medical device. Not intended for clinical use. Research only.
Paper in preparation.