Segmentation Pipeline
This package implements a machine learning pipeline for semantic segmentation on medical images. The package is a wrapper on monai and supports training and inference for UNETR and Swin-UNETR on arbitrary dataset. Development focused on BTCV(abdomen), MSD, and BRaTs datasets.
Set up
- Install segmentation pipeline package using
pip install 2404-segmentation-pipeline - Install pytorch.
- If on windows
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121- If on Linux
pip3 install torch torchvision torchaudio - (Optional) When working with BtCV dataset, the Swin-UNETR architecture offers self-supervised pretrained model on the dataset. When using pre-trained model before training, it allows the model to converge faster. Download the pretrained self-supervised model here
Documentation
Documention is provided here
Examples
from pipeline Import Pipeline
from monai.transforms import (
AsDiscrete,
EnsureChannelFirstd,
Compose,
CropForegroundd,
LoadImaged,
Orientationd,
RandFlipd,
RandCropByPosNegLabeld,
RandShiftIntensityd,
ScaleIntensityRanged,
Spacingd,
RandRotate90d,
ResizeWithPadOrCropd,
)
# Initialize Pipeline object. Below code works for BtCV but parameters need to be changed for other datasets.
pipeline = Pipeline(model_type="UNETR", modality=1, num_of_labels=14,
model_path="", debug=True)
# Transformations applied on training images
train_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
Orientationd(keys=["image", "label"], axcodes="RAS"),
Spacingd(
keys=["image", "label"],
pixdim=(1.5, 1.5, 2.0),
mode=("bilinear", "nearest"),
),
ScaleIntensityRanged(
keys=["image"],
a_min=-175,
a_max=250,
b_min=0.0,
b_max=1.0,
clip=True,
),
CropForegroundd(keys=["image", "label"], source_key="image"),
RandCropByPosNegLabeld(
keys=["image", "label"],
label_key="label",
# This here needs to be negative
spatial_size=(96, 96, -1),
pos=1,
neg=1,
num_samples=4,
image_key="image",
image_threshold=0,
),
ResizeWithPadOrCropd(keys=["image", "label"],
spatial_size=(96, 96, 96),
mode='constant'
),
RandFlipd(
keys=["image", "label"],
spatial_axis=[0],
prob=0.10,
),
RandFlipd(
keys=["image", "label"],
spatial_axis=[1],
prob=0.10,
),
RandFlipd(
keys=["image", "label"],
spatial_axis=[2],
prob=0.10,
),
RandRotate90d(
keys=["image", "label"],
prob=0.10,
max_k=3,
),
RandShiftIntensityd(
keys=["image"],
offsets=0.10,
prob=0.50,
),
]
)
# Transformation applied on validation images
val_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
Orientationd(keys=["image", "label"], axcodes="RAS"),
Spacingd(
keys=["image", "label"],
pixdim=(1.5, 1.5, 2.0),
mode=("bilinear", "nearest"),
),
ScaleIntensityRanged(keys=["image"], a_min=-175, a_max=250, b_min=0.0, b_max=1.0, clip=True),
CropForegroundd(keys=["image", "label"], source_key="image"),
]
)
# Initialize training
trainer.train(150,10)
# Transformations applied on images for inferencing. Transformation should be similar to val_transform
inf_transforms = Compose(
[
LoadImaged(keys=["image"]),
EnsureChannelFirstd(keys=["image"]),
Orientationd(keys=["image"], axcodes="RAS"),
Spacingd(
keys=["image"],
pixdim=(1.5, 1.5, 2.0),
mode="bilinear",
),
ScaleIntensityRanged(keys=["image"], a_min=-175, a_max=250, b_min=0.0, b_max=1.0, clip=True),
CropForegroundd(keys=["image"], source_key="image"),
]
)
# Inference
trainer.inference(data_folder = 'path/to/inference/data/folder', output_folder="path/to/output/folder", transforms=inf_transforms)
Metadata
Release files for 2404-segmentation-pipeline 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| 2404-segmentation-pipeline-1.0.0.tar.gz | 8.5 kB | Without provenance | Details for 2404-segmentation-pipeline-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 2404_segmentation_pipeline-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for 2404_segmentation_pipeline-1.0.0-py3-none-any.whl |
Total release size: 17.3 kB
Release files / 2404-segmentation-pipeline-1.0.0.tar.gz
| Download URL | 2404-segmentation-pipeline-1.0.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88aaac7fe8385879a4f155290cfce4a5ebc7e9ba9bca50cca1fcdb197f616937
|
|
BLAKE2b-256 checksum How to use checksums |
98c504b6b9818b96d1c9e5656060d1cf571a7a66fd9be6b94e1fba21920c7735
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.6
|
Release files / 2404_segmentation_pipeline-1.0.0-py3-none-any.whl
| Download URL | 2404_segmentation_pipeline-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cc246a0b6f4fd9b81cbac2f32ade33d1102b62f957de5abaaca619eca7d0877
|
|
BLAKE2b-256 checksum How to use checksums |
a793888a79c1fbd4cb18b95dd068d3db401302362772c7a6fc07f764914b807a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.6
|
Security for 2404-segmentation-pipeline 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.