如何用加权变量正确计算tf.nn.加权交叉熵

2024-05-16 11:43:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是卷积神经网络。

我的数据很不平衡,我有两个班。

我的第一个类包含:551462个图像文件

我的第二个类包含:52377个图像文件

我想使用weighted_cross_entropy_with_logits,但我不确定是否正确计算了pos_weight变量。

现在我在用

classes_weights = tf.constant([0.0949784, 1.0])
cross_entropy = tf.reduce_mean(tf.nn.weighted_cross_entropy_with_logits(logits=logits, targets=y_, pos_weight=classes_weights))
train_step = tf.train.AdamOptimizer(LEARNING_RATE, epsilon=1e-03).minimize(
      cross_entropy
    , global_step=global_step
    )

或者我应该用

classes_weights = 10.5287


Tags: postfstep图像文件withtrainglobal卷积