Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
SOLOv2-pytorch
Commits
1c9afecf
Unverified
Commit
1c9afecf
authored
Nov 27, 2019
by
Kai Chen
Committed by
GitHub
Nov 27, 2019
Browse files
recover PR#1115 to add flip direction (#1273)
parent
d0c04187
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
+25
-8
mmdet/datasets/pipelines/transforms.py
mmdet/datasets/pipelines/transforms.py
+25
-8
No files found.
mmdet/datasets/pipelines/transforms.py
View file @
1c9afecf
...
@@ -179,12 +179,14 @@ class RandomFlip(object):
...
@@ -179,12 +179,14 @@ class RandomFlip(object):
flip_ratio (float, optional): The flipping probability.
flip_ratio (float, optional): The flipping probability.
"""
"""
def
__init__
(
self
,
flip_ratio
=
None
):
def
__init__
(
self
,
flip_ratio
=
None
,
direction
=
'horizontal'
):
self
.
flip_ratio
=
flip_ratio
self
.
flip_ratio
=
flip_ratio
self
.
direction
=
direction
if
flip_ratio
is
not
None
:
if
flip_ratio
is
not
None
:
assert
flip_ratio
>=
0
and
flip_ratio
<=
1
assert
flip_ratio
>=
0
and
flip_ratio
<=
1
assert
direction
in
[
'horizontal'
,
'vertical'
]
def
bbox_flip
(
self
,
bboxes
,
img_shape
):
def
bbox_flip
(
self
,
bboxes
,
img_shape
,
direction
):
"""Flip bboxes horizontally.
"""Flip bboxes horizontally.
Args:
Args:
...
@@ -192,26 +194,41 @@ class RandomFlip(object):
...
@@ -192,26 +194,41 @@ class RandomFlip(object):
img_shape(tuple): (height, width)
img_shape(tuple): (height, width)
"""
"""
assert
bboxes
.
shape
[
-
1
]
%
4
==
0
assert
bboxes
.
shape
[
-
1
]
%
4
==
0
w
=
img_shape
[
1
]
flipped
=
bboxes
.
copy
()
flipped
=
bboxes
.
copy
()
flipped
[...,
0
::
4
]
=
w
-
bboxes
[...,
2
::
4
]
-
1
if
direction
==
'horizontal'
:
flipped
[...,
2
::
4
]
=
w
-
bboxes
[...,
0
::
4
]
-
1
w
=
img_shape
[
1
]
flipped
[...,
0
::
4
]
=
w
-
bboxes
[...,
2
::
4
]
-
1
flipped
[...,
2
::
4
]
=
w
-
bboxes
[...,
0
::
4
]
-
1
elif
direction
==
'vertical'
:
h
=
img_shape
[
0
]
flipped
[...,
1
::
4
]
=
h
-
bboxes
[...,
3
::
4
]
-
1
flipped
[...,
3
::
4
]
=
h
-
bboxes
[...,
1
::
4
]
-
1
else
:
raise
ValueError
(
'Invalid flipping direction "{}"'
.
format
(
direction
))
return
flipped
return
flipped
def
__call__
(
self
,
results
):
def
__call__
(
self
,
results
):
if
'flip'
not
in
results
:
if
'flip'
not
in
results
:
flip
=
True
if
np
.
random
.
rand
()
<
self
.
flip_ratio
else
False
flip
=
True
if
np
.
random
.
rand
()
<
self
.
flip_ratio
else
False
results
[
'flip'
]
=
flip
results
[
'flip'
]
=
flip
if
'flip_direction'
not
in
results
:
results
[
'flip_direction'
]
=
self
.
direction
if
results
[
'flip'
]:
if
results
[
'flip'
]:
# flip image
# flip image
results
[
'img'
]
=
mmcv
.
imflip
(
results
[
'img'
])
results
[
'img'
]
=
mmcv
.
imflip
(
results
[
'img'
],
direction
=
results
[
'flip_direction'
])
# flip bboxes
# flip bboxes
for
key
in
results
.
get
(
'bbox_fields'
,
[]):
for
key
in
results
.
get
(
'bbox_fields'
,
[]):
results
[
key
]
=
self
.
bbox_flip
(
results
[
key
],
results
[
key
]
=
self
.
bbox_flip
(
results
[
key
],
results
[
'img_shape'
])
results
[
'img_shape'
],
results
[
'flip_direction'
])
# flip masks
# flip masks
for
key
in
results
.
get
(
'mask_fields'
,
[]):
for
key
in
results
.
get
(
'mask_fields'
,
[]):
results
[
key
]
=
[
mask
[:,
::
-
1
]
for
mask
in
results
[
key
]]
results
[
key
]
=
[
mmcv
.
imflip
(
mask
,
direction
=
results
[
'flip_direction'
])
for
mask
in
results
[
key
]
]
return
results
return
results
def
__repr__
(
self
):
def
__repr__
(
self
):
...
...
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