搭建一个简简单单的2D卷积神经网络

import torch
import torch.nn as nn
import torch.nn.functional as F
#2D卷积神经网络
input = torch.randn(1, 1, 28, 28)

# With square kernels and equal stride
conv1 = nn.Conv2d(1, 10, kernel_size=5)
conv2 = nn.Conv2d(10, 20, kernel_size=5)
conv2_drop = nn.Dropout2d()
fc1 = nn.Linear(320, 50)
fc2 = nn.Linear(50, 10)


X = F.relu(F.max_pool2d(conv1(input),2))
X = F.relu(F.max_pool2d(conv2_drop(conv2(X)),2))
X = X.view(-1, 320)
X = F.relu(fc1(X))
X = F.dropout(X, training=True)
X = fc2(X)
X = F.log_softmax(X, dim=0)


print("output shape is {}".format(X.shape))

=================

1、学会了如何快速调整、改变每一层张量的大小;

2、学会了 搭建网络模型准备训练数据 相互解耦的流程;

3、学会了 如何阅读别人网络结构;

posted @ 2022-03-20 21:36  bH1pJ  阅读(95)  评论(0编辑  收藏  举报