Python3报错:TypeError: can't pickle _thread.RLock objects

在使用Keras框架,保存模型的时候,会遇到这样的错误:

原先保存模型的代码是:

model_path = "./ResNet/" + args.model + '_{epoch:03d}.hdf5'
checkpoints = ModelCheckpoint(model_path, monitor='val_loss', verbose=1, 
                              save_best_only=False,
                              save_weights_only=False, mode='auto', period=0)

报错原因是:网络结构中使用有Lambda层,这与ModelCheckpoint()的save_weights_only存在有冲突。

解决方法:将save_weights_only=False更换为save_weights_only=True

model_path = "./ResNet/" + args.model + '_{epoch:03d}.hdf5'
checkpoints = ModelCheckpoint(model_path, monitor='val_loss', verbose=1, 
                              save_best_only=False,
                              save_weights_only=True, mode='auto', period=0)

 

你可能感兴趣的:(Python基础,深度学习)