1. 程式人生 > 實用技巧 >keras AttributeError: module 'keras.preprocessing' has no attribute 'sequence' 錯誤解決辦法

keras AttributeError: module 'keras.preprocessing' has no attribute 'sequence' 錯誤解決辦法

參考部落格https://stackoverflow.com/questions/48561909/attributeerror-module-keras-preprocessing-has-no-attribute-text?answertab=oldest

原來我的理解是keras.preprocessing 沒有匯入或者公開text子模組,因此採用import text方法而不是.text方法。本人就是比葫蘆畫瓢,嘎嘎。

寫法:

import keras

x_pad = kr.preprocessing.sequence.pad_sequences(data_id, max_length)
出現錯誤:AttributeError: module 'keras.preprocessing' has no attribute 'sequence'

改為:

from keras.preprocessing import sequence
x_pad = sequence.pad_sequences(data_id, max_length)

解決~,執行沒問題