当前位置: 首页 > news >正文

学习pytorch8 土堆说卷积操作

土堆说卷积操作

    • 官网
    • debug torch版本只有nn 没有nn.functional
    • 代码
    • 执行结果

B站小土堆视频学习笔记

官网

https://pytorch.org/docs/stable/nn.html#convolution-layers

常用torch.nn, nn是对nn.functional的封装,使函数更易用。
在这里插入图片描述
在这里插入图片描述
卷积核从输入图像左上角,先向右遍历行,stride为1 挪一个格位置,向右遍历完,向下一格,再从左向右遍历。
卷积核和输入图像对应位置相乘后结果想加,得到右边的输出结果。
stride
在这里插入图片描述

padding
在这里插入图片描述

debug torch版本只有nn 没有nn.functional

 conda activate pytorchconda install pytorch-cpu torchvision-cpu -c pytorch

在当前环境安装pytorch-cpu后,functional函数就可以调用啦

https://www.saoniuhuo.com/question/detail-2646442.html

代码

import torch
from torch.nn import functional as Finput = 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]])input = torch.reshape(input, [1, 1, 5, 5])
kernel = torch.reshape(kernel, [1, 1, 3, 3])
print(input.shape)
print(kernel.shape)
output1 = F.conv2d(input, kernel, stride=1)
print(output1)output2 = F.conv2d(input, kernel, stride=2)
print(output2)
# 默认padding=0
output3 = F.conv2d(input, kernel, stride=1, padding=1)
print(output3)

执行结果

p14_conv.py
torch.Size([1, 1, 5, 5])
torch.Size([1, 1, 3, 3])
tensor([[[[10, 12, 12],[18, 16, 16],[13,  9,  3]]]])
tensor([[[[10, 12],[13,  3]]]])
tensor([[[[ 1,  3,  4, 10,  8],[ 5, 10, 12, 12,  6],[ 7, 18, 16, 16,  8],[11, 13,  9,  3,  4],[14, 13,  9,  7,  4]]]])Process finished with exit code 0
http://www.lryc.cn/news/152792.html

相关文章:

  • pytest自动化测试两种执行环境切换的解决方案
  • 说说TIME_WAIT和CLOSE_WAIT区别
  • Docker的优势
  • C++——string使用
  • 10. selenium API (二)
  • [国产MCU]-W801开发实例-用户报文协议(UDP)数据接收和发送
  • JavaScript 生成 16: 9 宽高比
  • HTML5之drawImage函数
  • leetcode7.整数反转-Java
  • 操作系统备考学习 day2 (1.3.2 - 1.6)
  • Django-跨域
  • wireshark抓包体验
  • Prometheus+grafana安装配置
  • 长连接和短连接有什么区别?
  • Qt应用开发(基础篇)——输入对话框 QInputDialog
  • C++ struct 笔记(超级详细)
  • Vue基础1:生命周期汇总(vue2)
  • Linux串口驱动
  • java反编译工具jd-gui使用
  • Linux 之 shell 脚本
  • 如何去阅读开源的第三方库的源码
  • 浅析Linux虚拟网络技术
  • 设计模式之九:迭代器与组合模式
  • 官方推荐:6种Pandas读取Excel的方法
  • Redis与Mysql区别
  • Black-Box Tuning for Language-Model-as-a-Service
  • 通用的ARM64架构镜像
  • git大文件推送报错
  • RDMA性能优化经验浅谈
  • day 44 | ● 309.最佳买卖股票时机含冷冻期 ● 714.买卖股票的最佳时机含手续费