当前位置:网站首页>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
原始图像:
卷积后的图像:
边栏推荐
- ospf map
- SQL Server数据类型转换函数cast()和convert()详解
- The curl command to get the network IP
- 小程序毕设作品之微信二手交易小程序毕业设计成品(2)小程序功能
- Nacos achieves high availability
- SQLSERVER将子查询数据合并拼接成一个字段
- How does the AI intelligent security video platform EasyCVR configure the simultaneous transmission of audio and video?
- Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (5) Task Book
- Taobao/Tmall get the list of sold product orders API
- OA项目之待开会议&历史会议&所有会议
猜你喜欢

为什么突然间麒麟 9000 5G 版本,又有库存了?

小程序毕设作品之微信二手交易小程序毕业设计成品(3)后台功能

使命、愿景、价值观到底有什么区别

Starlight does not ask passers-by!The young lady on the Wuhan campus successfully switched to software testing in three months and received a salary of 9k+13!

小程序毕设作品之微信积分商城小程序毕业设计成品(5)任务书

Summary of Rpc and gRpc Introduction

day10--install mysql on linux

一起来学习flutter 的布局组件

【转】Swift 中的面向协议编程:引言

小程序毕设作品之微信积分商城小程序毕业设计成品(7)中期检查报告
随机推荐
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Products (1) Development Overview
EasyCVR启动时报错“no such file or directory”,该如何解决?
ospf 综合实验(重发布,特殊区域)
写给技术人的管理入门知识1:什么是管理
AI智能安防视频平台EasyCVR如何配置音视频同时传输?
新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间
ospf 导图
论坛管理系统
Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (3) Background Functions
sqlmap使用教程大全命令大全(图文)
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Products (6) Question Opening and Defense PPT
2022-07-29 Group 4 Self-cultivation class study notes (every day)
Chapter 51 - Knowing the request header parameter analysis【2022-07-28】
小程序毕设作品之微信积分商城小程序毕业设计成品(2)小程序功能
SDL player in action
Boutique: Taobao/Tmall Get Order Details API for Purchased Products
Nacos service registration and discovery
高并发框架 Disruptor
(redistribute, special comprehensive experiment ospf area)
vscode 调试和远程