问题
I was doing deep run using Keras. However, the following error occurred in the process of storing the model after learning.
TypeError: can't pickle NotImplementedType objects
I had no problem when I ran the same code in another directory.
The code below is the portion of the code that is causing the error.
....
model.add(Dense(2, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model = multi_gpu_model(model, gpus=4)
model.compile(loss='binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
model.fit(x_train,y_train,epochs = 3, batch_size =500)
scores = model.evaluate(x_test,y_test)
#print("%s:.2f%%"%(model.metrics_names[1], scores[1]*100))
model.save('/disk3/seaice/seaice_keras_model2.h5')
Is the type error of pickle appearing in the storage method inside the keras?
It's also the same environment, but I don't know why it works differently in different directories.
I'd appreciate it if you could provide me with a solution to this problem.
回答1:
When saving a multi-gpu model, the Keras documentation recommends that you call the save(fname) or save_weights(fname) methods of the base model rather than those of the multi_gpu_model (see here, at the very bottom of the page).
I would assign your multi_gpu_model to a new variable rather than reassigning model. That way you'll have an easy reference to your base model that you can use to save weights.
来源:https://stackoverflow.com/questions/50577029/typeerror-cant-pickle-notimplementedtype-objects-in-keras-python