当前位置:网站首页>can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to host memory
can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to host memory
2022-07-28 22:52:00 【Meteor shower ADI】
Source code :
# Training curve
result1 = [100 - i['train'] for i in statistics]
result2 = [100 - i['valid'] for i in statistics]
plt.figure(figsize = (10, 7))
plt.plot(result1, label = 'Training')
plt.plot(result2, label = 'Validation')
plt.xlabel('Step')
plt.ylabel('Error Rate')
plt.legend()Error message :


The wrong content is unable to draw normally , This error message is the same as the one above .cpu() In the same , But the solution is slightly different , I found many ways on the Internet , But no suitable solution has been found , Most of the Internet is talking about adding .cpu(), But as far as this drawing program is concerned , Unable to find a suitable addition .cpu() The place of . The reason is , Still don't really understand the meaning of the program .
First, print the traversed statistics, Look at what's in it .

Pictured above , You can find statistic Itself is a list , And the elements inside are indeed dictionaries , In the dictionary train,valid The corresponding value yes torch Of tensor, That's why there are mistakes .
Change it as follows :
# Training curve
result1 = [100 - i['train'].cpu() for i in statistics]
result2 = [100 - i['valid'].cpu() for i in statistics]
plt.figure(figsize = (10, 7))
plt.plot(result1, label = 'Training')
plt.plot(result2, label = 'Validation')
plt.xlabel('Step')
plt.ylabel('Error Rate')
plt.legend()stay i['train'] and i['valid'] Add .cpu(), Click run again , You can run the program normally .

边栏推荐
- Yolov5 improvement 5: improve the feature fusion network panet to bifpn
- 轮子七:TCP客户端
- 希捷发布全新RISC-V架构处理器:机械硬盘相关性能暴涨3倍
- cannot resize variables that require grad
- Solve various problems of sudo rosdep init and rosdep update
- PC side special effects - animation function
- Simple es highlight practice
- PHP库neo4j怎么安装及使用
- Intelligent control -- fuzzy mathematics and control
- STM32 - Basic timer (tim6, tim7) working process, interpretation function block diagram, timing analysis, cycle calculation
猜你喜欢
![Padim [anomaly detection: embedded based]](/img/11/834d8b4fdd39959a9dd380e179d317.png)
Padim [anomaly detection: embedded based]

LTE cell search process and sch/bch design

无代码开发平台管理后台入门教程

Gd32f303 firmware library development (10) -- dual ADC polling mode scanning multiple channels

Intelligent control -- fuzzy mathematics and control
![Mspba [anomaly detection: representation_based]](/img/95/1f7390ec024a2865acb9e9a41100b1.png)
Mspba [anomaly detection: representation_based]
![[3D target detection] 3dssd (II)](/img/8a/e8927cd868eb99d8880d4f199d8918.png)
[3D target detection] 3dssd (II)

Vscode ROS configuration GDB debugging error record

OSV_ q AttributeError: ‘numpy. ndarray‘ object has no attribute ‘clone‘

es个人整理的相关面试题
随机推荐
轮子七:TCP客户端
Differernet [anomaly detection: normalizing flow]
歌尔股份与上海泰矽微达成长期合作协议!专用SoC共促TWS耳机发展
Lenovo r9000p installation matlab2018a+cuda10.0 compilation
Console.log() console display... Solution
JVM -- custom class loader
Improvement 17 of yolov5: cnn+transformer -- integrating bottleneck transformers
Summary of recent bugs
STM32 - Basic timer (tim6, tim7) working process, interpretation function block diagram, timing analysis, cycle calculation
STM32 - memory, I2C protocol
Use PCL to batch convert point cloud.Bin files to.Pcd
Leetcode exercise 3 - palindromes
STM32_ Hal library driven framework
776. String shift inclusion problem
Yolov5 improvement 15: network lightweight method deep separable convolution
STM32 - advanced control timer (time base unit, functional block diagram, input, capture, output, open circuit)
Shell script foundation - shell operation principle + variable and array definitions
Es personal arrangement of relevant interview questions
es个人整理的相关面试题
es学习目录