@yumetsu5151 (yu a)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

ランタイムエラーの解決方法

解決したいこと

google colaboratoryを使用しています。
https://colab.research.google.com/gist/hkwsdgeattt2/5474618a5f354d44dc44e52cacb14e59/yolov7_human-pose-estimation.ipynb
このプログラムをそのまま使用しようとしていたのですが、ランタイムエラーとなってしまいます。

発生している問題・エラー

RuntimeError                              Traceback (most recent call last)
<ipython-input-10-e63a24435863> in <cell line: 2>()
      1 device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
----> 2 weigths = torch.load('yolov7-w6-pose.pt')
      3 model = weigths['model']
      4 model = model.half().to(device)
      5 _ = model.eval()

6 frames
/usr/local/lib/python3.10/dist-packages/torch/serialization.py in validate_cuda_device(location)
    256 
    257     if not torch.cuda.is_available():
--> 258         raise RuntimeError('Attempting to deserialize object on a CUDA '
    259                            'device but torch.cuda.is_available() is False. '
    260                            'If you are running on a CPU-only machine, '

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

該当するソースコード

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
weigths = torch.load('yolov7-w6-pose.pt')
model = weigths['model']
model = model.half().to(device)
_ = model.eval(
0 likes

2Answer

以下のエラー文をグーグルで検索しましょう。

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

0Like

質問者さんの環境(OSや使用しているグラボ(GPU))が不明ですが、
メッセージが示す通り、torch.cuda.is_available()がFalseを返すことが原因では?

0Like

Your answer might help someone💌