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
843d44e9
Commit
843d44e9
authored
Aug 21, 2018
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MaskRCNN] train-time scale augmentation
parent
2efc98f7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
11 deletions
+17
-11
examples/FasterRCNN/common.py
examples/FasterRCNN/common.py
+11
-6
examples/FasterRCNN/config.py
examples/FasterRCNN/config.py
+2
-1
examples/FasterRCNN/data.py
examples/FasterRCNN/data.py
+1
-1
examples/FasterRCNN/eval.py
examples/FasterRCNN/eval.py
+1
-1
examples/FasterRCNN/train.py
examples/FasterRCNN/train.py
+2
-2
No files found.
examples/FasterRCNN/common.py
View file @
843d44e9
...
@@ -32,22 +32,27 @@ class CustomResize(transform.TransformAugmentorBase):
...
@@ -32,22 +32,27 @@ class CustomResize(transform.TransformAugmentorBase):
while avoiding the longest edge to exceed max_size.
while avoiding the longest edge to exceed max_size.
"""
"""
def
__init__
(
self
,
s
ize
,
max_size
,
interp
=
cv2
.
INTER_LINEAR
):
def
__init__
(
self
,
s
hort_edge_length
,
max_size
,
interp
=
cv2
.
INTER_LINEAR
):
"""
"""
Args:
Args:
size (int): the size to resize the shortest edge to.
short_edge_length ([int, int]): a [min, max] interval from which to sample the
max_size (int): maximum allowed longest edge.
shortest edge length.
max_size (int): maximum allowed longest edge length.
"""
"""
super
(
CustomResize
,
self
)
.
__init__
()
super
(
CustomResize
,
self
)
.
__init__
()
if
isinstance
(
short_edge_length
,
int
):
short_edge_length
=
(
short_edge_length
,
short_edge_length
)
self
.
_init
(
locals
())
self
.
_init
(
locals
())
def
_get_augment_params
(
self
,
img
):
def
_get_augment_params
(
self
,
img
):
h
,
w
=
img
.
shape
[:
2
]
h
,
w
=
img
.
shape
[:
2
]
scale
=
self
.
size
*
1.0
/
min
(
h
,
w
)
size
=
self
.
rng
.
randint
(
self
.
short_edge_length
[
0
],
self
.
short_edge_length
[
1
]
+
1
)
scale
=
size
*
1.0
/
min
(
h
,
w
)
if
h
<
w
:
if
h
<
w
:
newh
,
neww
=
s
elf
.
s
ize
,
scale
*
w
newh
,
neww
=
size
,
scale
*
w
else
:
else
:
newh
,
neww
=
scale
*
h
,
s
elf
.
s
ize
newh
,
neww
=
scale
*
h
,
size
if
max
(
newh
,
neww
)
>
self
.
max_size
:
if
max
(
newh
,
neww
)
>
self
.
max_size
:
scale
=
self
.
max_size
*
1.0
/
max
(
newh
,
neww
)
scale
=
self
.
max_size
*
1.0
/
max
(
newh
,
neww
)
newh
=
newh
*
scale
newh
=
newh
*
scale
...
...
examples/FasterRCNN/config.py
View file @
843d44e9
...
@@ -107,7 +107,8 @@ _C.TRAIN.NUM_EVALS = 20 # number of evaluations to run during training
...
@@ -107,7 +107,8 @@ _C.TRAIN.NUM_EVALS = 20 # number of evaluations to run during training
# preprocessing --------------------
# preprocessing --------------------
# Alternative old (worse & faster) setting: 600, 1024
# Alternative old (worse & faster) setting: 600, 1024
_C
.
PREPROC
.
SHORT_EDGE_SIZE
=
800
_C
.
PREPROC
.
TRAIN_SHORT_EDGE_SIZE
=
[
800
,
800
]
# [min, max] to sample from
_C
.
PREPROC
.
TEST_SHORT_EDGE_SIZE
=
800
_C
.
PREPROC
.
MAX_SIZE
=
1333
_C
.
PREPROC
.
MAX_SIZE
=
1333
# mean and std in RGB order.
# mean and std in RGB order.
# Un-scaled version: [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]
# Un-scaled version: [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]
...
...
examples/FasterRCNN/data.py
View file @
843d44e9
...
@@ -311,7 +311,7 @@ def get_train_dataflow():
...
@@ -311,7 +311,7 @@ def get_train_dataflow():
ds
=
DataFromList
(
roidbs
,
shuffle
=
True
)
ds
=
DataFromList
(
roidbs
,
shuffle
=
True
)
aug
=
imgaug
.
AugmentorList
(
aug
=
imgaug
.
AugmentorList
(
[
CustomResize
(
cfg
.
PREPROC
.
SHORT_EDGE_SIZE
,
cfg
.
PREPROC
.
MAX_SIZE
),
[
CustomResize
(
cfg
.
PREPROC
.
TRAIN_
SHORT_EDGE_SIZE
,
cfg
.
PREPROC
.
MAX_SIZE
),
imgaug
.
Flip
(
horiz
=
True
)])
imgaug
.
Flip
(
horiz
=
True
)])
def
preprocess
(
roidb
):
def
preprocess
(
roidb
):
...
...
examples/FasterRCNN/eval.py
View file @
843d44e9
...
@@ -70,7 +70,7 @@ def detect_one_image(img, model_func):
...
@@ -70,7 +70,7 @@ def detect_one_image(img, model_func):
"""
"""
orig_shape
=
img
.
shape
[:
2
]
orig_shape
=
img
.
shape
[:
2
]
resizer
=
CustomResize
(
cfg
.
PREPROC
.
SHORT_EDGE_SIZE
,
cfg
.
PREPROC
.
MAX_SIZE
)
resizer
=
CustomResize
(
cfg
.
PREPROC
.
TEST_
SHORT_EDGE_SIZE
,
cfg
.
PREPROC
.
MAX_SIZE
)
resized_img
=
resizer
.
augment
(
img
)
resized_img
=
resizer
.
augment
(
img
)
scale
=
np
.
sqrt
(
resized_img
.
shape
[
0
]
*
1.0
/
img
.
shape
[
0
]
*
resized_img
.
shape
[
1
]
/
img
.
shape
[
1
])
scale
=
np
.
sqrt
(
resized_img
.
shape
[
0
]
*
1.0
/
img
.
shape
[
0
]
*
resized_img
.
shape
[
1
]
/
img
.
shape
[
1
])
boxes
,
probs
,
labels
,
*
masks
=
model_func
(
resized_img
)
boxes
,
probs
,
labels
,
*
masks
=
model_func
(
resized_img
)
...
...
examples/FasterRCNN/train.py
View file @
843d44e9
...
@@ -162,7 +162,7 @@ class ResNetC4Model(DetectionModel):
...
@@ -162,7 +162,7 @@ class ResNetC4Model(DetectionModel):
fastrcnn_label_logits
,
fastrcnn_box_logits
=
fastrcnn_outputs
(
'fastrcnn'
,
feature_gap
,
cfg
.
DATA
.
NUM_CLASS
)
fastrcnn_label_logits
,
fastrcnn_box_logits
=
fastrcnn_outputs
(
'fastrcnn'
,
feature_gap
,
cfg
.
DATA
.
NUM_CLASS
)
fastrcnn_head
=
FastRCNNHead
(
rcnn_boxes
,
fastrcnn_box_logits
,
fastrcnn_label_logits
,
fastrcnn_head
=
FastRCNNHead
(
rcnn_boxes
,
fastrcnn_box_logits
,
fastrcnn_label_logits
,
tf
.
constant
(
cfg
.
FRCNN
.
BBOX_REG_WEIGHTS
),
tf
.
constant
(
cfg
.
FRCNN
.
BBOX_REG_WEIGHTS
,
dtype
=
tf
.
float32
),
rcnn_labels
,
matched_gt_boxes
)
rcnn_labels
,
matched_gt_boxes
)
if
is_training
:
if
is_training
:
...
@@ -293,7 +293,7 @@ class ResNetFPNModel(DetectionModel):
...
@@ -293,7 +293,7 @@ class ResNetFPNModel(DetectionModel):
fastrcnn_label_logits
,
fastrcnn_box_logits
=
fastrcnn_head_func
(
fastrcnn_label_logits
,
fastrcnn_box_logits
=
fastrcnn_head_func
(
'fastrcnn'
,
roi_feature_fastrcnn
,
cfg
.
DATA
.
NUM_CLASS
)
'fastrcnn'
,
roi_feature_fastrcnn
,
cfg
.
DATA
.
NUM_CLASS
)
fastrcnn_head
=
FastRCNNHead
(
rcnn_boxes
,
fastrcnn_box_logits
,
fastrcnn_label_logits
,
fastrcnn_head
=
FastRCNNHead
(
rcnn_boxes
,
fastrcnn_box_logits
,
fastrcnn_label_logits
,
tf
.
constant
(
cfg
.
FRCNN
.
BBOX_REG_WEIGHTS
),
tf
.
constant
(
cfg
.
FRCNN
.
BBOX_REG_WEIGHTS
,
dtype
=
tf
.
float32
),
rcnn_labels
,
matched_gt_boxes
)
rcnn_labels
,
matched_gt_boxes
)
if
is_training
:
if
is_training
:
...
...
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