当前位置:网站首页>Pytorch framework learning record 7 - convolutional layer
Pytorch framework learning record 7 - convolutional layer
2022-07-30 03:58:00 【Yuzu Roo】
Pytorch框架学习记录7——卷积层
1. torch.nn.Conv2d 介绍
torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode=‘zeros’, device=None, dtype=None)
参数
- in_channels ( int ) – 输入图像中的通道数
- out_channels ( int ) – 卷积产生的通道数
- kernel_size ( intortuple ) – 卷积核的大小
- stride ( intortuple,optional ) – 卷积的步幅.默认值:1
- padding ( int,tuple或str,optional ) – 添加到输入的所有四个边的填充.默认值:0
- padding_mode (字符串*,*可选) –
'zeros','reflect','replicate'或'circular'. 默认:'zeros' - dilation ( intortuple,optional ) – 内核元素之间的间距.默认值:1
- groups ( int,optional ) – 从输入通道到输出通道的阻塞连接数.默认值:1
- bias ( bool,optional ) – If
True,向输出添加可学习的偏差.默认:True
The formula for calculating the height and width of the input image and the height and width of the output image:
H o u t = ⌊ ( H i n + 2 × p a d d i n g [ 0 ] − d i l a t i o n [ 0 ] × ( k e r n e l _ s i z e [ 0 ] − 1 ) − 1 ) / s t r i d e [ 0 ] + 1 ⌋ H_{out}=⌊(H_{in}+2×padding[0]−dilation[0]×(kernel\_size[0]−1)−1)/stride[0]+1⌋ Hout=⌊(Hin+2×padding[0]−dilation[0]×(kernel_size[0]−1)−1)/stride[0]+1⌋
W o u t = ⌊ ( W i n + 2 × p a d d i n g [ 1 ] − d i l a t i o n [ 1 ] × ( k e r n e l _ s i z e [ 1 ] − 1 ) − 1 ) / s t r i d e [ 1 ] + 1 ⌋ W_{out}=⌊(W_{in}+2×padding[1]−dilation[1]×(kernel\_size[1]−1)−1)/stride[1]+1⌋ Wout=⌊(Win+2×padding[1]−dilation[1]×(kernel_size[1]−1)−1)/stride[1]+1⌋
这里的output_channelsrepresents the number of convolution kernels,卷积核的个数=The number of output channels
2. 实例
The following example builds a simple convolutional network using the methods learned earlier,And compare the input and output images.
import torch
import torchvision.datasets
from torch import nn
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset = torchvision.datasets.CIFAR10(root='./dataset', train=False, transform=torchvision.transforms.ToTensor(),
download=True)
dataloader = DataLoader(dataset=dataset, batch_size=64, num_workers=0)
class Test(nn.Module):
def __init__(self):
super(Test, self).__init__()
self.conv2d = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=3, stride=1, padding=0)
def forward(self, x):
x = self.conv2d(x)
return x
writer = SummaryWriter("logs")
test = Test()
step = 0
for data in dataloader:
imgs, target = data
output = test(imgs)
print(imgs.shape)
print(output.shape)
output = torch.reshape(output, (-1, 3, 30, 30))
writer.add_images("input", imgs, step)
writer.add_images("output", output, step)
step += 1
原始图像:
卷积后的图像:
边栏推荐
- Pytorch框架学习记录6——torch.nn.Module和torch.nn.functional.conv2d的使用
- 小程序毕设作品之微信积分商城小程序毕业设计成品(1)开发概要
- (redistribute, special comprehensive experiment ospf area)
- SDL player in action
- flutter 记录学习不一样的动画(一)
- Nacos集群分区
- 论坛管理系统
- How to solve the error "no such file or directory" when EasyCVR starts?
- Taobao/Tmall get Taobao store details API
- Let's learn the layout components of flutter together
猜你喜欢

Nacos cluster partition

The difference between BGP room and ordinary room in Beijing

Transformation of traditional projects

一直空、一直爽,继续抄顶告捷!

OpenFeign实现降级
![[ 云原生之谜 ] 云原生背景 && 定义 && 相关技术详解?](/img/eb/0cd6891fcc00d2c01ba8bd7f8d0822.png)
[ 云原生之谜 ] 云原生背景 && 定义 && 相关技术详解?

传统项目转型

写给技术人的管理入门知识1:什么是管理

小程序毕设作品之微信积分商城小程序毕业设计成品(7)中期检查报告

Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Work (7) Interim Inspection Report
随机推荐
Advanced Microservices Cloud Alibaba
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Products (1) Development Overview
Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (6) Question Opening Reply PPT
解决编译安装gdb-10.1 unistd.h:663:3: error: #error “Please include config.h first.“ 问题
Let's learn the layout components of flutter together
[Node accesses MongoDB database]
函数的底层机制
Nacos service registration and discovery
Nacos cluster partition
Microservice CAP Principles
cv2.polylines
小程序毕设作品之微信积分商城小程序毕业设计成品(5)任务书
Organizations Going Online: A New Trend in Organizational Digital Transformation
小程序毕设作品之微信积分商城小程序毕业设计成品(6)开题答辩PPT
vscode debugging and remote
微服务进阶 Cloud Alibaba
Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (4) Opening Report
What is the difference between mission, vision and values?
小程序毕设作品之微信积分商城小程序毕业设计成品(4)开题报告
Pytorch框架学习记录1——Dataset类代码实战