pytorch基本算子

permute

将tensor的维度换位。

nn.functional.unfold()

unfold的作用就是手动实现(卷积中)的滑动窗口操作,也就是只有卷,没有积

行数为4,即对应着2×2的滑动窗口大小;而每一列的元素为滑动窗口依次所覆盖的内容,一共滑动了16次,因此有16列。
https://blog.csdn.net/qq_40714949/article/details/112836897
 

torch.cat和torch.stack

torch.cat不增加维度
torch.stack增加维度

torch.split()和torch.chunk()

x = torch.rand(4,8,6)

y = torch.split(x,3,dim=0)  # 按照4这个维度去分,每大块包含3个小块
for i in y:
    print(i.size())
 
output:
torch.Size([3, 8, 6])
torch.Size([1, 8, 6])


区别:
(1)chunks只能是int型,而split_size_or_section可以是list。
(2)chunks在时,不满足该维度下的整除关系,会将块按照维度切分成1的结构。而split会报错。
https://blog.csdn.net/foneone/article/details/103875250
 

torch.range和torch.arange

总结:
1、torch.range(start=1, end=6) 的结果是会包含end的,而torch.arange(start=1, end=6)的结果并不包含end。
2、两者创建的tensor的类型也不一样。torch.range创建的是torch.float32,torch.arange创建的是torch.int64
https://blog.csdn.net/m0_37586991/article/details/88830026
 

reshape和view

.view()方法只能改变连续的(contiguous)张量,否则需要先调用.contiguous()方法,而.reshape()方法不受此限制;
https://www.cnblogs.com/sddai/p/14403333.html
 

torch.meshgrid()

h = 6
w = 10
ys,xs = torch.meshgrid(torch.arange(h), torch.arange(w))

>>> ys
tensor([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
        [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]])

>>> xs
tensor([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
https://www.jianshu.com/p/e1c8e51bc9b3
 

torch.mm, torch.mul, torch.matmul

一、点乘
可以用torch.mul(a, b)实现,也可以直接用*实现。

二、矩阵乘
矩阵相乘有torch.mm和torch.matmul两个函数。其中前一个是针对二维矩阵,后一个是高维。当torch.mm用于大于二维时将报错。
https://ofooo.github.io/wiki/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/pytorch/torch%E4%B9%98%E6%B3%95/

forward和__call__

当网络构建完之后,调__call__的时候,会去先调forward,即__call__其实是包了一层forward
https://blog.csdn.net/u013289254/article/details/103826591
 

grid_sample

 cuda插件
https://github.com/TrojanXu/onnxparser-trt-plugin-sample  (使用)
https://github.com/grimoire/amirstan_plugin/tree/master/src/plugin/gridSamplePlugin

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WX Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值