r"""Composes several transfomations together. Args: transforms: list of :class:`VisionTransform` to compose. batch_compose: whether keep the same transform order in batch data when shuffle. shuffle_indices: indices used for random shuffle, start at 1. order: the
| 176 | |
| 177 | |
| 178 | class Compose(VisionTransform): |
| 179 | r"""Composes several transfomations together. |
| 180 | |
| 181 | Args: |
| 182 | transforms: list of :class:`VisionTransform` to compose. |
| 183 | batch_compose: whether keep the same transform order in batch data when shuffle. |
| 184 | shuffle_indices: indices used for random shuffle, start at 1. |
| 185 | order: the same with :class:`VisionTransform` |
| 186 | |
| 187 | .. seealso:: Refer to :mod:`~.data.transform` module for vision transform APIs. |
| 188 | |
| 189 | Examples: |
| 190 | |
| 191 | >>> import megengine.data.transform as T |
| 192 | >>> T.Compose([ # doctest: +SKIP |
| 193 | ... T.RandomHorizontalFlip(), # 1st |
| 194 | ... T.RandomVerticalFlip(), # 2nd |
| 195 | ... T.CenterCrop(100), # 3rd |
| 196 | ... T.ToMode("CHW"), # 4th |
| 197 | ... ], |
| 198 | ... shuffle_indices=[(1, 2, 3)] |
| 199 | ... ) |
| 200 | |
| 201 | In this case, ``shuffle_indices`` is given so each input data will be transformed |
| 202 | out of order: |
| 203 | |
| 204 | .. math:: |
| 205 | |
| 206 | \begin{array}{cc} |
| 207 | [{\color{red}1 \quad 2 \quad 3} \quad 4] & [{\color{red}1 \quad 3 \quad 2} \quad 4] \\ |
| 208 | [{\color{red}2 \quad 1 \quad 3} \quad 4] & [{\color{red}2 \quad 3 \quad 1} \quad 4] \\ |
| 209 | [{\color{red}3 \quad 1 \quad 2} \quad 4] & [{\color{red}3 \quad 2 \quad 1} \quad 4] |
| 210 | \end{array} |
| 211 | |
| 212 | In another case, if ``[(1, 3), (2, 4)]`` is given, then the 1st and 3rd transfomation |
| 213 | will be random shuffled, the 2nd and 4th transfomation will also be shuffled: |
| 214 | |
| 215 | .. math:: |
| 216 | |
| 217 | \begin{array}{cc} |
| 218 | [{\color{red}1} \quad {\color{blue}2} \quad {\color{red}3} \quad {\color{blue}4}] & |
| 219 | [{\color{red}1} \quad {\color{blue}4} \quad {\color{red}3} \quad {\color{blue}2}] \\ |
| 220 | [{\color{red}3} \quad {\color{blue}2} \quad {\color{red}1} \quad {\color{blue}4}] & |
| 221 | [{\color{red}3} \quad {\color{blue}4} \quad {\color{red}1} \quad {\color{blue}2}] |
| 222 | \end{array} |
| 223 | |
| 224 | Different colors represent different groups that need to be internally shuffled. |
| 225 | |
| 226 | .. warning:: |
| 227 | |
| 228 | Different samples within each batch will also use random transfomation orders, |
| 229 | unless ``batch_compose`` is set to ``True``. |
| 230 | |
| 231 | """ |
| 232 | |
| 233 | def __init__( |
| 234 | self, |
| 235 | transforms: List[VisionTransform] = [], |
no outgoing calls