Skip to content

Commit

Permalink
update augmentation preimitives
Browse files Browse the repository at this point in the history
  • Loading branch information
daochenzha committed Mar 22, 2022
1 parent 1768c24 commit 4539810
Show file tree
Hide file tree
Showing 132 changed files with 1,312 additions and 486 deletions.
10 changes: 5 additions & 5 deletions autovideo/augmentation/arithmetic/AddElementwise_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,14 +27,14 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
value = hyperparams.Set[float](
default=(-40, 40),
value = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=(-20, 20),
description='Value to add to all pixels.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

per_channel = hyperparams.Constant[bool](
default=True,
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
Expand Down
10 changes: 5 additions & 5 deletions autovideo/augmentation/arithmetic/Add_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,14 +27,14 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
value = hyperparams.Set[float](
default=(-40, 40),
value = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=(-20, 20),
description='Value to add to all pixels.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

per_channel = hyperparams.Constant[bool](
default=True,
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,14 +27,20 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
scale = hyperparams.Hyperparameter[tuple](
loc = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=0,
description='Mean of the normal distribution from which the noise is sampled.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

scale = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=(0, 15),
description='Standard deviation of the normal distribution that generates the noise. Must be >=0. If 0 then loc will simply be added to all pixels.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

per_channel = hyperparams.Hyperparameter[bool](
default=True,
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
Expand All @@ -59,6 +65,7 @@ def _get_function(self):
"""

scale = self.hyperparams["scale"]
loc = self.hyperparams['loc']
per_channel = self.hyperparams["per_channel"]
seed = self.hyperparams["seed"]
return iaa.AdditiveGaussianNoise(scale=scale, per_channel=per_channel, seed=seed)
return iaa.AdditiveGaussianNoise(scale=scale, loc=loc,per_channel=per_channel, seed=seed)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,14 +27,20 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
scale = hyperparams.Hyperparameter[tuple](
loc = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=0,
description='Mean of the normal distribution from which the noise is sampled.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

scale = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=(0, 15),
description='Standard deviation of the normal distribution that generates the noise. Must be >=0. If 0 then loc will simply be added to all pixels.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

per_channel = hyperparams.Hyperparameter[bool](
default=True,
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
Expand All @@ -60,5 +66,6 @@ def _get_function(self):

scale = self.hyperparams["scale"]
per_channel = self.hyperparams["per_channel"]
loc = self.hyperparams['loc']
seed = self.hyperparams["seed"]
return iaa.AdditiveLaplaceNoise(scale=scale, per_channel=per_channel, seed=seed)
return iaa.AdditiveLaplaceNoise(scale=scale, loc=loc,per_channel=per_channel, seed=seed)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,14 +27,14 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
scale = hyperparams.Set[float](
default=(0.0, 15.0),
description='Standard deviation of the normal distribution that generates the noise. Must be >=0. If 0 then loc will simply be added to all pixels.',
lam = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=(0.0,15.0),
description='Lambda parameter of the poisson distribution.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

per_channel = hyperparams.Constant[bool](
default=True,
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
Expand All @@ -58,7 +58,7 @@ def _get_function(self):
set up function and parameter of functions
"""

scale = self.hyperparams["scale"]
lam = self.hyperparams["lam"]
per_channel = self.hyperparams["per_channel"]
seed = self.hyperparams["seed"]
return iaa.AdditivePoissonNoise(scale=scale, per_channel=per_channel, seed=seed)
return iaa.AdditivePoissonNoise(lam=lam, per_channel=per_channel, seed=seed)
34 changes: 26 additions & 8 deletions autovideo/augmentation/arithmetic/CoarseDropout_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,21 +27,36 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
size_percent = hyperparams.Constant[float](
p = hyperparams.Hyperparameter[typing.Union[float,tuple]](
default=(0.02,0.1),
description=' The probability of any pixel being dropped.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
size_px = hyperparams.Hyperparameter[typing.Union[int,tuple,None]](
default=None,
description=' The size of the lower resolution image from which to sample the dropout mask in absolute pixel dimensions..',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
size_percent = hyperparams.Hyperparameter[typing.Union[float,tuple,None]](
default=0.5,
description=' The size of the lower resolution image from which to sample the replacement mask in percent of the input image. ',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
min_size = hyperparams.Hyperparameter[int](
default=3,
description='Minimum height and width of the low resolution mask.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
seed = hyperparams.Constant[int](
default=0,
description='Minimum workers to extract frames simultaneously',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
p = hyperparams.Constant[float](
default=0.02,
description='The probability of an image to be inverted.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)


class CoarseDropoutPrimitive(AugmentationPrimitiveBase[Inputs, Hyperparams]):
Expand All @@ -57,5 +72,8 @@ def _get_function(self):
"""
seed = self.hyperparams["seed"]
p = self.hyperparams["p"]
size_px = self.hyperparams['size_px']
size_percent = self.hyperparams["size_percent"]
return iaa.CoarseDropout(p=p,size_percent=size_percent,seed=seed)
per_channel = self.hyperparams['per_channel']
min_size = self.hyperparams['min_size']
return iaa.CoarseDropout(p=p,size_percent=size_percent,size_px=size_px,per_channel=per_channel,min_size=min_size,seed=seed)
38 changes: 29 additions & 9 deletions autovideo/augmentation/arithmetic/CoarsePepper_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,21 +27,38 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
size_percent = hyperparams.Set[float](
default=(0.01,0.1),
p = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=(0.02,0.1),
description='Probability of changing a pixel to pepper noise.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

size_px = hyperparams.Hyperparameter[typing.Union[int,tuple,None]](
default=None,
description=' The size of the lower resolution image from which to sample the dropout mask in absolute pixel dimensions..',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

size_percent = hyperparams.Hyperparameter[typing.Union[float,tuple,None]](
default=0.5,
description=' The size of the lower resolution image from which to sample the replacement mask in percent of the input image. ',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
min_size = hyperparams.Hyperparameter[int](
default=3,
description='Minimum height and width of the low resolution mask.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
seed = hyperparams.Constant[int](
default=0,
description='Minimum workers to extract frames simultaneously',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
p = hyperparams.Constant[float](
default=0.05,
description='The probability of an image to be inverted.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)


class CoarsePepperPrimitive(AugmentationPrimitiveBase[Inputs, Hyperparams]):
Expand All @@ -57,5 +74,8 @@ def _get_function(self):
"""
seed = self.hyperparams["seed"]
p = self.hyperparams["p"]
size_px = self.hyperparams['size_px']
size_percent = self.hyperparams["size_percent"]
return iaa.CoarsePepper(p=p,size_percent=size_percent,seed=seed)
per_channel = self.hyperparams['per_channel']
min_size = self.hyperparams['min_size']
return iaa.CoarsePepper(p=p,size_percent=size_percent,size_px=size_px,per_channel=per_channel,min_size=min_size,seed=seed)
40 changes: 31 additions & 9 deletions autovideo/augmentation/arithmetic/CoarseSaltAndPepper_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from d3m import container
from d3m.metadata import hyperparams
import imgaug.augmenters as iaa

import typing
from autovideo.utils import construct_primitive_metadata
from autovideo.base.augmentation_base import AugmentationPrimitiveBase

Expand All @@ -27,21 +27,40 @@
Inputs = container.DataFrame

class Hyperparams(hyperparams.Hyperparams):
size_percent = hyperparams.Set[float](
default=(0.01,0.1),
p = hyperparams.Hyperparameter[typing.Union[float,tuple,list]](
default=(0.02,0.1),
description='Probability of changing a pixel to salt/pepper noise.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

size_px = hyperparams.Hyperparameter[typing.Union[int,tuple,None]](
default=None,
description=' The size of the lower resolution image from which to sample the dropout mask in absolute pixel dimensions..',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

size_percent = hyperparams.Hyperparameter[typing.Union[float,tuple,None]](
default=0.5,
description=' The size of the lower resolution image from which to sample the replacement mask in percent of the input image. ',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
per_channel = hyperparams.Hyperparameter[typing.Union[bool,float]](
default=False,
description='Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
min_size = hyperparams.Hyperparameter[int](
default=3,
description='Minimum height and width of the low resolution mask.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)

seed = hyperparams.Constant[int](
default=0,
description='Minimum workers to extract frames simultaneously',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)
p = hyperparams.Constant[float](
default=0.05,
description='The probability of an image to be inverted.',
semantic_types=['https://metadata.datadrivendiscovery.org/types/ControlParameter'],
)



class CoarseSaltAndPepperPrimitive(AugmentationPrimitiveBase[Inputs, Hyperparams]):
Expand All @@ -57,5 +76,8 @@ def _get_function(self):
"""
seed = self.hyperparams["seed"]
p = self.hyperparams["p"]
size_px = self.hyperparams['size_px']
size_percent = self.hyperparams["size_percent"]
return iaa.CoarseSaltAndPepper(p=p,size_percent=size_percent,seed=seed)
per_channel = self.hyperparams['per_channel']
min_size = self.hyperparams['min_size']
return iaa.CoarseSaltAndPepper(p=p,size_percent=size_percent,size_px=size_px,per_channel=per_channel,min_size=min_size,seed=seed)
Loading

0 comments on commit 4539810

Please sign in to comment.