DeSSL.transforms package¶
Submodules¶
autoaugment module¶
The example of original data.¶ |
The example of AutoAugment Augmentation.¶ |
- class CIFAR10Policy(fillcolor=(128, 128, 128))¶
Bases:
objectRandomly choose one of the best 25 Sub-policies on CIFAR10.
Example
>>> policy = CIFAR10Policy() >>> transformed = policy(image)
Example as a PyTorch Transform:
>>> transform=transforms.Compose([ >>> transforms.Resize(256), >>> CIFAR10Policy(), >>> transforms.ToTensor()])
cutmix module¶
- cutmix_for_integer(input: torch.Tensor, target: torch.Tensor, gamma: float, indices: Optional[torch.Tensor] = None) Tuple[torch.Tensor, float, torch.Tensor, torch.Tensor]¶
CutMix Augmentation for Tensor.
- Parameters
input – input tensor of data.
target – integer label of data.
gamma – The expected interpolation coefficient.
indices – indices[i] denotes the cutmix target of data i. If
indices=None, then cutmix generates indices by torch.perm.
Example
>>> from DeSSL.transforms import cutmix_for_integer >>> input = torch.randn([256, 3, 64, 64]) >>> target = torch.rand([256, 10]).argmax(dim=-1) >>> gamma = 0.995 >>> mix_input, real_gamma, target, perm_target = cutmix_for_integer(input, target, gamma)
- Returns
Mixed tensor, real gamma, targets and perm_targets.
- cutmix_for_one_hot(input: torch.Tensor, target: torch.Tensor, gamma: float, indices: Optional[torch.Tensor] = None) Tuple[torch.Tensor, torch.Tensor]¶
CutMix Augmentation for Tensor.
- Parameters
input – input tensor of data.
target – one-hot label of data.
gamma – The expected interpolation coefficient.
indices – indices[i] denotes the cutmix target of data i. If
indices=None, then cutmix generates indices by torch.perm.
Example
>>> from DeSSL.transforms import cutmix_for_one_hot >>> input = torch.randn([256, 3, 64, 64]) >>> target = torch.rand([256, 10]) >>> gamma = 0.995 >>> mix_input, mix_target = cutmix_for_one_hot(input, target, gamma)
- Returns
Mixed tensor and mixed targets.
cutout module¶
The example of CutOut Augmentation.¶
- class ImageCutout(length: int, color: Tuple[int, int, int] = (127, 127, 127))¶
Bases:
objectCutout Augmentation for Image.
- Parameters
length – side length of cutout part.
color – color of cutout part.
Example
>>> from torchvision import transforms as tf >>> transforms = tf.Compose([ImageCutout(10), tf.ToTensor()])
- Returns
An augmented image.
mixup module¶
- class IntegerMixLoss¶
Bases:
torch.nn.modules.module.ModuleCreates a criterion that measures the cross entropy loss between each element in the input and integer target.
- forward(mix_input: torch.Tensor, gamma: float, target: torch.LongTensor, perm_target: torch.LongTensor)¶
- Parameters
mix_input – The input tensor.
gamma – The interpolation coefficient.
target – The target tensor.
perm_target – The perm_target tensor.
- Returns
The cross entropy loss.
- training: bool¶
- class OneHotMixLoss¶
Bases:
torch.nn.modules.module.ModuleCreates a criterion that measures the cross entropy loss between each element in the input and one-hot target.
- forward(mix_input: torch.Tensor, mix_target: torch.Tensor) torch.Tensor¶
- Parameters
mix_input – The input tensor.
mix_target – The target tensor.
- Returns
The cross entropy loss.
- training: bool¶
- mixup_for_integer(input: torch.Tensor, target: torch.Tensor, gamma: float, indices: Optional[torch.Tensor] = None) Tuple[torch.Tensor, torch.Tensor, torch.Tensor]¶
Mixup Augmentation for Tensor.
- Parameters
input – input tensor of data.
target – integer label of data.
gamma – The interpolation coefficient.
indices – indices[i] denotes the mixup target of data i. If
indices=None, then mixup generates indices by torch.perm.
Example
>>> from allinone.transforms import mixup_for_integer >>> input = torch.randn([256, 3, 64, 64]) >>> target = torch.rand([256, 10]).argmax(dim=-1) >>> gamma = 0.995 >>> mix_input, target, perm_target = mixup_for_integer(input, target, gamma)
- Returns
Mixed tensor, targets and perm_targets.
- mixup_for_one_hot(input: torch.Tensor, target: torch.Tensor, gamma: Union[float, torch.Tensor], indices: Optional[torch.Tensor] = None) Tuple[torch.Tensor, torch.Tensor]¶
Mixup Augmentation for Tensor.
- Parameters
input – input tensor of data.
target – one-hot label of data.
gamma – The interpolation coefficient.
indices – indices[i] denotes the mixup target of data i. If
indices=None, then mixup generates indices by torch.perm.
Example
>>> from allinone.transforms import mixup_for_one_hot >>> input = torch.randn([256, 3, 64, 64]) >>> target = torch.rand([256, 10]) >>> gamma = 0.995 >>> mix_input, mix_target = mixup_for_one_hot(input, target, gamma)
- Returns
Mixed tensor and mixed targets.
- one_hot_mix_loss(mix_input, mix_target, is_logit=True)¶
randaugment module¶
- class RandAugment(n: int, m: int)¶
Bases:
objectThe RandAugment reproduced by pytorch. This code is completely duplicated from Github.
- Parameters
n – Number of augmentation transformations to apply sequentially.
m – Magnitude for all the transformaations.
DeSSL.transforms.transform_many_times module¶
- class ManyTimes(transform: Callable, n: int)¶
Bases:
objectThis class transfers an image to a series of augmented images.
- Parameters
transform – The transform for augmentation and normalization of images.
n – The times that the transform performs.
- Returns
The tuple of augmented images.
- Twice(transform: Callable) DeSSL.transforms.transform_many_times.ManyTimes¶
The easy call method of ManyTimes(transform, 2).
- Parameters
transform – The transform for augmentation and normalization of images.
- Returns
The class of ManyTimes(transform, 2).

