根据https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py
我不明白为什么 VGG 模型需要 512 * 7 * 7 input_size 的全连接层。最后一个卷积层是
- nn.Conv2d(512, 512, kernel_size=3, padding=1),
- nn.ReLU(真),
- nn.MaxPool2d(kernel_size=2, stride=2, dilation=1)
上面链接中的代码。
class VGG(nn.Module):
def __init__(self, features, num_classes=1000, init_weights=True):
super(VGG, self).__init__()
self.features = features
self.classifier = nn.Sequential(
nn.Linear(512 * 7 * 7, 4096),
nn.ReLU(True),
nn.Dropout(),
nn.Linear(4096, 4096),
nn.ReLU(True),
nn.Dropout(),
nn.Linear(4096, num_classes),
)