这是我第一次使用TensorBoard,我在图表中遇到了一个奇怪的错误。
然而,当我打开“RELATIVE”窗口时(打开“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_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()