Tensorboard权重直方图仅最后一层可见变化

时间:2017-07-12 13:35:34

标签: python tensorflow neural-network tensorboard

我在网络中添加了TensorBoard可视化,并注意到只有外层变化很多。为什么网络的权重不会发生很大变化?这在叠加直方图中尤为明显。

直方图 weight histogram 相同但覆盖视图 overlay

我的模特

def neural_network_model(inputdata):
    """The blueprint of the network and the tensorboard information
        :param inputdata: the placeholder for the inputdata
        :returns: the output of the network?
            """
    W1 = tf.get_variable("W1", shape=[set.input, nodes_h1],
                         initializer=tf.contrib.layers.xavier_initializer())
    B1 = tf.get_variable("B1", shape=[nodes_h1],
                         initializer=tf.random_normal_initializer())
    layer1 = tf.matmul(inputdata, W1)
    layer1_bias = tf.add(layer1, B1)
    layer1_act = tf.nn.relu(layer1)

    W2 = tf.get_variable("W2", shape=[nodes_h1, nodes_h2],
                         initializer=tf.contrib.layers.xavier_initializer())
    B2 = tf.get_variable("B2", shape=[nodes_h2],
                         initializer=tf.random_normal_initializer())
    layer2 = tf.matmul(layer1_act, W2)
    layer2_bias = tf.add(layer2, B2)
    layer2_act = tf.nn.relu(layer2)

    W3 = tf.get_variable("W3", shape=[nodes_h2, nodes_h3],
                         initializer=tf.contrib.layers.xavier_initializer())
    B3 = tf.get_variable("B3", shape=[nodes_h3],
                         initializer=tf.random_normal_initializer())

    layer3 = tf.matmul(layer2_act, W3)
    layer3_bias = tf.add(layer3, B3)
    layer3_act = tf.nn.relu(layer3)
    WO = tf.get_variable("WO", shape=[nodes_h3, set.output],
                         initializer=tf.contrib.layers.xavier_initializer())
    layerO = tf.matmul(layer3_act, WO)

    with tf.name_scope('Layer1'):
        tf.summary.histogram("weights", W1)
        tf.summary.histogram("layer", layer1)
        tf.summary.histogram("bias", layer1_bias)
        tf.summary.histogram("activations", layer1_act)
    with tf.name_scope('Layer2'):
        tf.summary.histogram("weights", W2)
        tf.summary.histogram("layer", layer2)
        tf.summary.histogram("bias", layer2_bias)
        tf.summary.histogram("activations", layer2_act)
    with tf.name_scope('Layer3'):
        tf.summary.histogram("weights", W3)
        tf.summary.histogram("layer", layer3)
        tf.summary.histogram("bias", layer3_bias)
        tf.summary.histogram("activations", layer3_act)
    with tf.name_scope('Output'):
        tf.summary.histogram("weights", WO)
        tf.summary.histogram("layer", layerO)
    return layerO

我对训练过程的理解是,应该调整重量,这在图像中几乎不会发生。然而,损失已经完成。我已经训练了10000个时代的网络,所以我期望整体上有一点变化。特别是我不理解的重量没有变化。

!] 3

1 个答案:

答案 0 :(得分:1)

我的神经网络中的重量直方图遇到了类似的问题。尽管Relu确实处理了隐藏层的消失梯度问题,但您应该检查您的学习速率并确保每个变量的更新不会太小。这可能导致接近零的更新,导致随时间的变化无关紧要。您只需使用以下代码段检查每个图层的渐变:

def replace_none_with_zero(tensor):
   return[0 if i==None else i for i in tensor]

with tf.name_scope('Gradients'):
   gradient_for_variable_of_interest=replace_none_with_zero(
                              tf.gradients(loss,[variable_of_interest]))

然后通过调用渐变上的tf.summary.histogram来检查张量板中的渐变。