Data¶
Auto Augmentation¶
mindcv.data.auto_augment.auto_augment_transform(configs, hparams)
¶
Create a AutoAugment transform Args: configs: A string that defines the automatic augmentation configuration. It is composed of multiple parts separated by dashes ("-"). The first part defines the AutoAugment policy ('autoaug', 'autoaugr' or '3a': 'autoaug' for the original AutoAugment policy with PosterizeOriginal, 'autoaugr' for the AutoAugment policy with PosterizeIncreasing operation, '3a' for the AutoAugment only with 3 augmentations.) There is no order requirement for the remaining config parts.
- mstd: Float standard deviation of applied magnitude noise.
Example: 'autoaug-mstd0.5' will be automatically augment using the autoaug strategy
and magnitude_std 0.5.
hparams: Other hparams of the automatic augmentation scheme.
Source code in mindcv/data/auto_augment.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
|
mindcv.data.auto_augment.rand_augment_transform(configs, hparams)
¶
Create a RandAugment transform Args: configs: A string that defines the random augmentation configuration. It is composed of multiple parts separated by dashes ("-"). The first part defines the AutoAugment policy ('randaug' policy). There is no order requirement for the remaining config parts.
- m: Integer magnitude of rand augment. Default: 10
- n: Integer num layer (number of transform operations selected for each image). Default: 2
- w: Integer probability weight index (the index that affects a group of weights selected by operations).
- mstd: Floating standard deviation of applied magnitude noise,
or uniform sampling at infinity (or greater than 100).
- mmax: Set the upper range limit for magnitude to a value
other than the default value of _LEVEL_DENOM (10).
- inc: Integer (bool), using the severity increase with magnitude (default: 0).
Example: 'randaug-w0-n3-mstd0.5' will be random augment
using the weights 0, num_layers 3, magnitude_std 0.5.
hparams: Other hparams (kwargs) for the RandAugmentation scheme.
Source code in mindcv/data/auto_augment.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
|
mindcv.data.auto_augment.trivial_augment_wide_transform(configs, hparams)
¶
Create a TrivialAugmentWide transform Args: configs: A string that defines the TrivialAugmentWide configuration. It is composed of multiple parts separated by dashes ("-"). The first part defines the AutoAugment name, it should be 'trivialaugwide'. the second part(not necessary) the maximum value of magnitude.
- m: final magnitude of a operation will uniform sampling from [0, m] . Default: 31
Example: 'trivialaugwide-m20' will be TrivialAugmentWide
with mgnitude uniform sampling from [0, 20],
hparams: Other hparams (kwargs) for the TrivialAugment scheme.
Returns: A Mindspore compatible Transform
Source code in mindcv/data/auto_augment.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
|
mindcv.data.auto_augment.augment_and_mix_transform(configs, hparams=None)
¶
Create AugMix PyTorch transform
PARAMETER | DESCRIPTION |
---|---|
configs |
String defining configuration of AugMix augmentation. Consists of multiple sections separated by dashes ('-'). The first section defines the specific name of augment, it should be 'augmix'. The remaining sections, not order sepecific determine 'm' - integer magnitude (severity) of augmentation mix (default: 3) 'w' - integer width of augmentation chain (default: 3) 'd' - integer depth of augmentation chain (-1 is random [1, 3], default: -1) 'a' - integer or float, the args of beta deviation of beta for generate the weight, default 1.. Ex 'augmix-m5-w4-d2' results in AugMix with severity 5, chain width 4, chain depth 2
TYPE:
|
hparams |
Other hparams (kwargs) for the Augmentation transforms
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
A Mindspore compatible Transform |
Source code in mindcv/data/auto_augment.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 |
|
Dataset Factory¶
mindcv.data.dataset_factory.create_dataset(name='', root=None, split='train', shuffle=True, num_samples=None, num_shards=None, shard_id=None, num_parallel_workers=None, download=False, num_aug_repeats=0, **kwargs)
¶
Creates dataset by name.
PARAMETER | DESCRIPTION |
---|---|
name |
dataset name like MNIST, CIFAR10, ImageNeT, ''. '' means a customized dataset. Default: ''.
TYPE:
|
root |
dataset root dir. Default: None.
TYPE:
|
split |
data split: '' or split name string (train/val/test), if it is '', no split is used. Otherwise, it is a subfolder of root dir, e.g., train, val, test. Default: 'train'.
TYPE:
|
shuffle |
whether to shuffle the dataset. Default: True.
TYPE:
|
num_samples |
Number of elements to sample (default=None, which means sample all elements).
TYPE:
|
num_shards |
Number of shards that the dataset will be divided into (default=None).
When this argument is specified,
TYPE:
|
shard_id |
The shard ID within
TYPE:
|
num_parallel_workers |
Number of workers to read the data (default=None, set in the config).
TYPE:
|
download |
whether to download the dataset. Default: False
TYPE:
|
num_aug_repeats |
Number of dataset repetition for repeated augmentation. If 0 or 1, repeated augmentation is disabled. Otherwise, repeated augmentation is enabled and the common choice is 3. (Default: 0)
TYPE:
|
Note
For custom datasets and imagenet, the dataset dir should follow the structure like: .dataset_name/ ├── split1/ │ ├── class1/ │ │ ├── 000001.jpg │ │ ├── 000002.jpg │ │ └── .... │ └── class2/ │ ├── 000001.jpg │ ├── 000002.jpg │ └── .... └── split2/ ├── class1/ │ ├── 000001.jpg │ ├── 000002.jpg │ └── .... └── class2/ ├── 000001.jpg ├── 000002.jpg └── ....
RETURNS | DESCRIPTION |
---|---|
Dataset object |
Source code in mindcv/data/dataset_factory.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Sampler¶
mindcv.data.distributed_sampler.RepeatAugSampler
¶
Sampler that restricts data loading to a subset of the dataset for distributed, with repeated augmentation. It ensures that different each augmented version of a sample will be visible to a different process.
This sampler was adapted from https://github.com/facebookresearch/deit/blob/0c4b8f60/samplers.py
PARAMETER | DESCRIPTION |
---|---|
dataset_size |
dataset size.
|
num_shards |
num devices.
DEFAULT:
|
rank_id |
device id.
DEFAULT:
|
shuffle(bool) |
True for using shuffle, False for not using.
|
num_repeats(int) |
num of repeated instances in repeated augmentation, Default:3.
|
selected_round(int) |
round the total num of samples by this factor, Defailt:256.
|
Source code in mindcv/data/distributed_sampler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
DataLoader¶
mindcv.data.loader.create_loader(dataset, batch_size, drop_remainder=False, is_training=False, mixup=0.0, cutmix=0.0, cutmix_prob=0.0, num_classes=1000, transform=None, target_transform=None, num_parallel_workers=None, python_multiprocessing=False, separate=False)
¶
Creates dataloader.
Applies operations such as transform and batch to the ms.dataset.Dataset
object
created by the create_dataset
function to get the dataloader.
PARAMETER | DESCRIPTION |
---|---|
dataset |
dataset object created by
TYPE:
|
batch_size |
The number of rows each batch is created with. An int or callable object which takes exactly 1 parameter, BatchInfo.
TYPE:
|
drop_remainder |
Determines whether to drop the last block whose data row number is less than batch size (default=False). If True, and if there are less than batch_size rows available to make the last batch, then those rows will be dropped and not propagated to the child node.
TYPE:
|
is_training |
whether it is in train mode. Default: False.
TYPE:
|
mixup |
mixup alpha, mixup will be enabled if > 0. (default=0.0).
TYPE:
|
cutmix |
cutmix alpha, cutmix will be enabled if > 0. (default=0.0). This operation is experimental.
TYPE:
|
cutmix_prob |
prob of doing cutmix for an image (default=0.0)
TYPE:
|
num_classes |
the number of classes. Default: 1000.
TYPE:
|
transform |
the list of transformations that wil be applied on the image,
which is obtained by
TYPE:
|
target_transform |
the list of transformations that will be applied on the label. If None, the label will be converted to the type of ms.int32. Default: None.
TYPE:
|
num_parallel_workers |
Number of workers(threads) to process the dataset in parallel (default=None).
TYPE:
|
python_multiprocessing |
Parallelize Python operations with multiple worker processes. This option could be beneficial if the Python operation is computational heavy (default=False).
TYPE:
|
separate(bool, |
separate the image clean and the image been transformed. If separate==True, that means the dataset returned has 3 parts: * the first part called image "clean", which means the image without auto_augment (e.g., auto-aug) * the second and third parts called image transformed, hence, with the auto_augment transform. Refer to ".transforms_factory.create_transforms" for more information.
TYPE:
|
Note
- cutmix is now experimental (which means performance gain is not guarantee) and can not be used together with mixup due to the label int type conflict.
is_training
,mixup
,num_classes
is used for MixUp, which is a kind of transform operation. However, we are not able to merge it intotransform
, due to the limitations of themindspore.dataset
API.
RETURNS | DESCRIPTION |
---|---|
BatchDataset, dataset batched. |
Source code in mindcv/data/loader.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
MixUp¶
mindcv.data.mixup.Mixup
¶
Mixup/Cutmix that applies different params to each element or whole batch
PARAMETER | DESCRIPTION |
---|---|
mixup_alpha |
mixup alpha value, mixup is active if > 0.
TYPE:
|
cutmix_alpha |
cutmix alpha value, cutmix is active if > 0.
TYPE:
|
cutmix_minmax |
cutmix min/max image ratio, cutmix is active and uses this vs alpha if not None.
TYPE:
|
prob |
probability of applying mixup or cutmix per batch or element
TYPE:
|
switch_prob |
probability of switching to cutmix instead of mixup when both are active
TYPE:
|
mode |
how to apply mixup/cutmix params (per 'batch', 'pair' (pair of elements), 'elem' (element)
TYPE:
|
correct_lam |
apply lambda correction when cutmix bbox clipped by image borders
TYPE:
|
label_smoothing |
apply label smoothing to the mixed target tensor
TYPE:
|
num_classes |
number of classes for target
TYPE:
|
Source code in mindcv/data/mixup.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
Transform Factory¶
mindcv.data.transforms_factory.create_transforms(dataset_name='', image_resize=224, is_training=False, auto_augment=None, separate=False, **kwargs)
¶
Creates a list of transform operation on image data.
PARAMETER | DESCRIPTION |
---|---|
dataset_name |
if '', customized dataset. Currently, apply the same transform pipeline as ImageNet. if standard dataset name is given including imagenet, cifar10, mnist, preset transforms will be returned. Default: ''.
TYPE:
|
image_resize |
the image size after resize for adapting to network. Default: 224.
TYPE:
|
is_training |
if True, augmentation will be applied if support. Default: False.
TYPE:
|
separate |
separate the image clean and the image been transformed. If separate==True, the transformers are returned as a tuple of 3 separate transforms for use in a mixing dataset that passes: * all data through the primary transform, called "clean" data * a portion of the data through the secondary transform (e.g., auto-aug) * normalized and converts the branches above with the third, transform
DEFAULT:
|
**kwargs |
additional args parsed to
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
A list of transformation operations |
Source code in mindcv/data/transforms_factory.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|