当前位置:网站首页>二维卷积——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
效果图

边栏推荐
- Is it safe for Mr. qiniu to open a securities account? Can I drive it?
- Zhao Ming, CEO of glory: it is difficult for a single manufacturer to achieve full scene product coverage
- Safety: how to provide more protection for pedestrians
- Concept of IP, classification of IP, IP multiplexing technology
- DBF menu driver: librarydatabaseproject
- 【GNN报告】腾讯AI lab 徐挺洋:图生成模型及其在分子生成中的应用
- Baidu PaddlePaddle easydl x wesken: see how to install the "eye of AI" in bearing quality inspection
- DHCP relay of HCNP Routing & Switching
- Topic 6 - message queue for client communication
- Work with growingio engineers this time | startdt Hackathon
猜你喜欢

Separation and merging of channels

Stop littering configuration files everywhere! Try our 7-year-old solution, which is stable

Bring 120W goods in 15 seconds. You can also shoot such a popular video

socat 端口转发

NC port forwarding

Programming language exercises (I)

Logical operation of image pixels

ufw 端口转发

Portfwd port forwarding

Still using xshell? You are out, recommend a more modern terminal connection tool!
随机推荐
Atcoder Beginner 202 E - Count Descendants(离线查询 重链剖分树上启发式合并)
启发式合并(含一般式、树上启发式合并 例题)
Use yarn
Want to make sandbox games? Then you must not miss this plug-in (unity3d)
Open source Invoicing system, 10 minutes to complete, it is recommended to collect!
Axi protocol (3): handshake mechanism and implementation details of Axi architecture
DHCP relay of HCNP Routing & Switching
[waiting for insurance] what does waiting for insurance rectification mean? What are the rectification contents?
Xxx.pro learning in QT
【GNN报告】腾讯AI lab 徐挺洋:图生成模型及其在分子生成中的应用
Socat port forwarding
Bring 120W goods in 15 seconds. You can also shoot such a popular video
CANN训练营学习2022第二季 模型系列 动漫风格化和AOE ATC调优
Amd Ruilong 7000 is expected to be available on September 15, and the 3D cache version will have to wait
Can Lu Zhengyao hide from the live broadcast room dominated by Luo min?
Axi protocol (2): five channels and two transactions of Axi architecture
Apachecon Asia 2022 opens registration: pulsar technology issues make a big debut
[array]nc143 matrix multiplication - simple
NATBypass 端口转发
调整图像亮度的滚动条演示实验
