Skip to content

Commit

Permalink
check anchor label
Browse files Browse the repository at this point in the history
  • Loading branch information
ijkguo committed Aug 2, 2018
1 parent e005b38 commit dff47b8
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions symdata/anchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,39 @@ def assign(self, anchors, gt_boxes, im_height, im_width):
# overlap between the anchors and the gt boxes
# overlaps (ex, gt)
overlaps = bbox_overlaps(anchors.astype(np.float), gt_boxes.astype(np.float))
gt_max_overlaps = overlaps.max(axis=0)

# fg anchors: anchor with highest overlap for each gt; or overlap > iou thresh
fg_inds = np.where((overlaps >= self._fg_overlap) | (overlaps == gt_max_overlaps))[0]

# subsample to num_fg
if len(fg_inds) > self._num_fg:
fg_inds = np.random.choice(fg_inds, size=self._num_fg, replace=False)

# bg anchor: anchor with overlap < iou thresh but not highest overlap for some gt
bg_inds = np.where((overlaps < self._bg_overlap) & (overlaps < gt_max_overlaps))[0]

if len(bg_inds) > self._num_batch - len(fg_inds):
bg_inds = np.random.choice(bg_inds, size=self._num_batch - len(fg_inds), replace=False)

# assign label
labels[fg_inds] = 1
labels[bg_inds] = 0
# fg anchors: anchor with highest overlap for each gt
gt_max_overlaps = overlaps.max(axis=0)
argmax_inds = np.where(overlaps == gt_max_overlaps)[0]
labels[argmax_inds] = 1

# fg anchors: anchor with overlap > iou thresh
max_overlaps = overlaps.max(axis=1)
labels[max_overlaps >= self._fg_overlap] = 1

# bg anchors: anchor with overlap < iou thresh
labels[max_overlaps < self._bg_overlap] = 1

This comment has been minimized.

Copy link
@ACkuku

ACkuku Aug 14, 2018

bg anchors: should labels[max_overlaps < self._bg_overlap] = 0,
not labels[max_overlaps < self._bg_overlap] = 1,
right?

This comment has been minimized.

Copy link
@ijkguo

ijkguo Aug 14, 2018

Author Owner

Yes, Thanks.


# sanity check
fg_inds = np.where(labels == 1)[0]
bg_inds = np.where(labels == 0)[0]
assert len(np.intersect1d(fg_inds, bg_inds)) == 0

# subsample positive anchors
cur_fg = len(fg_inds)
if cur_fg > self._num_fg:
disable_inds = np.random.choice(fg_inds, size=(cur_fg - self._num_fg), replace=False)
labels[disable_inds] = -1

# subsample negative anchors
cur_bg = len(bg_inds)
max_neg = self._num_batch - min(self._num_fg, cur_fg)
if cur_bg > max_neg:
disable_inds = np.random.choice(bg_inds, size=(cur_bg - max_neg), replace=False)
labels[disable_inds] = -1

# assign to argmax overlap
fg_inds = np.where(labels == 1)[0]
argmax_overlaps = overlaps.argmax(axis=1)
bbox_targets[fg_inds, :] = bbox_transform(anchors[fg_inds, :], gt_boxes[argmax_overlaps[fg_inds], :],
box_stds=(1.0, 1.0, 1.0, 1.0))
Expand Down

0 comments on commit dff47b8

Please sign in to comment.