使用交叉验证在训练中揭开TensorFlow和TensorBoard的黑暗谜团。出现奇怪的图表

这是我第一次使用TensorBoard,我在图表中遇到了一个奇怪的错误。

当我打开“STEP”窗口时,得到的是这样的结果。这是我打开“STEP”窗口时得到的结果。

然而,当我打开“RELATIVE”窗口时(打开“WALL”窗口时也是类似的结果),得到的是这样的结果。RELATIVE窗口

此外,为了测试模型的性能,我每隔几步就应用交叉验证。交叉验证的准确率从大约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_stepdef 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

现在我怀疑我的错误可能出在图表的损失函数定义上,但我并不确定。您认为问题可能出在哪里?还是说模型正常收敛,所有这些错误都是预期的?


回答:

是的,我认为您在交叉验证实现中多次运行了同一个模型。请尝试在每次循环结束时执行以下操作:

session.close()

Related Posts

Keras Dense层输入未被展平

这是我的测试代码: from keras import…

无法将分类变量输入随机森林

我有10个分类变量和3个数值变量。我在分割后直接将它们…

如何在Keras中对每个输出应用Sigmoid函数?

这是我代码的一部分。 model = Sequenti…

如何选择类概率的最佳阈值?

我的神经网络输出是一个用于多标签分类的预测类概率表: …

在Keras中使用深度学习得到不同的结果

我按照一个教程使用Keras中的深度神经网络进行文本分…

‘MatMul’操作的输入’b’类型为float32,与参数’a’的类型float64不匹配

我写了一个简单的TensorFlow代码,但不断遇到T…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注