使用Yolo檢測(cè)圖像時(shí)指定了device=0報(bào)錯(cuò):
Ultralytics YOLOv8.1.34 ?? Python-3.9.19 torch-2.0.1+cpu
Traceback (most recent call last):
File "E:\python-project\yolov10\test.py", line 6, in <module>
result = model.track(source=source, show=True, device=0)
File "E:\python-project\yolov10\ultralytics\engine\model.py", line 481, in track
return self.predict(source=source, stream=stream, **kwargs)
File "E:\python-project\yolov10\ultralytics\engine\model.py", line 434, in predict
self.predictor.setup_model(model=self.model, verbose=is_cli)
File "E:\python-project\yolov10\ultralytics\engine\predictor.py", line 299, in setup_model
device=select_device(self.args.device, verbose=verbose),
File "E:\python-project\yolov10\ultralytics\utils\torch_utils.py", line 128, in select_device
raise ValueError(
ValueError: Invalid CUDA 'device=0' requested. Use 'device=cpu' or pass valid CUDA device(s) if available, i.e. 'device=0' or 'device=0,1,2,3' for Multi-GPU.
torch.cuda.is_available(): False
torch.cuda.device_count(): 0
os.environ['CUDA_VISIBLE_DEVICES']: None
See https://pytorch.org/get-started/locally/ for up-to-date torch install instructions if no CUDA devices are seen by torch.
從錯(cuò)誤來看是使用了cpu版本的torch贤牛,從官方倉庫內(nèi)我看是存在GPU版本的torch,后面發(fā)現(xiàn)是我使用了清華源進(jìn)行加速鹉梨,而清華源上面只找到cpu的版本婴程,所以去掉清華源重新安裝即可!
這是原來我手動(dòng)指定清華源:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple
去掉清華源重新安裝即可:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121