本文介绍了无法导入keras.initializers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


但收到错误消息

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

我有Keras版本1.2.2

I have Keras version 1.2.2

推荐答案

使用

from keras import initializations

对于Keras 1.x.y.

for Keras 1.x.y.

initializations软件包在 Keras 2.0.0 中重命名为initializers.

The initializations package was renamed to initializers in Keras 2.0.0.

这篇关于无法导入keras.initializers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:15