当前位置:网站首页>Pytorch框架学习记录7——卷积层
Pytorch框架学习记录7——卷积层
2022-07-30 03:54:00 【柚子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
输入图像高度和宽度与输出图像的高度和宽度计算公式:
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_channels就代表着卷积核的个数,卷积核的个数=输出频道的个数
2. 实例
下面的实例就使用之前学习到的方法构建了一个简单的卷积网络,并对输入输出图像进行展示对比。
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
原始图像:
卷积后的图像:
边栏推荐
- Send it to your friends and let TA treat you to fried chicken!
- Nacos achieves high availability
- Monitor page deployment
- LoadBalancer 负载均衡
- 小程序毕设作品之微信积分商城小程序毕业设计成品(5)任务书
- 传统项目转型
- OA项目之待开会议&历史会议&所有会议
- Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (3) Background Functions
- mysql 结构、索引详解
- What is the difference between mission, vision and values?
猜你喜欢

新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间

智能答题功能,CRMEB知识付费系统必须有!

SDL播放器实战

Public chains challenging the "Impossible Triangle"

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

Monitor page deployment

Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Products (1) Development Overview

How to solve the error "no such file or directory" when EasyCVR starts?

ospf 导图

Nacos集群分区
随机推荐
EasyNVR平台级联到EasyCVR,视频播放一会就无法播放是什么原因?
Taobao/Tmall get the list of sold product orders API
Alibaba search new product data API by keyword
小程序毕设作品之微信积分商城小程序毕业设计成品(8)毕业设计论文模板
智能答题功能,CRMEB知识付费系统必须有!
高并发框架 Disruptor
Taobao/Tmall get Taobao store details API
小程序毕设作品之微信积分商城小程序毕业设计成品(7)中期检查报告
Wechat second-hand transaction small program graduation design finished product (1) Development overview
Flutter records and learns different animations (1)
为什么突然间麒麟 9000 5G 版本,又有库存了?
STM32 SPI+WM8978语音回环
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Product (8) Graduation Design Thesis Template
Mysql版本升级,直接复制Data文件,查询特别慢
New interface - API interface for "Taote" keyword search
2022-07-29 第四小组 修身课 学习笔记(every day)
OpenFeign realize load balance
(redistribute, special comprehensive experiment ospf area)
小程序毕设作品之微信积分商城小程序毕业设计成品(6)开题答辩PPT
MySQ死锁