简体   繁体   中英

keras model saving error

-in ubuntu16.04.1 -in keras 2.1.6

here is my try

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')

and save moment, this error is occur.

TypeError: can't pickle NotImplementedType objects

i didn't use call_back method.

why this error is occur and please give some solution

I also had the same error and my work around the issue was putting using this code after your model fit.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM