学习使用bilstm_crf_model出现的bug
1. TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [bool, float32] that don't all match.
出現地方:
bilstm_crf_model = Embedding(input_dim=n_words + 1, output_dim=20,input_length=max_len, mask_zero=True)(input) # 20-dim embedding解決:刪掉mask_zero=True
bilstm_crf_model = Embedding(input_dim=n_words + 1, output_dim=20,input_length=max_len)(input) # 20-dim embedding2.TensorFlow與Keras,CUDA版本問題
2.1 AttributeError: module 'keras.backend' has no attribute 'slice'
2.2 attributeerror: 'node' object has no attribute 'output_masks'
2.3?typeerror: __init__() got an unexpected keyword argument 'ragged'
2.4?keras_contrib attributeerror: module 'tensorflow' has no attribute 'get_default_graph'
2.5?importerror: cannot import name 'saving'
2.6?futurewarning: from version 0.24, get_params will raise an attributeerror if a parameter cannot be retrieved as an instance attribute. previously it would return none. futurewarning)
TensorFlow與Keras,CUDA,CUDNN,Python相應版本相對應很重要
我這邊目前是:CUDA Version 10.0.130,CUDNN:7.5 ,Python 3.6.10,GCC 7.3.0
我安裝的: TensorFlow:2.0.0,Keras:2.3.1
查看CUDA的方法:
第一種.:nvidia-smi
第二種:
cat /usr/local/cuda/version.txt
查看CUDNN的方法:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
查看python,GCC版本:
python?
CUDA,CUDNN與TensorFlow版本對應:https://tensorflow.google.cn/install/source
TensorFlow與Keras版本對應:https://docs.floydhub.com/guides/environments/
3.KeyError: 'accuracy'
出現地方:
model.compile(optimizer="rmsprop", loss=crf.loss_function, metrics=["accuracy"]) history = model.fit(X_train, np.array(y_train), batch_size=32, epochs=5,validation_split=0.1, verbose=1) hist = pd.DataFrame(history.history) plt.figure(figsize=(12,12)) plt.plot(hist["acc"]) plt.plot(hist["val_acc"]) plt.show()解決:列名要注意
?
plt.plot(hist["accuracy"]) plt.plot(hist["val_accuracy"])?4.typeerror: load_model() missing 1 required positional argument: 'filepath'
出現地方: model=load_model(filepath="../result/bi-lstm.h5")解決:
filepath = "result/bi-lstm.h5" model = load_model(filepath)5.attributeerror: 'float' object has no attribute 'lower'
出現原因:遇到了數據為NaN的情況
解決:用空格去填充缺失值
data=data.fillna('')?
?
?
總結
以上是生活随笔為你收集整理的学习使用bilstm_crf_model出现的bug的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 公主连结合刀是什么意思
- 下一篇: 廖雪峰Python教程-笔记