先放上模型结构:
对于stride=1或2的情况有不同的结构,stride=2时,不采用shortcut:
import torch
import torch.nn as nn
import torch.nn.functional as F
class Bottleneck(nn.Module):
def __init__(self, in_channels, out_channels, multiple, stride):
super(Bottleneck, self).__init__()
self.stride = stride
self.conv1 = nn.Conv2d(
in_channels=in_channels,
out_channels=in_channels*multiple,
kernel_size=1,
stride=1,
padding=0
)
self.bn1 = nn.BatchNorm2d(in_channels*multiple)
self.conv2 = nn.Conv2d(
in_channels=in_channels*multiple,
out_channels=in_channels*multiple,
kernel_size=3,
stride=stride,
padding=1,
groups=in_channels*multiple,
)
self.bn2 = nn.BatchNorm2d(in_channels*multiple)
self.conv3 = nn.Conv2d(
in_channels=in_channels*multiple