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

Method forward

imperative/python/megengine/module/vision.py:640–665  ·  view source on GitHub ↗
(self, data1, label1, data2, label2)

Source from the content-addressed store, hash-verified

638 return self.beta_func(self.beta, self.beta, size=(batch,))
639
640 def forward(self, data1, label1, data2, label2):
641 assert all(
642 isinstance(inp, Tensor) for inp in [data1, label1, data2, label2]
643 ), "expected input is megengine.Tensor"
644
645 batch, C, H, W = data1.shape
646
647 self.lamb = self.sample(batch)
648 lamb_rat = sqrt(1.0 - self.lamb)
649
650 label = self.lamb * label1 + (1.0 - self.lamb) * label2
651
652 self.cut_h = floor(H * lamb_rat)
653 self.cut_w = floor(W * lamb_rat)
654
655 # uniform
656 self.cx = self.uniform_func(high=H, size=(batch,))
657 self.cx = floor(self.cx)
658 self.cy = self.uniform_func(high=W, size=(batch,))
659 self.cy = floor(self.cy)
660
661 data = apply(
662 self.custom_func, data1, data2, self.cx, self.cy, self.cut_h, self.cut_w
663 )[0]
664
665 return data, label
666
667
668class CropAndPad(Module):

Callers

nothing calls this directly

Calls 4

sampleMethod · 0.95
sqrtFunction · 0.50
floorFunction · 0.50
applyFunction · 0.50

Tested by

no test coverage detected