python - 如何正确计算 tf.nn.weighted_cross_entropy_with_logits pos_weight 变量

标签 python machine-learning tensorflow artificial-intelligence convolution

我正在使用卷积神经网络。

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

我的第一个类包含:551,462 个图像文件

我的第二堂课包含:52,377 个图像文件

我想使用 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

最佳答案

来自文档:

pos_weight: A coefficient to use on the positive examples.

The argument pos_weight is used as a multiplier for the positive targets:

因此,如果您的第一类是正数,则 pos_weights = 52,377/551,462,否则 551,462/52,377

关于python - 如何正确计算 tf.nn.weighted_cross_entropy_with_logits pos_weight 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43564490/

相关文章:

r - Vowpal Wabbit 输入需要多少预处理?

machine-learning - 神经网络偏差实现的差异

python - 错误 : Out Of Memory, tensorflow cnn

python - Selenium :无法下载文件

python - pop()函数没有完全弹出列表中位数

python - 值错误: invalid literal for int() with base 10: '1\t20.1103\t17.00\n'

python - Python如何获取手册页内容?

python - Pandas 和 scikit-learn : KeyError: [. ...] 不在索引中

python - 层序的输入0与层: expected axis -1 of input shape to have value 784不兼容

python - 使用 tensorflow-gpu 1.14 和 tf.distribute.MirroredStrategy() 的自定义训练循环导致 ValueError