AI基础之卷积网络

亡梦爱人 提交于 2019-12-04 17:32:09

全连接是AI入门的第一个网络模型,所以其局限性也很大,它在准确度上确实还不是很高。下面就让我们来看看卷积网络是怎么搭建的吧。

import torch.nn as nnclass CNNet(nn.Module):    def __init__(self):        super(CNNet, self).__init__()        self.cnn_layer = nn.Sequential(            # input_size : 32*32*3            nn.Conv2d(3,16,3,1),            nn.ReLU(),            nn.MaxPool2d(2,2),            nn.Conv2d(16,32,3,1),            nn.ReLU(),            nn.MaxPool2d(2,2),            nn.Conv2d(32,64,3,1),            nn.ReLU()        )        self.mlp_layer = nn.Sequential(            nn.Linear(4*4*64, 128),            nn.ReLU(),            # nn.Linear(128,80),            # nn.ReLU(),            nn.Linear(128,10)        )    def forward(self, x):        # NaN        x = self.cnn_layer(x)        # shape: nchw nv        x = x.reshape(-1,4*4*64)        x = self.mlp_layer(x)        return x这就是卷积网络搭建的完整代码啦。
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!