Reproduce a given transform
See original GitHub issue🚀 Feature Given the history information saved in the sample for a given transform, how can I apply the exact same transform on a new volume
Motivation After doing a lot of data augmentation for training and validation, I would like to visually check some specific volume (the one having the worst loss for instance). Since saving all the transformed volume can become a very high cost (in terme of disk space) one prefer to save the transform’s parameter, and have the possibility to re-create the exact same transformed volume
Pitch I implemented once for the RandomElasticDeformation
def apply_given_transform(self, sample: Subject, bspline_params) -> dict:
for image_dict in sample.get_images(intensity_only=False):
if image_dict[TYPE] == LABEL:
interpolation = Interpolation.NEAREST
else:
interpolation = self.interpolation
image_dict[DATA] = self.apply_bspline_transform(
image_dict[DATA],
image_dict[AFFINE],
bspline_params,
interpolation,
)
return sample
Alternatives may be a more generic way would be to separate the apply_transform code in 2 disctinct par one to get the random param one to apply them so that the apply code could be reuse in both case …
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:55 (55 by maintainers)
Top GitHub Comments
The parameters were not being saved in the batch! That has been added in #226.
I think that the current implementation is a good compromise between feasibility in terms of how much information must be stored to reproduce/extract parameters and amount of work for the user.
Yes, please.
How about randomly generating a seed for a given transform (and saving it) and setting it specifically for this transform (and the given subject) ? This would only require to save the generated seed and resetting it at the beginning of the transform.
I would imagine something like that (the key point would be to systematically manually reset the seed)
Would it work ?