如何在 tensorflow.contrib.layers conv2d 中初始化权重

How to initialize weights in tensorflow.contrib.layers conv2d

我使用 tensorflow 库编写了一个简单的自动编码器。 This is the sample code I have written for the network of the autoencoder 我不明白的是如何在没有任何特定初始化的情况下将权重引入该模型,因为它现在正在工作?

正在创建 conv2d 层时定义权重初始化。在 API (https://www.tensorflow.org/api_docs/python/tf/contrib/layers/conv2d) there is a parameter in such function named weights_initializer that can be filled with a tf.initializer object and defines the way weights are initialized. By default, for TFv1.8, this is a xavier_initializer (https://www.tensorflow.org/api_docs/python/tf/contrib/layers/xavier_initializer), but you could set it to any of the initializers included here: https://www.tensorflow.org/api_docs/python/tf/initializers 中。例如,如果您希望权重初始化为常量值 12345,您可以这样写:

lays.conv2d(inputs, 32,[5,5], stride=2, padding="SAME", 
                   weights_initializer=tf.constant_initializer(12345))