Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Keras上使用Glorot重新初始化预训练模型的权重?_Python_Tensorflow_Keras - Fatal编程技术网

Python 如何在Keras上使用Glorot重新初始化预训练模型的权重?

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

我试图用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.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
您能具体说明吗?我不明白你的意思。