我想在线尝试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'.
但是,从理论上讲,我认为它不应引起任何错误。我可能会错过什么?