无法使用model.save保存模型在Keras中遵循multi_gpu_model [英] Can not save model using model.save following multi_gpu_model in Keras
问题描述
在升级到Keras 2.0.9之后,我一直在使用multi_gpu_model
实用程序,但是我无法使用
Following the upgrade to Keras 2.0.9, I have been using the multi_gpu_model
utility but I can't save my models or best weights using
model.save('path')
我得到的错误是
TypeError:无法腌制模块对象
TypeError: can’t pickle module objects
我怀疑在访问模型对象时存在一些问题.是否可以解决此问题?
I suspect there is some problem gaining access to the model object. Is there a work around this issue?
推荐答案
老实说,最简单的方法实际上是使用
To be honest, the easiest approach to this is to actually examine the multi gpu parallel model using
parallel_model.summary()
(并行模型只是应用multi_gpu函数之后的模型).这清楚地突出了实际模型(在我看来是倒数第二层-我现在不在电脑旁).然后,您可以使用该层的名称来保存模型.
(The parallel model is simply the model after applying the multi_gpu function). This clearly highlights the actual model (in I think the penultimate layer - I am not at my computer right now). Then you can use the name of this layer to save the model.
model = parallel_model.get_layer('sequential_1)
通常称为"sequence_1",但是如果您使用的是已发布的体系结构,则可能是"googlenet"或"alexnet".您将从摘要中看到层的名称.
Often its called sequential_1 but if you are using a published architecture, it may be 'googlenet' or 'alexnet'. You will see the name of the layer from the summary.
然后只需保存即可简单
model.save()
格言的方法行之有效,但我认为它过大了.
Maxims approach works, but its overkill I think.
Rem:您将需要同时编译模型和并行模型.
Rem: you will need to compile both the model, and the parallel model.
这篇关于无法使用model.save保存模型在Keras中遵循multi_gpu_model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!