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

Method forward

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

Source from the content-addressed store, hash-verified

490 return clip(table, 0, 255)
491
492 def forward(self, inp: Tensor) -> Tensor:
493 if inp.dtype.name == "uint8":
494 if self.per_channel is True:
495 flatten_inp = reshape(
496 inp, (inp.shape[0] * inp.shape[1], inp.shape[2] * inp.shape[3])
497 ).astype("int32")
498 else:
499 flatten_inp = flatten(inp, 1).astype("int32")
500 table = self._get_table(flatten_inp.shape[0])
501 result = gather(table, 1, flatten_inp)
502 result = reshape(result, inp.shape).astype("uint8")
503 return result
504 else:
505 input_dtype = inp.dtype
506 _, center_value, _ = _get_value_range_of_dtype(input_dtype)
507 if self.per_channel is True:
508 size = (inp.shape[0], inp.shape[1], 1, 1)
509 else:
510 size = (inp.shape[0], 1, 1, 1)
511 alpha = self._get_parameter(self.alpha, size)
512 if input_dtype.kind in ["u", "i"]:
513 center_value = int(center_value)
514 result = center_value + mul(inp.astype("float32") - center_value, alpha)
515 result = result.astype(input_dtype)
516 return result
517
518
519class Mixup(Module):

Callers

nothing calls this directly

Calls 8

_get_tableMethod · 0.95
_get_parameterMethod · 0.95
flattenFunction · 0.85
reshapeFunction · 0.50
gatherFunction · 0.50
mulFunction · 0.50
astypeMethod · 0.45

Tested by

no test coverage detected