[代码实战和详解]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
相关推荐
core5123 小时前
神经网络 (Neural Networks):模仿大脑的超级机器
人工智能·深度学习·神经网络
GitCode官方3 小时前
Qwen-Image-Edit-2509 正式上线 AtomGit AI:重新定义 AI 图像编辑体验!
人工智能·计算机视觉·atomgit
SCBAiotAigc3 小时前
Chrome的cookie编辑插件EditThisCookie
人工智能·chrome·python·ubuntu
啊阿狸不会拉杆3 小时前
《数字图像处理》实验6-图像分割方法
图像处理·人工智能·算法·计算机视觉·数字图像处理
不惑_3 小时前
通俗理解什么是神经网络
人工智能·深度学习·神经网络
愚公搬代码3 小时前
【愚公系列】《扣子开发 AI Agent 智能体应用》014-基于大模型的企业知识库(知识库的理论基础 RAG)
人工智能
Nwiliuyw3 小时前
Isaac Gym的WARNING: Forcing cpu pipeline. GPU pipeline disabled无法启用问题可能是个幌子骗了你
人工智能·经验分享·学习
GAOJ_K3 小时前
旋转花键如何保障精密设备长期运行高精度?
人工智能·科技·自动化·制造
神算大模型APi--天枢6463 小时前
合规落地加速期,大模型后端开发与部署的实战指南
大数据·前端·人工智能·架构·硬件架构
CaiGuoHui13 小时前
利用大型语言模型(LLM)实现Verilog设计中的功能缺陷定位
人工智能·深度学习·语言模型·自然语言处理