(self, inp)
| 36 | super().__init__(**kwargs) |
| 37 | |
| 38 | def forward(self, inp): |
| 39 | assert isinstance( |
| 40 | inp, Tensor |
| 41 | ), "expected input is megengine.Tensor, but got {}".format(type(inp)) |
| 42 | if self._per_channel is True: |
| 43 | noise = self.sample(inp.shape).to(inp.device) |
| 44 | elif self._per_channel is False: |
| 45 | if inp.format == "nchw": |
| 46 | N, C, H, W = inp.shape |
| 47 | c_noise = self.sample((N, 1, H, W)) |
| 48 | # TODO: fix this code because the inp.shape always nchw output, even if format is "nhwc", cjs. |
| 49 | elif inp.format == "nhwc": |
| 50 | N, H, W, C = inp.shape |
| 51 | c_noise = self.sample((N, H, W, 1)) |
| 52 | else: |
| 53 | raise RuntimeError( |
| 54 | "expect you create Tensor with format specified while per_channel is False, got format is {}".format( |
| 55 | inp.format |
| 56 | ) |
| 57 | ) |
| 58 | noise = broadcast_to(c_noise, inp.shape).to(inp.device) |
| 59 | else: |
| 60 | raise NotImplementedError("float point type per channel haven't impl") |
| 61 | return add(inp, noise) |
| 62 | |
| 63 | def sample(self, size): |
| 64 | raise NotImplementedError() |
nothing calls this directly
no test coverage detected