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 ...
随机推荐
- CentOS 6.7 hadoop free版本Spark 1.6安装与使用
最近的工作主要围绕文本分类,当前的解决方案是用R语言清洗数据,用tm包生成bag of words,用libsvm与liblinear训练模型.这个方案可以hold住6/70万的训练集: LIBLIN ...
- Comparison Theorem in Riemannian geometry
Given $p\in M$, locally, there exists a diffemorphism of $T_M$ and $B_r(p)\subset$, this is the most ...
- c++基础: uint8_t uint16_t uint32_t uint64_t size_t ssize_t数据类型
https://blog.csdn.net/lzx_bupt/article/details/7066577 在nesc的代码中,你会看到很多你不认识的数据类型,比如uint8_t等.咋一看,好像是个 ...
- GuzzleHttp示例
一般请求 $httpClient = new Client([ 'timeout' => 5 ]); $request = $httpClient->post("http://l ...
- 记下HTML中图片的路径
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 < ...
- python manage.py loaddata dumpdata 用于导出和导入数据库中的数据
1.数据导出python manage.py dumpdata python manage.py dumpdata [appname] > appname_data.json 指定appna ...
- 通过if 简单判断奇数偶数
方法一 方法二 方法三 通过取反的方式进行 其实这三个方法都差别不大都可以用
- ASP.NET WebAPI 单元测试-UnitTest
xUnit.Net
- 【JVM】学习JVM垃圾回收理论
参考链接:https://www.cnblogs.com/aspirant/p/8662690.html 一,垃圾回收算法 JVM内存结构:程序计数器.虚拟机栈.本地方法栈.堆区.方法区 1,引用计数 ...
- Docker 查看某一时间段日志
语法: docker logs [OPTIONS] CONTAINER Options: --details 显示更多的信息 -f, --follow 跟踪实时日志 --since string 显示 ...