ValueError :(当前不支持session_kwargs中的某些键:%s',dict_keys(['class_mode'])

时间:2018-10-31 12:26:37

标签: keras

from keras.models import Sequential  
from keras.layers.core import Dense, Dropout, Activation  
from keras.optimizers import SGD  
from keras.datasets import mnist  
import numpy 

model = Sequential()

model.add(Dense(500,input_shape=(784,))) # 28*28=784  
model.add(Activation('tanh')) # tanh  
model.add(Dropout(0.5)) # 50% dropout

model.add(Dense(500)) # 500个
model.add(Activation('tanh'))  
model.add(Dropout(0.5))

model.add(Dense(10))
model.add(Activation('softmax')) 


sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) 

model.compile(loss='categorical_crossentropy', optimizer=sgd, class_mode='categorical') 

(X_train, y_train), (X_test, y_test) = mnist.load_data() 

X_train = X_train.reshape(X_train.shape[0], X_train.shape[1] * X_train.shape[2]) 
X_test = X_test.reshape(X_test.shape[0], X_test.shape[1] * X_test.shape[2])  
Y_train = (numpy.arange(10) == y_train[:, None]).astype(int) 
Y_test = (numpy.arange(10) == y_test[:, None]).astype(int)

model.fit(X_train,Y_train,batch_size=200,epochs=50,shuffle=True,verbose=0,validation_split=0.3)
model.evaluate(X_test, Y_test, batch_size=200, verbose=0)

print("test set")
scores = model.evaluate(X_test,Y_test,batch_size=200,verbose=0)
print("")
print("The test loss is %f" % scores)
result = model.predict(X_test,batch_size=200,verbose=0) 

我在分析keras模型时发现了这篇文章Error,它修改了tensorflow库。

因此,我从链接中检查了Keras库代码。但是找不到像['class_mode']这样的东西来修改keras库。接下来,我尝试在重新安装keras之后运行代码,但是即使这样也没有用。

我曾用anaconda导入Kreas,也许我安装错了吗?

有人可以为此提出建议吗?

1 个答案:

答案 0 :(得分:1)

删除class_mode ='categorical',它将运行