[代码实战和详解]VGG16

VGG16 详解

我的github代码实现:vgg16

我们在vgg16神经网络上训练了SIGNS数据集,这是一个分类的数据集,在我的github上有介绍怎么下载数据集以及如何训练。

VGG16是一个卷积神经网络(CNN)架构,它在2014年的ILSVR(Imagenet)比赛中获胜。它被认为是迄今为止最优秀的视觉模型之一。VGG16最独特的地方在于,它不是使用大量的超参数,而是专注于使用3x3过滤器的卷积层,步幅为1,并始终使用相同的填充和2x2过滤器的最大池层。它始终在整个架构中一致地遵循这种卷积和最大池层的排列方式。最后,它有2个全连接层,后跟一个softmax输出。

VGG16网络使用pytorch实现

python 复制代码
class VGG16(nn.Module):
    def __init__(self, num_classes=6):
        super(VGG16, self).__init__()
        self.features = nn.Sequential(
            nn.Conv2d(3, 64, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(64, 64, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(64, 128, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(128, 128, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(128, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(256, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(256, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(256, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2)
        )
        self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
        self.classifier = nn.Sequential(
            nn.Linear(512 * 7 * 7, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, 1000),
            nn.Linear(1000, num_classes),
        )

    def forward(self, x):
        x = self.features(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.classifier(x)
        return x
相关推荐
逻辑君9 小时前
认知神经科学研究报告【20260112】
人工智能·深度学习·数学建模·量子计算
tyqtyq2210 小时前
求职信生成:AI 智能求职信撰写系统的鸿蒙实现
人工智能·学习·华为·生活·harmonyos
中微极客10 小时前
TensorFlow模型量化实战:从精度到延迟的优化指南
人工智能·python·tensorflow
Lambert-Wu10 小时前
常用激活函数总结
人工智能·深度学习·机器学习
MartinYeung510 小时前
[论文学习]PrivacyLens:评估语言模型在行动中的隐私规范意识
人工智能·学习·语言模型
ForDreamMusk10 小时前
批量归一化
人工智能·算法·机器学习
牧濑红莉10 小时前
零基础认识大语言模型(LLM)工作原理(2.Token 到底是什么?)
人工智能·语言模型·chatgpt
AImoon11.110 小时前
客易云关注“人工智能+”行动深化,智能经济新形态写入政府工作报告
人工智能
IT_陈寒10 小时前
Redis的KEYS命令把我搞崩溃了,改用SCAN才活过来
前端·人工智能·后端
Earth explosion10 小时前
大规模向量库的索引选型与查询性能调优:Milvus 实战指南
人工智能·milvus·ai智能体