首先是V1:
import torch
import torch.nn as nn
import torch.nn.functional as F
class MobileNetV1(nn.Module):
def __init__(self, num_classes=888):
super(MobileNetV1, self).__init__()
self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=2, padding=1)
self.bn1 = nn.BatchNorm2d(32)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
self.bn2 = nn.BatchNorm2d(64)
self.conv3 = nn.Conv2d(64, 128, kernel_size=3, stride=2, padding=1)
self.bn3 = nn.BatchNorm2d(128)
self.conv4 = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1)
self.bn4 = nn.BatchNorm2d(128)
self.conv5 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1)
self.bn5 = nn.BatchNorm2d(256)
self.conv6 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)
self.bn6 = nn.BatchNorm2d(256)
self.conv7 = nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1)
self.bn7 = nn.BatchNorm2d(512)
self.avgpool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Linear(512, num_classes)
def forward(self, x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
x = F.relu(self.bn3(self.conv3(x)))
x = F.relu(self.bn4(self.conv4(x)))
x = F.relu(self.bn5(self.conv5(x)))
x = F.relu(self.bn6(self.conv6(x)))
x = F.relu(self.bn7(self.conv7(x)))
x = self.avgpool(x)
x = x.view(x.size(0), -1)
x = self.fc(x)
return x
model = MobileNetV1().cuda()
print(model)
from torchsummary import summary
print(summary(model,(3, 224, 224)))
MobileNetV1(
(conv1): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))
(bn1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))
(bn3): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv4): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(bn4): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv5): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))
(bn5): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv6): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(bn6): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv7): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))
(bn7): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(avgpool): AdaptiveAvgPool2d(output_size=1)
(fc): Linear(in_features=512, out_features=888, bias=True)
)
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
Conv2d-1 [-1, 32, 112, 112] 896
BatchNorm2d-2 [-1, 32, 112, 112] 64
Conv2d-3 [-1, 64, 112, 112] 18,496
BatchNorm2d-4 [-1, 64, 112, 112] 128
Conv2d-5 [-1, 128, 56, 56] 73,856
BatchNorm2d-6 [-1, 128, 56, 56] 256
Conv2d-7 [-1, 128, 56, 56] 147,584
BatchNorm2d-8 [-1, 128, 56, 56] 256
Conv2d-9 [-1, 256, 28, 28] 295,168
BatchNorm2d-10 [-1, 256, 28, 28] 512
Conv2d-11 [-1, 256, 28, 28] 590,080
BatchNorm2d-12 [-1, 256, 28, 28] 512
Conv2d-13 [-1, 512, 14, 14] 1,180,160
BatchNorm2d-14 [-1, 512, 14, 14] 1,024
AdaptiveAvgPool2d-15 [-1, 512, 1, 1] 0
Linear-16 [-1, 888] 455,544
================================================================
Total params: 2,764,536
Trainable params: 2,764,536
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 38.29
Params size (MB): 10.55
Estimated Total Size (MB): 49.41
----------------------------------------------------------------
None
进程已结束,退出代码0
然后是V2:
import torch
import torch.nn as nn
import torch.nn.functional as F
class InvertedResidual(nn.Module):
def __init__(self, in_channels, out_channels, stride, expand_ratio):
super(InvertedResidual, self).__init__()
self.stride = stride
hidden_dim = round(in_channels * expand_ratio)
self.conv1 = nn.Conv2d(in_channels, hidden_dim, kernel_size=1, stride=1, padding=0, bias=False)
self.bn1 = nn.BatchNorm2d(hidden_dim)
self.conv2 = nn.Conv2d(hidden_dim, hidden_dim, kernel_size=3, stride=stride, padding=1, groups=hidden_dim,
bias=False)
self.bn2 = nn.BatchNorm2d(hidden_dim)
self.conv3 = nn.Conv2d(hidden_dim, out_channels, kernel_size=1, stride=1, padding=0, bias=False)
self.bn3 = nn.BatchNorm2d(out_channels)
self.use_res_connect = self.stride == 1 and in_channels == out_channels
def forward(self, x):
identity = x
x = F.relu6(self.bn1(self.conv1(x)))
x = F.relu6(self.bn2(self.conv2(x)))
x = self.bn3(self.conv3(x))
if self.use_res_connect:
x += identity
return x
class MobileNetV2(nn.Module):
def __init__(self, num_classes=666, width_mult=1.0):
super(MobileNetV2, self).__init__()
input_channel = 32
last_channel = 1280
inverted_residual_setting = [
[1, 16, 1, 1],
[6, 24, 2, 2],
[6, 32, 3, 2],
[6, 64, 4, 2],
[6, 96, 3, 1],
[6, 160, 3, 2],
[6, 320, 1, 1]
]
input_channel = int(input_channel * width_mult)
self.last_channel = int(last_channel * width_mult) if width_mult > 1.0 else last_channel
self.features = [nn.Conv2d(3, input_channel, kernel_size=3, stride=2, padding=1, bias=False),
nn.BatchNorm2d(input_channel),
nn.ReLU(inplace=True)]
for t, c, n, s in inverted_residual_setting:
output_channel = int(c * width_mult)
for i in range(n):
if i == 0:
self.features.append(InvertedResidual(input_channel, output_channel, s, expand_ratio=t))
else:
self.features.append(InvertedResidual(input_channel, output_channel, 1, expand_ratio=t))
input_channel = output_channel
self.features.append(
nn.Conv2d(input_channel, self.last_channel, kernel_size=1, stride=1, padding=0, bias=False))
self.features.append(nn.BatchNorm2d(self.last_channel))
self.features.append(nn.ReLU(inplace=True))
self.features = nn.Sequential(*self.features)
self.avgpool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Linear(self.last_channel, num_classes)
def forward(self, x):
x = self.features(x)
x = self.avgpool(x)
x = x.view(x.size(0), -1)
x = self.fc(x)
return x
model = MobileNetV2().cuda()
print(model)
from torchsummary import summary
print(summary(model,(3, 224, 224)))
MobileNetV2(
(features): Sequential(
(0): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
(1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): InvertedResidual(
(conv1): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=32, bias=False)
(bn2): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(32, 16, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(4): InvertedResidual(
(conv1): Conv2d(16, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(96, 96, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=96, bias=False)
(bn2): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(96, 24, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(5): InvertedResidual(
(conv1): Conv2d(24, 144, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(144, 144, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=144, bias=False)
(bn2): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(144, 24, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(6): InvertedResidual(
(conv1): Conv2d(24, 144, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(144, 144, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=144, bias=False)
(bn2): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(144, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(7): InvertedResidual(
(conv1): Conv2d(32, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=192, bias=False)
(bn2): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(192, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(8): InvertedResidual(
(conv1): Conv2d(32, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=192, bias=False)
(bn2): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(192, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(9): InvertedResidual(
(conv1): Conv2d(32, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(192, 192, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=192, bias=False)
(bn2): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(192, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(10): InvertedResidual(
(conv1): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=384, bias=False)
(bn2): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(384, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(11): InvertedResidual(
(conv1): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=384, bias=False)
(bn2): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(384, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(12): InvertedResidual(
(conv1): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=384, bias=False)
(bn2): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(384, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(13): InvertedResidual(
(conv1): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=384, bias=False)
(bn2): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(384, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(14): InvertedResidual(
(conv1): Conv2d(96, 576, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(576, 576, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=576, bias=False)
(bn2): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(576, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(15): InvertedResidual(
(conv1): Conv2d(96, 576, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(576, 576, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=576, bias=False)
(bn2): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(576, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(16): InvertedResidual(
(conv1): Conv2d(96, 576, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(576, 576, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=576, bias=False)
(bn2): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(576, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(17): InvertedResidual(
(conv1): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(960, 960, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=960, bias=False)
(bn2): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(960, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(18): InvertedResidual(
(conv1): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(960, 960, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=960, bias=False)
(bn2): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(960, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(19): InvertedResidual(
(conv1): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv2): Conv2d(960, 960, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=960, bias=False)
(bn2): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv3): Conv2d(960, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(20): Conv2d(320, 1280, kernel_size=(1, 1), stride=(1, 1), bias=False)
(21): BatchNorm2d(1280, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(22): ReLU(inplace=True)
)
(avgpool): AdaptiveAvgPool2d(output_size=1)
(fc): Linear(in_features=1280, out_features=666, bias=True)
)
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
Conv2d-1 [-1, 32, 112, 112] 864
BatchNorm2d-2 [-1, 32, 112, 112] 64
ReLU-3 [-1, 32, 112, 112] 0
Conv2d-4 [-1, 32, 112, 112] 1,024
BatchNorm2d-5 [-1, 32, 112, 112] 64
Conv2d-6 [-1, 32, 112, 112] 288
BatchNorm2d-7 [-1, 32, 112, 112] 64
Conv2d-8 [-1, 16, 112, 112] 512
BatchNorm2d-9 [-1, 16, 112, 112] 32
InvertedResidual-10 [-1, 16, 112, 112] 0
Conv2d-11 [-1, 96, 112, 112] 1,536
BatchNorm2d-12 [-1, 96, 112, 112] 192
Conv2d-13 [-1, 96, 56, 56] 864
BatchNorm2d-14 [-1, 96, 56, 56] 192
Conv2d-15 [-1, 24, 56, 56] 2,304
BatchNorm2d-16 [-1, 24, 56, 56] 48
InvertedResidual-17 [-1, 24, 56, 56] 0
Conv2d-18 [-1, 144, 56, 56] 3,456
BatchNorm2d-19 [-1, 144, 56, 56] 288
Conv2d-20 [-1, 144, 56, 56] 1,296
BatchNorm2d-21 [-1, 144, 56, 56] 288
Conv2d-22 [-1, 24, 56, 56] 3,456
BatchNorm2d-23 [-1, 24, 56, 56] 48
InvertedResidual-24 [-1, 24, 56, 56] 0
Conv2d-25 [-1, 144, 56, 56] 3,456
BatchNorm2d-26 [-1, 144, 56, 56] 288
Conv2d-27 [-1, 144, 28, 28] 1,296
BatchNorm2d-28 [-1, 144, 28, 28] 288
Conv2d-29 [-1, 32, 28, 28] 4,608
BatchNorm2d-30 [-1, 32, 28, 28] 64
InvertedResidual-31 [-1, 32, 28, 28] 0
Conv2d-32 [-1, 192, 28, 28] 6,144
BatchNorm2d-33 [-1, 192, 28, 28] 384
Conv2d-34 [-1, 192, 28, 28] 1,728
BatchNorm2d-35 [-1, 192, 28, 28] 384
Conv2d-36 [-1, 32, 28, 28] 6,144
BatchNorm2d-37 [-1, 32, 28, 28] 64
InvertedResidual-38 [-1, 32, 28, 28] 0
Conv2d-39 [-1, 192, 28, 28] 6,144
BatchNorm2d-40 [-1, 192, 28, 28] 384
Conv2d-41 [-1, 192, 28, 28] 1,728
BatchNorm2d-42 [-1, 192, 28, 28] 384
Conv2d-43 [-1, 32, 28, 28] 6,144
BatchNorm2d-44 [-1, 32, 28, 28] 64
InvertedResidual-45 [-1, 32, 28, 28] 0
Conv2d-46 [-1, 192, 28, 28] 6,144
BatchNorm2d-47 [-1, 192, 28, 28] 384
Conv2d-48 [-1, 192, 14, 14] 1,728
BatchNorm2d-49 [-1, 192, 14, 14] 384
Conv2d-50 [-1, 64, 14, 14] 12,288
BatchNorm2d-51 [-1, 64, 14, 14] 128
InvertedResidual-52 [-1, 64, 14, 14] 0
Conv2d-53 [-1, 384, 14, 14] 24,576
BatchNorm2d-54 [-1, 384, 14, 14] 768
Conv2d-55 [-1, 384, 14, 14] 3,456
BatchNorm2d-56 [-1, 384, 14, 14] 768
Conv2d-57 [-1, 64, 14, 14] 24,576
BatchNorm2d-58 [-1, 64, 14, 14] 128
InvertedResidual-59 [-1, 64, 14, 14] 0
Conv2d-60 [-1, 384, 14, 14] 24,576
BatchNorm2d-61 [-1, 384, 14, 14] 768
Conv2d-62 [-1, 384, 14, 14] 3,456
BatchNorm2d-63 [-1, 384, 14, 14] 768
Conv2d-64 [-1, 64, 14, 14] 24,576
BatchNorm2d-65 [-1, 64, 14, 14] 128
InvertedResidual-66 [-1, 64, 14, 14] 0
Conv2d-67 [-1, 384, 14, 14] 24,576
BatchNorm2d-68 [-1, 384, 14, 14] 768
Conv2d-69 [-1, 384, 14, 14] 3,456
BatchNorm2d-70 [-1, 384, 14, 14] 768
Conv2d-71 [-1, 64, 14, 14] 24,576
BatchNorm2d-72 [-1, 64, 14, 14] 128
InvertedResidual-73 [-1, 64, 14, 14] 0
Conv2d-74 [-1, 384, 14, 14] 24,576
BatchNorm2d-75 [-1, 384, 14, 14] 768
Conv2d-76 [-1, 384, 14, 14] 3,456
BatchNorm2d-77 [-1, 384, 14, 14] 768
Conv2d-78 [-1, 96, 14, 14] 36,864
BatchNorm2d-79 [-1, 96, 14, 14] 192
InvertedResidual-80 [-1, 96, 14, 14] 0
Conv2d-81 [-1, 576, 14, 14] 55,296
BatchNorm2d-82 [-1, 576, 14, 14] 1,152
Conv2d-83 [-1, 576, 14, 14] 5,184
BatchNorm2d-84 [-1, 576, 14, 14] 1,152
Conv2d-85 [-1, 96, 14, 14] 55,296
BatchNorm2d-86 [-1, 96, 14, 14] 192
InvertedResidual-87 [-1, 96, 14, 14] 0
Conv2d-88 [-1, 576, 14, 14] 55,296
BatchNorm2d-89 [-1, 576, 14, 14] 1,152
Conv2d-90 [-1, 576, 14, 14] 5,184
BatchNorm2d-91 [-1, 576, 14, 14] 1,152
Conv2d-92 [-1, 96, 14, 14] 55,296
BatchNorm2d-93 [-1, 96, 14, 14] 192
InvertedResidual-94 [-1, 96, 14, 14] 0
Conv2d-95 [-1, 576, 14, 14] 55,296
BatchNorm2d-96 [-1, 576, 14, 14] 1,152
Conv2d-97 [-1, 576, 7, 7] 5,184
BatchNorm2d-98 [-1, 576, 7, 7] 1,152
Conv2d-99 [-1, 160, 7, 7] 92,160
BatchNorm2d-100 [-1, 160, 7, 7] 320
InvertedResidual-101 [-1, 160, 7, 7] 0
Conv2d-102 [-1, 960, 7, 7] 153,600
BatchNorm2d-103 [-1, 960, 7, 7] 1,920
Conv2d-104 [-1, 960, 7, 7] 8,640
BatchNorm2d-105 [-1, 960, 7, 7] 1,920
Conv2d-106 [-1, 160, 7, 7] 153,600
BatchNorm2d-107 [-1, 160, 7, 7] 320
InvertedResidual-108 [-1, 160, 7, 7] 0
Conv2d-109 [-1, 960, 7, 7] 153,600
BatchNorm2d-110 [-1, 960, 7, 7] 1,920
Conv2d-111 [-1, 960, 7, 7] 8,640
BatchNorm2d-112 [-1, 960, 7, 7] 1,920
Conv2d-113 [-1, 160, 7, 7] 153,600
BatchNorm2d-114 [-1, 160, 7, 7] 320
InvertedResidual-115 [-1, 160, 7, 7] 0
Conv2d-116 [-1, 960, 7, 7] 153,600
BatchNorm2d-117 [-1, 960, 7, 7] 1,920
Conv2d-118 [-1, 960, 7, 7] 8,640
BatchNorm2d-119 [-1, 960, 7, 7] 1,920
Conv2d-120 [-1, 320, 7, 7] 307,200
BatchNorm2d-121 [-1, 320, 7, 7] 640
InvertedResidual-122 [-1, 320, 7, 7] 0
Conv2d-123 [-1, 1280, 7, 7] 409,600
BatchNorm2d-124 [-1, 1280, 7, 7] 2,560
ReLU-125 [-1, 1280, 7, 7] 0
AdaptiveAvgPool2d-126 [-1, 1280, 1, 1] 0
Linear-127 [-1, 666] 853,146
================================================================
Total params: 3,078,106
Trainable params: 3,078,106
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 115.95
Params size (MB): 11.74
Estimated Total Size (MB): 128.26
----------------------------------------------------------------
None
进程已结束,退出代码0
最后是V3:
import torch
import torch.nn as nn
import torch.nn.functional as F
class SqueezeExcitation(nn.Module):
def __init__(self, in_channels, reduced_dim):
super(SqueezeExcitation, self).__init__()
self.se = nn.Sequential(
nn.AdaptiveAvgPool2d(1),
nn.Conv2d(in_channels, reduced_dim, kernel_size=1),
nn.ReLU(inplace=True),
nn.Conv2d(reduced_dim, in_channels, kernel_size=1),
nn.Sigmoid()
)
def forward(self, x):
return x * self.se(x)
class InvertedResidual(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride, padding, expand_ratio, reduction_ratio=4):
super(InvertedResidual, self).__init__()
hidden_dim = round(in_channels * expand_ratio)
self.use_res_connect = stride == 1 and in_channels == out_channels
layers = []
if expand_ratio != 1:
layers.append(nn.Conv2d(in_channels, hidden_dim, kernel_size=1, stride=1, padding=0, bias=False))
layers.append(nn.BatchNorm2d(hidden_dim))
layers.append(nn.ReLU(inplace=True))
layers.extend([
nn.Conv2d(hidden_dim, hidden_dim, kernel_size, stride, padding, groups=hidden_dim, bias=False),
nn.BatchNorm2d(hidden_dim),
nn.ReLU(inplace=True),
SqueezeExcitation(hidden_dim, reduction_ratio),
nn.Conv2d(hidden_dim, out_channels, kernel_size=1, stride=1, padding=0, bias=False),
nn.BatchNorm2d(out_channels)
])
self.conv = nn.Sequential(*layers)
def forward(self, x):
if self.use_res_connect:
return x + self.conv(x)
else:
return self.conv(x)
class MobileNetV3(nn.Module):
def __init__(self, num_classes=1000, width_mult=1.0):
super(MobileNetV3, self).__init__()
input_channel = 16
last_channel = 1280
inverted_residual_setting = [
# k, t, c, SE, HS, s
[3, 1, 16, 0, 0, 1],
[3, 4, 24, 0, 0, 2],
[3, 3, 24, 0, 0, 1],
[5, 3, 40, 1, 0, 2],
[5, 3, 40, 1, 0, 1],
[5, 3, 40, 1, 0, 1],
[3, 6, 80, 0, 1, 2],
[3, 2.5, 80, 0, 1, 1],
[3, 2.3, 80, 0, 1, 1],
[3, 2.3, 80, 0, 1, 1],
[3, 6, 112, 1, 1, 1],
[3, 6, 112, 1, 1, 1],
[5, 6, 160, 1, 1, 2],
[5, 6, 160, 1, 1, 1],
[5, 6, 160, 1, 1, 1]
]
input_channel = int(input_channel * width_mult)
self.last_channel = int(last_channel * width_mult) if width_mult > 1.0 else last_channel
self.features = [nn.Conv2d(3, input_channel, kernel_size=3, stride=2, padding=1, bias=False),
nn.BatchNorm2d(input_channel),
nn.Hardswish(inplace=True)]
for k, t, c, se, hs, s in inverted_residual_setting:
output_channel = int(c * width_mult)
for i in range(1):
if i == 0:
self.features.append(InvertedResidual(input_channel, output_channel, k, s, k // 2, t))
else:
self.features.append(InvertedResidual(input_channel, output_channel, k, 1, k // 2, t))
input_channel = output_channel
self.features.append(
nn.Conv2d(input_channel, self.last_channel, kernel_size=1, stride=1, padding=0, bias=False))
self.features.append(nn.BatchNorm2d(self.last_channel))
self.features.append(nn.Hardswish(inplace=True))
self.features = nn.Sequential(*self.features)
self.avgpool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Linear(self.last_channel, num_classes)
def forward(self, x):
x = self.features(x)
x = self.avgpool(x)
x = x.view(x.size(0), -1)
x = self.fc(x)
return x
model = MobileNetV3().cuda()
print(model)
from torchsummary import summary
print(summary(model,(3, 224, 224)))
MobileNetV3(
(features): Sequential(
(0): Conv2d(3, 16, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
(1): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): Hardswish()
(3): InvertedResidual(
(conv): Sequential(
(0): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=16, bias=False)
(1): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(16, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 16, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(4): Conv2d(16, 16, kernel_size=(1, 1), stride=(1, 1), bias=False)
(5): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(4): InvertedResidual(
(conv): Sequential(
(0): Conv2d(16, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(64, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=64, bias=False)
(4): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(64, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 64, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(64, 24, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(5): InvertedResidual(
(conv): Sequential(
(0): Conv2d(24, 72, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(72, 72, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=72, bias=False)
(4): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(72, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 72, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(72, 24, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(6): InvertedResidual(
(conv): Sequential(
(0): Conv2d(24, 72, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(72, 72, kernel_size=(5, 5), stride=(2, 2), padding=(2, 2), groups=72, bias=False)
(4): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(72, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 72, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(72, 40, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(7): InvertedResidual(
(conv): Sequential(
(0): Conv2d(40, 120, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(120, 120, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=120, bias=False)
(4): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(120, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 120, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(120, 40, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(8): InvertedResidual(
(conv): Sequential(
(0): Conv2d(40, 120, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(120, 120, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=120, bias=False)
(4): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(120, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 120, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(120, 40, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(9): InvertedResidual(
(conv): Sequential(
(0): Conv2d(40, 240, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(240, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(240, 240, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=240, bias=False)
(4): BatchNorm2d(240, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(240, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 240, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(240, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(10): InvertedResidual(
(conv): Sequential(
(0): Conv2d(80, 200, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(200, 200, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=200, bias=False)
(4): BatchNorm2d(200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(200, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 200, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(200, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(11): InvertedResidual(
(conv): Sequential(
(0): Conv2d(80, 184, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(184, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(184, 184, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=184, bias=False)
(4): BatchNorm2d(184, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(184, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 184, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(184, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(12): InvertedResidual(
(conv): Sequential(
(0): Conv2d(80, 184, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(184, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(184, 184, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=184, bias=False)
(4): BatchNorm2d(184, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(184, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 184, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(184, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(13): InvertedResidual(
(conv): Sequential(
(0): Conv2d(80, 480, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(480, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(480, 480, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=480, bias=False)
(4): BatchNorm2d(480, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(480, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 480, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(480, 112, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(112, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(14): InvertedResidual(
(conv): Sequential(
(0): Conv2d(112, 672, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(672, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(672, 672, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=672, bias=False)
(4): BatchNorm2d(672, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(672, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 672, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(672, 112, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(112, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(15): InvertedResidual(
(conv): Sequential(
(0): Conv2d(112, 672, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(672, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(672, 672, kernel_size=(5, 5), stride=(2, 2), padding=(2, 2), groups=672, bias=False)
(4): BatchNorm2d(672, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(672, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 672, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(672, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(16): InvertedResidual(
(conv): Sequential(
(0): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(960, 960, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=960, bias=False)
(4): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(960, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 960, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(960, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(17): InvertedResidual(
(conv): Sequential(
(0): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace=True)
(3): Conv2d(960, 960, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=960, bias=False)
(4): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace=True)
(6): SqueezeExcitation(
(se): Sequential(
(0): AdaptiveAvgPool2d(output_size=1)
(1): Conv2d(960, 4, kernel_size=(1, 1), stride=(1, 1))
(2): ReLU(inplace=True)
(3): Conv2d(4, 960, kernel_size=(1, 1), stride=(1, 1))
(4): Sigmoid()
)
)
(7): Conv2d(960, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(8): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
)
(18): Conv2d(160, 1280, kernel_size=(1, 1), stride=(1, 1), bias=False)
(19): BatchNorm2d(1280, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(20): Hardswish()
)
(avgpool): AdaptiveAvgPool2d(output_size=1)
(fc): Linear(in_features=1280, out_features=1000, bias=True)
)
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
Conv2d-1 [-1, 16, 112, 112] 432
BatchNorm2d-2 [-1, 16, 112, 112] 32
Hardswish-3 [-1, 16, 112, 112] 0
Conv2d-4 [-1, 16, 112, 112] 144
BatchNorm2d-5 [-1, 16, 112, 112] 32
ReLU-6 [-1, 16, 112, 112] 0
AdaptiveAvgPool2d-7 [-1, 16, 1, 1] 0
Conv2d-8 [-1, 4, 1, 1] 68
ReLU-9 [-1, 4, 1, 1] 0
Conv2d-10 [-1, 16, 1, 1] 80
Sigmoid-11 [-1, 16, 1, 1] 0
SqueezeExcitation-12 [-1, 16, 112, 112] 0
Conv2d-13 [-1, 16, 112, 112] 256
BatchNorm2d-14 [-1, 16, 112, 112] 32
InvertedResidual-15 [-1, 16, 112, 112] 0
Conv2d-16 [-1, 64, 112, 112] 1,024
BatchNorm2d-17 [-1, 64, 112, 112] 128
ReLU-18 [-1, 64, 112, 112] 0
Conv2d-19 [-1, 64, 56, 56] 576
BatchNorm2d-20 [-1, 64, 56, 56] 128
ReLU-21 [-1, 64, 56, 56] 0
AdaptiveAvgPool2d-22 [-1, 64, 1, 1] 0
Conv2d-23 [-1, 4, 1, 1] 260
ReLU-24 [-1, 4, 1, 1] 0
Conv2d-25 [-1, 64, 1, 1] 320
Sigmoid-26 [-1, 64, 1, 1] 0
SqueezeExcitation-27 [-1, 64, 56, 56] 0
Conv2d-28 [-1, 24, 56, 56] 1,536
BatchNorm2d-29 [-1, 24, 56, 56] 48
InvertedResidual-30 [-1, 24, 56, 56] 0
Conv2d-31 [-1, 72, 56, 56] 1,728
BatchNorm2d-32 [-1, 72, 56, 56] 144
ReLU-33 [-1, 72, 56, 56] 0
Conv2d-34 [-1, 72, 56, 56] 648
BatchNorm2d-35 [-1, 72, 56, 56] 144
ReLU-36 [-1, 72, 56, 56] 0
AdaptiveAvgPool2d-37 [-1, 72, 1, 1] 0
Conv2d-38 [-1, 4, 1, 1] 292
ReLU-39 [-1, 4, 1, 1] 0
Conv2d-40 [-1, 72, 1, 1] 360
Sigmoid-41 [-1, 72, 1, 1] 0
SqueezeExcitation-42 [-1, 72, 56, 56] 0
Conv2d-43 [-1, 24, 56, 56] 1,728
BatchNorm2d-44 [-1, 24, 56, 56] 48
InvertedResidual-45 [-1, 24, 56, 56] 0
Conv2d-46 [-1, 72, 56, 56] 1,728
BatchNorm2d-47 [-1, 72, 56, 56] 144
ReLU-48 [-1, 72, 56, 56] 0
Conv2d-49 [-1, 72, 28, 28] 1,800
BatchNorm2d-50 [-1, 72, 28, 28] 144
ReLU-51 [-1, 72, 28, 28] 0
AdaptiveAvgPool2d-52 [-1, 72, 1, 1] 0
Conv2d-53 [-1, 4, 1, 1] 292
ReLU-54 [-1, 4, 1, 1] 0
Conv2d-55 [-1, 72, 1, 1] 360
Sigmoid-56 [-1, 72, 1, 1] 0
SqueezeExcitation-57 [-1, 72, 28, 28] 0
Conv2d-58 [-1, 40, 28, 28] 2,880
BatchNorm2d-59 [-1, 40, 28, 28] 80
InvertedResidual-60 [-1, 40, 28, 28] 0
Conv2d-61 [-1, 120, 28, 28] 4,800
BatchNorm2d-62 [-1, 120, 28, 28] 240
ReLU-63 [-1, 120, 28, 28] 0
Conv2d-64 [-1, 120, 28, 28] 3,000
BatchNorm2d-65 [-1, 120, 28, 28] 240
ReLU-66 [-1, 120, 28, 28] 0
AdaptiveAvgPool2d-67 [-1, 120, 1, 1] 0
Conv2d-68 [-1, 4, 1, 1] 484
ReLU-69 [-1, 4, 1, 1] 0
Conv2d-70 [-1, 120, 1, 1] 600
Sigmoid-71 [-1, 120, 1, 1] 0
SqueezeExcitation-72 [-1, 120, 28, 28] 0
Conv2d-73 [-1, 40, 28, 28] 4,800
BatchNorm2d-74 [-1, 40, 28, 28] 80
InvertedResidual-75 [-1, 40, 28, 28] 0
Conv2d-76 [-1, 120, 28, 28] 4,800
BatchNorm2d-77 [-1, 120, 28, 28] 240
ReLU-78 [-1, 120, 28, 28] 0
Conv2d-79 [-1, 120, 28, 28] 3,000
BatchNorm2d-80 [-1, 120, 28, 28] 240
ReLU-81 [-1, 120, 28, 28] 0
AdaptiveAvgPool2d-82 [-1, 120, 1, 1] 0
Conv2d-83 [-1, 4, 1, 1] 484
ReLU-84 [-1, 4, 1, 1] 0
Conv2d-85 [-1, 120, 1, 1] 600
Sigmoid-86 [-1, 120, 1, 1] 0
SqueezeExcitation-87 [-1, 120, 28, 28] 0
Conv2d-88 [-1, 40, 28, 28] 4,800
BatchNorm2d-89 [-1, 40, 28, 28] 80
InvertedResidual-90 [-1, 40, 28, 28] 0
Conv2d-91 [-1, 240, 28, 28] 9,600
BatchNorm2d-92 [-1, 240, 28, 28] 480
ReLU-93 [-1, 240, 28, 28] 0
Conv2d-94 [-1, 240, 14, 14] 2,160
BatchNorm2d-95 [-1, 240, 14, 14] 480
ReLU-96 [-1, 240, 14, 14] 0
AdaptiveAvgPool2d-97 [-1, 240, 1, 1] 0
Conv2d-98 [-1, 4, 1, 1] 964
ReLU-99 [-1, 4, 1, 1] 0
Conv2d-100 [-1, 240, 1, 1] 1,200
Sigmoid-101 [-1, 240, 1, 1] 0
SqueezeExcitation-102 [-1, 240, 14, 14] 0
Conv2d-103 [-1, 80, 14, 14] 19,200
BatchNorm2d-104 [-1, 80, 14, 14] 160
InvertedResidual-105 [-1, 80, 14, 14] 0
Conv2d-106 [-1, 200, 14, 14] 16,000
BatchNorm2d-107 [-1, 200, 14, 14] 400
ReLU-108 [-1, 200, 14, 14] 0
Conv2d-109 [-1, 200, 14, 14] 1,800
BatchNorm2d-110 [-1, 200, 14, 14] 400
ReLU-111 [-1, 200, 14, 14] 0
AdaptiveAvgPool2d-112 [-1, 200, 1, 1] 0
Conv2d-113 [-1, 4, 1, 1] 804
ReLU-114 [-1, 4, 1, 1] 0
Conv2d-115 [-1, 200, 1, 1] 1,000
Sigmoid-116 [-1, 200, 1, 1] 0
SqueezeExcitation-117 [-1, 200, 14, 14] 0
Conv2d-118 [-1, 80, 14, 14] 16,000
BatchNorm2d-119 [-1, 80, 14, 14] 160
InvertedResidual-120 [-1, 80, 14, 14] 0
Conv2d-121 [-1, 184, 14, 14] 14,720
BatchNorm2d-122 [-1, 184, 14, 14] 368
ReLU-123 [-1, 184, 14, 14] 0
Conv2d-124 [-1, 184, 14, 14] 1,656
BatchNorm2d-125 [-1, 184, 14, 14] 368
ReLU-126 [-1, 184, 14, 14] 0
AdaptiveAvgPool2d-127 [-1, 184, 1, 1] 0
Conv2d-128 [-1, 4, 1, 1] 740
ReLU-129 [-1, 4, 1, 1] 0
Conv2d-130 [-1, 184, 1, 1] 920
Sigmoid-131 [-1, 184, 1, 1] 0
SqueezeExcitation-132 [-1, 184, 14, 14] 0
Conv2d-133 [-1, 80, 14, 14] 14,720
BatchNorm2d-134 [-1, 80, 14, 14] 160
InvertedResidual-135 [-1, 80, 14, 14] 0
Conv2d-136 [-1, 184, 14, 14] 14,720
BatchNorm2d-137 [-1, 184, 14, 14] 368
ReLU-138 [-1, 184, 14, 14] 0
Conv2d-139 [-1, 184, 14, 14] 1,656
BatchNorm2d-140 [-1, 184, 14, 14] 368
ReLU-141 [-1, 184, 14, 14] 0
AdaptiveAvgPool2d-142 [-1, 184, 1, 1] 0
Conv2d-143 [-1, 4, 1, 1] 740
ReLU-144 [-1, 4, 1, 1] 0
Conv2d-145 [-1, 184, 1, 1] 920
Sigmoid-146 [-1, 184, 1, 1] 0
SqueezeExcitation-147 [-1, 184, 14, 14] 0
Conv2d-148 [-1, 80, 14, 14] 14,720
BatchNorm2d-149 [-1, 80, 14, 14] 160
InvertedResidual-150 [-1, 80, 14, 14] 0
Conv2d-151 [-1, 480, 14, 14] 38,400
BatchNorm2d-152 [-1, 480, 14, 14] 960
ReLU-153 [-1, 480, 14, 14] 0
Conv2d-154 [-1, 480, 14, 14] 4,320
BatchNorm2d-155 [-1, 480, 14, 14] 960
ReLU-156 [-1, 480, 14, 14] 0
AdaptiveAvgPool2d-157 [-1, 480, 1, 1] 0
Conv2d-158 [-1, 4, 1, 1] 1,924
ReLU-159 [-1, 4, 1, 1] 0
Conv2d-160 [-1, 480, 1, 1] 2,400
Sigmoid-161 [-1, 480, 1, 1] 0
SqueezeExcitation-162 [-1, 480, 14, 14] 0
Conv2d-163 [-1, 112, 14, 14] 53,760
BatchNorm2d-164 [-1, 112, 14, 14] 224
InvertedResidual-165 [-1, 112, 14, 14] 0
Conv2d-166 [-1, 672, 14, 14] 75,264
BatchNorm2d-167 [-1, 672, 14, 14] 1,344
ReLU-168 [-1, 672, 14, 14] 0
Conv2d-169 [-1, 672, 14, 14] 6,048
BatchNorm2d-170 [-1, 672, 14, 14] 1,344
ReLU-171 [-1, 672, 14, 14] 0
AdaptiveAvgPool2d-172 [-1, 672, 1, 1] 0
Conv2d-173 [-1, 4, 1, 1] 2,692
ReLU-174 [-1, 4, 1, 1] 0
Conv2d-175 [-1, 672, 1, 1] 3,360
Sigmoid-176 [-1, 672, 1, 1] 0
SqueezeExcitation-177 [-1, 672, 14, 14] 0
Conv2d-178 [-1, 112, 14, 14] 75,264
BatchNorm2d-179 [-1, 112, 14, 14] 224
InvertedResidual-180 [-1, 112, 14, 14] 0
Conv2d-181 [-1, 672, 14, 14] 75,264
BatchNorm2d-182 [-1, 672, 14, 14] 1,344
ReLU-183 [-1, 672, 14, 14] 0
Conv2d-184 [-1, 672, 7, 7] 16,800
BatchNorm2d-185 [-1, 672, 7, 7] 1,344
ReLU-186 [-1, 672, 7, 7] 0
AdaptiveAvgPool2d-187 [-1, 672, 1, 1] 0
Conv2d-188 [-1, 4, 1, 1] 2,692
ReLU-189 [-1, 4, 1, 1] 0
Conv2d-190 [-1, 672, 1, 1] 3,360
Sigmoid-191 [-1, 672, 1, 1] 0
SqueezeExcitation-192 [-1, 672, 7, 7] 0
Conv2d-193 [-1, 160, 7, 7] 107,520
BatchNorm2d-194 [-1, 160, 7, 7] 320
InvertedResidual-195 [-1, 160, 7, 7] 0
Conv2d-196 [-1, 960, 7, 7] 153,600
BatchNorm2d-197 [-1, 960, 7, 7] 1,920
ReLU-198 [-1, 960, 7, 7] 0
Conv2d-199 [-1, 960, 7, 7] 24,000
BatchNorm2d-200 [-1, 960, 7, 7] 1,920
ReLU-201 [-1, 960, 7, 7] 0
AdaptiveAvgPool2d-202 [-1, 960, 1, 1] 0
Conv2d-203 [-1, 4, 1, 1] 3,844
ReLU-204 [-1, 4, 1, 1] 0
Conv2d-205 [-1, 960, 1, 1] 4,800
Sigmoid-206 [-1, 960, 1, 1] 0
SqueezeExcitation-207 [-1, 960, 7, 7] 0
Conv2d-208 [-1, 160, 7, 7] 153,600
BatchNorm2d-209 [-1, 160, 7, 7] 320
InvertedResidual-210 [-1, 160, 7, 7] 0
Conv2d-211 [-1, 960, 7, 7] 153,600
BatchNorm2d-212 [-1, 960, 7, 7] 1,920
ReLU-213 [-1, 960, 7, 7] 0
Conv2d-214 [-1, 960, 7, 7] 24,000
BatchNorm2d-215 [-1, 960, 7, 7] 1,920
ReLU-216 [-1, 960, 7, 7] 0
AdaptiveAvgPool2d-217 [-1, 960, 1, 1] 0
Conv2d-218 [-1, 4, 1, 1] 3,844
ReLU-219 [-1, 4, 1, 1] 0
Conv2d-220 [-1, 960, 1, 1] 4,800
Sigmoid-221 [-1, 960, 1, 1] 0
SqueezeExcitation-222 [-1, 960, 7, 7] 0
Conv2d-223 [-1, 160, 7, 7] 153,600
BatchNorm2d-224 [-1, 160, 7, 7] 320
InvertedResidual-225 [-1, 160, 7, 7] 0
Conv2d-226 [-1, 1280, 7, 7] 204,800
BatchNorm2d-227 [-1, 1280, 7, 7] 2,560
Hardswish-228 [-1, 1280, 7, 7] 0
AdaptiveAvgPool2d-229 [-1, 1280, 1, 1] 0
Linear-230 [-1, 1000] 1,281,000
================================================================
Total params: 2,837,716
Trainable params: 2,837,716
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 111.75
Params size (MB): 10.83
Estimated Total Size (MB): 123.15
----------------------------------------------------------------
None