yolov5剪枝时报错:TypeError: run() got an unexpected keyword argument 'cfg'

问题遇到的现象和发生背景

使用python prune.py --percent 0.5 --weights ./runs/train/exp3/weights/last.pt --data ./data/dataset.yaml --cfg ./models/yolov5s.yaml 命令对yolov5s进行剪枝时报错:TypeError: run() got an unexpected keyword argument 'cfg'

运行结果及报错内容

报错内容:

yolo: data=./data/dataset.yaml, weights=['./runs/train/exp3/weights/last.pt'], cfg=./models/yolov5s.yaml, percent=0.5, batch_size=32, imgsz=512, conf_thres=0.001, iou_thres=0.6, task=val, device=, workers=8, single_cls=False, augment=False, verbose=False, save_txt=False, save_hybrid=False, save_conf=False, save_json=False, project=C:\Users\shuyf\yolov5\runs\val, name=exp, exist_ok=False, half=False, dnn=False
test before prune ...
Traceback (most recent call last):
  File "prune.py", line 805, in <module>
    main(opt)
  File "prune.py", line 775, in main
    run(**vars(opt))
  File "C:\ProgramData\Anaconda3\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
TypeError: run() got an unexpected keyword argument 'cfg'

我的解答思路和尝试过的方法

以为是版本问题,将库的版本降低后也未解决,现在就是不知道怎么改了。

我想要达到的结果

不报错,尽快跑通。

我看了下6.0的prune.py中run函数,不接受cfg参数

你看一下github给出的启动命令 对比一下

基本我见到过的这种情况都是库和python的版本不匹配,要不你查一下?

这是prune.py种输入的内容,并没有cfg这个参数


if __name__ == '__main__':
    parser = argparse.ArgumentParser(prog='test.py')
    parser.add_argument('--weights', nargs='+', type=str, default='./runs/train/exp4/weights/last.pt',
                        help='model.pt path(s)')
    parser.add_argument('--data', type=str, default='data/mini.yaml', help='*.data path')
    parser.add_argument('--percent', type=float, default=0.9, help='prune percentage')
    parser.add_argument('--batch-size', type=int, default=32, help='size of each image batch')
    parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
    parser.add_argument('--conf-thres', type=float, default=0.001, help='object confidence threshold')
    parser.add_argument('--iou-thres', type=float, default=0.6, help='IOU threshold for NMS')
    parser.add_argument('--task', default='val', help='train, val, test, speed or study')
    parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
    parser.add_argument('--single-cls', action='store_true', help='treat as single-class dataset')
    parser.add_argument('--augment', action='store_true', help='augmented inference')
    parser.add_argument('--verbose', action='store_true', help='report mAP by class')
    parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
    parser.add_argument('--save-hybrid', action='store_true', help='save label+prediction hybrid results to *.txt')
    parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
    parser.add_argument('--save-json', action='store_true', help='save a cocoapi-compatible JSON results file')
    parser.add_argument('--project', default='runs/test', help='save to project/name')
    parser.add_argument('--name', default='exp', help='save to project/name')
    parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')

run方法里根本就没有设置cfg这个参数,这个工程有问题。