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

Method forward

imperative/python/megengine/module/vision.py:38–61  ·  view source on GitHub ↗
(self, inp)

Source from the content-addressed store, hash-verified

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()

Callers

nothing calls this directly

Calls 5

sampleMethod · 0.95
addFunction · 0.85
broadcast_toFunction · 0.50
formatMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected