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
ResNet50_tensorflow
Commits
ec4b78f3
Commit
ec4b78f3
authored
Nov 13, 2020
by
A. Unique TensorFlower
Committed by
TF Object Detection Team
Nov 13, 2020
Browse files
Add a preprocessing method to adjust gamma.
PiperOrigin-RevId: 342373365
parent
e1d7dafb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
2 deletions
+62
-2
research/object_detection/builders/preprocessor_builder.py
research/object_detection/builders/preprocessor_builder.py
+2
-0
research/object_detection/builders/preprocessor_builder_test.py
...ch/object_detection/builders/preprocessor_builder_test.py
+13
-0
research/object_detection/core/preprocessor.py
research/object_detection/core/preprocessor.py
+17
-1
research/object_detection/core/preprocessor_test.py
research/object_detection/core/preprocessor_test.py
+22
-0
research/object_detection/protos/preprocessor.proto
research/object_detection/protos/preprocessor.proto
+8
-1
No files found.
research/object_detection/builders/preprocessor_builder.py
View file @
ec4b78f3
...
...
@@ -109,6 +109,8 @@ PREPROCESSING_FUNCTION_MAP = {
preprocessor
.
subtract_channel_mean
,
'convert_class_logits_to_softmax'
:
preprocessor
.
convert_class_logits_to_softmax
,
'adjust_gamma'
:
preprocessor
.
adjust_gamma
,
}
...
...
research/object_detection/builders/preprocessor_builder_test.py
View file @
ec4b78f3
...
...
@@ -753,6 +753,19 @@ class PreprocessorBuilderTest(tf.test.TestCase):
'max_border'
:
128
})
def
test_adjust_gamma
(
self
):
preprocessor_text_proto
=
"""
adjust_gamma {
gamma: 2.2
gain: 2.0
}
"""
preprocessor_proto
=
preprocessor_pb2
.
PreprocessingStep
()
text_format
.
Parse
(
preprocessor_text_proto
,
preprocessor_proto
)
function
,
args
=
preprocessor_builder
.
build
(
preprocessor_proto
)
self
.
assertEqual
(
function
,
preprocessor
.
adjust_gamma
)
self
.
assert_dictionary_close
(
args
,
{
'gamma'
:
2.2
,
'gain'
:
2.0
})
if
__name__
==
'__main__'
:
tf
.
test
.
main
()
research/object_detection/core/preprocessor.py
View file @
ec4b78f3
...
...
@@ -1049,6 +1049,22 @@ def random_rgb_to_gray(image,
return
image
def
adjust_gamma
(
image
,
gamma
=
1.0
,
gain
=
1.0
):
"""Adjusts the gamma.
Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 255].
gamma: the gamma value. Must be a non-negative real number.
gain: a constant multiplier.
Returns:
image: image which is the same shape as input image.
"""
with
tf
.
name_scope
(
'AdjustGamma'
,
values
=
[
image
]):
return
tf
.
image
.
adjust_gamma
(
image
,
gamma
,
gain
)
def
random_adjust_brightness
(
image
,
max_delta
=
0.2
,
seed
=
None
,
...
...
@@ -1069,7 +1085,6 @@ def random_adjust_brightness(image,
Returns:
image: image which is the same shape as input image.
boxes: boxes which is the same shape as input boxes.
"""
with
tf
.
name_scope
(
'RandomAdjustBrightness'
,
values
=
[
image
]):
generator_func
=
functools
.
partial
(
tf
.
random_uniform
,
[],
...
...
@@ -4504,6 +4519,7 @@ def get_default_func_arg_map(include_label_weights=True,
fields
.
InputDataFields
.
groundtruth_classes
,
groundtruth_label_weights
,
groundtruth_instance_masks
,
groundtruth_keypoints
,
groundtruth_label_confidences
),
adjust_gamma
:
(
fields
.
InputDataFields
.
image
,),
}
return
prep_func_arg_map
...
...
research/object_detection/core/preprocessor_test.py
View file @
ec4b78f3
...
...
@@ -3957,6 +3957,28 @@ class PreprocessorTest(test_case.TestCase, parameterized.TestCase):
self
.
assertLen
(
boxes
,
2
)
self
.
assertAllEqual
(
confidences
,
[
-
1.0
,
1.0
])
def
testAdjustGamma
(
self
):
def
graph_fn
():
preprocessing_options
=
[]
preprocessing_options
.
append
((
preprocessor
.
normalize_image
,
{
'original_minval'
:
0
,
'original_maxval'
:
255
,
'target_minval'
:
0
,
'target_maxval'
:
1
}))
preprocessing_options
.
append
((
preprocessor
.
adjust_gamma
,
{}))
images_original
=
self
.
createTestImages
()
tensor_dict
=
{
fields
.
InputDataFields
.
image
:
images_original
}
tensor_dict
=
preprocessor
.
preprocess
(
tensor_dict
,
preprocessing_options
)
images_gamma
=
tensor_dict
[
fields
.
InputDataFields
.
image
]
image_original_shape
=
tf
.
shape
(
images_original
)
image_gamma_shape
=
tf
.
shape
(
images_gamma
)
return
[
image_original_shape
,
image_gamma_shape
]
(
image_original_shape_
,
image_gamma_shape_
)
=
self
.
execute_cpu
(
graph_fn
,
[])
self
.
assertAllEqual
(
image_original_shape_
,
image_gamma_shape_
)
if
__name__
==
'__main__'
:
tf
.
test
.
main
()
research/object_detection/protos/preprocessor.proto
View file @
ec4b78f3
...
...
@@ -4,7 +4,7 @@ package object_detection.protos;
// Message for defining a preprocessing operation on input data.
// See: //third_party/tensorflow_models/object_detection/core/preprocessor.py
// Next ID:
39
// Next ID:
40
message
PreprocessingStep
{
oneof
preprocessing_step
{
NormalizeImage
normalize_image
=
1
;
...
...
@@ -45,6 +45,7 @@ message PreprocessingStep {
RandomPatchGaussian
random_patch_gaussian
=
36
;
RandomSquareCropByScale
random_square_crop_by_scale
=
37
;
RandomScaleCropAndPadToSquare
random_scale_crop_and_pad_to_square
=
38
;
AdjustGamma
adjust_gamma
=
39
;
}
}
...
...
@@ -590,3 +591,9 @@ message RandomScaleCropAndPadToSquare {
optional
float
scale_min
=
2
[
default
=
0.1
];
optional
float
scale_max
=
3
[
default
=
2.0
];
}
// Adjusts the gamma of the image using the specified gamma and gain values.
message
AdjustGamma
{
optional
float
gamma
=
1
[
default
=
1.0
];
optional
float
gain
=
2
[
default
=
1.0
];
}
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