jwyang / jwyang/fpn.pytorch

bbox_outside_weights normalized incorrectly (anchor_target_layer_fpn.py:136)

Open
#44 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
969
Forks
220
PR merge metrics
No merged PRs in 30d

Description

the positive and negative weights are normalized by num_examples in anchor_target_layer_fpn.py. num_examples is calculated based on index i outside of i's batch loop, thus the only number of examples that matter is the last batch, all weights for every example in the batch will be normalized by the last example in the batch, rather than on a example by example basis OR by a num_example that considers the entire batch.

for i in range(batch_size):
... ...
offset = torch.arange(0, batch_size)*gt_boxes.size(1)

argmax_overlaps = argmax_overlaps + offset.view(batch_size, 1).type_as(argmax_overlaps)
bbox_targets = _compute_targets_batch(anchors, gt_boxes.view(-1,5 [argmax_overlaps.view(-1), :].view(batch_size, -1, 5))

# use a single value instead of 4 values for easy index.
bbox_inside_weights[labels==1] = cfg.TRAIN.RPN_BBOX_INSIDE_WEIGHTS[0]

if cfg.TRAIN.RPN_POSITIVE_WEIGHT < 0:
#note that i = batch_size-1
num_examples = torch.sum(labels[i] >= 0)
positive_weights = 1.0 / num_examples
negative_weights = 1.0 / num_examples
else:
assert ((cfg.TRAIN.RPN_POSITIVE_WEIGHT > 0) &
(cfg.TRAIN.RPN_POSITIVE_WEIGHT < 1))

bbox_outside_weights[labels == 1] = positive_weights
bbox_outside_weights[labels == 0] = negative_weights

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in anchor_target_layer_fpn.py around line 136 and trace how num_examples is computed relative to the batch loop. Verify whether normalization should use each example's count or one count for the whole batch, then confirm that bbox_outside_weights uses the intended denominator for every batch item.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.