AttributeError:模块'yaml'没有属性'warnings'

问题描述 投票:0回答:1

我想在线尝试LSTM的示例,但是遇到一些问题。这是我第一次使用YAML。

我运行包括以下部分的代码,并且发生这些错误:

Traceback (most recent call last):
    File "lstm_test.py", line 112, in <module>
        lstm_predict(strings)
    File "lstm_test.py", line 74, in lstm_predict
        yaml.warnings({'YAMLLoadWarning': False})
AttributeError: module 'yaml' has no attribute 'warnings'

我在Windows 10上运行代码,并且使用Python 3.7。

def lstm_predict(strings):

    print('loading model......')

    with open('../model/lstm.yml', 'r') as f:
        yaml_string = yaml.load(f)

    model = model_from_yaml(yaml_string)

    print('loading weights......')
    model.load_weights('../model/lstm.h5')
    model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])

    for string in strings:
        line = Converter('zh-hant').convert(string.encode().decode('utf-8'))
        string0 = line.encode('utf-8')
        print("="*20)
        data=input_transform(string0)
        data.reshape(1,-1)

        #print data
        result=model.predict_classes(data)
        print(result) # [[1]]
        if result[0]==1:
           print(string,' positive')
        elif result[0]==0:
           print(string,' neural')
        else:
           print(string,' negative')

实际上,我得到了错误:

AttributeError: module 'yaml' has no attribute 'warnings'.

但是,从理论上讲,我认为它不应引起任何错误。我可能会错过什么?

python-3.x yaml warnings
1个回答
0
投票

我有与下图类似的问题enter image description here

现在我可以像下面的命令那样安装PyYAML软件包了

pip install PyYAML --upgrade --force-reinstall

顺便说一下,它是pyyamlPyYAML]之间的不同包。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.