Use of PyYAML's yaml.load function without specifying the Loader=... parameter, has been deprecated.

本文解决使用Keras的model_from_yaml函数时遇到的警告崩溃问题,涉及YAML 5.1版本不兼容的情况,提供三种解决方案,包括代码修改、环境变量调整及版本降级。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用keras函数model_from_yaml时会触发警告崩溃,崩溃是因为使用YAML 5.1版本导致的,崩溃如下:

错误:Use of PyYAML's yaml.load function without specifying the Loader=... parameter, has been deprecated. 

触发原因:YAML 5.1版本不支持keras\engine\saving.py行437:config = yaml.load(yaml_string),

解决:

1)需要修改为:config = yaml.load(yaml_string, Loader=yaml.FullLoader)。这个仅限YAML 5.1。

2)修改环境变量消除警告 PYTHONWARNINGS=ignore::yaml.YAMLLoadWarning

3)或者降YAML版本,pip install pyYAML==3.13

Ref:

https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation

If you are simply using Python software that issues the "load() deprecation" warning, you should notify the authors of that software about it, so they can make and release the proper adjustments. One way to control/disable the warning is with the PYTHONWARNINGS environment variable:

PYTHONWARNINGS=ignore::yaml.YAMLLoadWarning

You can read more about PYTHONWARNINGS here.

If you are the author/maintainer of the Python code that is triggering the warning, the best way to stop getting the warning is to specify the Loader= argument like so:

yaml.load(input, Loader=yaml.FullLoader)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值