YOLOv5训练报错PermissionError

YOLOv5-7.0运行detect.py没有问题,运行train出错


```python
train: weights=yolov5s.pt, cfg=models\yolovs2.yaml, data=data\helmet.yaml, hyp=data\hyps\hyp.scratch-low.yaml, epochs=3, batch_size=4, imgsz=640, rect=False, resume=True, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, 
bucket=, cache=None, image_weights=False, device=cpu, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=1, project=runs\train, name=exp, exist_ok=False, quad=False, cos_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest     
github: skipping check (not a git repository), for updates see https://github.com/ultralytics/yolov5
Traceback (most recent call last):
  File "d:\ATR\yolov5\train.py", line 633, in <module>
    main(opt)
  File "d:\ATR\yolov5\train.py", line 495, in main
    d = torch.load(last, map_location='cpu')['opt']
  File "C:\Users\lenovo\anaconda3\envs\yolov5Env\lib\site-packages\torch\serialization.py", line 791, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "C:\Users\lenovo\anaconda3\envs\yolov5Env\lib\site-packages\torch\serialization.py", line 271, in _open_file_like   
    return _open_file(name_or_buffer, mode)
  File "C:\Users\lenovo\anaconda3\envs\yolov5Env\lib\site-packages\torch\serialization.py", line 252, in __init__
    super().__init__(open(name, mode))
PermissionError: [Errno 13] Permission denied: '.'


  • 这篇博客: YOLOv5火焰烟雾检测中的 5.3.2 detect.py 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 其中需要了解的是第216行开始的parse_opt函数,代码如下:

    def parse_opt():
        parser = argparse.ArgumentParser()
        parser.add_argument('--weights', nargs='+', type=str, default=ROOT / 'yolov5s.pt', help='model path(s)')
        parser.add_argument('--source', type=str, default=ROOT / 'data/images', help='file/dir/URL/glob, 0 for webcam')
        parser.add_argument('--data', type=str, default=ROOT / 'data/coco128.yaml', help='(optional) dataset.yaml path')
        parser.add_argument('--imgsz', '--img', '--img-size', nargs='+', type=int, default=[640], help='inference size h,w')
        parser.add_argument('--conf-thres', type=float, default=0.25, help='confidence threshold')
        parser.add_argument('--iou-thres', type=float, default=0.45, help='NMS IoU threshold')
        parser.add_argument('--max-det', type=int, default=1000, help='maximum detections per image')
        parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
        parser.add_argument('--view-img', action='store_true', help='show results')
        parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
        parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
        parser.add_argument('--save-crop', action='store_true', help='save cropped prediction boxes')
        parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
        parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --classes 0, or --classes 0 2 3')
        parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
        parser.add_argument('--augment', action='store_true', help='augmented inference')
        parser.add_argument('--visualize', action='store_true', help='visualize features')
        parser.add_argument('--update', action='store_true', help='update all models')
        parser.add_argument('--project', default=ROOT / 'runs/detect', help='save results to project/name')
        parser.add_argument('--name', default='exp', help='save results to project/name')
        parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
        parser.add_argument('--line-thickness', default=3, type=int, help='bounding box thickness (pixels)')
        parser.add_argument('--hide-labels', default=False, action='store_true', help='hide labels')
        parser.add_argument('--hide-conf', default=False, action='store_true', help='hide confidences')
        parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference')
        parser.add_argument('--dnn', action='store_true', help='use OpenCV DNN for ONNX inference')
        opt = parser.parse_args()
        opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1  # expand
        print_args(FILE.stem, opt)
        return opt
    

    weights:训练的权重

    source:测试数据,可以是图片/视频路径,也可以是'0'(电脑自带摄像头),也可以是rtsp等视频流

    output:网络预测之后的图片/视频的保存路径

    img-size:网络输入图片大小

    conf-thres:置信度阈值

    iou-thres:做nms的iou阈值

    device:设置设备

    view-img:是否展示预测之后的图片/视频,默认False

    save-txt:是否将预测的框坐标以txt文件形式保存,默认False

    classes:设置只保留某一部分类别,形如0或者0 2 3

    agnostic-nms:进行nms是否也去除不同类别之间的框,默认False

    augment:推理的时候进行多尺度,翻转等操作(TTA)推理

    update:如果为True,则对所有模型进行strip_optimizer操作,去除pt文件中的优化器等信息,默认为False

resume这个参数改为False。你都没有上一次训练,哪来的从上一次断点开始训练