r"""Change input data to a target mode. For example, most transforms use HWC mode image, while the neural network might use CHW mode input tensor. Args: mode: output mode of input. Default: "CHW" order: the same with :class:`VisionTransform`
| 147 | |
| 148 | |
| 149 | class ToMode(VisionTransform): |
| 150 | r"""Change input data to a target mode. |
| 151 | For example, most transforms use HWC mode image, |
| 152 | while the neural network might use CHW mode input tensor. |
| 153 | |
| 154 | Args: |
| 155 | mode: output mode of input. Default: "CHW" |
| 156 | order: the same with :class:`VisionTransform` |
| 157 | """ |
| 158 | |
| 159 | def __init__(self, mode="CHW", *, order=None): |
| 160 | super().__init__(order) |
| 161 | assert mode in ["CHW"], "unsupported mode: {}".format(mode) |
| 162 | self.mode = mode |
| 163 | |
| 164 | def _apply_image(self, image): |
| 165 | if self.mode == "CHW": |
| 166 | return np.ascontiguousarray(np.rollaxis(image, 2)) |
| 167 | return image |
| 168 | |
| 169 | def _apply_coords(self, coords): |
| 170 | return coords |
| 171 | |
| 172 | def _apply_mask(self, mask): |
| 173 | if self.mode == "CHW": |
| 174 | return np.ascontiguousarray(np.rollaxis(mask, 2)) |
| 175 | return mask |
| 176 | |
| 177 | |
| 178 | class Compose(VisionTransform): |
no outgoing calls