執行時報錯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
- As 除錯 no target device found除錯dev
- CUDA程式設計(4.1)—— 宣告符(global、device、host等)程式設計dev
- PVE安裝Windows 95報錯 while initializing device IOSWindowsWhiledeviOS
- 電腦開機時報錯No Bootable Device找不到索引的解決方法bootdev索引
- Android studio virtual Device 啟動失敗時某個報錯解決方案Androiddev
- PyTorch出現錯誤“RuntimeError: Found dtype Double but expected Float”PyTorchError
- yolov5 train報錯:TypeError: expected np.ndarray (got numpy.ndarray)YOLOAIErrorGo
- flutter開發提示Flutter device daemon #1報錯解決方法Flutterdev
- vue報錯:[Vue warn]: Invalid prop: type check failed for prop "value". Expected Number, got String....VueAIGo
- matplotlib使用時報錯RuntimeError: Python is not installed as a framework(一)ErrorPythonFramework
- mumu模擬器 adb shell 登入後執行命令 Inappropriate ioctl for deviceAPPdev
- 翻譯:Linux and the Device TreeLinuxdev
- kubernetes container device interface (CDI)AIdev
- Waiting for target device to come onlineAIdev
- Flutter常見問題-Error retrieving device properties for ro.product.cpu.abiFlutterErrordev
- Apache啟動報錯No space left on device: AH00023該怎麼解決Apachedev
- yii執行phpunit時報錯PHP
- 解決Mac M晶片 Wireshark 執行rvictl -s 後,出現Starting device failedMac晶片devAI
- iOS Device ID 的前世今生iOSdev
- XDS: Cross-Device Scripting AttacksROSdev
- gpg: signing failed: Inappropriate ioctl for deviceAIAPPdev
- SciTech-OS-Linux-Device Driver: 英文原版電子書“Linux Device Drivers, Third Edition”Linuxdev
- win10系統連線蘋果裝置提示Apple Mobile Device USB Composite Device驅動程式錯誤怎麼辦Win10蘋果APPdev
- 淺談 iOS Device ID 的修改iOSdev
- Android Studio: /dev/kvm device permission deniedAndroiddev
- Error: Connection activation failed: Device not managed by NetworkManagerErrorAIdev
- Structure of Linux Kernel Device Driver(Part II)StructLinuxdev
- 簡述CUDA執行緒及求CUDA中執行緒索引執行緒索引
- pytorch執行錯誤:RuntimeError: a leaf Variable that requires grad is being used in an in-place operationPyTorchErrorUI
- VMware - 與 Device/Credential Guard 不相容dev
- The following instances are in the device manifest but not specified in framework compatibility matrix:devFramework
- [Linux Device Driver] wifi adb 使用方法LinuxdevWiFi
- 沒有磁碟空間 No space left on devicedev
- Oka Mirror for Any Device快速入門教程dev
- python用pyinstaller生成exe時報錯 TypeError: an integer is required (got type bytes)PythonErrorUIGo
- TensorFlow 報錯 CUDA driver version is insufficient for CUDA runtime version
- Androidstudio除錯真機提示-Device supports,but APK only supports armeabi rmeabi-v7aAndroid除錯devAPK