2024-09-01
Linux运维
00

Windows跑yolov5推理出现报错NotImplementedError: cannot instantiate 'PosixPath' on your system

D:\code\envs\pytorch\python.exe C:/Users/sun/Desktop/yolov5-master/detect.py

detect: weights=best_x.pt, source=democ.mp4, data=data\coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_csv=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1

YOLOv5 2024-3-10 Python-3.9.16 torch-2.0.0 CUDA:0 (NVIDIA GeForce GTX 1650 Ti, 4096MiB)

Traceback (most recent call last):

File "C:\Users\sun\Desktop\yolov5-master\detect.py", line 312, in

main(opt)

File "C:\Users\sun\Desktop\yolov5-master\detect.py", line 307, in main

run(**vars(opt))

File "D:\code\envs\pytorch\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context

return func(*args, **kwargs)

File "C:\Users\sun\Desktop\yolov5-master\detect.py", line 115, in run

model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)

File "C:\Users\sun\Desktop\yolov5-master\models\common.py", line 467, in init

model = attempt_load(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse)

File "C:\Users\sun\Desktop\yolov5-master\models\experimental.py", line 98, in attempt_load

ckpt = torch.load(attempt_download(w), map_location="cpu") # load

File "D:\code\envs\pytorch\lib\site-packages\torch\serialization.py", line 809, in load

return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)

File "D:\code\envs\pytorch\lib\site-packages\torch\serialization.py", line 1172, in _load

result = unpickler.load()

File "D:\code\envs\pytorch\lib\pathlib.py", line 1084, in new

raise NotImplementedError("cannot instantiate %r on your system"

NotImplementedError: cannot instantiate 'PosixPath' on your system

解决:

找到from pathlib import Path这句,在后面加上这2句话:

python
import pathlib pathlib.PosixPath = pathlib.WindowsPath
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!