keras模型保存错误

时间:2018-06-14 09:44:15

标签: python keras pickle

-in ubuntu16.04.1 -in keras 2.1.6

这是我的尝试

model =Sequential()
model.add(Dense(4096, input_shape=(3,), activation='relu'))
model.add(Dense(2048, activation='relu'))
model.add(Dense(1024, activation='relu'))
model.add(Dense(512, activation='relu'))
model.add(Dense(256, activation='relu'))
model.add(Dense(128, activation='relu'))
model.add(Dense(64, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(16, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(2, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
parallel_model = multi_gpu_model(model, gpus=4)
parallel_model.compile(loss='binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
parallel_model.fit(x_train,y_train,epochs = 1, batch_size =2000)
model.save('test_train_model_re_re.h5')

并节省时间,发生此错误。

TypeError:无法挑选NotImplementedType对象

我没有使用call_back方法。

为什么会出现此错误,请提供一些解决方案

1 个答案:

答案 0 :(得分:2)

我也遇到了同样的错误,我在解决问题时的工作是在你的模型适合之后使用这段代码。

parallel_model.fit(x_train,y_train,epochs = 1, batch_size =2000) 

from keras.models import model_from_json   
# serialize model to JSON
model_json = parallel_model.to_json()
with open("model.json", "w") as json_file:
    json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("model.h5")
print("Saved model to disk")