Cannot import keras.initializers

纵饮孤独 提交于 2020-06-18 11:58:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!