当前位置:网站首页>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
原始图像:
卷积后的图像:
边栏推荐
- FreeRTOS个人笔记-内存管理
- Has been empty, a straightforward, continue to copy the top off!
- 路由过滤器
- Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (3) Background Functions
- 监控页面部署
- Mysql版本升级,直接复制Data文件,查询特别慢
- After 5 years of Ali internship interview~
- 传统项目转型
- day10--install mysql on linux
- 北京bgp机房和普通机房的区别
猜你喜欢
spicy (1) basic definition
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Products (3) Background Functions
JIT vs AOT
CMake的安装和测试
ospf map
组织在线化:组织数字化变革的新趋势
vscode 调试和远程
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Product (2) Mini Program Function
操作配置:如何在一台服务器中以服务方式运行多个EasyCVR程序?
How does the AI intelligent security video platform EasyCVR configure the simultaneous transmission of audio and video?
随机推荐
Nacos服务注册与发现
What is the difference between mission, vision and values?
高并发框架 Disruptor
EasyNVR平台级联到EasyCVR,视频播放一会就无法播放是什么原因?
护网行动基本介绍
小程序毕设作品之微信二手交易小程序毕业设计成品(1)开发概要
Nacos集群分区
小程序毕设作品之微信二手交易小程序毕业设计成品(8)毕业设计论文模板
WeChat second-hand transaction small program graduation design finished works (8) graduation design thesis template
小程序毕设作品之微信二手交易小程序毕业设计成品(5)任务书
Boutique: Taobao/Tmall Get Order Details API for Purchased Products
Nacos配置中心
小程序毕设作品之微信二手交易小程序毕业设计成品(2)小程序功能
Problems caused by List getting the difference
Microservice CAP Principles
Public chains challenging the "Impossible Triangle"
Nacos命名空间
Nacos service registration and discovery
CMake的安装和测试
Nacos namespace