本文主要是介绍FileNotFoundError: C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\000490.jpg does not exist,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题描述:在运行YOLOV8的predict.py,出现找不到图片的问题。
具体错误如下所示:
Traceback (most recent call last):File "C:/Users/aoqia/Desktop/ultralytics-main/ultralytics/yolo/v8/detect/predict.py", line 101, in <module>predict()File "C:/Users/aoqia/Desktop/ultralytics-main/ultralytics/yolo/v8/detect/predict.py", line 97, in predictpredictor.predict_cli()File "C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\yolo\engine\predictor.py", line 119, in predict_clifor _ in gen: # running CLI inference without accumulating any outputs (do not modify)File "C:\Users\aoqia\anaconda3\envs\pytorch\lib\site-packages\torch\autograd\grad_mode.py", line 44, in generator_contextresponse = gen.send(None)File "C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\yolo\engine\predictor.py", line 146, in stream_inferenceself.setup_source(source if source is not None else self.args.source)File "C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\yolo\engine\predictor.py", line 128, in setup_sourceself.dataset = load_inference_source(source=source,File "C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\yolo\data\build.py", line 186, in load_inference_sourcedataset = LoadImages(source,File "C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\yolo\data\dataloaders\stream_loaders.py", line 188, in __init__raise FileNotFoundError(f'{p} does not exist')
FileNotFoundError: C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\000490.jpg does not exist
解决办法1:这个图片是需要放到assets这个文件夹才行。因为predict.py是从assets文件夹中找图片的,放到根目录,肯定找不到了。解决之后第二个图所示。
图1
图2
解决办法2:
把后面的代码修改
源代码是这个
def predict(cfg=DEFAULT_CFG, use_python=False):model = cfg.model or 'best.pt'source = cfg.source if cfg.source is not None else ROOT / 'assets/000490.jpg' if (ROOT / 'assets').exists() \else 'https://ultralytics.com/images/bus.jpg'args = dict(model=model, source=source)if use_python:from ultralytics import YOLOYOLO(model)(**args)else:predictor = DetectionPredictor(overrides=args)predictor.predict_cli()
改后的代码是这个:注意两点,图片路径必须是绝对路径,并且python路径是双斜杠。之后就运行通了。如图3就是运行通的结果图。
def predict(cfg=DEFAULT_CFG, use_python=False):model = 'best.pt'source = 'C:\\Users\\aoqia\\Desktop\\ultralytics-main\\000490.jpg'args = dict(model=model, source=source)if use_python:from ultralytics import YOLOYOLO(model)(**args)else:predictor = DetectionPredictor(overrides=args)predictor.predict_cli()
图3
这篇关于FileNotFoundError: C:\Users\aoqia\Desktop\ultralytics-main\ultralytics\000490.jpg does not exist的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!