Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
5140610d
Commit
5140610d
authored
Nov 12, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FasterRCNN] reorganize sample_fastrcnn_target
parent
bda9e14e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
33 deletions
+22
-33
examples/FasterRCNN/model.py
examples/FasterRCNN/model.py
+22
-33
No files found.
examples/FasterRCNN/model.py
View file @
5140610d
...
@@ -242,25 +242,6 @@ def sample_fast_rcnn_targets(boxes, gt_boxes, gt_labels):
...
@@ -242,25 +242,6 @@ def sample_fast_rcnn_targets(boxes, gt_boxes, gt_labels):
target_boxes: tx4 encoded box, the regression target
target_boxes: tx4 encoded box, the regression target
labels: t labels
labels: t labels
"""
"""
@
under_name_scope
()
def
assign_class_to_roi
(
iou
,
gt_boxes
,
gt_labels
):
"""
Args:
iou: nxm (#proposal x #gt)
Returns:
fg_mask: n boolean, whether each roibox is fg
roi_labels: n int32, best label for each roi box
best_gt_boxes: nx4
"""
# find best gt box for each roi box
best_iou_ind
=
tf
.
argmax
(
iou
,
axis
=
1
)
# n, each in 1~m
best_iou
=
tf
.
reduce_max
(
iou
,
axis
=
1
)
# n,
best_gt_boxes
=
tf
.
gather
(
gt_boxes
,
best_iou_ind
)
# nx4
best_gt_labels
=
tf
.
gather
(
gt_labels
,
best_iou_ind
)
# n, each in 1~C
fg_mask
=
best_iou
>=
config
.
FASTRCNN_FG_THRESH
return
fg_mask
,
best_gt_labels
,
best_gt_boxes
iou
=
pairwise_iou
(
boxes
,
gt_boxes
)
# nxm
iou
=
pairwise_iou
(
boxes
,
gt_boxes
)
# nxm
proposal_metrics
(
iou
)
proposal_metrics
(
iou
)
...
@@ -268,22 +249,30 @@ def sample_fast_rcnn_targets(boxes, gt_boxes, gt_labels):
...
@@ -268,22 +249,30 @@ def sample_fast_rcnn_targets(boxes, gt_boxes, gt_labels):
boxes
=
tf
.
concat
([
boxes
,
gt_boxes
],
axis
=
0
)
# (n+m) x 4
boxes
=
tf
.
concat
([
boxes
,
gt_boxes
],
axis
=
0
)
# (n+m) x 4
iou
=
tf
.
concat
([
iou
,
tf
.
eye
(
tf
.
shape
(
gt_boxes
)[
0
])],
axis
=
0
)
# (n+m) x m
iou
=
tf
.
concat
([
iou
,
tf
.
eye
(
tf
.
shape
(
gt_boxes
)[
0
])],
axis
=
0
)
# (n+m) x m
# n+m, n+m, (n+m)x4
# #proposal=n+m from now on
fg_mask
,
roi_labels
,
best_gt_boxes
=
assign_class_to_roi
(
iou
,
gt_boxes
,
gt_labels
)
best_iou_ind
=
tf
.
argmax
(
iou
,
axis
=
1
)
# #proposal, each in 1~m
best_gt_boxes
=
tf
.
gather
(
gt_boxes
,
best_iou_ind
)
# #proposalx4
best_gt_labels
=
tf
.
gather
(
gt_labels
,
best_iou_ind
)
# #proposal, each in 1~C
def
sample_fg_bg
(
iou
):
fg_mask
=
tf
.
reduce_max
(
iou
,
axis
=
1
)
>=
config
.
FASTRCNN_FG_THRESH
fg_inds
=
tf
.
where
(
fg_mask
)[:,
0
]
num_fg
=
tf
.
minimum
(
int
(
config
.
FASTRCNN_BATCH_PER_IM
*
config
.
FASTRCNN_FG_RATIO
),
tf
.
size
(
fg_inds
),
name
=
'num_fg'
)
fg_inds
=
tf
.
random_shuffle
(
fg_inds
)[:
num_fg
]
fg_inds
=
tf
.
where
(
fg_mask
)[:,
0
]
bg_inds
=
tf
.
where
(
tf
.
logical_not
(
fg_mask
)
)[:,
0
]
num_fg
=
tf
.
minimum
(
int
(
num_bg
=
tf
.
minimum
(
config
.
FASTRCNN_BATCH_PER_IM
*
config
.
FASTRCNN_FG_RATIO
)
,
config
.
FASTRCNN_BATCH_PER_IM
-
num_fg
,
tf
.
size
(
fg_inds
),
name
=
'num_f
g'
)
tf
.
size
(
bg_inds
),
name
=
'num_b
g'
)
fg_inds
=
tf
.
random_shuffle
(
fg_inds
)[:
num_f
g
]
bg_inds
=
tf
.
random_shuffle
(
bg_inds
)[:
num_b
g
]
bg_inds
=
tf
.
where
(
tf
.
logical_not
(
fg_mask
))[:,
0
]
add_moving_summary
(
num_fg
,
num_bg
)
num_bg
=
tf
.
minimum
(
return
fg_inds
,
bg_inds
config
.
FASTRCNN_BATCH_PER_IM
-
num_fg
,
tf
.
size
(
bg_inds
),
name
=
'num_bg'
)
bg_inds
=
tf
.
random_shuffle
(
bg_inds
)[:
num_bg
]
add_moving_summary
(
num_fg
,
num_bg
)
fg_inds
,
bg_inds
=
sample_fg_bg
(
iou
)
all_indices
=
tf
.
concat
([
fg_inds
,
bg_inds
],
axis
=
0
)
# ind in all n+m boxes
all_indices
=
tf
.
concat
([
fg_inds
,
bg_inds
],
axis
=
0
)
# ind in all n+m boxes
ret_boxes
=
tf
.
gather
(
boxes
,
all_indices
,
name
=
'sampled_boxes'
)
ret_boxes
=
tf
.
gather
(
boxes
,
all_indices
,
name
=
'sampled_boxes'
)
...
@@ -293,7 +282,7 @@ def sample_fast_rcnn_targets(boxes, gt_boxes, gt_labels):
...
@@ -293,7 +282,7 @@ def sample_fast_rcnn_targets(boxes, gt_boxes, gt_labels):
# bg boxes will not be trained on
# bg boxes will not be trained on
ret_labels
=
tf
.
concat
(
ret_labels
=
tf
.
concat
(
[
tf
.
gather
(
roi
_labels
,
fg_inds
),
[
tf
.
gather
(
best_gt
_labels
,
fg_inds
),
tf
.
zeros_like
(
bg_inds
,
dtype
=
tf
.
int64
)],
axis
=
0
,
name
=
'sampled_labels'
)
tf
.
zeros_like
(
bg_inds
,
dtype
=
tf
.
int64
)],
axis
=
0
,
name
=
'sampled_labels'
)
return
ret_boxes
,
tf
.
stop_gradient
(
ret_encoded_boxes
),
tf
.
stop_gradient
(
ret_labels
)
return
ret_boxes
,
tf
.
stop_gradient
(
ret_encoded_boxes
),
tf
.
stop_gradient
(
ret_labels
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment