pytorch函数测试
pytorch函数测试
- 1、函数测试
- 1.1、测试 .sum(dim=(m,n))
- 1.2、测试.sum(dim=-1)
主要针对不知道函数结果的操作进行测试
1、函数测试
1.1、测试 .sum(dim=(m,n))
f = torch.arange(4 * 5 * 6).view(1,1, 4, 5, 6)
f.shape
Out[19]: torch.Size([1, 1, 4, 5, 6])
f
Out[20]:
tensor([[[[[ 0, 1, 2, 3, 4, 5],[ 6, 7, 8, 9, 10, 11],[ 12, 13, 14, 15, 16, 17],[ 18, 19, 20, 21, 22, 23],[ 24, 25, 26, 27, 28, 29]],[[ 30, 31, 32, 33, 34, 35],[ 36, 37, 38, 39, 40, 41],[ 42, 43, 44, 45, 46, 47],[ 48, 49, 50, 51, 52, 53],[ 54, 55, 56, 57, 58, 59]],[[ 60, 61, 62, 63, 64, 65],[ 66, 67, 68, 69, 70, 71],[ 72, 73, 74, 75, 76, 77],[ 78, 79, 80, 81, 82, 83],[ 84, 85, 86, 87, 88, 89]],[[ 90, 91, 92, 93, 94, 95],[ 96, 97, 98, 99, 100, 101],[102, 103, 104, 105, 106, 107],[108, 109, 110, 111, 112, 113],[114, 115, 116, 117, 118, 119]]]]])
g = torch.arange(6).view(1,1, 1, 1, 6)
g.shape
Out[22]: torch.Size([1, 1, 1, 1, 6])
g
Out[23]: tensor([[[[[0, 1, 2, 3, 4, 5]]]]])
k = f*g
k.shape
Out[25]: torch.Size([1, 1, 4, 5, 6])
k
Out[26]:
tensor([[[[[ 0, 1, 4, 9, 16, 25],[ 0, 7, 16, 27, 40, 55],[ 0, 13, 28, 45, 64, 85],[ 0, 19, 40, 63, 88, 115],[ 0, 25, 52, 81, 112, 145]],[[ 0, 31, 64, 99, 136, 175],[ 0, 37, 76, 117, 160, 205],[ 0, 43, 88, 135, 184, 235],[ 0, 49, 100, 153, 208, 265],[ 0, 55, 112, 171, 232, 295]],[[ 0, 61, 124, 189, 256, 325],[ 0, 67, 136, 207, 280, 355],[ 0, 73, 148, 225, 304, 385],[ 0, 79, 160, 243, 328, 415],[ 0, 85, 172, 261, 352, 445]],[[ 0, 91, 184, 279, 376, 475],[ 0, 97, 196, 297, 400, 505],[ 0, 103, 208, 315, 424, 535],[ 0, 109, 220, 333, 448, 565],[ 0, 115, 232, 351, 472, 595]]]]])n = k.sum(dim=(2,3))
n.shape
Out[31]: torch.Size([1, 1, 6])
n
Out[32]: tensor([[[ 0, 1160, 2360, 3600, 4880, 6200]]])
1.2、测试.sum(dim=-1)
程序接上面程序执行
所以dim取值就是要消除的维度,dim取-1就是要消除最后一个维度。
对于上面的有5个维度的矩阵,维度索引 0,1,2,3,4。
先执行消除维度2,3,保留的维度0,1,4,然后再执行消除维度-1,即消除维度4,则剩下的维度是0,1.
o = n.sum(dim=-1)
o.shape
Out[34]: torch.Size([1, 1])
o
Out[35]: tensor([[18200]])
pytorch函数测试相关推荐
- pytorch 函数clamp
pytorch 函数clamp clamp表示夹紧,夹住的意思,torch.clamp(input,min,max,out=None)-> Tensor 将input中的元素限制在[min,ma ...
- pytorch方法测试——卷积(二维)
pytorch方法测试--卷积(二维) 测试代码: import torch import torch.nn as nnm = nn.Conv2d(2, 2, 3, stride=2) input = ...
- 经典笔试题:用C写一个函数测试当前机器大小端模式
"用C语言写一个函数测试当前机器的大小端模式"是一个经典的笔试题,如下使用两种方式进行解答: 1. 用union来测试机器的大小端 1 #include <stdio.h&g ...
- Boost:用成员函数测试bind <void>
Boost:用成员函数测试bind 实现功能 C++实现代码 实现功能 boost::bind模块,用成员函数测试bind C++实现代码 #include <boost/config.hpp& ...
- wnoise matlab,MATLAB中用wnoise函数测试去噪算法
MATLAB中用wnoise函数测试去噪算法 sqrt_snr=3; init=231434; [x,xn]=wnoise(3,11,sqrt_snr,init); % WNOISE generate ...
- PyTorch安装测试训练建自己的数据集
Pytorch安装测试训练建自己的数据集 前言 一.PyTorch是什么? 二.PyTorch环境搭建 1.设备要求 2.安装Pytorch 3.验证PyTorch 二.CIFAR10测试 1.关于C ...
- 深入浅出Pytorch函数——torch.zeros
分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出Pytorch函数--torch.Tensor · 深入浅出Pytorch函数--torch.ones · 深入浅出 ...
- 深入浅出Pytorch函数——torch.arange
分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.range · 深入浅出Pytorch函数--torch.arange · 深入 ...
- 深入浅出Pytorch函数——torch.zeros_like
分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出Pytorch函数--torch.Tensor · 深入浅出Pytorch函数--torch.ones · 深入浅出 ...
- Pytorch函数expand()详解
Pytorch函数 .expand( ) 其将单个维度扩大成更大维度,返回一个新的tensor,具体看下例: import torcha = torch.Tensor([[1], [2], [3],[ ...
最新文章
- Azure正式对外发布容器服务,支持Swarm和Mesos
- java操作XML文件--读取内容
- 动态加载___import__动态加载技术
- Serilog 日志框架如何自动删除超过 N 天的日志 ?
- 搜索引擎关键词劫持之php篇(源码与分析)
- 基于python和opencv的人脸识别
- 使用一个for循环将N*N的二维数组的所有值置1
- oracle修改用户密码
- Android 资源(Resources)访问
- 计算机网络路由计算,计算机网络中的多播路由算法
- 七.项目管理基础知识
- 计算机桌面墙纸更换,电脑系统教程:win7桌面壁纸怎么换
- 2020强网杯部分题总结与复现
- 日积(Running)月累(ZSSURE):Learning How to Learn,学习习惯
- 2023最新猕猴桃影视系统源码/影视APP源码+安卓/苹果双端
- Matlab图片预处理——截取图片中有效部分保存在其余文件夹下
- shell一键安装lnmp
- 前端学习资料网址汇总
- 炫舞时代显示服务器出错,qq炫舞2各种常见bug大全 FAQ详解
- 淘宝/天猫如何获取sku API接口,item_sku - 获取sku详细信息