参考链接1: 睿智的目标检测23——Pytorch搭建SSD目标检测平台
参考链接2: bubbliiiing/ssd-pytorch
参考链接3: Pytorch 搭建自己的SSD目标检测平台(Bubbliiiing 深度学习 教程)
代码:
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import os
base = [
64, 64,
'M', 128, 128,
'M', 256, 256, 256,
'C', 512, 512, 512,
'M',512, 512, 512
]
def vgg(i): # add_vgg(3)
layers = []
in_channels = i
for v in base:
if v == 'M':
layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
elif v == 'C':
layers += [nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True)]
else:
conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1)
layers += [conv2d, nn.ReLU(inplace=True)]
in_channels = v
pool5 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1)
conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6)
conv7 = nn.Conv2d(1024, 1024, kernel_size=1)
layers += [pool5, conv6,
nn.ReLU(inplace=True), conv7, nn.ReLU(inplace=True)]
return layers
if __name__ == "__main__":
print(r'运行程序: nets\vgg.py')
my_vgg = vgg(3)
print(r'结束程序: nets\vgg.py')
调试程序,查看主干部分结构:
手工模拟代码执行手稿: