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
a03774d6
Commit
a03774d6
authored
May 30, 2022
by
YuanLiuuuuuu
Committed by
zhouzaida
Jul 19, 2022
Browse files
[Refactor]: Grascale return uint8 type
parent
5867a97a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
mmcv/transforms/processing.py
mmcv/transforms/processing.py
+2
-0
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 @
a03774d6
...
@@ -692,6 +692,7 @@ class RandomGrayscale(BaseTransform):
...
@@ -692,6 +692,7 @@ class RandomGrayscale(BaseTransform):
normalized_weights
=
(
normalized_weights
=
(
np
.
array
(
self
.
channel_weights
)
/
sum
(
self
.
channel_weights
))
np
.
array
(
self
.
channel_weights
)
/
sum
(
self
.
channel_weights
))
img
=
(
normalized_weights
*
img
).
sum
(
axis
=
2
)
img
=
(
normalized_weights
*
img
).
sum
(
axis
=
2
)
img
=
img
.
astype
(
'uint8'
)
if
self
.
keep_channels
:
if
self
.
keep_channels
:
img
=
img
[:,
:,
None
]
img
=
img
[:,
:,
None
]
results
[
'img'
]
=
np
.
dstack
(
results
[
'img'
]
=
np
.
dstack
(
...
@@ -699,6 +700,7 @@ class RandomGrayscale(BaseTransform):
...
@@ -699,6 +700,7 @@ class RandomGrayscale(BaseTransform):
else
:
else
:
results
[
'img'
]
=
img
results
[
'img'
]
=
img
return
results
return
results
img
=
img
.
astype
(
'uint8'
)
results
[
'img'
]
=
img
results
[
'img'
]
=
img
return
results
return
results
...
...
tests/test_transforms/test_transforms_processing.py
View file @
a03774d6
...
@@ -474,7 +474,7 @@ class TestRandomGrayscale:
...
@@ -474,7 +474,7 @@ class TestRandomGrayscale:
@
classmethod
@
classmethod
def
setup_class
(
cls
):
def
setup_class
(
cls
):
cls
.
img
=
np
.
random
.
rand
(
10
,
10
,
3
).
astype
(
np
.
float32
)
cls
.
img
=
(
np
.
random
.
rand
(
10
,
10
,
3
)
*
255
)
.
astype
(
np
.
uint8
)
def
test_repr
(
self
):
def
test_repr
(
self
):
# test repr
# test repr
...
@@ -504,9 +504,9 @@ class TestRandomGrayscale:
...
@@ -504,9 +504,9 @@ class TestRandomGrayscale:
random_gray_scale_module
=
TRANSFORMS
.
build
(
transform
)
random_gray_scale_module
=
TRANSFORMS
.
build
(
transform
)
results
[
'img'
]
=
copy
.
deepcopy
(
self
.
img
)
results
[
'img'
]
=
copy
.
deepcopy
(
self
.
img
)
img
=
random_gray_scale_module
(
results
)[
'img'
]
img
=
random_gray_scale_module
(
results
)[
'img'
]
computed_gray
=
(
computed_gray
=
(
self
.
img
[:,
:,
0
]
*
0.299
+
self
.
img
[:,
:,
0
]
*
0.299
+
self
.
img
[:,
:,
1
]
*
0.587
+
self
.
img
[:,
:,
1
]
*
0.587
+
self
.
img
[:,
:,
2
]
*
0.114
)
self
.
img
[:,
:,
2
]
*
0.114
)
.
astype
(
np
.
uint8
)
for
i
in
range
(
img
.
shape
[
2
]):
for
i
in
range
(
img
.
shape
[
2
]):
assert_array_almost_equal
(
img
[:,
:,
i
],
computed_gray
,
decimal
=
4
)
assert_array_almost_equal
(
img
[:,
:,
i
],
computed_gray
,
decimal
=
4
)
assert
img
.
shape
==
(
10
,
10
,
3
)
assert
img
.
shape
==
(
10
,
10
,
3
)
...
...
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