list直接转tensor,这种的可能会慢:

import torch
pick=[1,2,3,4]
bbb=torch.tensor(pick, dtype=torch.long)
print(bbb)

numpy转化的比较快

import cv2
import torch
import timeimg = cv2.imread('d:/nv.jpg')
start=time.time()
# tensor = torch.Tensor(img)
tensor= torch.from_numpy(img)print("cost time",time.time()-start,tensor.shape)

如果数据维度没有对齐,会报错:

import cv2
import torch
import timestart=time.time()data_a=[[1,2,3],[2,3,4],[1]]data_b=torch.Tensor(data_a)print("cost time",time.time()-start,data_b.shape)

异常:

Traceback (most recent call last):

File "E:/github/YOLOv3_PyTorch/common/__init__.py", line 4, in     b=torch.Tensor(a) ValueError: expected sequence of length 3 at dim 1 (got 1)

解决方&

list转torch tensor相关推荐

  1. PyTorch 笔记(02)— 常用创建 Tensor 方法(torch.Tensor、ones、zeros、eye、arange、linspace、rand、randn、new)

    1. Tensor 概念分类 PyTorch 中的张量(Tensor)类似 NumPy 中的 ndarrays,之所以称之为 Tensor 的另一个原因是它可以运行在 GPU 中,以加速运算. 1.1 ...

  2. pytorch中的torch.tensor.repeat以及torch.tensor.expand用法

    文章目录 torch.tensor.expand torch.tensor.repeat torch.tensor.expand 先看招 import torch x = torch.tensor([ ...

  3. 通俗讲解Pytorch梯度的相关问题:计算图、torch.no_grad、zero_grad、detach和backward;Variable、Parameter和torch.tensor

    文章目录 with torch.no_grad()和requires_grad backward() Variable,Parameter和torch.tensor() zero_grad() 计算图 ...

  4. Unable to get repr for<class‘torch.Tensor‘>

    Unable to get repr for <class 'torch.Tensor'> tensor越界访问后就会变成这样. import torcha_data=torch.Tens ...

  5. unable to get repr for class ‘torch.tensor‘

    unable to get repr for class 'torch.tensor' 出错代码: batch_conf.gather(1, conf_t.view(-1,1)) 最近码代码使用pyt ...

  6. torch.Tensor和torch.tensor的区别

    torch.Tensor和torch.tensor的区别 2019-06-10 16:34:48 Vic_Hao 阅读数 4058更多 分类专栏: Pytorch 在Pytorch中,Tensor和t ...

  7. c++ 打印 torch tensor

    目录 c++ 打印 torch tensor cuda cu代码中打印: tensorflow::Tensor打印: 打印tensorrt cuda值: c++ 打印 torch tensor for ...

  8. torch tensor用法

    1.x = torch.Tensor(5):zero() Tensor转int: int(x1.cpu().data) range与arange区别: if __name__ == '__main__ ...

  9. pytorch torch.Tensor.numpy()(从张量创建一个numpy数组,数组和张量共享相同内存)

    https://pytorch.org/docs/1.1.0/tensors.html?highlight=numpy#torch.Tensor.numpy numpy() → numpy.ndarr ...

最新文章

  1. android地图遮罩,Android 实现遮罩
  2. mysql5.6怎么配置_MySQL 5.6和5.7怎么进行最优配置的方法
  3. android 安装 apk 7.0,android 7.0及以上版本安装apk
  4. RHEL7OSP-6.0的openstack云主机发放
  5. 5年没有工资收入,他如何支撑世界上最大的免费编程社区?
  6. PetShop 4.0 系列之五 [转]
  7. AbilitySlice之间的传递值
  8. SVG.js 基础图形绘制整理(二)
  9. WPF笔记(1.1 WPF基础)——Hello,WPF!
  10. c++thread里暂停线程_多线程技术
  11. sqlrelay mysql_SQLrelay数据库负载均衡
  12. py导入包异常跳出_Python:尝试从导入的包导入模块时出现“ModuleNotFoundError”
  13. Pandas to_datetime
  14. 如何调试神经网络参数
  15. 香港推广“绿色年宵” 呼吁商贩和市民惜物减废
  16. c语言文件读不同格式,c语言文件的读写格式
  17. python能干什么知乎-python能做什么知乎
  18. 幼儿抽象逻辑思维举例_3-6岁,抓住幼儿思维发展关键期,培养孩子逻辑思维能力...
  19. 基于WinPcap的网络流量在线分析系统的设计与实现
  20. ppt 形状 文字不居中 怎么办

热门文章

  1. OpenStack配置keystone报错HTTP500
  2. python如何调用字典_如何访问python字典里的值?(实例解析)
  3. 算法 - 折半查找(C#)
  4. mysql安装到最后报错_mysql 安装到最后一步时,start service 为失败状态
  5. tox.ConfigError: ConfigError: substitution key 'posargs' not found
  6. 2004年c语言试题2,C语言试题(2004~2005第2学期)A重修
  7. phpeditor编写php_在php中使用CKEDITOR在线编辑器
  8. 1102示波器使用方法_使用示波器进行故障诊断的方法(1):常见传感器波形分析-汽车用品行业...
  9. dram和nand哪个难生产_DRAM与NAND差别这么大,存储之争都争啥?-嵌入式系统-与非网...
  10. 有些人一眼就能认出来,你认出来几个?