[英]How to access and visualize the weights in a pre-trained TensorFlow 2 model?
So, I have re-trained a pre-trained ResNet50 V2 model in TensorFlow 2 using the tf.keras framework with two Dense layers added to the top.因此,我使用 tf.keras 框架在 TensorFlow 2 中重新训练了一个预训练的 ResNet50 V2 模型,并在顶部添加了两个 Dense 层。 Now I want to visualize the weights in the layers within the base ResNet model.
现在我想以可视化的权重基本RESNET模型中的层。 However, reloading the saved model with
但是,重新加载保存的模型
model = tf.keras.models.load_model(path/to/model.hdf5)
model.summary()
results in结果是
As you can see, the layers of ResNet model are not individually listed, meaning that calling可以看到,ResNet 模型的层数没有单独列出,这意味着调用
model.layers[0].get_weights()[1]
will only result in只会导致
[7 7 3 64]
Thus, how do I access the weights inside each of the layers in the base ResNet50 V2 model?因此,如何访问基本 ResNet50 V2 模型中每个层内的权重?
The right answer here was to write这里的正确答案是写
model.layers[0].summary()
instead of代替
model.summary()
Which will let me then see what all the layers are within the pre-trained model.这将让我看到预训练模型中的所有层。 Thus, writing
因此,写
model.layers[0].layers[0].get_weights(name='input_1')
will give me the weights of the input to the ResNet base model.会给我输入到 ResNet 基础模型的权重。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.