bd2f006eb0170735290f180dc9a8e95aed72411f,frcnn/rpn.py,RPN,loss,#RPN#Any#,108

Before Change


                    rpn_cls_target, -1, name="labels_not_ignored")

                // Flatten rpn_cls_prob (only anchors, not completely).
                rpn_cls_prob = tf.reshape(
                    rpn_cls_prob, [-1, 2], name="rpn_cls_prob_flatten")

                // Now we only have the labels we are going to compare with the
                // cls probability. We need to remove the background.
                labels = tf.boolean_mask(

After Change


        

        rpn_cls_prob = prediction_dict["rpn_cls_prob"]
        rpn_cls_score = prediction_dict["rpn_cls_score"]
        rpn_cls_target = prediction_dict["rpn_cls_target"]

        rpn_bbox_target = prediction_dict["rpn_bbox_target"]
        rpn_bbox_pred = prediction_dict["rpn_bbox_pred"]

        // First, we need to calculate classification loss over `rpn_cls_prob`
        // and `rpn_cls_target`. Ignoring all anchors where `rpn_cls_target =
        // -1`.

        // For classification loss we use log loss of two classes. So we need to:
        // - filter `rpn_cls_prob` that are ignored. We need to reshape both labels and prob
        // - transform positive and negative `rpn_cls_target` to same shape as `rpn_cls_prob`.
        // - then we can use `tf.losses.log_loss` which returns a tensor.

        with self._enter_variable_scope():
            with tf.name_scope("RPNLoss"):
                // Flatten already flat Tensor for usage as boolean mask filter.
                rpn_cls_target = tf.cast(tf.reshape(
                    rpn_cls_target, [-1]), tf.int32, name="rpn_cls_target")
                // Transform to boolean tensor with True only when != -1 (else
                // == -1 -> False)
                labels_not_ignored = tf.not_equal(
                    rpn_cls_target, -1, name="labels_not_ignored")

                // Now we only have the labels we are going to compare with the
                // cls probability.
                labels = tf.boolean_mask(rpn_cls_target, labels_not_ignored)
                cls_prob = tf.boolean_mask(rpn_cls_prob, labels_not_ignored)
                cls_score = tf.boolean_mask(rpn_cls_score, labels_not_ignored)

                // We need to transform `labels` to `cls_prob` shape.
                // convert [1, 0] to [[0, 1], [1, 0]]
                cls_target = tf.one_hot(labels, depth=2)

                cross_entropy_per_anchor = tf.nn.softmax_cross_entropy_with_logits(
                    labels=cls_target, logits=cls_score
                )

                prediction_dict["cross_entropy_per_anchor"] = cross_entropy_per_anchor

                // Finally, we need to calculate the regression loss over
                // `rpn_bbox_target` and `rpn_bbox_pred`.
                // Since `rpn_bbox_target` is obtained from AnchorTargetLayer then we
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: tryolabs/luminoth
Commit Name: bd2f006eb0170735290f180dc9a8e95aed72411f
Time: 2017-06-28
Author: javirey@gmail.com
File Name: frcnn/rpn.py
Class Name: RPN
Method Name: loss


Project Name: dmlc/dgl
Commit Name: fc7cd275980445b8f63bb25ccec51e33577f6c1a
Time: 2020-06-22
Author: VoVAllen@users.noreply.github.com
File Name: python/dgl/distributed/sampling.py
Class Name:
Method Name: sample_neighbors


Project Name: GoogleCloudPlatform/cloudml-samples
Commit Name: 75f5092acce738243f4d8dd258bbaa56fcb9f816
Time: 2019-05-20
Author: luoshixin@google.com
File Name: sklearn/sklearn-template/template/trainer/model.py
Class Name:
Method Name: get_estimator