英文:
python keras.preprocessing.sequence has no attribute pad_sequences
问题
from keras.preprocessing import sequence
的翻译是:
from keras.preprocessing import sequence
AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'
的翻译是:
AttributeError: 模块 'keras.preprocessing.sequence' 没有 'pad_sequences' 属性
对于 "Why?" 和 "How can I edit this?" 这两个问题,我不会回答,因为你要求只翻译代码部分。
英文:
import:from keras.preprocessing import sequence
but:
AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'
Why?
How can I edit this?
答案1
得分: 3
似乎您的Keras版本大于2.8,这就是为什么出现错误的原因。
用早期版本的代码:
from keras.preprocessing import sequence
替换为以下提供的代码:
from keras.utils.data_utils import pad_sequences
您还可以使用:
from tensorflow.keras.preprocessing.sequence import pad_sequences
它们都对我起作用。
英文:
Seems like your keras version is greater than 2.8 that's why getting error as
<code>from keras.preprocessing import sequence</code>
works for earlier version. Instead, replace with the below given code:
<code>from keras.utils.data_utils import pad_sequences</code>
You can also use:
<code>from tensorflow.keras.preprocessing.sequence import pad_sequences</code>
They both worked for me.
答案2
得分: 0
Just use keras_preprocessing
instead keras.preprocessing
:
from keras_preprocessing import sequence
英文:
Just use keras_preprocessing
instead keras.preprocessing
:
from keras_preprocessing import sequence
答案3
得分: 0
To resolve this issue, you can use the tf.keras
version of pad_sequences
directly from TensorFlow.
Just use:
import tensorflow as tf
英文:
To resolve this issue, you can use the tf.keras
version of pad_sequences
directly from TensorFlow.
Just use:
import tensorflow as tf
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论