Python 张力板权重直方图仅最后一层可见变化
我在网络中添加了一个TensorBoard可视化,并注意到只有异常值变化很大。为什么网络的权重变化不大?这在叠加直方图中尤其明显 直方图 相同但重叠的视图 我的模型Python 张力板权重直方图仅最后一层可见变化,python,tensorflow,neural-network,tensorboard,Python,Tensorflow,Neural Network,Tensorboard,我在网络中添加了一个TensorBoard可视化,并注意到只有异常值变化很大。为什么网络的权重变化不大?这在叠加直方图中尤其明显 直方图 相同但重叠的视图 我的模型 def neural_network_model(inputdata): """The blueprint of the network and the tensorboard information :param inputdata: the placeholder for the inputdata
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个时代的网络,所以我预计总体上会有更多的变化。尤其是重量没有变化,我不明白
我的神经网络中的权重直方图也遇到了类似的问题。尽管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来检查tensorboard中的梯度。我的神经网络也有类似的问题,我发现大部分损失都被偏差消耗掉了。你有没有偶然得出什么结论?