File size: 3,117 Bytes
9b525be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
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.