Compose¶
- class Compose(transforms=[], batch_compose=False, shuffle_indices=None, *, order=None)[source]¶
Composes several transfomations together.
- Parameters
transforms (
List
[VisionTransform
]) – list ofVisionTransform
to compose.batch_compose (
bool
) – whether keep the same transform order in batch data when shuffle.shuffle_indices (
Optional
[List
[Tuple
]]) – indices used for random shuffle, start at 1.order – the same with
VisionTransform
See also
Refer to
transform
module for vision transform APIs.Examples
>>> import megengine.data.transform as T >>> T.Compose([ ... T.RandomHorizontalFlip(), # 1st ... T.RandomVerticalFlip(), # 2nd ... T.CenterCrop(100), # 3rd ... T.ToMode("CHW"), # 4th ... ], ... shuffle_indices=[(1, 2, 3)] ... )
In this case,
shuffle_indices
is given so each input data will be transformed out of order:\[\begin{split}\begin{array}{cc} [{\color{red}1 \quad 2 \quad 3} \quad 4] & [{\color{red}1 \quad 3 \quad 2} \quad 4] \\ [{\color{red}2 \quad 1 \quad 3} \quad 4] & [{\color{red}2 \quad 3 \quad 1} \quad 4] \\ [{\color{red}3 \quad 1 \quad 2} \quad 4] & [{\color{red}3 \quad 2 \quad 1} \quad 4] \end{array}\end{split}\]In another case, if
[(1, 3), (2, 4)]
is given, then the 1st and 3rd transfomation will be random shuffled, the 2nd and 4th transfomation will also be shuffled:\[\begin{split}\begin{array}{cc} [{\color{red}1} \quad {\color{blue}2} \quad {\color{red}3} \quad {\color{blue}4}] & [{\color{red}1} \quad {\color{blue}4} \quad {\color{red}3} \quad {\color{blue}2}] \\ [{\color{red}3} \quad {\color{blue}2} \quad {\color{red}1} \quad {\color{blue}4}] & [{\color{red}3} \quad {\color{blue}4} \quad {\color{red}1} \quad {\color{blue}2}] \end{array}\end{split}\]Different colors represent different groups that need to be internally shuffled.
Warning
Different samples within each batch will also use random transfomation orders, unless
batch_compose
is set toTrue
.