<p>The Object Detection API losses are defined in: <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/core/losses.py" rel="nofollow noreferrer">https://github.com/tensorflow/models/blob/master/research/object_detection/core/losses.py</a></p>

<p>In particular, the following loss classes have been implemented:</p>

<p><strong>Classification losses:</strong></p>

<ol>
<li>WeightedSigmoidClassificationLoss</li>
<li>SigmoidFocalClassificationLoss</li>
<li>WeightedSoftmaxClassificationLoss</li>
<li>WeightedSoftmaxClassificationAgainstLogitsLoss</li>
<li>BootstrappedSigmoidClassificationLoss</li>
</ol>

<p><strong>Localization losses:</strong></p>

<ol>
<li>WeightedL2LocalizationLoss</li>
<li>WeightedSmoothL1LocalizationLoss</li>
<li>WeightedIOULocalizationLoss</li>
</ol>

<p>The weight parameters are used to balance anchors (prior boxes) and are of size <code>[batch_size, num_anchors]</code> in addition to hard negative mining. Alternatively, the <a href="https://arxiv.org/pdf/1708.02002.pdf" rel="nofollow noreferrer">focal loss</a> down weighs well classified examples and focusses on the hard examples.</p>

<p>The primary class imbalance is due to many more negative examples (bounding boxes without objects of interest) in comparison to very few positive examples (bounding boxes with object classes). That seems to be the reason why class imbalance within positive examples (i.e. unequal distribution of positive class labels) is not implemented as part of object detection losses.</p>
Class weights for balancing data in TensorFlow Object Detection API
<p>I'm fine-tuning <a href="https://arxiv.org/pdf/1512.02325.pdf" rel="noreferrer">SSD</a> object detector using <a href="https://github.com/tensorflow/models/tree/master/research/object_detection" rel="noreferrer">TensorFlow object detection API</a> on <a href="https://storage.googleapis.com/openimages/web/index.html" rel="noreferrer">Open Images Dataset</a>. My training data contains imbalanced classes, e.g.</p>

<ol>
<li>top (5K images)</li>
<li>dress (50K images)</li>
<li>etc...</li>
</ol>

<p>I would like to add class weights to classification loss to improve performance. How do I do that? The following section of the config file seems relevant:</p>

<pre><code>loss {
  classification_loss {
    weighted_sigmoid {
    }
  }
  localization_loss {
    weighted_smooth_l1 {
    }
  }
 ...
  classification_weight: 1.0
  localization_weight: 1.0
}
</code></pre>

<p>How can I change the config file to add classification loss weights per class? If not through a config file, what's a recommended way of doing that? </p>