Skip to content

Bug in rcnn.py - loss function #260

@meyerjo

Description

@meyerjo

As described in #185 I get a similar problem. I fixed it by applying the boolean_mask cls_flatten not only to the bbox_flatten tensor but also the bbox_offset_targets_labeled. Thus, the elements not only get deleted from the one tensor but also from the other.

In luminoth/models/fasterrcnn/rcnn.py from line 378
`

        # We use the flatten cls_target_one_hot as boolean mask for the
        # bboxes.
        cls_flatten = tf.cast(tf.reshape(
            cls_target_one_hot, [-1]), tf.bool, 'cls_flatten_as_bool')

        bbox_offset_cleaned = tf.boolean_mask(
            bbox_flatten, cls_flatten, 'bbox_offset_cleaned')

        bbox_offsets_target_labeled_cleaned = tf.boolean_mask(
            bbox_offsets_target_labeled, cls_flatten, 'bbox_offsets_target_labeled_cleaned'
        )

        # Calculate the smooth l1 loss between the "cleaned" bboxes
        # offsets (that means, the useful results) and the labeled
        # targets.
        reg_loss_per_proposal = smooth_l1_loss(
            bbox_offset_cleaned, bbox_offsets_target_labeled_cleaned,
            sigma=self._l1_sigma
        )

`

This is the error I get beforehand and is fixed with snippet above:
File "/code/ext/luminoth/luminoth/models/fasterrcnn/fasterrcnn.py", line 192, in loss
prediction_dict['classification_prediction']
File "
/code/ext/luminoth/luminoth/models/fasterrcnn/rcnn.py", line 391, in loss
sigma=self._l1_sigma
File "/code/ext/luminoth/luminoth/utils/losses.py", line 22, in smooth_l1_loss
diff = bbox_prediction - bbox_target
File "
/.local/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 850, in binary_op_wrapper
return func(x, y, name=name)
File "/.local/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 8188, in sub
"Sub", x=x, y=y, name=name)
File "
/.local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/.local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "
/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
op_def=op_def)
File "~/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1717, in init
self._traceback = tf_stack.extract_stack()

InvalidArgumentError (see above for traceback): Incompatible shapes: [27,4] vs. [28,4]
[[Node: losses/RCNNLoss/sub_1 = Sub[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"](losses/RCNNLoss/bbox_offset_cleaned/GatherV2, losses/RCNNLoss/bbox_offsets_target_labeled/GatherV2)]]
[[Node: losses/total_loss_1/_5777 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_11279_losses/total_loss_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

Do you fix this problem or shall I do a pull request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions