简体   繁体   English

将图层从一个CNN模型复制到另一个模型。 (layer_from_config在第二版中不起作用)

[英]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_configkeras.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.

相关问题 在Keras中,CNN层结果与模型结果不同 - In Keras, CNN layer result is different from the result of model.predict 有没有办法使用python将过滤器从一层复制到另一层 - is there a way to copy a filter from one layer to another layer using python 将一层的权重从一个 Huggingface BERT model 复制到另一个 - Copy one layer's weights from one Huggingface BERT model to another Keras中的CNN model条件层 - CNN model conditional layer in Keras 如何将从 cnn 密集层提取的特征传递给另一个 cnn? - How to pass feature extracted from cnn dense layer to another cnn? 如何在训练到全连接层之前将潜在向量作为 cnn 模型的输出? - How to get the latent vector as an output from a cnn model before training to the fully connected layer? Photoshop:使用 python 将图层从一个文件复制到另一个文件 - Photoshop: copy a layer from one file to another with python “AttributeError:Layer cnn_model has no inbound nodes”从 Keras GradCam 教程的子类 model 制作 model 时 - "AttributeError: Layer cnn_model has no inbound nodes" when making a model from a subclassed model for Keras GradCam tutorial 从.dxf 文件中获取图层并将该图层复制到新文件 - Get a layer from .dxf file and copy that layer to new file 如何从Tensorflow中的CNN获取全连接层的output? - How to get the output of the fully connected layer from CNN in Tensorflow?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM