1. 卷积原理

① 卷积核不停的在原图上进行滑动,对应元素相乘再相加。

② 下图为每次滑动移动1格,然后再利用原图与卷积核上的数值进行计算得到缩略图矩阵的数据,如下图右所示。

python 复制代码
import torch
import torch.nn.functional as F

input = torch.tensor([[1, 2, 0, 3, 1],
                      [0, 1, 2, 3, 1],
                      [1, 2, 1, 0, 0],
                      [5, 2, 3, 1, 1],
                      [2, 1, 0, 1, 1]])

kernel = torch.tensor([[1, 2, 1],
                       [0, 1, 0],
                       [2, 1, 0]])

print(input.shape)
print(kernel.shape)
input = torch.reshape(input, (1,1,5,5))
kernel = torch.reshape(kernel, (1,1,3,3))
print(input.shape)
print(kernel.shape)

output = F.conv2d(input, kernel, stride=1)
print(output)

结果:

效果:

python 复制代码
import torch
import torch.nn.functional as F

input = torch.tensor([[1, 2, 0, 3, 1],
                      [0, 1, 2, 3, 1],
                      [1, 2, 1, 0, 0],
                      [5, 2, 3, 1, 1],
                      [2, 1, 0, 1, 1]])

kernel = torch.tensor([[1, 2, 1],
                       [0, 1, 0],
                       [2, 1, 0]])

print(input.shape)
print(kernel.shape)
input = torch.reshape(input, (1,1,5,5))
kernel = torch.reshape(kernel, (1,1,3,3))
print(input.shape)
print(kernel.shape)

output2 = F.conv2d(input, kernel, stride=2)  # 步伐为2
print(output2)

结果 :

python 复制代码
import torch
import torch.nn.functional as F

input = torch.tensor([[1, 2, 0, 3, 1],
                      [0, 1, 2, 3, 1],
                      [1, 2, 1, 0, 0],
                      [5, 2, 3, 1, 1],
                      [2, 1, 0, 1, 1]])

kernel = torch.tensor([[1, 2, 1],
                       [0, 1, 0],
                       [2, 1, 0]])

print(input.shape)
print(kernel.shape)
input = torch.reshape(input, (1,1,5,5))
kernel = torch.reshape(kernel, (1,1,3,3))
print(input.shape)
print(kernel.shape)

output3 = F.conv2d(input, kernel, stride=1, padding=1)  # 周围只填充一层
print(output3)

效果:

相关推荐
GIS数据转换器几秒前
基于低空巡检的空地一体智慧治理平台
大数据·人工智能·数据挖掘·数据分析·无人机
ar01232 分钟前
深度解析AR远程专家协助系统在工业4.0时代的变革力量
人工智能·ar
名不经传的养虾人3 分钟前
从0到1:企业级AI项目迭代日记 Vol.31|可视化、可编辑、可脱敏、可隔离——企业系统接管的四个“可”
人工智能·ai编程·ai工作流·企业ai
AI玫瑰助手4 分钟前
Python运算符:逻辑运算符(and/or/not)的短路特性
开发语言·python·信息可视化
是梦终空4 分钟前
计算机源码274—基于深度学习的中医舌象智能识别与健康管理系统(源代码+数据库+12000字论文)
人工智能·python·深度学习·opencv·django·vue·springboot
城事漫游Molly5 分钟前
AI 快速生成标准化问卷分析报告:从 SUS 到 UMUX-LITE,如何把“分数”写成“结论”
人工智能·算法·机器学习·论文笔记·科研统计·问卷设计
明志数科6 分钟前
具身智能数据标注工具对比评测:6大平台横向测评
开发语言·python
杨超越luckly8 分钟前
HTML应用指南:利用GET请求获取智己汽车门店位置信息
python·arcgis·html·汽车·数据可视化
程序猿阿伟8 分钟前
《OpenClaw Active Memory的智能遗忘与抽象机制》
人工智能