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
b915db4e
Commit
b915db4e
authored
Nov 26, 2018
by
Menglong Zhu
Committed by
dreamdragon
Nov 26, 2018
Browse files
Fix dependency issues.
PiperOrigin-RevId: 222888231
parent
8ab3e7a0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
23 deletions
+89
-23
research/lstm_object_detection/README
research/lstm_object_detection/README
+4
-1
research/lstm_object_detection/lstm/lstm_cells.py
research/lstm_object_detection/lstm/lstm_cells.py
+5
-4
research/lstm_object_detection/seq_dataset_builder.py
research/lstm_object_detection/seq_dataset_builder.py
+2
-2
research/lstm_object_detection/tf_sequence_example_decoder.py
...arch/lstm_object_detection/tf_sequence_example_decoder.py
+73
-13
research/lstm_object_detection/tf_sequence_example_decoder_test.py
...lstm_object_detection/tf_sequence_example_decoder_test.py
+5
-3
No files found.
research/lstm_object_detection/README
View file @
b915db4e
...
@@ -10,4 +10,7 @@ http://openaccess.thecvf.com/content_cvpr_2018/papers/Liu_Mobile_Video_Object_CV
...
@@ -10,4 +10,7 @@ http://openaccess.thecvf.com/content_cvpr_2018/papers/Liu_Mobile_Video_Object_CV
year={2018}
year={2018}
}
}
If you have any questions regarding this codebase, please contact menglong@google.com
If you have any questions regarding this codebase, please contact us:
\ No newline at end of file
masonliuw@gmail.com
yinxiao@google.com
menglong@google.com
\ No newline at end of file
research/lstm_object_detection/lstm/lstm_cells.py
View file @
b915db4e
...
@@ -15,11 +15,11 @@
...
@@ -15,11 +15,11 @@
"""BottleneckConvLSTMCell implementation."""
"""BottleneckConvLSTMCell implementation."""
import
google3
import
tensorflow
as
tf
import
tensorflow.google
as
tf
import
google3.learning.brain.contrib.slim
as
slim
from
tensorflow.contrib.framework.python.ops
import
variables
from
tensorflow.contrib.framework.python.ops
import
variables
slim
=
tf
.
contrib
.
slim
_batch_norm
=
tf
.
contrib
.
layers
.
batch_norm
_batch_norm
=
tf
.
contrib
.
layers
.
batch_norm
...
@@ -195,4 +195,5 @@ class BottleneckConvLSTMCell(tf.contrib.rnn.RNNCell):
...
@@ -195,4 +195,5 @@ class BottleneckConvLSTMCell(tf.contrib.rnn.RNNCell):
]
]
for
s
,
r
in
zip
(
state_size
,
ret_flat
):
for
s
,
r
in
zip
(
state_size
,
ret_flat
):
r
.
set_shape
([
None
]
+
s
)
r
.
set_shape
([
None
]
+
s
)
return
tf
.
nest
.
pack_sequence_as
(
structure
=
[
1
,
1
],
flat_sequence
=
ret_flat
)
return
tf
.
contrib
.
framework
.
nest
.
pack_sequence_as
(
structure
=
[
1
,
1
],
flat_sequence
=
ret_flat
)
research/lstm_object_detection/seq_dataset_builder.py
View file @
b915db4e
...
@@ -24,7 +24,6 @@ that wraps the build function.
...
@@ -24,7 +24,6 @@ that wraps the build function.
"""
"""
import
tensorflow
as
tf
import
tensorflow
as
tf
import
tensorflow.google
as
google_tf
import
tensorflow.google
as
google_tf
from
google3.learning.brain.contrib.slim.data
import
parallel_reader
from
tensorflow.contrib.training.python.training
import
sequence_queueing_state_saver
as
sqss
from
tensorflow.contrib.training.python.training
import
sequence_queueing_state_saver
as
sqss
from
lstm_object_detection
import
tf_sequence_example_decoder
from
lstm_object_detection
import
tf_sequence_example_decoder
from
lstm_object_detection.protos
import
input_reader_google_pb2
from
lstm_object_detection.protos
import
input_reader_google_pb2
...
@@ -34,6 +33,7 @@ from object_detection.core import standard_fields as fields
...
@@ -34,6 +33,7 @@ from object_detection.core import standard_fields as fields
from
object_detection.protos
import
input_reader_pb2
from
object_detection.protos
import
input_reader_pb2
from
object_detection.utils
import
ops
as
util_ops
from
object_detection.utils
import
ops
as
util_ops
parallel_reader
=
tf
.
contrib
.
slim
.
parallel_reader
# TODO(yinxiao): Make the following variable into configurable proto.
# TODO(yinxiao): Make the following variable into configurable proto.
# Padding size for the labeled objects in each frame. Here we assume each
# Padding size for the labeled objects in each frame. Here we assume each
# frame has a total number of objects less than _PADDING_SIZE.
# frame has a total number of objects less than _PADDING_SIZE.
...
@@ -142,7 +142,7 @@ def build(input_reader_config,
...
@@ -142,7 +142,7 @@ def build(input_reader_config,
min_after_dequeue
=
input_reader_config
.
min_after_dequeue
)
min_after_dequeue
=
input_reader_config
.
min_after_dequeue
)
# TODO(yinxiao): Add loading instance mask option.
# TODO(yinxiao): Add loading instance mask option.
decoder
=
tf_sequence_example_decoder
.
T
f
SequenceExampleDecoder
()
decoder
=
tf_sequence_example_decoder
.
T
F
SequenceExampleDecoder
()
keys_to_decode
=
[
keys_to_decode
=
[
fields
.
InputDataFields
.
image
,
fields
.
InputDataFields
.
groundtruth_boxes
,
fields
.
InputDataFields
.
image
,
fields
.
InputDataFields
.
groundtruth_boxes
,
...
...
research/lstm_object_detection/tf_sequence_example_decoder.py
View file @
b915db4e
...
@@ -21,14 +21,74 @@ TODO(yinxiao): When TensorFlow object detection API officially supports
...
@@ -21,14 +21,74 @@ TODO(yinxiao): When TensorFlow object detection API officially supports
tensorflow.SequenceExample, merge this decoder.
tensorflow.SequenceExample, merge this decoder.
"""
"""
import
tensorflow
as
tf
import
tensorflow
as
tf
from
google3.learning.brain.contrib.slim.data
import
tfexample_decoder
from
object_detection.core
import
data_decoder
from
object_detection.core
import
data_decoder
from
object_detection.core
import
standard_fields
as
fields
from
object_detection.core
import
standard_fields
as
fields
slim_
example_decoder
=
tf
.
contrib
.
slim
.
tfexample_decoder
tf
example_decoder
=
tf
.
contrib
.
slim
.
tfexample_decoder
class
TfSequenceExampleDecoder
(
data_decoder
.
DataDecoder
):
class
BoundingBoxSequence
(
tfexample_decoder
.
ItemHandler
):
"""An ItemHandler that concatenates SparseTensors to Bounding Boxes.
"""
def
__init__
(
self
,
keys
=
None
,
prefix
=
None
,
return_dense
=
True
,
default_value
=-
1.0
):
"""Initialize the bounding box handler.
Args:
keys: A list of four key names representing the ymin, xmin, ymax, xmax
in the Example or SequenceExample.
prefix: An optional prefix for each of the bounding box keys in the
Example or SequenceExample. If provided, `prefix` is prepended to each
key in `keys`.
return_dense: if True, returns a dense tensor; if False, returns as
sparse tensor.
default_value: The value used when the `tensor_key` is not found in a
particular `TFExample`.
Raises:
ValueError: if keys is not `None` and also not a list of exactly 4 keys
"""
if
keys
is
None
:
keys
=
[
'ymin'
,
'xmin'
,
'ymax'
,
'xmax'
]
elif
len
(
keys
)
!=
4
:
raise
ValueError
(
'BoundingBoxSequence expects 4 keys but got {}'
.
format
(
len
(
keys
)))
self
.
_prefix
=
prefix
self
.
_keys
=
keys
self
.
_full_keys
=
[
prefix
+
k
for
k
in
keys
]
self
.
_return_dense
=
return_dense
self
.
_default_value
=
default_value
super
(
BoundingBoxSequence
,
self
).
__init__
(
self
.
_full_keys
)
def
tensors_to_item
(
self
,
keys_to_tensors
):
"""Maps the given dictionary of tensors to a concatenated list of bboxes.
Args:
keys_to_tensors: a mapping of TF-Example keys to parsed tensors.
Returns:
[time, num_boxes, 4] tensor of bounding box coordinates, in order
[y_min, x_min, y_max, x_max]. Whether the tensor is a SparseTensor
or a dense Tensor is determined by the return_dense parameter. Empty
positions in the sparse tensor are filled with -1.0 values.
"""
sides
=
[]
for
key
in
self
.
_full_keys
:
value
=
keys_to_tensors
[
key
]
expanded_dims
=
tf
.
concat
(
[
tf
.
to_int64
(
tf
.
shape
(
value
)),
tf
.
constant
([
1
],
dtype
=
tf
.
int64
)],
0
)
side
=
tf
.
sparse_reshape
(
value
,
expanded_dims
)
sides
.
append
(
side
)
bounding_boxes
=
tf
.
sparse_concat
(
2
,
sides
)
if
self
.
_return_dense
:
bounding_boxes
=
tf
.
sparse_tensor_to_dense
(
bounding_boxes
,
default_value
=
self
.
_default_value
)
return
bounding_boxes
class
TFSequenceExampleDecoder
(
data_decoder
.
DataDecoder
):
"""Tensorflow Sequence Example proto decoder."""
"""Tensorflow Sequence Example proto decoder."""
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -62,30 +122,30 @@ class TfSequenceExampleDecoder(data_decoder.DataDecoder):
...
@@ -62,30 +122,30 @@ class TfSequenceExampleDecoder(data_decoder.DataDecoder):
}
}
self
.
items_to_handlers
=
{
self
.
items_to_handlers
=
{
fields
.
InputDataFields
.
image
:
fields
.
InputDataFields
.
image
:
slim_
example_decoder
.
Image
(
tf
example_decoder
.
Image
(
image_key
=
'image/encoded'
,
image_key
=
'image/encoded'
,
format_key
=
'image/format'
,
format_key
=
'image/format'
,
channels
=
3
,
channels
=
3
,
repeated
=
True
),
repeated
=
True
),
fields
.
InputDataFields
.
source_id
:
(
fields
.
InputDataFields
.
source_id
:
(
slim_
example_decoder
.
Tensor
(
'image/source_id'
)),
tf
example_decoder
.
Tensor
(
'image/source_id'
)),
fields
.
InputDataFields
.
key
:
(
fields
.
InputDataFields
.
key
:
(
slim_
example_decoder
.
Tensor
(
'image/key/sha256'
)),
tf
example_decoder
.
Tensor
(
'image/key/sha256'
)),
fields
.
InputDataFields
.
filename
:
(
fields
.
InputDataFields
.
filename
:
(
slim_
example_decoder
.
Tensor
(
'image/filename'
)),
tf
example_decoder
.
Tensor
(
'image/filename'
)),
# Object boxes and classes.
# Object boxes and classes.
fields
.
InputDataFields
.
groundtruth_boxes
:
fields
.
InputDataFields
.
groundtruth_boxes
:
tfexample_decoder
.
BoundingBoxSequence
(
prefix
=
'bbox/'
),
BoundingBoxSequence
(
prefix
=
'bbox/'
),
fields
.
InputDataFields
.
groundtruth_classes
:
(
fields
.
InputDataFields
.
groundtruth_classes
:
(
slim_
example_decoder
.
Tensor
(
'bbox/label/index'
)),
tf
example_decoder
.
Tensor
(
'bbox/label/index'
)),
fields
.
InputDataFields
.
groundtruth_area
:
fields
.
InputDataFields
.
groundtruth_area
:
slim_
example_decoder
.
Tensor
(
'area'
),
tf
example_decoder
.
Tensor
(
'area'
),
fields
.
InputDataFields
.
groundtruth_is_crowd
:
(
fields
.
InputDataFields
.
groundtruth_is_crowd
:
(
slim_
example_decoder
.
Tensor
(
'is_crowd'
)),
tf
example_decoder
.
Tensor
(
'is_crowd'
)),
fields
.
InputDataFields
.
groundtruth_difficult
:
(
fields
.
InputDataFields
.
groundtruth_difficult
:
(
slim_
example_decoder
.
Tensor
(
'difficult'
)),
tf
example_decoder
.
Tensor
(
'difficult'
)),
fields
.
InputDataFields
.
groundtruth_group_of
:
(
fields
.
InputDataFields
.
groundtruth_group_of
:
(
slim_
example_decoder
.
Tensor
(
'group_of'
))
tf
example_decoder
.
Tensor
(
'group_of'
))
}
}
def
decode
(
self
,
tf_seq_example_string_tensor
,
items
=
None
):
def
decode
(
self
,
tf_seq_example_string_tensor
,
items
=
None
):
...
...
research/lstm_object_detection/tf_sequence_example_decoder_test.py
View file @
b915db4e
...
@@ -13,17 +13,19 @@
...
@@ -13,17 +13,19 @@
# limitations under the License.
# limitations under the License.
# ==============================================================================
# ==============================================================================
"""Tests for
video
_object_detection.tf_sequence_example_decoder."""
"""Tests for
lstm
_object_detection.tf_sequence_example_decoder."""
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
from
tensorflow.core.example
import
example_pb2
from
tensorflow.core.example
import
example_pb2
from
tensorflow.core.example
import
feature_pb2
from
tensorflow.core.example
import
feature_pb2
from
tensorflow.python.framework
import
dtypes
from
tensorflow.python.ops
import
parsing_ops
from
lstm_object_detection
import
tf_sequence_example_decoder
from
lstm_object_detection
import
tf_sequence_example_decoder
from
object_detection.core
import
standard_fields
as
fields
from
object_detection.core
import
standard_fields
as
fields
class
T
f
SequenceExampleDecoderTest
(
tf
.
test
.
TestCase
):
class
T
F
SequenceExampleDecoderTest
(
tf
.
test
.
TestCase
):
"""Tests for sequence example decoder."""
"""Tests for sequence example decoder."""
def
_EncodeImage
(
self
,
image_tensor
,
encoding_type
=
'jpeg'
):
def
_EncodeImage
(
self
,
image_tensor
,
encoding_type
=
'jpeg'
):
...
@@ -86,7 +88,7 @@ class TfSequenceExampleDecoderTest(tf.test.TestCase):
...
@@ -86,7 +88,7 @@ class TfSequenceExampleDecoderTest(tf.test.TestCase):
]),
]),
})).
SerializeToString
()
})).
SerializeToString
()
example_decoder
=
tf_sequence_example_decoder
.
T
f
SequenceExampleDecoder
()
example_decoder
=
tf_sequence_example_decoder
.
T
F
SequenceExampleDecoder
()
tensor_dict
=
example_decoder
.
decode
(
tf
.
convert_to_tensor
(
sequence_example
))
tensor_dict
=
example_decoder
.
decode
(
tf
.
convert_to_tensor
(
sequence_example
))
# Test tensor dict image dimension.
# Test tensor dict image dimension.
...
...
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