问题描述
在使用 callbacks.ModelCheckpoint()
并进行多 gpu 并行计算时,callbacks
函数会报错:
TypeError: can't pickle ...(different text at different situation) objects
这个错误形式其实跟使用多 gpu 训练时保存模型不当造成的错误比较相似:
To save the multi-gpu model, use
.save(fname)
or.save_weights(fname)
with the template model (the argument you passed tomulti_gpu_model
),
rather than the model returned bymulti_gpu_model
.
这个问题在我之前的文章中也有提到:[Keras] 使用Keras调用多GPU,并保存模型
。显然,在使用检查点时,默认还是使用了 paralleled_model.save()
,进而导致错误。为了解决这个问题,我们需要自己定义一个召回函数。