can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
predict=predict.data.numpy() 这一行报错
意思是:如果想把CUDA tensor格式的数据改成numpy时
,需要先将其转换成cpu float-tensor随后再转到numpy格式。
numpy不能读取CUDA tensor 需要将它转化为 CPU tensor
将predict.data.numpy() 改为predict.data.cpu().numpy()即可
转 https://blog.csdn.net/qq_38410428/article/details/82973711
can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.的更多相关文章
- TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
报错原因:numpy不能读取CUDA tensor 需要将它转化为 CPU tensor. 所以如果想把CUDA tensor格式的数据改成numpy时,需要先将其转换成cpu float-tenso ...
- TypeError: Fetch argument 0.484375 has invalid type <class 'numpy.float32'>, must be a string or Tensor. (Can not convert a float32 into a Tensor or Operation.)
报错: TypeError: Fetch argument 0.484375 has invalid type <class 'numpy.float32'>, must be a str ...
- has invalid type <class 'numpy.ndarray'>, must be a string or Tensor
转自: https://blog.csdn.net/jacke121/article/details/78833922 has invalid type <class 'numpy.ndarra ...
- pytorch tensor与numpy转换
从官网拷贝过来的,就是做个学习记录.版本 0.4 tensor to numpy a = torch.ones(5) print(a) 输出 tensor([1., 1., 1., 1., 1.]) ...
- pytorch_13_pytorch 中tensor,numpy,PIL的转换
PIL:使用Python自带图像处理库读取出来的图片格式numpy:使用Python-opencv库读取出来的图片格式tensor:pytorch中训练时所采取的向量格式 import torch i ...
- torch.Tensor和numpy.ndarray
1. torch.Tensor和numpy.ndarray相互转换 import torch import numpy as np # <class 'numpy.ndarray'> np ...
- typeError:The value of a feed cannot be a tf.Tensor object.Acceptable feed values include Python scalars,strings,lists.numpy ndarrays,or TensorHandles.For reference.the tensor object was Tensor...
如上贴出了:错误信息和错误代码. 这个问题困扰了自己两天,报错大概是说输入的数据和接受的格式不一样,不能作为tensor. 后来问了大神,原因出在tf.reshape(),因为网络训练时用placeh ...
- Pytorch中的variable, tensor与numpy相互转化的方法
1.将numpy矩阵转换为Tensor张量 sub_ts = torch.from_numpy(sub_img) #sub_img为numpy类型 2.将Tensor张量转化为numpy矩阵 sub_ ...
- 「Python」Convert map object to numpy array in python 3
转自Stackoverflow.备忘用. Question In Python 2 I could do the following: import numpy as np f = lambda x: ...
- CUDA[2] Hello,World
Section 0:Hello,World 这次我们亲自尝试一下如何用粗(CU)大(DA)写程序 CUDA最新版本是7.5,然而即使是最新版本也不兼容VS2015 ...推荐使用VS2012 进入VS ...
随机推荐
- mybatis_01 初运行
maven坐标 <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</ ...
- 修改 Ubuntu 的软件源
1.将 /etc/apt/ 路径下的 sources.list 的内容修改为如下内容(此内容为 Ubuntu Kylin 里面的内容,直接拿过来用,也可以用其它的国内的源). deb http://m ...
- vue3 深度选择器 scss用法
使用 :deep() 替换 ::v-deep .carousel { // Vue 2.0 写法 // ::v-deep .carousel-btn.prev { // left: 270px; // ...
- python的GIL全局解释器锁
global interpreter lock -- 全局解释器锁 CPython 解释器所采用的一种机制,它确保同一时刻只有一个线程在执行 Python bytecode.此机制通过设置对象模型(包 ...
- Vue源码主体分析
vue的响应式和react的函数式编程思想是很不同的. vue最基本的原理是对getter和setter的代理模式.以及观察者模式. 当数据发生变化时,通知观察者. 而watcher是通过触发数据的g ...
- python获取当前运行函数名
两种方式: #!/usr/bin/env python3#coding:utf-8 import sys, inspectdef test_a(): print('func name: ', sys. ...
- chklist
1. 重复检查的必要性.一段代码如果在测试期间没问题,也要间隔几天再去观察是否有问题.2. 如果是集群式的服务,使用定时任务要采用分布式锁,或使用工具随机发送一台都可以.3. 如果任务跑失败,需要支持 ...
- Rest-Assured:发送PATCH请求:更新Hello-imook(java.lang.IllegalArgumentException: Invalid number of path parameters. Expected 2, was 0. Undefined path parameters are: owner, repo.)
代码: /* * 发送PATCH请求:更新Hello-imook */ @Test public void test003_PatchMethod() { S ...
- JDBC之Statement
Statement 目录 Statement Statement Statement概述 要执行的SQL分为两类 查询 增删改 Statement继承体系 SQL注入问题 SQL注入问题解决 获取得到 ...
- c#获取当前进程使用内存
public static string GetMemory() { Process proc = Process.GetCurrentProcess(); ...