Pytorch中的tensor又包括CPU上的数据类型和GPU上的数据类型,一般GPU上的Tensor是CPU上的Tensor加cuda()函数得到。

一般系统默认是torch.FloatTensor类型。例如data = torch.Tensor(2,3)是一个2*3的张量,类型为FloatTensor;

data.cuda()就转换为GPU的张量类型,torch.cuda.FloatTensor类型。

if cuda:
dtype = torch.cuda.FloatTensor
else:
if torch.cuda.is_available():
print("WARNING: You have a CUDA device, so you should probably set cuda=True")
dtype = torch.FloatTensor

torch.cuda.FloatTensor的更多相关文章

  1. one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3, 1280, 28, 28]], which is output 0 of LeakyReluBackward1, is at version 2;

    RuntimeError: one of the variables needed for gradient computation has been modified by an inplace o ...

  2. [报错]-RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same

    RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be ...

  3. 常见错误 RuntimeError: expected type torch.FloatTensor but got torch.cuda.FloatTensor

    https://www.jianshu.com/p/0be7a375bdbe https://blog.csdn.net/qq_38410428/article/details/82973895 计算 ...

  4. pytorch torch.Stroage();torch.cuda()

    转自:https://ptorch.com/news/52.html torch.Storage是单个数据类型的连续的一维数组,每个torch.Tensor都具有相同数据类型的相应存储.他是torch ...

  5. 【FAQ】P3. 为什么 torch.cuda.is_available() 是 False

    为什么 torch.cuda.is_available() 是 False torch.cuda.is_available(),这个指令的作用是看,你电脑的 GPU 能否被 PyTorch 调用. 如 ...

  6. pytorch,cuda8,torch.cuda.is_available return flase (ubuntu14)

    因为ubuntu 系统是14.0的,安装pytorch1.0的时候,本身已经安装好了cuda8,在验证gpu的时候,torch.cuda.is_available()返回false 安装命令是: co ...

  7. PyTorch官方中文文档:torch.Tensor

    torch.Tensor torch.Tensor是一种包含单一数据类型元素的多维矩阵. Torch定义了七种CPU tensor类型和八种GPU tensor类型: Data tyoe CPU te ...

  8. Pytorch基本变量类型FloatTensor与Variable

    pytorch中基本的变量类型当属FloatTensor(以下都用floattensor),而Variable(以下都用variable)是floattensor的封装,除了包含floattensor ...

  9. torch.Tensor文档学习笔记

    A torch.Tensor is a multi-dimensional matrix containing elements of a single data type. 张量(torch.Ten ...

随机推荐

  1. 十四 Spring的AOP的基于AspectJ的注解开发

    Spring的AOP的基于AspectJ的注解开发 创建项目,引入jar包 编写目标类.切面类 配置目标类.切面类 在注解文件里开启AOP的开发 <?xml version="1.0& ...

  2. 十五 链表与递归,leetCode203题

    两种方式: package com.lt.datastructure.LinkedList; /** * leetCode 203题 * /** * Definition for singly-lin ...

  3. js面试代码中的“坑”

    1.typeof 对类型的判断 (function() { return typeof arguments; } )(); 答案:"Object" 解释:arguments是一个伪 ...

  4. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:元素浮动到右边

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. mathematica练习程序(第一章 Mathematica的基本量)

    虽然过去有用Mathematica解过一些问题,不过对这个语言并没有系统学习过. 所以最近想重新把Mathematica系统的学一遍. 偶然在B站上找到了这样一组教程:https://www.bili ...

  6. 2_01_MSSQL课程_查询

    查询 1.查询结果的别名 列 as 别名 (建议用这种) 列 别名 别名=列 Select sum(score1) as 成绩1,sum(score2)as  成绩2 from talScore 2. ...

  7. Python学习第一课——if-else

    #if 基本语句 if 1==1: print("如果条件为真,if执行该语句") else: print("如果条件为假,if则执行这条语句") #if 多重 ...

  8. 导弹拦截p1020(LIS问题)

    题目描述(题目链接:https://www.luogu.org/problem/P1020) 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够 ...

  9. Day2-M-Prime Ring Problem-HDU1016

    A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle ...

  10. 攻防世界--web新手练习区(1)

      1. 题目描述:X老师想让小明同学查看一个网页的源代码,但小明却发现鼠标右键不管用了.  http://111.198.29.45:53629 通过阅读题目描述分析,我们需要查看源码,但是鼠标右键 ...