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
OpenDAS
MMCV
Commits
30b38446
Commit
30b38446
authored
Apr 26, 2022
by
Yuan Liu
Committed by
zhouzaida
Jul 19, 2022
Browse files
[Fix]: Update img_shape in resize related transform (#1907)
parent
ff0dfb74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
mmcv/transforms/processing.py
mmcv/transforms/processing.py
+13
-13
tests/test_transforms/test_transforms_processing.py
tests/test_transforms/test_transforms_processing.py
+4
-4
No files found.
mmcv/transforms/processing.py
View file @
30b38446
...
@@ -99,8 +99,7 @@ class Resize(BaseTransform):
...
@@ -99,8 +99,7 @@ class Resize(BaseTransform):
- gt_bboxes
- gt_bboxes
- gt_seg_map
- gt_seg_map
- gt_keypoints
- gt_keypoints
- height
- img_shape
- width
Added Keys:
Added Keys:
...
@@ -187,7 +186,7 @@ class Resize(BaseTransform):
...
@@ -187,7 +186,7 @@ class Resize(BaseTransform):
return_scale
=
True
,
return_scale
=
True
,
backend
=
self
.
backend
)
backend
=
self
.
backend
)
results
[
'img'
]
=
img
results
[
'img'
]
=
img
results
[
'
height'
],
results
[
'width
'
]
=
img
.
shape
[:
2
]
results
[
'
img_shape
'
]
=
img
.
shape
[:
2
]
results
[
'scale'
]
=
img
.
shape
[:
2
][::
-
1
]
results
[
'scale'
]
=
img
.
shape
[:
2
][::
-
1
]
results
[
'scale_factor'
]
=
(
w_scale
,
h_scale
)
results
[
'scale_factor'
]
=
(
w_scale
,
h_scale
)
results
[
'keep_ratio'
]
=
self
.
keep_ratio
results
[
'keep_ratio'
]
=
self
.
keep_ratio
...
@@ -198,9 +197,10 @@ class Resize(BaseTransform):
...
@@ -198,9 +197,10 @@ class Resize(BaseTransform):
bboxes
=
results
[
'gt_bboxes'
]
*
np
.
tile
(
bboxes
=
results
[
'gt_bboxes'
]
*
np
.
tile
(
np
.
array
(
results
[
'scale_factor'
]),
2
)
np
.
array
(
results
[
'scale_factor'
]),
2
)
if
self
.
clip_object_border
:
if
self
.
clip_object_border
:
bboxes
[:,
0
::
2
]
=
np
.
clip
(
bboxes
[:,
0
::
2
],
0
,
results
[
'width'
])
bboxes
[:,
0
::
2
]
=
np
.
clip
(
bboxes
[:,
0
::
2
],
0
,
results
[
'img_shape'
][
1
])
bboxes
[:,
1
::
2
]
=
np
.
clip
(
bboxes
[:,
1
::
2
],
0
,
bboxes
[:,
1
::
2
]
=
np
.
clip
(
bboxes
[:,
1
::
2
],
0
,
results
[
'
height'
])
results
[
'
img_shape'
][
0
])
results
[
'gt_bboxes'
]
=
bboxes
results
[
'gt_bboxes'
]
=
bboxes
def
_resize_seg
(
self
,
results
:
dict
)
->
None
:
def
_resize_seg
(
self
,
results
:
dict
)
->
None
:
...
@@ -229,9 +229,9 @@ class Resize(BaseTransform):
...
@@ -229,9 +229,9 @@ class Resize(BaseTransform):
results
[
'scale_factor'
])
results
[
'scale_factor'
])
if
self
.
clip_object_border
:
if
self
.
clip_object_border
:
keypoints
[:,
:,
0
]
=
np
.
clip
(
keypoints
[:,
:,
0
],
0
,
keypoints
[:,
:,
0
]
=
np
.
clip
(
keypoints
[:,
:,
0
],
0
,
results
[
'
width'
])
results
[
'
img_shape'
][
1
])
keypoints
[:,
:,
1
]
=
np
.
clip
(
keypoints
[:,
:,
1
],
0
,
keypoints
[:,
:,
1
]
=
np
.
clip
(
keypoints
[:,
:,
1
],
0
,
results
[
'
height'
])
results
[
'
img_shape'
][
0
])
results
[
'gt_keypoints'
]
=
keypoints
results
[
'gt_keypoints'
]
=
keypoints
def
transform
(
self
,
results
:
dict
)
->
dict
:
def
transform
(
self
,
results
:
dict
)
->
dict
:
...
@@ -242,7 +242,7 @@ class Resize(BaseTransform):
...
@@ -242,7 +242,7 @@ class Resize(BaseTransform):
results (dict): Result dict from loading pipeline.
results (dict): Result dict from loading pipeline.
Returns:
Returns:
dict: Resized results, 'img', 'gt_bboxes', 'gt_seg_map',
dict: Resized results, 'img', 'gt_bboxes', 'gt_seg_map',
'gt_keypoints', 'scale', 'scale_factor', '
height', 'width
',
'gt_keypoints', 'scale', 'scale_factor', '
img_shape
',
and 'keep_ratio' keys are updated in result dict.
and 'keep_ratio' keys are updated in result dict.
"""
"""
...
@@ -895,8 +895,7 @@ class RandomChoiceResize(BaseTransform):
...
@@ -895,8 +895,7 @@ class RandomChoiceResize(BaseTransform):
Modified Keys:
Modified Keys:
- img
- img
- height
- img_shape
- width
- gt_bboxes (optional)
- gt_bboxes (optional)
- gt_seg_map (optional)
- gt_seg_map (optional)
- gt_keypoints (optional)
- gt_keypoints (optional)
...
@@ -952,7 +951,7 @@ class RandomChoiceResize(BaseTransform):
...
@@ -952,7 +951,7 @@ class RandomChoiceResize(BaseTransform):
Returns:
Returns:
dict: Resized results, 'img', 'gt_bboxes', 'gt_seg_map',
dict: Resized results, 'img', 'gt_bboxes', 'gt_seg_map',
'gt_keypoints', 'scale', 'scale_factor', '
height', 'width
',
'gt_keypoints', 'scale', 'scale_factor', '
img_shape
',
and 'keep_ratio' keys are updated in result dict.
and 'keep_ratio' keys are updated in result dict.
"""
"""
...
@@ -1226,6 +1225,7 @@ class RandomResize(BaseTransform):
...
@@ -1226,6 +1225,7 @@ class RandomResize(BaseTransform):
- gt_bboxes
- gt_bboxes
- gt_seg_map
- gt_seg_map
- gt_keypoints
- gt_keypoints
- img_shape
Added Keys:
Added Keys:
...
@@ -1335,8 +1335,8 @@ class RandomResize(BaseTransform):
...
@@ -1335,8 +1335,8 @@ class RandomResize(BaseTransform):
results (dict): Result dict from loading pipeline.
results (dict): Result dict from loading pipeline.
Returns:
Returns:
dict: Resized results, ``img``, ``gt_bboxes``, ``gt_semantic_seg``,
dict: Resized results, ``img``, ``gt_bboxes``, ``gt_semantic_seg``,
``gt_keypoints``, ``scale``, ``scale_factor``, ``
height``,
``gt_keypoints``, ``scale``, ``scale_factor``, ``
img_shape``, and
``width``, and
``keep_ratio`` keys are updated in result dict.
``keep_ratio`` keys are updated in result dict.
"""
"""
results
[
'scale'
]
=
self
.
_random_scale
()
results
[
'scale'
]
=
self
.
_random_scale
()
self
.
resize
.
scale
=
results
[
'scale'
]
self
.
resize
.
scale
=
results
[
'scale'
]
...
...
tests/test_transforms/test_transforms_processing.py
View file @
30b38446
...
@@ -874,10 +874,10 @@ class TestRandomResize:
...
@@ -874,10 +874,10 @@ class TestRandomResize:
(
224
,
224
),
(
1.0
,
2.0
),
(
224
,
224
),
(
1.0
,
2.0
),
resize_cfg
=
dict
(
type
=
'Resize'
,
keep_ratio
=
True
))
resize_cfg
=
dict
(
type
=
'Resize'
,
keep_ratio
=
True
))
results_update
=
TRANSFORMS
.
transform
(
copy
.
deepcopy
(
results
))
results_update
=
TRANSFORMS
.
transform
(
copy
.
deepcopy
(
results
))
assert
224
<=
results_update
[
'
height'
]
assert
224
<=
results_update
[
'
img_shape'
][
0
]
assert
448
>=
results_update
[
'
height'
]
assert
448
>=
results_update
[
'
img_shape'
][
0
]
assert
224
<=
results_update
[
'
width'
]
assert
224
<=
results_update
[
'
img_shape'
][
1
]
assert
448
>=
results_update
[
'
width'
]
assert
448
>=
results_update
[
'
img_shape'
][
1
]
assert
results_update
[
'keep_ratio'
]
assert
results_update
[
'keep_ratio'
]
assert
results
[
'gt_bboxes'
][
0
][
2
]
>=
112
assert
results
[
'gt_bboxes'
][
0
][
2
]
>=
112
assert
results
[
'gt_bboxes'
][
0
][
2
]
<=
112
assert
results
[
'gt_bboxes'
][
0
][
2
]
<=
112
...
...
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