TypeError: can't pickle NotImplementedType objects (in keras, python)

自闭症网瘾萝莉.ら 提交于 2020-01-02 07:10:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!