執行時報錯RuntimeError: expected device cpu but got device cuda:0
最近在執行pytorch程式碼時發現的該錯誤,不管是 expected cpu 還是 expected cuda, 本質原因都是型別不匹配。
一般是因為:
- 等號左邊和右邊型別不一樣
- 運算子左右兩端型別不同,例:+ - * /
- 同一個函式內,傳入引數的型別不同,例matmul等
你要考慮你的大環境是在什麼上面部署的,CPU 還是 CUDA,然後再出錯位置嘗試修改資料.
->cuda : data.cuda()
->cpu: data.cpu()
->numpy:注意cuda型別不能直接轉numpy 須先轉成Cpu型別,data.cpu().numpy()
注意在CUDA下訓練中的資料不能直接轉換為numpy,data.cpu().detach().numpy()
承接Matlab、Python和C++的程式設計,機器學習、計算機視覺的理論實現及輔導,本科和碩士的均可,鹹魚交易,專業回答請走知乎,詳談請聯絡QQ號757160542,非誠勿擾。
相關文章
- 【踩坑】RuntimeError: CUDA error: device-side assert triggeredErrordevIDE
- CUDA VISIBLE DEVICEdev
- As 除錯 no target device found除錯dev
- 電腦開機時報錯No Bootable Device找不到索引的解決方法bootdev索引
- CUDA程式設計(4.1)—— 宣告符(global、device、host等)程式設計dev
- inconsistent datatypes: expected - got CLOB錯誤一例Go
- wrap devicedev
- device dirverdev
- platform devicePlatformdev
- raw devicedev
- [Linux] device eth0 does not seem to presentLinuxdev
- “pseudo-device: devinfo0″ for solaris 10dev
- PyTorch出現錯誤“RuntimeError: Found dtype Double but expected Float”PyTorchError
- linux 執行shell 報錯stty: standard input: Inappropriate ioctl for device解決LinuxAPPdev
- yii執行phpunit時報錯PHP
- device-mapper create ioctl failed: Device or resource busydevAPPAI
- device eth0 does not seem to be present, delaying initializationdev
- No space left on devicedev
- 模擬LINUX磁碟分割槽有可用空間無可用Inodes時報錯:No space left on deviceLinuxdev
- 獨顯接顯示器報錯提示:Mouse0: cannot open input devicedev
- matplotlib使用時報錯RuntimeError: Python is not installed as a framework(一)ErrorPythonFramework
- Multipath and Device MapperdevAPP
- raw device, first blockdevBloC
- about raw device[zt]dev
- nmap報錯: Failed to open device ethxxxAIdev
- CentOS Linux解決Device eth0 does not seem to be presentCentOSLinuxdev
- RAC-device eth0 does not seem to be present, delaying initializationdev
- virtualbox虛擬機器遷移出現"connot find device eth0"錯誤虛擬機dev
- Bringing up interface eth0: Device eth0 does not seem to be present ,delayindev
- android: ADB錯誤“more than one device and emulator”Androiddev
- Running the app on your deviceAPPdev
- How to mount usb device in CentOS?devCentOS
- Raw Device vs File Systemdev
- vmware克隆linux出現Device eth0 does not seem to be presentLinuxdev
- 執行dbca時報錯:Xlib:No protocol specifiedProtocol
- Flutter常見問題-Error retrieving device properties for ro.product.cpu.abiFlutterErrordev
- CUDA執行模式模式
- yolov5 train報錯:TypeError: expected np.ndarray (got numpy.ndarray)YOLOAIErrorGo