当前位置:网站首页>Introduction notes to pytorch deep learning (10) neural network convolution layer
Introduction notes to pytorch deep learning (10) neural network convolution layer
2022-06-30 07:34:00 【Snow fish】
Course notes , Course link
The learning notes are synchronously posted on my Personal website On , Welcome to check .
List of articles
One 、torch.nn.Conv2d brief introduction
Open the official website file torch.nn.Conv2d Section 
You can see some of the parameters required for this function , The first five parameters are commonly used , The specific introduction is shown in the figure below :
Color pictures are generally RGB Format , A pixel has RGB Three parameters , therefore channels by 3.
official A dynamic diagram of convolution operation is provided :
Yes padding Of , Yes strides Of .
- kernel_size Is used to set the size of convolution kernel , It can be int perhaps tuple data type , For example, set to 3 when , The size of the convolution kernel is 3*3,. In the actual training process , The network will constantly adjust the convolution kernel .
- out-channels Is the number of channels of the output image , When the number of input picture channels is n when , Will use n Channel convolution kernel to convolute the input image , If only one n Channel convolution kernel , The number of channels generated is 1 Output , If you have any m individual n Channel convolution kernel , Then the number of output channels is m.
Two 、 Code demonstration
Sample code :
import torch
from torch import nn
import torchvision
from torch.nn import Conv2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset = torchvision.datasets.CIFAR10("./dataset", train=False, transform=torchvision.transforms.ToTensor(),
download=True)
dataloader = DataLoader(dataset, batch_size=64)
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = Conv2d(in_channels=3, out_channels=6, kernel_size=3, stride=1, padding=0)
def forward(self, x):
x = self.conv1(x)
return x
Net1 = Net()
writer = SummaryWriter("./logs")
step = 0
for data in dataloader:
imgs, targets = data
output = Net1(imgs)
# print(imgs.shape)
# print(output.shape)
# torch.Size([64, 3, 32, 32])
writer.add_images("input", imgs, step)
# torch.Size([64, 6, 30, 30])
output = torch.reshape(output, (-1, 3, 30, 30))
writer.add_images("output", output, step)
step = step + 1
use tensorboard To view the :
Input :
Output :
3、 ... and 、VGG16 CNN Model brief introduction
So let's see Vgg16 This CNN Model 
2242243 The first and second operation of the input image , It's all convoluted 22422464 Result , The output channel is 64, Constant size , Explain what is going on padding,padding The size can be deduced by the formula :
边栏推荐
- Cmake generate map file
- Solve the linear equation of a specified point and a specified direction
- Assembly learning register
- Binary tree related operations (based on recursion, implemented in C language)
- Global digital industry strategy and policy observation in 2021 (China Academy of ICT)
- 期末复习-PHP学习笔记9-PHP会话控制
- Quick placement of devices by module in Ad
- 342 maps covering exquisite knowledge, one of which is classic and pasted on the wall
- LabVIEW program code update is slow
- Installation software operation manual (continuous update)
猜你喜欢
随机推荐
The most convenient serial port screen chip scheme designed at the charging pile in China
QT elementary notes
uniapp图片下方加标签标图片
Adjacency matrix representation of weighted undirected graph (implemented in C language)
Minecraft 1.16.5 module development (50) guide book
PMIC power management
套接字socket编程——UDP
DXP software uses shortcut keys
Implementation of binary search in C language
网络安全-三层交换技术和内部网络规划
网络安全-路由原理
动态内存管理
C language implements sequential queue, circular queue and chain queue
4diac getting started example
nRF52832 GPIO LED
Spring Festival inventory of Internet giants in 2022
模拟接口没声明异常抛出异常
Local unloading traffic of 5g application
Network security ARP protocol and defense
Thread pool - C language









