当前位置:网站首页>二维卷积——torch.nn.conv2d的使用
二维卷积——torch.nn.conv2d的使用
2022-07-24 17:26:00 【程序小黑】
首先打开官方函数,查看conv2d的使用方法。
conv函数由三个必填的参数,
in_channels指输入的通道数,out_channels指输出的通道数,kernel_size是指的卷积核的核心数,
还有一些非必填的参数。例如padding和stride参数,这两个参数的详细作用如下图所示。
stride控制的是卷积一次能经过几个矩阵的行和列,padding则是对要处理的数据进行一次填充。
1.padding=0、stride=0的情况。

2.padding=2、stride=0的情况。
https://github.com/vdumoulin/conv_arithmetic/blob/master/gif/arbitrary_padding_no_strides.gif
3.padding=1、stride=0的情况。
conv_arithmetic/same_padding_no_strides.gif at master · vdumoulin/conv_arithmetic · GitHub
对于2维卷积更多详细演示图的github链接:
conv_arithmetic/README.md at master · vdumoulin/conv_arithmetic · GitHub
通过debug代码,可以看到我们的图片通道数由3通道被转成了6通道,但是在最后添加到tensorboard中的时候,需要转换成3通道,因此使用torch.reshape进行转换。
#coding=utf-8
#主要学习torch.nn.conv2d()
import torch
import torchvision
from torch.utils.data import DataLoader
from PIL import Image
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 this_network(torch.nn.Module):
def __init__(self):
super(this_network,self).__init__()
self.conv1 = torch.nn.Conv2d(in_channels=3,out_channels=6,kernel_size=3,stride=1,padding=0)
def forward(self,x):
x = self.conv1(x)
return x
init_network = this_network()
print(init_network)
writer = SummaryWriter("./logs")
step = 0
for data in dataloader:
imgs,targets = data
output = init_network(imgs)
#print(imgs.shape)
#print(output.shape)
#使用tensorboard进行数据浏览
writer.add_images("input",imgs,step)
output = torch.reshape(output,(-1,3,30,30))
writer.add_images("output",output,step)
step = step + 1
效果图

边栏推荐
- Yolopose practice: one-stage human posture estimation with hands + code interpretation
- 一个实际使用SwiftUI 4.0中ViewThatFits自适应视图的例子
- Iqiyi Tiktok reconciled, Weibo lying gun?
- Delay and jitter in network
- The orders in the same city are delivered in the same city, and the order explosion is still handy!
- Internet Download Manager Configuration
- Topic 6 - message queue for client communication
- Still using xshell? You are out, recommend a more modern terminal connection tool!
- CDN (content delivery network) content distribution network from entry to practice
- 2022 Asia International Internet of things exhibition
猜你喜欢

UFW port forwarding
![[sequential logic circuit] - counter](/img/a5/c92e0404c6a970a62595bc7a3b68cd.gif)
[sequential logic circuit] - counter

2022年最新浙江建筑安全员模拟题库及答案

Eth POS 2.0 stacking test network pledge process

Kyligence attended the Huawei global smart finance summit to accelerate the expansion of the global market

Programming language exercises (I)

数论整除分块讲解 例题:2021陕西省赛C
![Why can't sizeof (ARR) / size (arr[0]) be used to calculate the array length inside the called function?](/img/e6/1d2213f3eb9bd0ff537a66d2b01f98.png)
Why can't sizeof (ARR) / size (arr[0]) be used to calculate the array length inside the called function?

Transformer structure analysis -- learning notes

还在用Xshell?你out了,推荐一个更现代的终端连接工具!
随机推荐
Nearly 30 colleges and universities were named and praised by the Ministry of education!
Want to make sandbox games? Then you must not miss this plug-in (unity3d)
启发式合并(含一般式、树上启发式合并 例题)
ShardingSphere数据库读写分离
Why can't sizeof (ARR) / size (arr[0]) be used to calculate the array length inside the called function?
portmap 端口转发
调整图像亮度的滚动条演示实验
Still developing games with unity? Then you're out. Try unity to build an answer system
ROS主从机通信经验总结
[GNN report] Tencent AI Lab Xu TingYang: graph generation model and its application in molecular generation
Programming language exercises (I)
2022 Yangtze River Delta industrial automation exhibition will be held in Nanjing International Exhibition Center in October
Digital transformation must have digital thinking
Portfwd port forwarding
Using unity to do simulation, I don't allow this chart plug-in, you don't know
[how to optimize her] teach you how to locate unreasonable SQL? And optimize her~~~
In the morning, Tencent took out 38K, which let me see the ceiling of the foundation
TCP protocol debugging tool tcpengine v1.3.0 tutorial
Natbypass port forwarding
Bring 120W goods in 15 seconds. You can also shoot such a popular video
