![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pytorch
文章平均质量分 88
wzg2016
这个作者很懒,什么都没留下…
展开
-
torch.backends.cudnn.enabled = False会引起CUDA out of memory和CUDA error: an illegal memory access was
一般来说,题目所示这种问题都是由batch_size的设置引起的,修改batch_size之后就能有效解决。但是,我今天遇到一种情况,这个问题不是由batch_size引起的,而是由torch.backends.cudnn.enabled = False这个设置引起的。torch.backends.cudnn.enabled = False这个设置主要用于实验过程的可复现,具体的实验过程可复现代码设置如下:import numpy as npimport torc...原创 2021-10-20 18:39:52 · 7338 阅读 · 0 评论 -
pytorch: torch.nn.functional.affine_grid(theta,size)
# 仍有部分疑惑 torch.nn.functional.affine_grid(theta,size):给定一组仿射矩阵(theta),生成一个2d的流场.通常与 grid_sample() 结合使用,用于空间变换网络.参数: theta(Tensor 类型):输入的一组仿射矩阵(N*2*3) size(torch.Size 类型):要输出的图像的...原创 2018-10-21 20:50:08 · 5302 阅读 · 2 评论 -
Pytorch + LSTM
LSTM 原理图(图来源)LSTM原理解析(更多细节参考: LSTM详细介绍):class torch.nn.LSTMCell(input_size, hidden_size, num_of_layers,bias=True)在torch...原创 2018-10-21 22:57:20 · 2777 阅读 · 2 评论 -
pytorch 与 numpy 的相互转换
# -*- coding: utf-8 -*- # @Time : 2018/1/17 16:37 # @Author : Zhiwei Zhong # @Site : # @File : Numpy_Pytorch.py # @Software: PyCharm import torch import numpy as np np_data = np.arange(6).r...转载 2018-10-24 16:03:19 · 1068 阅读 · 0 评论 -
tensorboardX 介绍
初学tensorboardX 在pytorch中的使用,做一些笔记,以备忘。官方文档(github):https://github.com/lanpa/tensorboardX/blob/master/docs/tutorial.rst各种应用的综合demo:https://github.com/lanpa/tensorboardX比较详细的知乎介绍:https://zhuanlan....转载 2018-11-25 11:18:57 · 2409 阅读 · 0 评论 -
pytorch: MaxUnpool2d 与 Upsampling
Upsampling:上采样,被nn.functional.interpolate代替 nn.Upsampling is deprecated. Use nn.functional.interpolate instead. #-*-coding:utf-8-*-import torchimport torch.nn as nnimport numpy as np...原创 2019-01-05 16:01:47 · 8004 阅读 · 2 评论 -
tensorflow/pytorch 设置GPU的使用
os.environ[“CUDA_DEVICE_ORDER”] = “PCI_BUS_ID” # 按照PCI_BUS_ID顺序从0开始排列GPU设备os.environ[“CUDA_VISIBLE_DEVICES”] = “0” #设置当前使用的GPU设备仅为0号设备 设备名称为'/gpu:0'os.environ[“CUDA_VISIBLE_DEVICES”] = “1” #设置当前使用的...转载 2019-06-11 09:09:50 · 3167 阅读 · 0 评论 -
PyTorch常用代码段
转向:https://lonepatient.top/2018/12/30/pytorch-styleguide.html转载 2019-07-24 15:38:35 · 149 阅读 · 0 评论 -
PyTorch 中如何指定GPU
PyTorch默认使用从0开始的GPU,如果GPU0正在运行程序,需要指定其他GPU。有如下两种方法来指定需要使用的GPU。1. 类似tensorflow指定GPU的方式,使用CUDA_VISIBLE_DEVICES。1.1 直接终端中设定:CUDA_VISIBLE_DEVICES=1 python my_script.py1.2 python代码中设定:## 建议使用...转载 2019-07-20 20:56:17 · 2344 阅读 · 0 评论 -
pytorch 如何将张量、类实例、函数放到GPU上
调用“.cuda()”函数,将tensor从GPU中取回到CPU中,只需调用“.cpu()”即可直接看代码:import torchimport torch.nn as nnimport copyclass MyClass(nn.Module): def __init__(self,para1,para2): super(MyClass,self).__i...原创 2019-07-22 10:06:40 · 16071 阅读 · 3 评论 -
PyTorch学习:参数初始化
Sequential 模型的参数初始化import numpy as npimport torchfrom torch import nn# 定义一个 Sequential 模型net1 = nn.Sequential( nn.Linear(2, 4), #nn.Linear(2, 4) shape为(4,2) nn...转载 2019-07-23 10:26:42 · 336 阅读 · 0 评论 -
pytorch: Parameter 的数据结构
一般来说,pytorch 的Parameter是一个tensor,但是跟通常意义上的tensor有些不一样1)通常意义上的tensor 仅仅是数据2)而Parameter所对应的tensor 除了包含数据之外,还包含一个属性:requires_grad(=True/False) 在Parameter所对应的tensor中获取纯数据,可以通过以下操作: param_d...原创 2018-10-21 20:13:39 · 3115 阅读 · 0 评论 -
pytorch: nn.Sequential(func1,func2,func3)
function = nn.Sequential(func1,func2,func3) 生成的是一个列表,可分别通过function[0], function[1], function[2]来获取func1,func2,func3原创 2018-10-21 20:05:22 · 416 阅读 · 0 评论 -
pytorch: 网络层参数初始化
# Initialize the weights/bias with identity transformation self.fc_loc[2].weight.data.zero_() self.fc_loc[2].bias.data.copy_(torch.tensor([1, 0, 0, 0, 1, 0], dtype=torch.float))或者用apply函数执行批量初始化...原创 2018-10-21 19:56:06 · 1471 阅读 · 2 评论 -
Pytorch 学习笔记:
pytorch 0.4 相比0.3版本有了很大的变化,具体可参考以下链接https://blog.csdn.net/jacke121/article/details/80597759-----------------------------------------------------------------------w1.grad.zero_(): .zero_()的作用 在计算...原创 2018-10-19 17:39:06 · 306 阅读 · 0 评论 -
pytorch: 将一序列操作串联
参考: https://pytorch.org/tutorials/beginner/pytorch_with_examples.html#id23# Use the nn package to define our model as a sequence of layers.# nn.Sequential is a model which contains other Modules,a...原创 2018-10-19 17:41:17 · 848 阅读 · 0 评论 -
pytorch:定义自己的网络结构
参考:https://pytorch.org/tutorials/beginner/pytorch_with_examples.html#id23--pytorch : custom nn modules 模块Sometimes you will want to specify models that are more complex than a sequence of existing M...转载 2018-10-19 17:46:45 · 1511 阅读 · 0 评论 -
pytorch中调整学习率: torch.optim.lr_scheduler
文章翻译自:https://pytorch.org/docs/stable/optim.htmltorch.optim.lr_scheduler 中提供了基于多种epoch数目调整学习率的方法.torch.optim.lr_scheduler.ReduceLROnPlateau :允许基于一些验证测量对学习率进行动态的下降-------------------------------...翻译 2018-10-20 16:15:35 · 49171 阅读 · 2 评论 -
Pytorch 的迁移学习的理解
个人理解,迁移学习可以分为三类:第一类:以训练好的模型参数为基础,对所有参数进行继续优化. 即,先在别的训练数据集上训练模型,达到一定训练标准之后,用当前的数据集继续进行训练.第二类:将已经训练好的模型当作特征提取器,仅对模型中的部分层的参数进行优化(或继续优化). 此时,在加载模型后,需要通过对模型的所有参数的"requires_gra...原创 2018-10-20 17:32:27 · 1089 阅读 · 0 评论 -
pytorch 状态字典:state_dict
pytorch 中的 state_dict 是一个简单的python的字典对象,将每一层与它的对应参数建立映射关系.(如model的每一层的weights及偏置等等)(注意,只有那些参数可以训练的layer才会被保存到模型的state_dict中,如卷积层,线性层等等)优化器对象Optimizer也有一个state_dict,它包含了优化器的状态以及被使用的超参数(如lr, momentu...原创 2018-10-21 11:20:10 · 34111 阅读 · 8 评论 -
【干货】深度学习实验流程及PyTorch提供的解决方案
转载自:[干货]深度学习实验流程及PyTorch提供的解决方案【导读】近日,专知小组博士生huaiwen创作了一系列PyTorch实战教程,致力于介绍如何用PyTorch实践你的科研想法。今天推出其创作的第一篇《深度学习实验流程及PyTorch提供的解决方案》。在研究深度学习的过程中,当你脑中突然迸发出一个灵感,你是否发现没有趁手的工具可以快速实现你的想法?看完本文之后,你可能会多出一个选择。...转载 2018-10-28 23:38:34 · 731 阅读 · 0 评论 -
pytorch: torch.Tensor.view ------ reshape
torch.Tensoe.view(python method, in torch.Tensor)作用: 将输入的torch.Tensor改变形状(size)并返回.返回的Tensor与输入的Tensor必须有相同的元素,相同的元素数目,但形状可以不一样即,view起到的作用是reshape,view的参数的是改变后的shape.示例如下:>>> x = tor...原创 2018-10-21 11:30:31 · 6907 阅读 · 2 评论 -
torch.nn.Conv2d
class torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)参数:Conv2d( 输入channels, 输出channels, kernel_size,...原创 2018-10-21 11:41:57 · 5523 阅读 · 3 评论 -
torch.nn.Module.eval
torch.nn.Module.eval:Sets the module in evaluation mode.This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation ...原创 2018-10-21 12:23:11 · 1823 阅读 · 0 评论 -
torch.nn 介绍(部分)
翻译自:https://pytorch.org/docs/stable/nn.html?highlight=nn module#torch.nn.Moduleclass torch.nn.Parameter是Tensor的子类,被认为是一个模块的参数Parameters 是Tendor的子类,当与模块一起用时有特殊的属性--当它们被分配为一个模块的属性时,它们会被自动加入到模块的...翻译 2018-10-21 19:11:55 · 995 阅读 · 0 评论 -
pytorch 与numpy 部分操作的对应关系
pytorch号称神经网络界的numpy,确实非常好用,容易上手,自己在学习中总结了 pytorch 与numpy 的一些运算操作上的不同.np.dot(a,b) ==> torch.mm(a,b)np.maxmum(h,0) ==> h.clamp(min=0)np.square(x) ==> x.pow(2)y=x.copy() ==> y=x.c...原创 2018-10-18 12:18:44 · 2577 阅读 · 1 评论