Class: TorchVision::Models::Bottleneck
- Inherits:
-
Torch::NN::Module
- Object
- Torch::NN::Module
- TorchVision::Models::Bottleneck
- Defined in:
- lib/torchvision/models/bottleneck.rb
Class Method Summary collapse
Instance Method Summary collapse
- #forward(x) ⇒ Object
-
#initialize(inplanes, planes, stride: 1, downsample: nil, groups: 1, base_width: 64, dilation: 1, norm_layer: nil) ⇒ Bottleneck
constructor
A new instance of Bottleneck.
Constructor Details
#initialize(inplanes, planes, stride: 1, downsample: nil, groups: 1, base_width: 64, dilation: 1, norm_layer: nil) ⇒ Bottleneck
Returns a new instance of Bottleneck.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/torchvision/models/bottleneck.rb', line 4 def initialize(inplanes, planes, stride: 1, downsample: nil, groups: 1, base_width: 64, dilation: 1, norm_layer: nil) super() norm_layer ||= Torch::NN::BatchNorm2d width = (planes * (base_width / 64.0)).to_i * groups # Both self.conv2 and self.downsample layers downsample the input when stride != 1 @conv1 = Torch::NN::Conv2d.new(inplanes, width, 1, stride: 1, bias: false) @bn1 = norm_layer.new(width) @conv2 = Torch::NN::Conv2d.new(width, width, 3, stride: stride, padding: dilation, groups: groups, bias: false, dilation: dilation) @bn2 = norm_layer.new(width) @conv3 = Torch::NN::Conv2d.new(width, planes * self.class.expansion, 1, stride: 1, bias: false) @bn3 = norm_layer.new(planes * self.class.expansion) @relu = Torch::NN::ReLU.new(inplace: true) @downsample = downsample @stride = stride end |
Class Method Details
.expansion ⇒ Object
42 43 44 |
# File 'lib/torchvision/models/bottleneck.rb', line 42 def self.expansion 4 end |
Instance Method Details
#forward(x) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/torchvision/models/bottleneck.rb', line 20 def forward(x) identity = x out = @conv1.call(x) out = @bn1.call(out) out = @relu.call(out) out = @conv2.call(out) out = @bn2.call(out) out = @relu.call(out) out = @conv3.call(out) out = @bn3.call(out) identity = @downsample.call(x) if @downsample out += identity out = @relu.call(out) out end |