Weighted Training Examples in Tensorflow

前端 未结 1 1101
抹茶落季
抹茶落季 2021-01-18 14:15

Given a set of training examples for training a neural network, we want to give more or less weight to various examples in training. We apply a weight between 0.0 and 1.0 to

相关标签:
1条回答
  • 2021-01-18 14:27

    In the most common case where you call tf.nn.sparse_softmax_cross_entropy_with_logits with logits of shape [batch_size, num_classes] and labels of shape [batch_size], the function returns a tensor of shape batch_size. You can multiply this tensor with a weight tensor before reducing them to a single loss value:

    weights = tf.placeholder(name="loss_weights", shape=[None], dtype=tf.float32)
    loss_per_example = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels)
    loss = tf.reduce_mean(weights * loss_per_example)
    
    0 讨论(0)
提交回复
热议问题