Tensor高阶## PyTorch ## 高阶OP 主讲人:龙良曲 ## Tensor advanced operation ## Where ## Gather ## where torch.where(condition, x, y) → Tensor Return a tensor of elements selected from either x or y, depending on condition ☐ ☐ ☐ 1 In [198]: cond 2 tensor([[0.6769, 0.7271], 3 [0.8884, 0.4163]]) 4 5 In [199]: a 6 tensor([[0., 0.], 7 [0., 0.]]) 8 9 In [200]: b 10 tensor([[1., 1.], 11 14 Out[203]: 15 tensor([[0., 0.], 16 [0., 1.]]) ## gather torch.gather(input, dim, index, out=None) → Tensor Gathers values along an axis specified by dim. For a 3-D tensor the output is0 码力 | 8 页 | 501.85 KB | 2 年前3
Tensor统计[105]: b=a.view(2,4) In [106]: c=a.view(2,2,2) In [107]: b tensor([[1., 1., 1., 1.], [1., 1., 1., 1.]]) In [108]: c tensor([[1., 1.], [1., 1.]], [[1 c.norm(1) Out[109]: (tensor(8.), tensor(8.)) In [110]: a.norm(2), b.norm(2), c.norm(2)) Out[110]: (tensor(2.8284), tensor(2.8284)) In [111]: b.norm(1, dim=1) Out[111]: tensor([4., 4.]) In [112]: b b.norm(2, dim=1) Out[112]: tensor([2., 2.]) In [113]: c.norm(1, dim=0) tensor([[2., 2.], [2., 2.]]) In [114]: c.norm(2, dim=0) tensor([[1.4142, 1.4142], [1.4142,0 码力 | 11 页 | 1.28 MB | 2 年前3
创建Tensor## PyTorch ## 创建Tensor 主讲人:龙良曲 ## I mport from numpy ## ● ● ● 1 In [62]: a=np.array([2,3.3]) 3 In [63]: torch.from_numpy(a) 4 Out[63]: tensor([2.0000, 3.3000], dtype=torch.float64) 6 In [65]: a=np from_numpy(a) 8 Out[66]: 9 tensor([[1., 1., 1.], 10 [1., 1., 1.]], dtype=torch.float64) ## I mport from List ## ● ● ● 1 In [67]: torch.tensor([2., 3.2]) 2 Out[67]: tensor([2.0000, 3.2000]) 4 In [68]: [68]: torch.FloatTensor([2., 3.2]) 5 Out[68]: tensor([2.0000, 3.2000]) 7 In [69]: torch.tensor([[2., 3.2], [1., 8.0], 8.0], 8.0]) 9 tensor([[ 2.0000, 3.2000], 10 [ 1.0000, 22.3000] ) ## uninitialized0 码力 | 16 页 | 1.43 MB | 2 年前3
深度学习与PyTorch入门实战 - 08. 索引与切片In [138]: a[0,0].shape 7 Out[138]: torch.Size([28, 28]) 8 9 In [139]: a[0,0,2,4] 10 Out[139]: tensor(0.8082) ## select first/last N ## ☀️ ☁️ ☁️ 1 In [140]: a.shape 2 Out[140]: torch.Size([4, 3, 28 4) 2 tensor([[ -1.3911, -0.7871, -1.6558, -0.2542], 3 [-0.9011, 0.5404, -0.6612, 0.3917], 4 [-0.3854, 0.2968, 0.6040, 1.5771]]) 6 In [172]: mask = x.ge(0.5) 7 tensor([[0 Out[174]: tensor([0.5404, 0.6040, 1.5771]) 13 14 In [175]: torch.masked_select(x, mask).shape 15 Out[175]: torch.Size([3]) ## select by flatten index ## ● 5 In [177]: torch.take(src, torch.tensor([0, 20 码力 | 10 页 | 883.44 KB | 2 年前3
深度学习与PyTorch入门实战 - 06. 基本数据类型## PyTorch ## 基本数据类型 主讲人:龙良曲 ## All is about Tensor |python|PyTorch| |---|---| |Int|IntTensor of size()| |float|FloatTensor of size()| |Int array|IntTensor of size \[d1, d2, ...]| |Float array|FloatTensor One - hot [0, 1, 0, 0, ...] Embedding Word2vec glove ## Data type |Data type|dtype|CPU tensor|GPU tensor| |---|---|---|---| |32-bit floating point|torch.float32 or torch.float|torch.FloatTensor|torch 3) 3 In [6]: a.type() 4 Out[6]: 'torch.FloatTensor' 6 In [7]: type(a) 7 Out[7]: torch.Tensor 9 In [8]: isinstance(a, torch.FloatTensor) 10 Out[8]: True ## ☐ ☐ ☐ 1 In [21]: isinstance(data0 码力 | 16 页 | 1.09 MB | 2 年前3
【PyTorch深度学习-龙龙老师】-测试版2021124.3 待优化张量 4.4 创建张量 4.5 张量的典型应用 4.6 索引与切片 4.7 维度变换 4.8 Broadcasting 4.9 数学运算 4.10 前向传播实战 4.11 参考文献 第5章 PyTorch进阶 5.1 合并与分割 5.2 数据统计 5.3 张量比较 5.4 填充与复制 作为对比,现在介绍动态图方式来完成 $ 2.0 + 4.0 $ 运算。PyTorch 实现代码如下: import torch # 导入 pytorch 库 # 1. 创建输入张量,并赋初始值 a = torch.tensor(2.) b = torch.tensor(4.) # 2. 直接计算,并打印结果 print('a+b=', a+b) 可以看到,计算过程非常简洁,没有多余的计算步骤,并且和 Python # 导入梯度计算函数 from torch import autograd # 创建 4 个张量 a = torch.tensor(1.) b = torch.tensor(2.) c = torch.tensor(3.) # 需要求导的张量,要设置 requires_grad w = torch.tensor(4., requires_grad=True) # 构建计算过程 y = a * w**20 码力 | 439 页 | 29.91 MB | 2 年前3
机器学习课程-温州大学-03深度学习-PyTorch入门Tensors张量 02 Autograd自动求导 03 神经网络 04 训练一个分类器 ### 1. Tensors张量 ## 01 Tensors张量 02 Autograd自动求导 03 神经网络 04 训练一个分类器 ### 1. Tensors张量的概念 Tensor实际上就是一个多维数组(multidimensional array)标量(0阶张量) 向量(1阶张量) 向量(1阶张量) 1.2 矩阵(2阶张量)  张量(大于等于3阶张量)  ### ### 1. Tensors张量的概念 ## • 创建张量的几种方法 - 用现有数据创建张量,使用 torch.tensor() • 如torch.tensor([[1., -1.], [1., -1.]]) - 要创建具有特定大小的张量,请使用torch.* • 如torch.randn() # 满足标准正态分布的一组随机数据 - 创建与另一个张量具有相同大小的张量,请使用 torch.*_like0 码力 | 40 页 | 1.64 MB | 2 年前3
Keras: 基于 Python 的深度学习库VGG16 提取特征 159 13.2.3 从 VGG19 的任意中间层中抽取特征 159 13.2.4 在新类上微调 InceptionV3 160 13.2.5 通过自定义输入 tensor 构建 InceptionV3 161 13.3 模型概览 162 13.3.1 Xception 162 13.3.2 VGG16 163 13.3.3 VGG19 164 13 cd keras sudo python setup.py install ### 1.5 使用 TensorFlow 以外的后端 默认情况下,Keras 将使用 TensorFlow 作为其张量操作库。请跟随这些指引来配置其他 Keras 后端。 ### 1.6 技术支持 你可以提出问题并参与开发讨论: • Keras Google group. • Keras Slack cha size=(20, 1)), num_classes=10) model = Sequential() # 输入: 3 通道 100x100 像素图像 -> (100, 100, 3) 张量。 # 使用 32 个大小为 3x3 的卷积滤波器。 model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(1000 码力 | 257 页 | 1.19 MB | 2 年前3
PyTorch OpenVINO 开发实战系列教程第一篇1.3 Pytorch 基础术语与概念.....4 1.4 Pytorch 基础操作.....5 1.4.1 PyCharm 的安装与配置.....5 1.4.2 张量定义与声明.....6 1.4.3 张量操作.....7 1.5 线性回归预测.....9 1.5.1 线性回归过程.....9 1.5.2 线性回归代码演示.....9 1.6 小结.....11 ## 中编程模式主要是基于计算图、张量数据、自动微分、优化器等组件构成。面向对象编程运行的结果是交互式可视化的,而深度学习通过训练模型生成模型文件,然后再使用模型预测,本质数据流图的方式工作。所以学习深度学习首先必须厘清深度学习编程中计算图、张量数据、自动微分、优化器这些基本术语概念,下面分别解释如下: ## 张量 张量是深度学习编程框架中需要理解最重要的一个概念,张量的本质是数据,在深度学习框架中 一切的数据都可以看成张量。深度学习中的计算图是以张量数据为输入,通过算子运算,实现对整个计算图参数的评估优化。但是到底什么是张量?可以看下面这张图:  标量  4.2 带参数的层 ..... 207 5.5 读写文件 ..... 208 5.5.1 加载和保存张量 ..... 208 5.5.2 加载和保存模型参数 ..... 209 5.6 GPU ..... 211 5.6.1 计算设备 ..... 212 5.6.2 张量与GPU ..... 213 5.6.3 神经网络与GPU ..... 215 卷积神经网络 .. 节,这些的细节通常会被深度学习框架的高级抽象隐藏起来。特别是在基础教程中,我们希望读者了解在给定层或优化器中发生的一切。在这些情况下,我们通常会提供两个版本的示例:一个是我们从零开始实现一切,仅依赖张量操作和自动微分;另一个是更实际的示例,我们使用深度学习框架的高级API编写简洁的代码。一旦我们教了您一些组件是如何工作的,我们就可以在随后的教程中使用高级API了。 ## 内容和结构 全书大致可0 码力 | 797 页 | 29.45 MB | 2 年前3
共 296 条
- 1
- 2
- 3
- 4
- 5
- 6
- 30













