Tensor高阶
高阶OP 主讲人:龙良曲 Tensor advanced operation https://blog.openai.com/generative-models/ ▪ Where ▪ Gather where example gather retrieve global label ▪ argmax(pred) to get relative labeling ▪ On some0 码力 | 8 页 | 501.85 KB | 1 年前3Tensor统计
0 码力 | 11 页 | 1.28 MB | 1 年前3创建Tensor
创建Tensor 主讲人:龙良曲 Import from numpy Import from List uninitialized ▪ Torch.empty() ▪ Torch.FloatTensor(d1, d2, d3) ▪ NOT torch.FloatTensor([1, 2]) = torch.tensor([1, 2]) ▪ Torch.IntTensr(d1, d2 arange/range linspace/logspace Ones/zeros/eye Ones/zeros/eye randperm ▪ random.shuffle 下一课时 Tensor切片 Thank You.0 码力 | 16 页 | 1.43 MB | 1 年前3PyTorch Release Notes
SDK accelerates widely-used deep learning frameworks such as PyTorch. PyTorch is a GPU-accelerated tensor computational framework with a Python front end. Functionality can be easily extended with common memory consumption of your model). Additionally, GEMMs and convolutions with FP16 inputs can run on Tensor Cores, which provide an 8X increase in computational throughput over FP32 arithmetic. APEX AMP is Mixed Precision Guide. Tensor Core Examples The tensor core examples provided in GitHub and NGC focus on achieving the best performance and convergence from NVIDIA Volta™ tensor cores by using the latest0 码力 | 365 页 | 2.94 MB | 1 年前3机器学习课程-温州大学-03深度学习-PyTorch入门
训练一个分类器 4 1.Tensors张量的概念 Tensor实际上就是一个多维数组(multidimensional array) 标量(0阶张量) 向量(1阶张量) 矩阵(2阶张量) 张量(大于等于3阶张量) 1.2 5 创建张量的几种方法 用现有数据创建张量,使用 torch.tensor() 如torch.tensor([[1., -1.], [1., -1.]]) 创建与其他张量具有相似类型但大小不同的张量,请使 用tensor.new_*创建操作。 1.Tensors张量的概念 6 查看张量的属性 查看Tensor类型 tensor1 = torch.randn(2,3) #形状为(2,3)一组从标准正态分布 中随机抽取的数据 tensor1.dtype # torch.float32 查看Tensor维度和形状 tensor1.shape #查看形状或尺寸 #查看形状或尺寸 tensor1.ndim #查看维度 查看Tensor是否存储在GPU上 tensor1.is_cuda 查看Tensor的梯度 tensor1.grad 1.Tensors张量的概念 7 Tensor在CPU和GPU之间转换,以及numpy之间的转换 CPU tensor转GPU tensor cpu_tensor.cuda() 0 码力 | 40 页 | 1.64 MB | 1 年前3【PyTorch深度学习-龙龙老师】-测试版202112
+ 4.0运算。PyTorch 实现代码如下: import torch # 导入 pytorch 库 # 1.创建输入张量,并赋初始值 a = torch.tensor(2.) b = torch.tensor(4.) # 2.直接计算,并打印结果 print('a+b=',a+b) 可以看到,计算过程非常简洁,没有多余的计算步骤,并且和 Python 语言的编程方式非常 autograd # 创建 4 个张量 a = torch.tensor(1.) b = torch.tensor(2.) 预览版202112 1.6 开发环境安装 17 c = torch.tensor(3.) # 需要求导的张量,要设置 requires_grad w = torch.tensor(4., requires_grad=True) # 构建计算过程 w + c # 求导 w_grad = autograd.grad(y, [w]) print('w_grad :', w_grad) 程序的运行结果为: w_grad : (tensor(10.),) 可以看到,PyTorch 自动求导的结果与手动计算的结果完全一致。 3) 常用神经网络接口 PyTorch 除了提供底层的矩阵相乘、加减等数学函数,还内建了常用神经网络运算函0 码力 | 439 页 | 29.91 MB | 1 年前3动手学深度学习 v2.0
如果没有某种方法来存储数据,那么获取数据是没有意 义的。 首先,我们介绍n维数组,也称为张量(tensor)。使用过Python中NumPy计算包的读者会对本部分很熟悉。 无论使用哪个深度学习框架,它的张量类(在MXNet中为ndarray,在PyTorch和TensorFlow中为Tensor)都 与Numpy的ndarray类似。但深度学习框架又比Numpy的ndarray多一些重要功能:首先,GPU很好地支持加 都称为张量的 元素(element)。例如,张量 x 中有 12 个 元素。除非额外指定,新的张量将存储在内存中,并采用基于CPU的计算。 x = torch.arange(12) x tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) 可以通过张量的shape属性来访问张量(沿每个轴的长度)的形状。 x.shape torch.Size([12]) 被看成一个3行4列 的矩阵。要重点说明一下,虽然张量的形状发生了改变,但其元素值并没有变。注意,通过改变张量的形状, 张量的大小不会改变。 X = x.reshape(3, 4) X tensor([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) 我们不需要通过手动指定每个维度来改变形状。也就是说,如果我们的目标形状是(高度,宽度),那么在0 码力 | 797 页 | 29.45 MB | 1 年前3TVM Meetup: Quantization
lower-precision INT8 numbers • Integer number stands as a proxy for FP32 number (not a downcast) • Quantized tensor is represented with a scale and a zero point http://on-demand.gputechconf.com/gtc/2017/presenta templates written in TVM Tensor IR .. More targets AutoTVM – Tuning the kernels Optimized Binary Codegen – LLVM, Cuda, C, … Framework Parsers Graph level optimizations Tensor-level optimizations Machine (%input_data: Tensor[(2, 5), float32]) { qnn.quantize(%input_data, out_dtype="uint8", output_zero_point=127, output_scale=0.5f) } def @main(%input_data: Tensor[(2, 5), float32]) -> Tensor[(2, 5), uint8]0 码力 | 19 页 | 489.50 KB | 5 月前3PyTorch OpenVINO 开发实战系列教程第一篇
式来创建与声明张量数据,一种是通过常量数值来直接声明为 tensor 数据,代码如下: a = torch.tensor([[2., 3.], [4., 5.]]) print(a, a.dtype) 运行结果 tensor([[2., 3.], [4., 5.]]) torch.float32 其中 torch.Tensor 是 torch.FloatTensor 的别名,所以默认的 flaot32,这点从 a.dtype 的打印结果上也得了印 证。此外 torch.Tensor 函数还支持从 Numpy 数组直接转换 为张量数据,这种定义声明张量数据的代码如下: b = torch.tensor(np.array([[1,2],[3,4],[5,6],[7, 8]])) print(b) 运行结果: tensor([[1, 2], [3, 4], = torch.zeros([2, 4], dtype=torch.float32) print(c) PyTorch + OpenVINO 开发实战系列教程 第一篇 7 运行结果: tensor([[0., 0., 0., 0.], [0., 0., 0., 0.]]) 初始化了一个两行四列值全部为零的数组。torch.zeros 表示 初始化全部为零,torch0 码力 | 13 页 | 5.99 MB | 1 年前3全连接神经网络实战. pytorch 版
介绍,因此没有必要赘述。 1.1 导入 pytorch 首先我们需要明白一个术语:tensor。这个词被翻译为中文叫张量。1 维标量是一种 tensor; 向量也是一种 tensor;而一些微分量,例如梯度、导数等也都是 tensor;矩阵也是张量;多张矩 阵或者多张图像也是张量(3 维张量)。我们在做实验时,可以将 tensor 理解为是“data”。 我们需要先导入 pytorch,顺便导入 numpy: [ 3 , 4 ] ] data_tensor = torch . tensor ( data1 ) print ( data_tensor . shape ) np_array1 = np . array ( data1 ) data_tensor = torch . from_numpy( np_array1 ) print ( data_tensor . shape ) 输出都是: Size ( [ 2 , 2 ] ) 对于二维 tensor 之间的相乘,@ 和 .matmul 函数表示矩阵相乘;∗ 和 .mul 表示矩阵元素之 间相乘: 6 Chapter 1. 准备章节 7 y = data_tensor @ data_tensor .T print (y) y = data_tensor ∗ data_tensor print (y) 输出分别是: [ [0 码力 | 29 页 | 1.40 MB | 1 年前3
共 180 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18