【问题标题】:Poor loss convergence and accuracy with CNN modelCNN模型的损失收敛性和准确性差
【发布时间】:2018-09-16 02:16:21
【问题描述】:

我使用 TF 构建了一个二元分类器,它将 16x16 灰度图像分类为分布为 87-13 的两个类别之一。我遇到的问题是模型的log loss converges to ~0.4,它比随机的要好,但是我无法让它改进。

视觉问题是在视频编码领域This image should provide some understanding to the problem,其中图像要么被分割,要么不被分割(0/1),基于它们的同质性。注意靠近边缘的正方形更有可能被分割成更小的正方形。

验证模型时(1.1e7 示例,87-13 分布),我无法获得F1-score better than ~50%

我的训练数据由 2.2e8 个示例组成,这些示例被过采样/欠采样以实现 50-50 分布。我正在使用一个 1024 的批量大小的大量洗牌缓冲区(数据不是从一开始就排序的)。使用 Adam 优化,具有默认超参数。

我试图提高性能的事情(测试(结果)):

  • 更大的网络,不断变化的层数、激活、卷积核大小和步幅等(收敛相同)
  • 密集层之间的丢失(与大型网络的性能相同,小型网络的性能更差)
  • 其他 Adam 超参数(最终都导致相同的收敛)
  • 其他优化器(同上)
  • 使用非常小的数据集进行训练以测试收敛性(损失饱和到 0)
  • 正则化输入(无效)
  • 不同的批量大小(只会影响损失和收敛时间中的噪声)

我一直在努力提高性能,我想我已经阅读了我能找到的每一个 SO 问题。任何建议都会有很大帮助。

def cnn_model(features, labels, mode):
#   downsample to 8x8 using 2x2 local averaging
    features_8x8 = tf.nn.avg_pool(
            value=tf.cast(features["x"], tf.float32),
            ksize=[1, 2, 2, 1],
            strides=[1, 2, 2, 1],
            padding="SAME",
            data_format='NHWC'
            )
    conv2d_0 = tf.layers.conv2d(inputs=features_8x8,
                                filters=6,
                                kernel_size=[3, 3],
                                strides=(1, 1),
                                activation=tf.nn.relu,
                                name="conv2d_0")
    pool0 = tf.layers.max_pooling2d(
            inputs=conv2d_0,
            pool_size=(2, 2),
            strides=(2, 2),
            padding="SAME",
            data_format='channels_last'
            )
    conv2d_1 = tf.layers.conv2d(inputs=pool0,
                                filters=16,
                                kernel_size=[3, 3],
                                strides=(3, 3),
                                activation=tf.nn.relu,
                                name="conv2d_1")
    reshape1 = tf.reshape(conv2d_1, [-1, 16])
    dense0 = tf.layers.dense(inputs=reshape1,
                             units=10,
                             activation=tf.nn.relu,
                             name="dense0")
    logits = tf.layers.dense(inputs=dense0,
                             units=1,
                             name="logits")

    # ########################################################

    predictions = {
            "classes": tf.round(tf.nn.sigmoid(logits)),
            "probabilities": tf.nn.sigmoid(logits)
            }

    # ########################################################

    if mode == tf.estimator.ModeKeys.PREDICT:
        return tf.estimator.EstimatorSpec(mode=mode,
                                          predictions=predictions)

    # ########################################################

    cross_entropy = tf.nn.sigmoid_cross_entropy_with_logits(
            labels=tf.cast(labels['y'], tf.float32),
            logits=logits
            )

    loss = tf.reduce_mean(cross_entropy)

    # ########################################################

    # Configure the Training Op (for TRAIN mdoe)
    if mode == tf.estimator.ModeKeys.TRAIN:
        optimiser = tf.train.AdamOptimizer(learning_rate=0.001,
                                           beta1=0.9,
                                           beta2=0.999,
                                           epsilon=1e-08)
        train_op = optimiser.minimize(
                loss=loss,
                global_step=tf.train.get_global_step())
        return tf.estimator.EstimatorSpec(mode=mode,
                                          loss=loss,
                                          train_op=train_op)
    # Add evalutation metrics (for EVAL mode)
    eval_metric_ops = {
            "accuracy": tf.metrics.accuracy(
                    labels=labels["y"],
                    predictions=predictions["classes"]),
            }
    return tf.estimator.EstimatorSpec(mode=mode,
                                      loss=loss,
                                      eval_metric_ops=eval_metric_ops)

【问题讨论】:

    标签: tensorflow loss-function


    【解决方案1】:

    看来你已经做了很多了。我的下一步将是可视化

    • 数据集:人类可以区分类别吗?
    • 权重:它们在训练过程中是否收敛/变化
    • VGG 等微调模型如何工作?

    您可能要求解决一个非常困难的视力问题。我们可以查看图像或获取数据样本吗?然后,有经验的人可以尝试提出一个(希望)有效的基本模型......

    【讨论】:

    • 我在编辑中添加了有关视力问题的信息(第 2 段)。您如何建议我使用 TensorBoard 监控权重?我到底在寻找什么? (你能提供一个来源吗?)
    • 这是正确的答案(关于数据集:人类可以区分类别)。虽然每个训练示例的标签都是 0|1,但并非编码器所做的所有分类都具有相同的确定性,即:某些标签比其他标签更好。因此,模型很可能在识别编码瓦片的类别时遇到问题,该瓦片的编码没有很强的确定性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 2017-07-16
    相关资源
    最近更新 更多