类型错误:load()缺少一个必需的位置参数:'Loader'。

4
我正试图运行这个GitHub存储库,链接如下:https://github.com/HowieMa/DeepSORT_YOLOv5_Pytorch。 在通过pip install -r requirements.txt安装依赖项之后,我在Python 3.8虚拟环境中运行此程序,该虚拟环境位于DJI Manifold 2G上,后者运行在Nvidia Jetson TX2上。 以下是终端输出结果。
$ python main.py --cam 0 --display
Namespace(agnostic_nms=False, augment=False, cam=0, classes=[0], conf_thres=0.5, config_deepsort='./configs/deep_sort.yaml', device='', display=True, display_height=600, display_width=800, fourcc='mp4v', frame_interval=2, img_size=640, input_path='input_480.mp4', iou_thres=0.5, save_path='output/', save_txt='output/predict/', weights='yolov5/weights/yolov5s.pt')
Initialize DeepSORT & YOLO-V5
Using CPU

Using webcam 0
Traceback (most recent call last):
  File "main.py", line 259, in <module>
    with VideoTracker(args) as vdo_trk:
  File "main.py", line 53, in __init__
    cfg.merge_from_file(args.config_deepsort)
  File "/home/dji/Desktop/targetTrackers/howieMa/DeepSORT_YOLOv5_Pytorch/utils_ds/parser.py", line 23, in merge_from_file
    self.update(yaml.load(fo.read()))
TypeError: load() missing 1 required positional argument: 'Loader'

我在Github上找到了一些建议,比如在这里 TypeError: load() missing 1 required positional argument: 'Loader' in Google Colab,建议将yaml.load更改为yaml.safe_load。

需要修改的代码块如下:


class YamlParser(edict):
    """
    This is yaml parser based on EasyDict.
    """
    def __init__(self, cfg_dict=None, config_file=None):
        if cfg_dict is None:
            cfg_dict = {}

        if config_file is not None:
            assert(os.path.isfile(config_file))
            with open(config_file, 'r') as fo:
                cfg_dict.update(yaml.load(fo.read()))

        super(YamlParser, self).__init__(cfg_dict)

    
    def merge_from_file(self, config_file):
        with open(config_file, 'r') as fo:
            self.update(yaml.load(fo.read()))

    
    def merge_from_dict(self, config_dict):
        self.update(config_dict)

然而,将yaml.load更改为yaml.safe_load会导致我遇到以下错误


$ python main.py --cam 0 --display
Namespace(agnostic_nms=False, augment=False, cam=0, classes=[0], conf_thres=0.5, config_deepsort='./configs/deep_sort.yaml', device='', display=True, display_height=600, display_width=800, fourcc='mp4v', frame_interval=2, img_size=640, input_path='input_480.mp4', iou_thres=0.5, save_path='output/', save_txt='output/predict/', weights='yolov5/weights/yolov5s.pt')
Initialize DeepSORT & YOLO-V5
Using CPU

Using webcam 0
Done..
Camera ...
Done. Create output file  output/results.mp4
Illegal instruction (core dumped)


有人遇到过类似的问题吗?谢谢!
2个回答

16

试一下这个:

yaml.load(fo.read(), Loader=yaml.FullLoader)

看起来 pyyaml>=5.1 需要一个 Loader 参数。


嘿,@zeit。谢谢你。那帮了我大忙。当我输入Fullloader而不是FullLoader(L要大写)时,我差点搞错了。 - fatbringer

3

如果你需要使用 FullLoader,你也可以使用 "sugar" 方法,即 yaml.full_load()

从 pyyaml>=5.4 开始,它没有发现任何重大漏洞,pyyaml 状态

更多关于 yaml.load(input) 的信息请查看这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接