为什么我的 Tensorboard 图表中的所有内容都已断开连接?

Why everything is disconnected in my Tensorboard graph?

我已经实现了一个 CNN,用于使用加速度计数据检测人类 activity,我的模型工作得非常好,但是当我在张量板上可视化我的图形时,一切似乎都断开了连接。现在我没有使用 Namescopes 但即使没有它 grpagh 也应该有意义吧?

EDIT 执行 @user1735003 给出的答案后,这是输出。我仍然不明白的是为什么我得到左边的所有节点

我实现的是:我有两个卷积层和两个最大池化层,最重要的是我有两个隐藏层 1024 512 个神经元。

所以这是我的代码:

#Weights
def init_weights(shape):
    init_random_dist = tf.truncated_normal(shape, stddev=0.1)
    return tf.Variable(init_random_dist)


#Bias
def init_bias(shape):
    init_bias = tf.constant(0.1,shape=shape)
    return tf.Variable(init_bias)

def conv1d(x,weights):
    #x is input accelration data and W is corresponding weight
    return tf.nn.conv1d(value=x,filters = weights,stride=1,padding='VALID')

def convolution_layer(input_x,shape):
   w1 = init_weights(shape)
   b = init_bias([shape[2]])
   return tf.nn.relu(conv1d(input_x,weights=w1)+b)


def normal_full_layer(input_layer,size):
    input_size = int(input_layer.get_shape()[1])
    W = init_weights([input_size, size])
    b = init_bias([size])
    return tf.matmul(input_layer, W) +b


x = tf.placeholder(tf.float32,shape=[None ,window_size,3]) #input tensor with 3 input channels
y = tf.placeholder(tf.float32,shape=[None,6]) #Labels

con_layer_1 = convolution_layer(x,shape=[4,3,32])#filter  of shape [filter_width, in_channels, out_channels]

max_pool_1=tf.layers.max_pooling1d(inputs=con_layer_1,pool_size=2,strides=2,padding='Valid')

con_layer_2 = convolution_layer(max_pool_1,shape=[4,32,64])

max_pool_2 = tf.layers.max_pooling1d(inputs=con_layer_2,pool_size=2,strides=2,padding='Valid')

flat = tf.reshape(max_pool_2,[-1,max_pool_2.get_shape()[1]*max_pool_2.get_shape()[2]])

fully_conected = tf.nn.relu(normal_full_layer(flat,1024))


second_hidden_layer = tf.nn.relu(normal_full_layer(fully_conected,512))
hold_prob = tf.placeholder(tf.float32)
full_one_dropout = tf.nn.dropout(second_hidden_layer,keep_prob=hold_prob)


y_pred = normal_full_layer(full_one_dropout,6)
pred_softmax = tf.nn.softmax(y_pred)


cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=y_pred))

optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
train = optimizer.minimize(cross_entropy)
init = tf.global_variables_initializer()




with tf.Session() as sess:
sess.run(init)
filename="./summary_log11/run"
summary_writer = tf.summary.FileWriter(filename, graph_def=sess.graph_def)

for i in range(5000):
    batch_x,batch_y = next_batch(100,X_train,y_train)
    sess.run(train, feed_dict={x: batch_x, y: batch_y, hold_prob: 0.5})

    # PRINT OUT A MESSAGE EVERY 100 STEPS
    if i%100 == 0:

        print('Currently on step {}'.format(i))
        print('Accuracy is:')
        # Test the Train Model
        matches = tf.equal(tf.argmax(y_pred,1),tf.argmax(y,1))

        acc = tf.reduce_mean(tf.cast(matches,tf.float32))

        print(sess.run(acc,feed_dict={x:X_test,y:y_test,hold_prob:1.0}))
        print('\n')

尝试将您的节点组织到范围内。这将有助于 Tensorboard 找出你的图形层次结构。例如,

with tf.variable_scope('input'):
    x = tf.placeholder(tf.float32,shape=[None ,window_size,3]) #input tensor with 3 input channels
    y = tf.placeholder(tf.float32,shape=[None,6]) #Labels

with tf.variable_scope('net'):

    con_layer_1 = convolution_layer(x,shape=[4,3,32])#filter  of shape [filter_width, in_channels, out_channels]

    max_pool_1=tf.layers.max_pooling1d(inputs=con_layer_1,pool_size=2,strides=2,padding='Valid')

    con_layer_2 = convolution_layer(max_pool_1,shape=[4,32,64])

    max_pool_2 = tf.layers.max_pooling1d(inputs=con_layer_2,pool_size=2,strides=2,padding='Valid')

    flat = tf.reshape(max_pool_2,[-1,max_pool_2.get_shape()[1]*max_pool_2.get_shape()[2]])

    fully_conected = tf.nn.relu(normal_full_layer(flat,1024))


    second_hidden_layer = tf.nn.relu(normal_full_layer(fully_conected,512))
    hold_prob = tf.placeholder(tf.float32)
    full_one_dropout = tf.nn.dropout(second_hidden_layer,keep_prob=hold_prob)


    y_pred = normal_full_layer(full_one_dropout,6)
    pred_softmax = tf.nn.softmax(y_pred)

with tf.variable_scope('loss'):

    cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=y_pred))

with tf.variable_scope('optimizer'):
    optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
    train = optimizer.minimize(cross_entropy)

由于您没有明确命名您的 tf 操作,它是由 tensorflow 自动完成的,例如ReLu 运算符被命名为 ReLu_1ReLu_2、...。根据tensorboard documentation:

One last structural simplification is series collapsing. Sequential motifs--that is, nodes whose names differ by a number at the end and have isomorphic structures--are collapsed into a single stack of nodes, as shown below. For networks with long sequences, this greatly simplifies the view.

正如您在图表右侧看到的那样,所有 add_[0-7]MatMul_[0-5]Relu_[0-5] 节点都分组在一起,因为它们具有相似的名称,这并不意味着节点在你的图表中断开连接,这只是张量板的节点分组策略。

如果你想避免这种情况,那么给你的操作起一个比最后一个数字更不同的名字。或如您所述使用 tf.name_scope(),例如:

with tf.name_scope("conv1"):
  con_layer_1 = convolution_layer(x,shape=[4,3,32])
  max_pool_1=tf.layers.max_pooling1d(inputs=con_layer_1,pool_size=2,strides=2,padding='Valid')

with tf.name_scope("conv2"):
  con_layer_2 = convolution_layer(max_pool_1,shape=[4,32,64])
  max_pool_2 = tf.layers.max_pooling1d(inputs=con_layer_2,pool_size=2,strides=2,padding='Valid')

# etc.