MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / ToMode

Class ToMode

imperative/python/megengine/data/transform/vision/transform.py:149–175  ·  view source on GitHub ↗

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`

Source from the content-addressed store, hash-verified

147
148
149class 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
178class Compose(VisionTransform):

Callers 5

test_stream_dataloaderFunction · 0.90
test_stream_dataloaderFunction · 0.90
test_ToModeFunction · 0.85
test_ComposeFunction · 0.85

Calls

no outgoing calls

Tested by 5

test_stream_dataloaderFunction · 0.72
test_stream_dataloaderFunction · 0.72
test_ToModeFunction · 0.68
test_ComposeFunction · 0.68