当前位置:网站首页>【Pytorch】torch.nn.functional.conv2d(F.conv2d) same padding实现方法(输入与输出大小相同)
【Pytorch】torch.nn.functional.conv2d(F.conv2d) same padding实现方法(输入与输出大小相同)
2022-08-06 05:26:00 【小丫么小阿豪】
Motivation
在做图像退化的时候发现pytorch早期版本不支持same padding(新版本是有padding = 'same'这个选项的,但是本人试了也没成功,暂时没找到原因)。于是去查有没有办法自己实现一下same padding。
torch.nn.functional.conv2d 详解
官方文档写的非常清楚,直接贴上来
实现方法
由于F.conv2d的padding最多只支持两个参数(对称填充),有些输出大小没办法实现。因此可以通过F.pad()先做填充,再用F.conv2d做卷积。
import torch.nn.functional as F
import torch.nn as nn
filters = torch.randn(1, 1, 8, 15)
inputs = torch.randn(16, 1, 256, 256)
# 手动填充
inputs = F.pad(inputs, (7, 7, 4, 3))
out = F.conv2d(inputs, filters)
print(out.shape)
输出:
torch.Size([16, 1, 256, 256])
边栏推荐
- arcpy 将本地mxd自动发布arcgis server 的mapserver
- IO流文件复制
- yolov4、yolov5训练nuscenes数据集/nuscenes数据集转coco格式
- FAS820铜合金FAS820对应国内牌号
- 【多传感器融合】技术学习路线一篇全
- 泊松回归R语言实例
- MySql data table structure optimization summary
- How to jailbreak the Kindle series 5.12.2.2 ~ 5.14.2 without disassembly?How to install third-party plugins
- R语言处理时间序列数据
- Distributed, Microservices, Cluster Concepts and Differences
猜你喜欢

what is an API

使用Qt XmlStreamWriter写 Plist 文件

Build your own V Rising self-built server, and solutions to common V Rising server problems

Qt教程(3) : 信号与槽

R语言模糊匹配

分层架构&SOA架构

PointNeXt: 通过改进的训练以及模型缩放策略重新探究PointNet++

创建线程,线程状态转换,join,yield,stop,interrupt,wait方法

ECCV 2022 | 登顶SemanticKITTI!基于二维先验辅助的激光雷达点云语义分割

Explain in detail how to install Home Assistant Supervised on Raspberry Pi to make smart devices at home smarter
随机推荐
C64725铜合金带
地理加权回归R语言实例
Convolutional Neural Network Notes 2
How routers work
How to jailbreak the Kindle series 5.12.2.2 ~ 5.14.2 without disassembly?How to install third-party plugins
R语言实现空间对象可视化--以郑州市为例
Explain in detail how to install Home Assistant Supervised on Raspberry Pi to make smart devices at home smarter
ECCV 2022 Oral | 满分文章!视频实例分割新SOTA:SeqFormer & IDOL
工业相机镜头选型
openalyers 好玩的效果之蒙版图层
R语言Logist回归
R语言 地理加权随机森林(GWRFC )
MAE入局多模态分析,CMU联合微软发布仅需文本监督的视觉语言新模型VLC
C#脚本CSharpScript
Talk预告 | 德国马普所修宇亮:如何多快好省地重建三维数字人
在这个数字化的时代,如何做好用户体验与应用性能管理
C#和DL-EPI通信
Docker quickly installs & builds Mysql environment
九、一起学习Lua 运算符
动态规划之最大子数组和