--- license: cc-by-nc-4.0 tags: - medical-imaging - segmentation - brain-extraction - skull-stripping - mri - monai - segresnet - pytorch - pig - veterinary library_name: pytorch pipeline_tag: image-segmentation --- # Pig Brain SegResNet — brain extraction for porcine T2/CISS MRI > ⚠️ **License is a placeholder (`cc-by-nc-4.0`).** Confirm the final license > before making this repo public / before publication. 3D `SegResNet` (MONAI) for binary brain extraction (brain vs. background) on sub-millimeter porcine **T2-weighted / 3D-CISS** MRI. This is the deep-learning component of the pipeline described in *"Automated Brain Extraction Using Deep Learning and Atlas-Guided Refinement."* The released pipeline pairs this model with **ANTs SyN template refinement**; the model alone provides a fast, template-free brain mask and the initial mask that anchors the iterative curation workflow. ## Files - `pig_brain_segresnet.pth` — model `state_dict` (load into the architecture below). - `config.yaml` — full training/inference config (architecture + post-processing). ## Architecture | field | value | |---|---| | init_filters | 32 | | blocks_down | (1, 2, 2, 4) | | blocks_up | (1, 1, 1) | | in / out channels | 1 / 2 | | spatial_dims | 3 | | params | ~18.8 M | ## Preprocessing LPS orientation → 1 mm isotropic resampling (bilinear) → foreground crop → spatial pad to 128³ → per-channel non-zero z-score normalization. ## Inference Gaussian-weighted sliding window (ROI 128³, overlap 0.75) with flip TTA, then: softmax → Gaussian smooth → threshold 0.6 → remove small objects (min 500) → keep largest connected component → fill holes. Spatial preprocessing is inverted to return the mask to native resolution. ## Usage ```python import torch from omegaconf import OmegaConf from huggingface_hub import hf_hub_download from monai.networks.nets import SegResNet repo = "madhavappaneni9/pig-brain-segresnet" cfg = OmegaConf.load(hf_hub_download(repo, "config.yaml")) weights = hf_hub_download(repo, "pig_brain_segresnet.pth") model = SegResNet( spatial_dims=cfg.model.spatial_dims, init_filters=cfg.model.init_filters, in_channels=cfg.model.in_channels, out_channels=cfg.model.out_channels, blocks_down=tuple(cfg.model.blocks_down), blocks_up=tuple(cfg.model.blocks_up), dropout_prob=0.0, ) model.load_state_dict(torch.load(weights, map_location="cpu", weights_only=False)) model.eval() ``` A full preprocessing + sliding-window + post-processing example is in the [demo Space](https://huggingface.co/spaces/madhavappaneni9/pig-brain-segresnet-demo). ## Intended use & limitations - **Intended:** research brain extraction for porcine T2/CISS MRI; baseline for future porcine brain MRI studies. - **Not for clinical/diagnostic use.** - Trained on a small cohort; defaults calibrated to ~1-month Yorkshire piglets. Out-of-distribution scans (other ages/cohorts/contrasts) may segment poorly and benefit from transfer-learning the checkpoint on a small new-cohort sample. ## Citation Citation to be added on publication.