Overview

I have published an inference app using YOLOv8 at the following link:

https://huggingface.co/spaces/nakamura196/yolov8-ndl-layout

Initially, the following error occurred:

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.

This error was resolved by adding device as follows:

results = model.predict(img, device="cpu")

Details

I was using the following library:

https://github.com/fcakyon/ultralyticsplus

When using it as shown below, the error above occurred:

from ultralyticsplus import YOLO, render_result

# load model
model = YOLO("nakamura196/yolov8-ndl-layout")

img = 'https://dl.ndl.go.jp/api/iiif/2534020/T0000001/full/full/0/default.jpg'

results = model.predict(img)

Adding the argument as follows resolved the error:

results = model.predict(img, device="cpu")

Supplement

When using a local model as shown below, the error above did not occur even without device="cpu":

model = YOLO('./model_- 19 may 2024 15_13.pt')

Summary

I hope this serves as a useful reference.