TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory
项目场景:
运行程序,出现报错信息 TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
。
Traceback (most recent call last):File "tools/demo.py", line 97, in <module>visualize_result(gallery_img, detections, similarities)File "tools/demo.py", line 41, in visualize_result(x1, y1), x2 - x1, y2 - y1, fill=False, edgecolor="#4CAF50", linewidth=3.5File "/environment/miniconda3/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 2358, in add_patchself._update_patch_limits(p)File "/environment/miniconda3/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 2381, in _update_patch_limitspatch_trf = patch.get_transform()File "/environment/miniconda3/lib/python3.7/site-packages/matplotlib/patches.py", line 278, in get_transformreturn self.get_patch_transform() + artist.Artist.get_transform(self)File "/environment/miniconda3/lib/python3.7/site-packages/matplotlib/patches.py", line 752, in get_patch_transformbbox = self.get_bbox()File "/environment/miniconda3/lib/python3.7/site-packages/matplotlib/patches.py", line 845, in get_bboxreturn transforms.Bbox.from_extents(x0, y0, x1, y1)File "/environment/miniconda3/lib/python3.7/site-packages/matplotlib/transforms.py", line 839, in from_extentsbbox = Bbox(np.reshape(args, (2, 2)))File "<__array_function__ internals>", line 6, in reshapeFile "/home/featurize/work/.local/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 298, in reshapereturn _wrapfunc(a, 'reshape', newshape, order=order)File "/home/featurize/work/.local/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 54, in _wrapfuncreturn _wrapit(obj, method, *args, **kwds)File "/home/featurize/work/.local/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 43, in _wrapitresult = getattr(asarray(obj), method)(*args, **kwds)File "/home/featurize/work/.local/lib/python3.7/site-packages/torch/tensor.py", line 458, in __array__return self.numpy()
TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
问题描述
这个问题是由 python 3.7 版本引起的。修改部分 python 源码即可。
根据报错信息,定位到 /home/featurize/work/.local/lib/python3.7/site-packages/torch/tensor.py
解决方案:
将 self.numpy() 改成 self.cpu().numpy(),即找到 tensor.py 的第 458 行
def __array__(self, dtype=None):if dtype is None:return self.numpy()else:return self.numpy().astype(dtype, copy=False)
改成
TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory相关推荐
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
问题描述: Traceback (most recent call last):File "D:\rotation-yolov5-master\detect.py", line 1 ...
- Pycharm中运行yolov5-pytorch出现错误“TypeError: can‘t convert cuda:0 device type tensor to numpy....“
具体错误如下: TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the te ...
- 2021-07-26 TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the
can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. 意思是:如果 ...
- pytorch:tensor与numpy转换 .cpu.numpy()和.numpy() torch.from_numpy VS torch.Tensor
1.tensor to numpy 1.1代码 .numpy() import torch a0 = torch.ones(6) print(a0) 运行结果: tensor([1., 1., 1., ...
- can‘t convert cuda:0 device type tensor to numpy
can't convert cuda:0 device type tensor to numpy x是list,list内容是tensor cuda 代码: x = np.array(x) 则会报错: ...
- TypeError: Can not convert a float32 into a Tensor or Operation.
错误 TypeError: Can not convert a float32 into a Tensor or Operation. # 类型错误:不能将一个浮动32转换为一个张量或操作.TypeE ...
- PyTorch 安装和基本运算— Tensor 的数据类型(浮点型、整型、随机浮点型等)、基本运算(绝对值、求和、裁剪、求商、求积、求幂等)、Tensor 与 Numpy 转换
PyTorch 的安装可以到官网 https://pytorch.org/,选择适合自己机器以及安装方式,执行对应的命令即可. 除了安装 PyTorch 之外,建议也安装 torchvision 包. ...
- ValueError: cannot convert to ‘int64‘-dtype NumPy array with missing values. Specify an appropriate
ValueError: cannot convert to 'int64'-dtype NumPy array with missing values. Specify an appropriate ...
- has invalid type class 'numpy.ndarray', must be a string or Tensor
has invalid type <class 'numpy.ndarray'>, must be a string or Tensor. (Can not convert a ndarr ...
最新文章
- mysql统计不及格科目_SQL语句 统计各个学生的不及格科目数量及不及格率 ,2条语句...
- 今天试了一下iscroll
- YUV常用的两种保存方式_YUY2和YV12
- Mac os下android studio模拟器无法联网解决方法
- PyCharm运行出现 Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run
- 和思科Boss四年后重逢
- pyspark连接SQLServer数据库,执行SQL语句,返回数据查询结果
- 常用名词理解(APK,SDK,JDK,API,DLL)
- Android使用BottomNavigationView+NavigationUI报错
- 华为微认证华为云计算服务实践稳过 笔记资料
- python根须系统斜杠_尝试在Win10系统搭建esp32编译系统.下
- PandoraBox潘多拉多线多播
- 【微信】一、微信开发环境
- [Windows][VC]开机自动启动程序的几种方法
- DM单机包含集群搭建
- ABS系统的Simulink仿真
- Python线程详解
- 使用codesense的GJB 8114模板对c++源代码规则检测示例
- Docker部署onlyoffice并完成20最大连接数破解
- 工业控制系统安全需求的变化
热门文章
- python编写程序 计算1_《Python程序设计》——第1章 计算与问题求解简介 1.1 计算与Python简介-阿里云开发者社区...
- 黑客零基础入门:手把手带你实现简单的QQ/邮件攻击,注册表/系统安全防护,学不会请给我只因木马
- 13. JS jQuery
- 如何设计神经网络结构图,神经网络设计与实现
- 博通收购 VMware 计划受阻,英国监管机构介入
- KVM虚拟化技术(三)之克隆虚拟机
- 谷歌收购摩托罗拉移动引思:封闭是移动互联趋同之路
- 你自己写春联吗?你会贴春联吗?还是毛笔墨水早就不见了?
- Python机器学习bug:ValueError_ Expected 2D array, got 1D array instead
- doraemon的python 函数与装饰器(哎呀,忘记传了)