【问题标题】:The dark mystery of tensorflow and tensorboard using cross-validation in training. Weird graphs showing up张量流和张量板在训练中使用交叉验证的黑暗之谜。奇怪的图表出现
【发布时间】:2017-09-29 07:11:44
【问题描述】:

这是我第一次使用 tensorboard,因为我的图表出现了一个奇怪的错误。

如果我打开“STEP”窗口,这就是我得到的。

但是,如果我打开“相对”,这就是我得到的。 (打开“WALL”窗口时类似)。

除此之外,为了测试模型的性能,我每隔几个步骤应用一次交叉验证。这种交叉验证的准确度从大约 10%(随机猜测)下降到 0%。我不确定我在哪里犯了错误,因为我不是 tensorflow 的专业人士,但我怀疑我的问题出在图形构建中。代码如下:

def initialize_parameters():
    global_step = tf.get_variable("global_step", shape=[], trainable=False, 
            initializer=tf.constant_initializer(1), dtype=tf.int64)

    Weights = {
        "W_Conv1": tf.get_variable("W_Conv1", shape=[3, 3, 1, 64],
            initializer=tf.random_normal_initializer(mean=0.00, stddev=0.01),
        ),
...
        "W_Affine3": tf.get_variable("W_Affine3", shape=[128, 10],
            initializer=tf.random_normal_initializer(mean=0.00, stddev=0.01),
    )
}
    Bias = {
        "b_Conv1": tf.get_variable("b_Conv1", shape=[1, 16, 8, 64],
            initializer=tf.random_normal_initializer(mean=0.00, stddev=0.01),
        ),
...
        "b_Affine3": tf.get_variable("b_Affine3", shape=[1, 10],
            initializer=tf.random_normal_initializer(mean=0.00, stddev=0.01),
    )
}
    return Weights, Bias, global_step


def build_model(W, b, global_step):

    keep_prob = tf.placeholder(tf.float32)
    learning_rate = tf.placeholder(tf.float32)
    is_training = tf.placeholder(tf.bool)

    ## 0.Layer: Input
    X_input = tf.placeholder(shape=[None, 16, 8], dtype=tf.float32, name="X_input")
    y_input = tf.placeholder(shape=[None, 10], dtype=tf.int8, name="y_input")

    inputs = tf.reshape(X_input, (-1, 16, 8, 1)) #must be a 4D input into the CNN layer
    inputs = tf.contrib.layers.batch_norm(
                        inputs,
                        center=False,
                        scale=False,
                        is_training=is_training
                    )

    ## 1. Layer: Conv1 (64, stride=1, 3x3)
    inputs = layer_conv(inputs, W['W_Conv1'], b['b_Conv1'], is_training)
... 

    ## 7. Layer: Affine 3 (128 units)
    logits = layer_affine(inputs, W['W_Affine3'], b['b_Affine3'], is_training)

    ## 8. Layer: Softmax, or loss otherwise
    predict = tf.nn.softmax(logits) #should be an argmax, or should this even go through


    ## Output: Loss functions and model trainers
    loss = tf.reduce_mean(
                tf.nn.softmax_cross_entropy_with_logits( 
                      labels=y_input, 
                      logits=logits
                )
           )
    trainer = tf.train.GradientDescentOptimizer(
                learning_rate=learning_rate
              ) 
    updateModel = trainer.minimize(loss, global_step=global_step)

    ## Test Accuracy
    correct_pred = tf.equal(tf.argmax(y_input, 1), tf.argmax(predict, 1))
    acc_op = tf.reduce_mean(tf.cast(correct_pred, "float"))

return X_input, y_input, loss, predict, updateModel, keep_prob, learning_rate, is_training

现在我怀疑我的错误出在图形损失函数的定义中,但我不确定。知道问题可能是什么吗?或者模型是否正确收敛并且所有这些错误都是预期的?

【问题讨论】:

    标签: machine-learning tensorflow deep-learning cross-validation tensorboard


    【解决方案1】:

    是的,我认为您的交叉验证实施不止一次运行相同的模型。 只需在每个循环结束时尝试

    session.close()
    

    【讨论】:

      【解决方案2】:

      我怀疑您得到了如此奇怪的输出(我自己也看到过类似的输出),因为您不止一次运行同一个模型,并且它将 Tensorboard 输出保存在完全相同的位置。我在您的代码中看不到您如何命名放置输出的文件?尝试使这部分代码中的文件路径唯一:

      `summary_writer = tf.summary.FileWriter(unique_path_to_log, sess.graph)`
      

      您还可以尝试找到已放入现有输出的目录,并尝试删除具有较旧(或较新?)时间戳的文件,这样 Tensorboard 就不会混淆使用哪一个。

      【讨论】:

        猜你喜欢
        • 2016-04-01
        • 2020-05-24
        • 2020-09-05
        • 2019-07-15
        • 2020-03-04
        • 1970-01-01
        • 2016-06-01
        • 1970-01-01
        • 2017-04-12
        相关资源
        最近更新 更多