
PyTorch
gy笨瓜
这个作者很懒,什么都没留下…
展开
-
pytorch和numpy默认浮点类型位数
numpy中默认浮点类型为64位,pytorch中默认浮点类型位32位测试代码如下 numpy版本:1.19.2 pytorch版本:1.2.0In [1]: import torchIn [2]: import numpy as np# 版本信息In [3]: "pytorch ve原创 2021-02-10 17:45:00 · 3655 阅读 · 0 评论 -
PyTorch基础——torch.nn.CrossEntropyLoss交叉熵损失
torch.nnCrossEntropyLosss使用的公式loss(x,class)=−log(exp(x[class]∑exp(x[j]))loss(x,class)=-log(\frac {exp(x[class]} {\sum exp(x[j])})loss(x,class)=−log(∑exp(x[j])exp(x[class])原创 2020-12-13 11:40:47 · 4763 阅读 · 2 评论 -
PyTorch——torch.randn()创建正态分布随机数
torch.randn(*size)从均值为0,方差为1的正态分布中获取随机数【sample】In [1]: import torchIn [2]: torch.randn(3)Out[2]: tensor([1.7896, 0.7974, 0.7416])In [3]: torch.randn(2,3)Out[3]: tensor([[ 0.4030, -0.3138, -0.7579], [-0.1486, 1.0306, 0.0734]])In [4]: torch.原创 2020-12-01 22:52:29 · 4471 阅读 · 0 评论 -
PyTorch基础——使用pytorch加载cifar10数据集
使用torchvision.datasets模块可以加载cifar10数据集,涉及函数为torchvision.datasets.CIFAR10(root, train, download)root: cifar10数据集存放目录train: True,表示加载训练数据集,False,表示加载验证数据集download: True,表示cifar10数据集在root指定的文件夹不存在时,会自动下载,False,表示不管root指定文件夹是否存在cifar10数据集,都不会自动下载cifar10数据集原创 2020-11-29 21:58:10 · 3818 阅读 · 0 评论 -
PyTorch基础——torch.Tensor.permute(...)和torch.transpose(...)
torch.permute可以进行多个维度的交换,而torch.transpose只能进行两个维度的交换In [1]: dat = torch.tensor( [[[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]], [[13, 14, 15, 16], [17, 18, 19,原创 2020-11-27 23:49:55 · 548 阅读 · 0 评论 -
PyTorch基础——torch.gather
torch.gather(input, dim, index)函数:根据指定的索引在某一tensor取出对应元素示例:dat = torch.tensor([[1, 2, 3, 4],  原创 2020-11-27 23:28:41 · 433 阅读 · 1 评论 -
PyTorch torch.Tensor相关操作
1. tensor维度: torch.Tensor.ndimension()In [1]: import torchIn [2]: dat = torch.tensor([[1,2,3]])In [3]: dat.ndimension()Out[3]: 2原创 2020-11-25 23:17:00 · 234 阅读 · 0 评论 -
pytorch判断某一变量是否为torch.Tensor类型
使用函数为torch.is_tensor(…)In [1]: import torchIn [2]: dat = 10 In [4]: dat = torch.tensor([[1,2,3]])In [3]: torch.is_tensor(dat) In [5]: torch.is_tensor(dat)Out[3]: False Out[5]: True原创 2020-11-25 23:12:13 · 11911 阅读 · 0 评论 -
阅读Deep Learning with PyTorch相关缩略词
缩写英文名称NLLnegative log likelihoodMSEmean square error原创 2020-11-16 22:07:40 · 125 阅读 · 0 评论 -
⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)阅读Deep Learning With PyTorch学习到的新单词(✿◡‿◡)
1. intricate 错综复杂的2. under-performing 表现不佳3. a context with nuance and a fair bit of heft to it 一个带有细微差别和相当重要的背景___(1)nuance 细微差别 (2) a fair bit of 相当一部分 (3) heft 重(量);重要(性)4. eye-catching 引入注目5. implied hyperbole 含蓄夸张6. be akin to 类似于7. haystack 干草堆原创 2020-11-14 00:57:59 · 834 阅读 · 0 评论 -
PyTorch基础——PyTorch常用模块及相关类
常用模块import torchimport torch.nn as nnimport torch.optim as optimimport torch.cuda as cudafrom torch.utils.data import Datasetfrom torch.utils.data import DataLoaderfrom torch.utils.tensorboard import SummaryWriterfrom torchvision import datas原创 2020-11-14 00:12:23 · 1337 阅读 · 0 评论 -
PyTorch基础——阅读Deep Learning with PyTorch学习到一些概念
weightThe weight tells us how much a given input influences the output.weight告诉我们输入对输出的影响程度。biasThe bias is what the output would be if all inputs were zero.bias表示当所有输入为0时的输出值。摘抄自:Eli Stevens, Luca Antiga, Thomas Viehmann. Deep Learning with PyTorch.原创 2020-11-12 23:33:34 · 250 阅读 · 0 评论 -
PyTorch基础——输入image各维度含义
2D:N×C×H×W2D: N \times C \times H \times W2D:N×C×H×WN−number of samples\qquad N-number \;of \;samplesN−numberofsamplesC−channels per sample\qquad C - channels \;per \;sampleC−channelspersampleH−height\qquad H-heightH−heightW−width\qquad W-widthW−wi原创 2020-11-07 00:28:59 · 5483 阅读 · 0 评论 -
PyTorch基础——torch.nn.Conv2d中自定义权重
torch.nn.Conv2d函数调用后会自动初始化weight和bias,本章主要涉及如何自定义weight和bias为需要的数均分布类型: torch.nn.Conv2d.weight.data以及torch.nn.Conv2d.bias.data为torch.tensor类型,因此只要对这两个属性进行操作即可。【sample】以input_channels = 2, output_channels = 1 为例In [1]: import torchIn [2]原创 2020-10-25 11:40:01 · 16153 阅读 · 1 评论 -
PyTorch基础——torch.nn.Conv2d中groups参数
torch.nn.Conv2d:对输入的二维图像进行卷积运算# 函数声明:torch.nn.Conv2d( in_channels = in_channels, out_channels = out_channels, kernel_size = kernel_size, stride = 1, padding =原创 2020-10-20 23:16:25 · 2598 阅读 · 2 评论 -
PyTorch基础——torch.nn.BatchNorm2d
torch.nn>batchNorm2d:对输入batch进行batch normalize以2 x 3 x 4 x 5输入为例,其中2:batch中样本数量3:每个样本通道数4:每个样本行数5:每个样本列数第一个样本:3(通道) x 4(行) x 5(列) 141 138 143 144 145 138 135 ..原创 2020-10-17 11:59:07 · 9569 阅读 · 3 评论 -
PyTorch基础——二维卷积时的卷积核以及输入tensor的shape
以3通道100行200列的一幅图像img为例,期望输出16通道卷积特征,卷积核为3行3列,则(1)函数调用: conv =nn.Conv2d(3, 16, 3) out = conv(img)其中,nn.Conv2d函数中 第一个参数表示输入图像的通道数 第二个参数表示输出图像的通道数 第三个参数表示卷积核尺寸,行列相等时可直接缩写为一个数(2)卷积核的shape: out_channels x ...原创 2020-10-13 22:55:02 · 2450 阅读 · 0 评论 -
PyTorch基础——输入batch第0维含义
根据Deep Learning with PyTorch英文原版Chapter 6 Using 啊neural network to fit the data (Page 154)中:To accommodate multiple samples, modules expect the zeroth dimension of the input to be the number of samples in the batch.PyToch中输入batch第0维一般为样本数量。...原创 2020-10-12 23:47:33 · 2430 阅读 · 0 评论 -
Pytorch基础——torch.randperm
torch.randperm(n):将0~n-1(包括0和n-1)随机打乱后获得的数字序列,函数名是random permutation缩小【sample】 torch.randperm(10)===> tensor([2, 3, 6, 7, 8, 9, 1, 5, 0, 4])原创 2020-10-12 23:37:26 · 33694 阅读 · 0 评论 -
PyTorch基础——one hot编码转换
主要使用函数:torch.Tensor.scatter_(.....)【sample】将[1, 5, 4, 2]转换为one hot编码,形式如下:[[0, 1, 0, 0, 0, 0],[0, 0, 0, 0, 0, 1],[0, 0, 0, 0, 1, 0],[0, 0, 1, 0, 0, 0]],其中每一行表示一个样本函数调用:torch.zeros(4, 6).scatter_(1, torch.tensor([1,5,4,2]).unsqueeze(1), 1)说明...原创 2020-10-12 23:21:28 · 4299 阅读 · 0 评论 -
PyTorch基础——均值、(无偏估计)方差
import torch dat = torch.Tensor([1,2,3])# 1.求均值dat_mean = torch.mean(dat) # => dat_mean = tensor(2.)# 2.求方差dat_var1 = torch.var(dat) # => dat_var1 = tensor(1.),对应于无偏估计dat_var2 = torch.var(dat, unbiased=False) # => dat_v.原创 2020-10-10 23:46:59 · 11816 阅读 · 1 评论