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
12c8aa69
You need to sign in or sign up before continuing.
Commit
12c8aa69
authored
Jul 16, 2018
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MaskRCNN] accelerate numpy iou computation
parent
17c25692
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
examples/FasterRCNN/data.py
examples/FasterRCNN/data.py
+20
-1
examples/FasterRCNN/utils/np_box_ops.py
examples/FasterRCNN/utils/np_box_ops.py
+4
-4
No files found.
examples/FasterRCNN/data.py
View file @
12c8aa69
...
@@ -16,13 +16,32 @@ from tensorpack.utils import logger
...
@@ -16,13 +16,32 @@ from tensorpack.utils import logger
from
coco
import
COCODetection
from
coco
import
COCODetection
from
utils.generate_anchors
import
generate_anchors
from
utils.generate_anchors
import
generate_anchors
from
utils.np_box_ops
import
iou
as
np_iou
from
utils.np_box_ops
import
area
as
np_area
from
utils.np_box_ops
import
area
as
np_area
from
common
import
(
from
common
import
(
DataFromListOfDict
,
CustomResize
,
filter_boxes_inside_shape
,
DataFromListOfDict
,
CustomResize
,
filter_boxes_inside_shape
,
box_to_point8
,
point8_to_box
,
segmentation_to_mask
)
box_to_point8
,
point8_to_box
,
segmentation_to_mask
)
from
config
import
config
as
cfg
from
config
import
config
as
cfg
try
:
import
pycocotools.mask
as
cocomask
# Much faster than utils/np_box_ops
def
np_iou
(
A
,
B
):
def
to_xywh
(
box
):
box
=
box
.
copy
()
box
[:,
2
]
-=
box
[:,
0
]
box
[:,
3
]
-=
box
[:,
1
]
return
box
ret
=
cocomask
.
iou
(
to_xywh
(
A
),
to_xywh
(
B
),
np
.
zeros
((
len
(
B
),),
dtype
=
np
.
bool
))
# can accelerate even more, if using float32
return
ret
.
astype
(
'float32'
)
except
ImportError
:
from
utils.np_box_ops
import
iou
as
np_iou
class
MalformedData
(
BaseException
):
class
MalformedData
(
BaseException
):
pass
pass
...
...
examples/FasterRCNN/utils/np_box_ops.py
View file @
12c8aa69
...
@@ -50,12 +50,12 @@ def intersection(boxes1, boxes2):
...
@@ -50,12 +50,12 @@ def intersection(boxes1, boxes2):
all_pairs_min_ymax
=
np
.
minimum
(
y_max1
,
np
.
transpose
(
y_max2
))
all_pairs_min_ymax
=
np
.
minimum
(
y_max1
,
np
.
transpose
(
y_max2
))
all_pairs_max_ymin
=
np
.
maximum
(
y_min1
,
np
.
transpose
(
y_min2
))
all_pairs_max_ymin
=
np
.
maximum
(
y_min1
,
np
.
transpose
(
y_min2
))
intersect_heights
=
np
.
maximum
(
intersect_heights
=
np
.
maximum
(
np
.
zeros
(
all_pairs_max_ymin
.
shape
),
np
.
zeros
(
all_pairs_max_ymin
.
shape
,
dtype
=
'f4'
),
all_pairs_min_ymax
-
all_pairs_max_ymin
)
all_pairs_min_ymax
-
all_pairs_max_ymin
)
all_pairs_min_xmax
=
np
.
minimum
(
x_max1
,
np
.
transpose
(
x_max2
))
all_pairs_min_xmax
=
np
.
minimum
(
x_max1
,
np
.
transpose
(
x_max2
))
all_pairs_max_xmin
=
np
.
maximum
(
x_min1
,
np
.
transpose
(
x_min2
))
all_pairs_max_xmin
=
np
.
maximum
(
x_min1
,
np
.
transpose
(
x_min2
))
intersect_widths
=
np
.
maximum
(
intersect_widths
=
np
.
maximum
(
np
.
zeros
(
all_pairs_max_xmin
.
shape
),
np
.
zeros
(
all_pairs_max_xmin
.
shape
,
dtype
=
'f4'
),
all_pairs_min_xmax
-
all_pairs_max_xmin
)
all_pairs_min_xmax
-
all_pairs_max_xmin
)
return
intersect_heights
*
intersect_widths
return
intersect_heights
*
intersect_widths
...
@@ -93,5 +93,5 @@ def ioa(boxes1, boxes2):
...
@@ -93,5 +93,5 @@ def ioa(boxes1, boxes2):
a numpy array with shape [N, M] representing pairwise ioa scores.
a numpy array with shape [N, M] representing pairwise ioa scores.
"""
"""
intersect
=
intersection
(
boxes1
,
boxes2
)
intersect
=
intersection
(
boxes1
,
boxes2
)
areas
=
np
.
expand_dims
(
area
(
boxes2
),
axis
=
0
)
inv_areas
=
np
.
expand_dims
(
1.0
/
area
(
boxes2
),
axis
=
0
)
return
intersect
/
areas
return
intersect
*
inv_
areas
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