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

Method forward

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

Source from the content-addressed store, hash-verified

218 super().__init__(**kwargs)
219
220 def forward(self, inp):
221 assert isinstance(
222 inp, Tensor
223 ), "expected input is megengine.Tensor, but got {}".format(type(inp))
224 if inp.format == "nchw" or inp.format == "default":
225 _norm_inp = inp
226 N, C, H, W = inp.shape
227 else:
228 raise RuntimeError(
229 "expect you create Tensor with format NCHW, got format is {}".format(
230 inp.format
231 )
232 )
233 kernel = self.get_kernel(_norm_inp, C)
234 pad_inp = pad(
235 _norm_inp, pad_width=((0, 0), (0, 0), (1, 1), (1, 1)), mode="reflect"
236 )
237 result = conv2d(pad_inp, kernel, groups=C)
238 result = _check_out_dtype(result, inp.dtype)
239 return result
240
241 def _get_parameter(self, param):
242 if isinstance(param, bool):

Callers

nothing calls this directly

Calls 5

get_kernelMethod · 0.95
_check_out_dtypeFunction · 0.85
padFunction · 0.50
conv2dFunction · 0.50
formatMethod · 0.45

Tested by

no test coverage detected