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

Class RandomHorizontalFlip

imperative/python/megengine/module/vision.py:758–773  ·  view source on GitHub ↗

r"""Horizontally flip the given image randomly with a given probability. Input format must be nhwc. Args: prob(float, optional): probability of the image being flipped. Default value is 0.5.

Source from the content-addressed store, hash-verified

756
757
758class RandomHorizontalFlip(Module):
759 r"""Horizontally flip the given image randomly with a given probability.
760 Input format must be nhwc.
761
762 Args:
763 prob(float, optional): probability of the image being flipped. Default value is 0.5.
764 """
765
766 def __init__(self, prob=0.5):
767 super().__init__()
768 self.prob = prob
769
770 def forward(self, inp):
771 if np.random.rand(1) < self.prob:
772 return flip(inp, horizontal=True)
773 return inp
774
775
776class RandomVerticalFlip(Module):

Callers 3

__init__Method · 0.90
test_ComposeFunction · 0.50

Calls

no outgoing calls

Tested by 3

__init__Method · 0.72
test_ComposeFunction · 0.40