Class: TorchVision::Transforms::RandomVerticalFlip

Inherits:
Torch::NN::Module
  • Object
show all
Defined in:
lib/torchvision/transforms/random_vertical_flip.rb

Instance Method Summary collapse

Constructor Details

#initialize(p: 0.5) ⇒ RandomVerticalFlip

Returns a new instance of RandomVerticalFlip.



4
5
6
7
# File 'lib/torchvision/transforms/random_vertical_flip.rb', line 4

def initialize(p: 0.5)
  super()
  @p = p
end

Instance Method Details

#forward(img) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/torchvision/transforms/random_vertical_flip.rb', line 9

def forward(img)
  if Torch.rand(1).item < @p
    F.vflip(img)
  else
    img
  end
end