Project-MONAI / Project-MONAI/MONAI
Save and load parameters of a pre-processing or augmentation (transforms) pipeline
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.7k
- Forks
- 1.6k
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 20
Description
Description
After training a model, it is useful to be able to save the pre-processing steps used in training. Later, one can load the transforms along with the model at inference or production. At the moment, the composed transforms lack a method that can save the transforms. This feature can help with making monai-based deployments more reliable.
Proposed solution
I would suggest a similar solution to the one devised by albumentations (see https://albumentations.ai/docs/examples/serialization/). For example:
train_transforms = Compose([ScaleIntensity(), EnsureChannelFirst(), Resize((96, 96, 96)), RandRotate90()])
monai.transforms.save(transform, '/tmp/transform.json')
loaded_transform = monai.transforms.load('/tmp/transform.json')
The json would look like this (example from albumentations):
{
"__version__": "1.3.1",
"transform": {
"__class_fullname__": "Compose",
"p": 1,
"transforms": [
{
"__class_fullname__": "albumentations.transforms.RandomCrop",
"always_apply": true,
"p": 1,
"height": 768,
"width": 768
},
{
"__class_fullname__": "albumentations.transforms.RGBShift",
"always_apply": false,
"p": 0.5,
"hue_shift_limit": (-20, 20),
"sat_shift_limit": (-30, 30),
"val_shift_limit": (-20, 20)
}
],
"bbox_params": null,
"keypoint_params": null,
"additional_targets": {},
"is_check_shapes": true
}
}
Alternatives considered
I could pickle the transforms. I think that is a bad solution as it relies on the specifically installed package versions, and is not readable. Therefore, it is not portable.
Additional context
None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names composed transforms and the Compose pipeline but no repository files or tests. Start by locating Compose and the transform serialization entry points, then compare the proposed behavior with the linked Albumentations serialization example. Done means a preprocessing or augmentation pipeline can be saved and loaded in a readable, portable form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100