简体   繁体   English

tf.layers.dense内核初始化程序和正则化程序

[英]tf.layers.dense kernel initializer and regularizer

The tf.layers.dense function defined as: tf.layers.dense函数定义为:

tf.layers.dense(
    inputs,
    units,
    activation=None,
    use_bias=True,
    kernel_initializer=None,
    bias_initializer=tf.zeros_initializer(),
    kernel_regularizer=None,
    bias_regularizer=None,
    activity_regularizer=None,
    trainable=True,
    name=None,
    reuse=None
)

has two optional arguments kernel_initializer and kernel_regularizer . 有两个可选参数kernel_initializerkernel_regularizer I have two different regularization and initialization techniques of my own that I wish to experiment with. 我想尝试两种不同的正则化和初始化技术。 I am not keen on implementing the entire neural network from scratch. 我不热衷于从头开始实现整个神经网络。 Could someone provide an example for supplying custom functions to these two arguments? 有人可以提供为这两个参数提供自定义函数的示例吗?

The best thing to do is to check the implementation of initializer and regularizer in tensorflow. 最好的办法是检查tensorflow中initializerregularizer的实现。 For instance, the variance_scaling_initializer initializer is defined in this code: https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/contrib/layers/python/layers/initializers.py#L62-L152 例如,此代码中定义了variance_scaling_initializer初始化程序: https : //github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/contrib/layers/python/layers/initializers.py#L62-L152

It is consituted of an initializer function with the following signature: 它由具有以下签名的initializer函数组成:

initializer(shape, dtype=dtype, partition_info=None)

that returns a tensor. 返回张量。

The regularizers are defined here: https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/contrib/layers/python/layers/regularizers.py 正则化器在这里定义: https : //github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/contrib/layers/python/layers/regularizers.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM