Python 如何在Keras上使用Glorot重新初始化预训练模型的权重?
我试图用Tensorflow的Glorot Uniform和Keras重新初始化冰层重量。最接近的方法是:Python 如何在Keras上使用Glorot重新初始化预训练模型的权重?,python,tensorflow,keras,Python,Tensorflow,Keras,我试图用Tensorflow的Glorot Uniform和Keras重新初始化冰层重量。最接近的方法是: import numpy as np import tensorflow as tf for layer in base_model.layers: layer_new_weights = [] for layer_weights in layer.get_weights(): initializer = tf.compat.v1.keras.initializers.gl
import numpy as np
import tensorflow as tf
for layer in base_model.layers:
layer_new_weights = []
for layer_weights in layer.get_weights():
initializer = tf.compat.v1.keras.initializers.glorot_normal
weights = initializer(np.shape(layer_weights))
layer_new_weights .append(weights)
layer.set_wegiths(layer_new_weights)
你知道如何从Glorot将每层预训练模型的权重设置为ResNet50吗
谢谢 如果您是在keras.applications.exception或其他keras迁移学习模型上执行此操作。试试这个:
InceptionV3(input_shape=(150,150,3),include_top=False,weights=None)
通过将权重设置为None(随机初始化),可能您可以获得“重新初始化”的预训练模型。Glorot似乎并不适用于Resnet中的所有层。此代码似乎完全符合您的要求,问题是什么?不起作用。权重结果为GlorotNorm
您能具体说明吗?我不明白你的意思。