Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional probabilities to augmentations #314

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dacapo/experiments/trainers/gp_augments/elastic_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class ElasticAugmentConfig(AugmentConfig):
"3D rotations."
},
)
augmentation_probability: float = attr.ib(
default=1.,
metadata={
"help_text": "Probability of applying the augmentations."
},
)

def node(self, _raw_key=None, _gt_key=None, _mask_key=None):
"""
Expand All @@ -87,4 +93,5 @@ def node(self, _raw_key=None, _gt_key=None, _mask_key=None):
rotation_interval=self.rotation_interval,
subsample=self.subsample,
uniform_3d_rotation=self.uniform_3d_rotation,
augmentation_probability=self.augmentation_probability,
)
7 changes: 7 additions & 0 deletions dacapo/experiments/trainers/gp_augments/intensity_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class IntensityAugmentConfig(AugmentConfig):
"help_text": "Set to False if modified values should not be clipped to [0, 1]"
},
)
augmentation_probability: float = attr.ib(
default=1.,
metadata={
"help_text": "Probability of applying the augmentation."
},
)

def node(self, raw_key: gp.ArrayKey, _gt_key=None, _mask_key=None):
"""
Expand All @@ -58,4 +64,5 @@ def node(self, raw_key: gp.ArrayKey, _gt_key=None, _mask_key=None):
shift_min=self.shift[0],
shift_max=self.shift[1],
clip=self.clip,
p=self.augmentation_probability,
)
9 changes: 8 additions & 1 deletion dacapo/experiments/trainers/gp_augments/simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class SimpleAugmentConfig(AugmentConfig):
This class is a subclass of AugmentConfig.
"""

augmentation_probability: float = attr.ib(
default=1.,
metadata={
"help_text": "Probability of applying the augmentations."
},
)

def node(self, _raw_key=None, _gt_key=None, _mask_key=None):
"""
Get a gp.SimpleAugment node.
Expand All @@ -36,4 +43,4 @@ def node(self, _raw_key=None, _gt_key=None, _mask_key=None):
>>> node = simple_augment_config.node()

"""
return gp.SimpleAugment()
return gp.SimpleAugment(p=self.augmentation_probability)
Loading