Add custom augmentation feature to pose_estimation_pytorch #3148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My team wanted to expand DeepLabCut's limited augmentation options by incorporating the albumentations library as our project needed augmentations that mimic glares. We developed a hybrid approach that preserves DLC's existing augmentation method while enabling custom augmentations.
For this to work, we added a new 'transform' section inside 'train' in the pytorch_config file. The new format is a list which has each entry in this list to specify an augmentation name followed by its parameters. Our solution maintains DLC's default augmentation values and calculations in a function called transforms_legacy (supporting dictionary). We then created a new function, transform_new, which handles both legacy DLC augmentations and our custom augmentations.
Example config format:
The transform_new function works sequentially. First, it checks whether the 'augmentation' section exists, if not, then it loops to the next augmentation. Next, it checks if an augmentation is one of DLC's original methods. If it is, the function calls transforms_legacy and we pass it the augmentation name and its parameters in dictionary format, to retrieve the appropriate augmentation settings. If not, it proceeds to check whether the augmentation exists in the albumentations library. When an albumentations augmentation is found, the function extracts its parameters and adds it to a list of transforms. Otherwise, it issues a warning that the given augmentation does not exist. When finished looping through augmentations, it returns the transform list to build_transforms, which integrates these augmentations into the training pipeline.
To add a new augmentation:
- augmentation: <name_of_augmentation>- augmentation: <name_of_augmentation>p: 0.6Below is our augmentation that we applied using our new method:
This approach allows us to leverage albumentations' extensive library while maintaining DLC's existing method.