问题
I have imported all necessary modules from keras into jupyter notebook
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
from keras.layers import Embedding, Dense, Dropout, Reshape, Merge,
BatchNormalization, TimeDistributed, Lambda, Activation, LSTM, Flatten,
Convolution1D, GRU, MaxPooling1D
from keras.regularizers import l2
from keras.callbacks import Callback, ModelCheckpoint, EarlyStopping
from keras import initializers
from keras import backend as K
from keras.optimizers import SGD
but get error message
ImportErrorTraceback (most recent call last)
<ipython-input-104-b13df7676198> in <module>()
16 from keras.regularizers import l2
17 from keras.callbacks import Callback, ModelCheckpoint, EarlyStopping
---> 18 from keras import initializers
19 from keras import backend as K
20 from keras.optimizers import SGD
ImportError: cannot import name initializers
I have Keras version 1.2.2
回答1:
Use
from keras import initializations
for Keras 1.x.y.
The initializations
package was renamed to initializers
in Keras 2.0.0.
回答2:
Use:
from keras import initializers
for Keras 2.x
来源:https://stackoverflow.com/questions/43531434/cannot-import-keras-initializers