Custom weight initialization tensorflow tf.layers.dense

后端 未结 3 683
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 12:14

I\'m trying to set up custom initializer to tf.layers.dense where I initialize kernel_initializer with a weight matrix I already have.



        
3条回答
  •  失恋的感觉
    2020-12-29 13:08

    There are at least two ways to achieve this:

    1 Create your own layer

      W1 = tf.Variable(YOUR_WEIGHT_MATRIX, name='Weights')
      b1 = tf.Variable(tf.zeros([YOUR_LAYER_SIZE]), name='Biases') #or pass your own
      h1 = tf.add(tf.matmul(X, W1), b1)
    

    2 Use the tf.constant_initializer

    init = tf.constant_initializer(YOUR_WEIGHT_MATRIX)
    l1 = tf.layers.dense(X, o, kernel_initializer=init)
    

提交回复
热议问题