in classy_vision/models/efficientnet.py [0:0]
def forward(self, inputs, drop_connect_rate=None):
# Expansion and Depthwise Convolution
if self.expand_ratio != 1:
x = self.relu_fn(self.bn0(self.expand_conv(inputs)))
else:
x = inputs
x = self.relu_fn(self.bn1(self.depthwise_conv(x)))
# Squeeze and Excitation
if self.has_se:
# squeeze x in the spatial dimensions
x_squeezed = self.se_avgpool(x)
x_expanded = self.se_expand(self.relu_fn(self.se_reduce(x_squeezed)))
x = torch.sigmoid(x_expanded) * x
x = self.bn2(self.project_conv(x))
# Skip connection and Drop Connect
if self.id_skip:
if self.stride == 1 and self.input_filters == self.output_filters:
# only apply drop connect if a skip connection is present
if drop_connect_rate:
x = drop_connect(x, self.training, drop_connect_rate)
x = x + inputs
return x