# 類神經網路踩坑紀錄
###### tags: `PyTorch` `Darknet`
> 紀錄PyTorch問題並解決
[TOC]
## :memo: RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_addmm
> Pytorch [color=#efc6c6]
> 這個問題通常表示開啟CUDA(torch.device("cuda:0")),但實際上卻還是用CPU在跑程式,解決辦法是在自定義model內使用到的函式加入.cuda()[color=#3b75c6]
```python=1
model = torch.nn.Sequential(
torch.nn.Linear(dim_in, hidden_dim).cuda(),
torch.nn.ReLU().cuda(),
torch.nn.Linear(hidden_dim, dim_out).cuda(),
)
```
## :memo: cuda_runtime.h: No such file or directory
> Darknet [color=#efc6c6]
> 此為archlinux下cuda安裝路徑為/opt,因此須手動新增軟連結[color=#3b75c6]
```bash
sudo ln -s /opt/cuda/ /usr/local/cuda
```
---
## Reference
- stackoverflow ➜ [Expected object of device type cuda but got device type cpu in Pytorch](https://stackoverflow.com/questions/58799486/expected-object-of-device-type-cuda-but-got-device-type-cpu-in-pytorch)
- github ➜ [Error on make: 'cuda_runtime.h: No such file or directory' #553](https://github.com/pjreddie/darknet/issues/553)