[英]Copy a layer from one CNN model to other. (layer_from_config not working in ver 2)
In Keras 2, layer_from_config was removed from keras.utils.layer_utils . 在Keras 2,layer_from_config从keras.utils.layer_utils除去。 Does anyone know any replacement to that.
有谁知道有什么替代品吗?
Detailed Description: I have a trained CNN model. 详细说明:我有一个训练有素的CNN模型。 I need to copy a layer from that model to another.
我需要从该模型复制一个层到另一个。 Earlier I used to do layer_from_config and set_weights functions.
之前我曾经做过layer_from_config和set_weights函数。 But they are removed in Keras 2.0.
但是在Keras 2.0中已将其删除。 Needed help to do this functionality.
需要帮助才能执行此功能。
Thanks 谢谢
The function is now a class function of the class Layers (which seems to make more sense). 该函数现在是Layers类的一个类函数(似乎更有意义)。 Same for set_weights.
与set_weights相同。 The way to use it (the doc is up to date) :
使用方式(文档是最新的) :
layer = Dense(32)
config = layer.get_config()
reconstructed_layer = Dense.from_config(config)
So you need to know the class name of the layer you want to rebuild. 因此,您需要知道要重建的图层的类名称。 Or you can build a dictionnary like below, which contains the class name (so that you can store the config somewhere to rebuild the layer in an empty code) :
或者,您可以构建如下所示的字典,其中包含类名称(以便您可以将配置存储在某处以用空代码重建该层):
from keras import layers
config = layer.get_config()
layer = layers.deserialize({'class_name': layer.__class__.__name__,
'config': config})
Does it help? 有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.