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
ad83b2db
Commit
ad83b2db
authored
Jul 12, 2022
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 460499239
parent
0cda06fa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
47 deletions
+73
-47
official/vision/dataloaders/tf_example_decoder.py
official/vision/dataloaders/tf_example_decoder.py
+14
-2
official/vision/dataloaders/tf_example_decoder_test.py
official/vision/dataloaders/tf_example_decoder_test.py
+17
-12
official/vision/dataloaders/tfexample_utils.py
official/vision/dataloaders/tfexample_utils.py
+42
-33
No files found.
official/vision/dataloaders/tf_example_decoder.py
View file @
ad83b2db
...
@@ -39,8 +39,8 @@ class TfExampleDecoder(decoder.Decoder):
...
@@ -39,8 +39,8 @@ class TfExampleDecoder(decoder.Decoder):
self
.
_regenerate_source_id
=
regenerate_source_id
self
.
_regenerate_source_id
=
regenerate_source_id
self
.
_keys_to_features
=
{
self
.
_keys_to_features
=
{
'image/encoded'
:
tf
.
io
.
FixedLenFeature
((),
tf
.
string
),
'image/encoded'
:
tf
.
io
.
FixedLenFeature
((),
tf
.
string
),
'image/height'
:
tf
.
io
.
FixedLenFeature
((),
tf
.
int64
),
'image/height'
:
tf
.
io
.
FixedLenFeature
((),
tf
.
int64
,
-
1
),
'image/width'
:
tf
.
io
.
FixedLenFeature
((),
tf
.
int64
),
'image/width'
:
tf
.
io
.
FixedLenFeature
((),
tf
.
int64
,
-
1
),
'image/object/bbox/xmin'
:
tf
.
io
.
VarLenFeature
(
tf
.
float32
),
'image/object/bbox/xmin'
:
tf
.
io
.
VarLenFeature
(
tf
.
float32
),
'image/object/bbox/xmax'
:
tf
.
io
.
VarLenFeature
(
tf
.
float32
),
'image/object/bbox/xmax'
:
tf
.
io
.
VarLenFeature
(
tf
.
float32
),
'image/object/bbox/ymin'
:
tf
.
io
.
VarLenFeature
(
tf
.
float32
),
'image/object/bbox/ymin'
:
tf
.
io
.
VarLenFeature
(
tf
.
float32
),
...
@@ -148,6 +148,18 @@ class TfExampleDecoder(decoder.Decoder):
...
@@ -148,6 +148,18 @@ class TfExampleDecoder(decoder.Decoder):
boxes
=
self
.
_decode_boxes
(
parsed_tensors
)
boxes
=
self
.
_decode_boxes
(
parsed_tensors
)
classes
=
self
.
_decode_classes
(
parsed_tensors
)
classes
=
self
.
_decode_classes
(
parsed_tensors
)
areas
=
self
.
_decode_areas
(
parsed_tensors
)
areas
=
self
.
_decode_areas
(
parsed_tensors
)
decode_image_shape
=
tf
.
logical_or
(
tf
.
equal
(
parsed_tensors
[
'image/height'
],
-
1
),
tf
.
equal
(
parsed_tensors
[
'image/width'
],
-
1
))
image_shape
=
tf
.
cast
(
tf
.
shape
(
image
),
dtype
=
tf
.
int64
)
parsed_tensors
[
'image/height'
]
=
tf
.
where
(
decode_image_shape
,
image_shape
[
0
],
parsed_tensors
[
'image/height'
])
parsed_tensors
[
'image/width'
]
=
tf
.
where
(
decode_image_shape
,
image_shape
[
1
],
parsed_tensors
[
'image/width'
])
is_crowds
=
tf
.
cond
(
is_crowds
=
tf
.
cond
(
tf
.
greater
(
tf
.
shape
(
parsed_tensors
[
'image/object/is_crowd'
])[
0
],
0
),
tf
.
greater
(
tf
.
shape
(
parsed_tensors
[
'image/object/is_crowd'
])[
0
],
0
),
lambda
:
tf
.
cast
(
parsed_tensors
[
'image/object/is_crowd'
],
dtype
=
tf
.
bool
),
lambda
:
tf
.
cast
(
parsed_tensors
[
'image/object/is_crowd'
],
dtype
=
tf
.
bool
),
...
...
official/vision/dataloaders/tf_example_decoder_test.py
View file @
ad83b2db
...
@@ -26,18 +26,21 @@ from official.vision.dataloaders import tfexample_utils
...
@@ -26,18 +26,21 @@ from official.vision.dataloaders import tfexample_utils
class
TfExampleDecoderTest
(
tf
.
test
.
TestCase
,
parameterized
.
TestCase
):
class
TfExampleDecoderTest
(
tf
.
test
.
TestCase
,
parameterized
.
TestCase
):
@
parameterized
.
parameters
(
@
parameterized
.
parameters
(
(
100
,
100
,
0
,
True
),
(
100
,
100
,
0
,
True
,
True
),
(
100
,
100
,
1
,
True
),
(
100
,
100
,
1
,
True
,
True
),
(
100
,
100
,
2
,
True
),
(
100
,
100
,
2
,
True
,
True
),
(
100
,
100
,
0
,
False
),
(
100
,
100
,
0
,
False
,
True
),
(
100
,
100
,
1
,
False
),
(
100
,
100
,
1
,
False
,
True
),
(
100
,
100
,
2
,
False
),
(
100
,
100
,
2
,
False
,
True
),
(
100
,
100
,
0
,
True
,
False
),
(
100
,
100
,
1
,
True
,
False
),
(
100
,
100
,
2
,
True
,
False
),
(
100
,
100
,
0
,
False
,
False
),
(
100
,
100
,
1
,
False
,
False
),
(
100
,
100
,
2
,
False
,
False
),
)
)
def
test_result_shape
(
self
,
def
test_result_shape
(
self
,
image_height
,
image_width
,
num_instances
,
image_height
,
regenerate_source_id
,
fill_image_size
):
image_width
,
num_instances
,
regenerate_source_id
):
decoder
=
tf_example_decoder
.
TfExampleDecoder
(
decoder
=
tf_example_decoder
.
TfExampleDecoder
(
include_mask
=
True
,
regenerate_source_id
=
regenerate_source_id
)
include_mask
=
True
,
regenerate_source_id
=
regenerate_source_id
)
...
@@ -45,7 +48,9 @@ class TfExampleDecoderTest(tf.test.TestCase, parameterized.TestCase):
...
@@ -45,7 +48,9 @@ class TfExampleDecoderTest(tf.test.TestCase, parameterized.TestCase):
image_height
=
image_height
,
image_height
=
image_height
,
image_width
=
image_width
,
image_width
=
image_width
,
image_channel
=
3
,
image_channel
=
3
,
num_instances
=
num_instances
).
SerializeToString
()
num_instances
=
num_instances
,
fill_image_size
=
fill_image_size
,
).
SerializeToString
()
decoded_tensors
=
decoder
.
decode
(
decoded_tensors
=
decoder
.
decode
(
tf
.
convert_to_tensor
(
value
=
serialized_example
))
tf
.
convert_to_tensor
(
value
=
serialized_example
))
...
...
official/vision/dataloaders/tfexample_utils.py
View file @
ad83b2db
...
@@ -194,9 +194,12 @@ def create_3d_image_test_example(image_height: int, image_width: int,
...
@@ -194,9 +194,12 @@ def create_3d_image_test_example(image_height: int, image_width: int,
return
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
feature
))
return
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
feature
))
def
create_detection_test_example
(
image_height
:
int
,
image_width
:
int
,
def
create_detection_test_example
(
image_channel
:
int
,
image_height
:
int
,
num_instances
:
int
)
->
tf
.
train
.
Example
:
image_width
:
int
,
image_channel
:
int
,
num_instances
:
int
,
fill_image_size
:
bool
=
True
)
->
tf
.
train
.
Example
:
"""Creates and returns a test example containing box and mask annotations.
"""Creates and returns a test example containing box and mask annotations.
Args:
Args:
...
@@ -204,6 +207,7 @@ def create_detection_test_example(image_height: int, image_width: int,
...
@@ -204,6 +207,7 @@ def create_detection_test_example(image_height: int, image_width: int,
image_width: The width of test image.
image_width: The width of test image.
image_channel: The channel of test image.
image_channel: The channel of test image.
num_instances: The number of object instances per image.
num_instances: The number of object instances per image.
fill_image_size: If image height and width will be added to the example.
Returns:
Returns:
A tf.train.Example for testing.
A tf.train.Example for testing.
...
@@ -233,36 +237,41 @@ def create_detection_test_example(image_height: int, image_width: int,
...
@@ -233,36 +237,41 @@ def create_detection_test_example(image_height: int, image_width: int,
for
_
in
range
(
num_instances
):
for
_
in
range
(
num_instances
):
mask
=
make_image_bytes
([
image_height
,
image_width
],
fmt
=
'PNG'
)
mask
=
make_image_bytes
([
image_height
,
image_width
],
fmt
=
'PNG'
)
masks
.
append
(
mask
)
masks
.
append
(
mask
)
return
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
{
feature
=
{
'image/encoded'
:
'image/encoded'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
bytes_list
=
tf
.
train
.
BytesList
(
value
=
[
image
]))),
bytes_list
=
tf
.
train
.
BytesList
(
value
=
[
image
]))),
'image/source_id'
:
(
tf
.
train
.
Feature
(
'image/source_id'
:
(
tf
.
train
.
Feature
(
bytes_list
=
tf
.
train
.
BytesList
(
value
=
[
DUMP_SOURCE_ID
]))),
bytes_list
=
tf
.
train
.
BytesList
(
value
=
[
DUMP_SOURCE_ID
]))),
'image/object/bbox/xmin'
:
'image/height'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
float_list
=
tf
.
train
.
FloatList
(
value
=
xmins
))),
int64_list
=
tf
.
train
.
Int64List
(
value
=
[
image_height
]))),
'image/object/bbox/xmax'
:
'image/width'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
float_list
=
tf
.
train
.
FloatList
(
value
=
xmaxs
))),
int64_list
=
tf
.
train
.
Int64List
(
value
=
[
image_width
]))),
'image/object/bbox/ymin'
:
'image/object/bbox/xmin'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
float_list
=
tf
.
train
.
FloatList
(
value
=
ymins
))),
float_list
=
tf
.
train
.
FloatList
(
value
=
xmins
))),
'image/object/bbox/ymax'
:
'image/object/bbox/xmax'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
float_list
=
tf
.
train
.
FloatList
(
value
=
ymaxs
))),
float_list
=
tf
.
train
.
FloatList
(
value
=
xmaxs
))),
'image/object/class/label'
:
'image/object/bbox/ymin'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
int64_list
=
tf
.
train
.
Int64List
(
value
=
labels
))),
float_list
=
tf
.
train
.
FloatList
(
value
=
ymins
))),
'image/object/class/text'
:
'image/object/bbox/ymax'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
bytes_list
=
tf
.
train
.
BytesList
(
value
=
labels_text
))),
float_list
=
tf
.
train
.
FloatList
(
value
=
ymaxs
))),
'image/object/is_crowd'
:
'image/object/class/label'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
int64_list
=
tf
.
train
.
Int64List
(
value
=
is_crowds
))),
int64_list
=
tf
.
train
.
Int64List
(
value
=
labels
))),
'image/object/area'
:
'image/object/class/text'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
float_list
=
tf
.
train
.
FloatList
(
value
=
areas
))),
bytes_list
=
tf
.
train
.
BytesList
(
value
=
labels_text
))),
'image/object/mask'
:
'image/object/is_crowd'
:
(
tf
.
train
.
Feature
(
(
tf
.
train
.
Feature
(
bytes_list
=
tf
.
train
.
BytesList
(
value
=
masks
))),
int64_list
=
tf
.
train
.
Int64List
(
value
=
is_crowds
))),
}
'image/object/area'
:
(
tf
.
train
.
Feature
(
float_list
=
tf
.
train
.
FloatList
(
value
=
areas
))),
if
fill_image_size
:
'image/object/mask'
:
(
tf
.
train
.
Feature
(
feature
.
update
({
bytes_list
=
tf
.
train
.
BytesList
(
value
=
masks
))),
'image/height'
:
(
tf
.
train
.
Feature
(
}))
int64_list
=
tf
.
train
.
Int64List
(
value
=
[
image_height
]))),
'image/width'
:
(
tf
.
train
.
Feature
(
int64_list
=
tf
.
train
.
Int64List
(
value
=
[
image_width
]))),
})
return
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
feature
))
def
create_segmentation_test_example
(
image_height
:
int
,
image_width
:
int
,
def
create_segmentation_test_example
(
image_height
:
int
,
image_width
:
int
,
...
...
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