首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError: load()缺少1个必需的位置参数:'Loader‘

TypeError: load()缺少1个必需的位置参数:'Loader‘
EN

Stack Overflow用户
提问于 2021-11-05 07:36:36
回答 2查看 3.6K关注 0票数 1

在通过pip install -r requirements.txt安装了需求之后,我正在尝试运行这个位于以下链接的github代码库:https://github.com/HowieMa/DeepSORT_YOLOv5_Pytorch。我在Python3.8虚拟环境中运行,在一台运行在Nvidia jetson tx2上的dji歧管2g上。

以下是终端输出。

代码语言:javascript
复制
$ 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

这是要修改的代码块:

代码语言:javascript
复制
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会导致以下错误

代码语言:javascript
复制
$ 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)

有没有人遇到过类似的情况?谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-11 05:39:22

试试这个:

代码语言:javascript
复制
yaml.load(fo.read(), Loader=yaml.FullLoader)

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

票数 5
EN

Stack Overflow用户

发布于 2021-11-23 17:20:20

如果你需要糖,你也可以使用“FullLoader”方法,yaml.full_load()

从pyyaml>=5.4开始,它没有发现任何关键漏洞,pyyaml status

更多关于yaml.load(input) here的信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69849870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档