【发布时间】: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)
【问题讨论】: