Commit 87fbcfec authored by Kaushik Shivakumar's avatar Kaushik Shivakumar
Browse files

fixes to sequence example utils

parent 9da43afc
...@@ -264,7 +264,7 @@ class Ava(object): ...@@ -264,7 +264,7 @@ class Ava(object):
print(total_boxes) print(total_boxes)
yield seq_example_util.make_sequence_example("AVA", media_id, total_images, yield seq_example_util.make_sequence_example("AVA", media_id, total_images,
int(height), int(width), 'jpeg', total_source_ids, None, total_is_annotated, int(height), int(width), 'jpeg', total_source_ids, None, total_is_annotated,
total_boxes, total_label_strings) total_boxes, total_label_strings, use_strs_for_source_id=True)
#Move middle_time_frame, skipping excluded frames #Move middle_time_frame, skipping excluded frames
frames_mv = 0 frames_mv = 0
......
...@@ -122,6 +122,13 @@ def sequence_bytes_feature(ndarray): ...@@ -122,6 +122,13 @@ def sequence_bytes_feature(ndarray):
feature.bytes_list.value[:] = row feature.bytes_list.value[:] = row
return feature_list return feature_list
def sequence_strings_feature(strings):
new_str_arr = []
for str in strings:
new_str_arr.append(tf.train.Feature(
bytes_list=tf.train.BytesList(
value=[str.encode("utf8")])))
return tf.train.FeatureList(feature=new_str_arr)
def boxes_to_box_components(bboxes): def boxes_to_box_components(bboxes):
"""Converts a list of numpy arrays (boxes) to box components. """Converts a list of numpy arrays (boxes) to box components.
...@@ -137,8 +144,11 @@ def boxes_to_box_components(bboxes): ...@@ -137,8 +144,11 @@ def boxes_to_box_components(bboxes):
ymax_list = [] ymax_list = []
xmax_list = [] xmax_list = []
for bbox in bboxes: for bbox in bboxes:
bbox = np.array(bbox).astype(np.float32) if bbox != []:
ymin, xmin, ymax, xmax = np.split(bbox, 4, axis=1) bbox = np.array(bbox).astype(np.float32)
ymin, xmin, ymax, xmax = np.split(bbox, 4, axis=1)
else:
ymin, xmin, ymax, xmax = [], [], [], []
ymin_list.append(np.reshape(ymin, [-1])) ymin_list.append(np.reshape(ymin, [-1]))
xmin_list.append(np.reshape(xmin, [-1])) xmin_list.append(np.reshape(xmin, [-1]))
ymax_list.append(np.reshape(ymax, [-1])) ymax_list.append(np.reshape(ymax, [-1]))
...@@ -159,7 +169,8 @@ def make_sequence_example(dataset_name, ...@@ -159,7 +169,8 @@ def make_sequence_example(dataset_name,
label_strings=None, label_strings=None,
detection_bboxes=None, detection_bboxes=None,
detection_classes=None, detection_classes=None,
detection_scores=None): detection_scores=None,
use_strs_for_source_id=False):
"""Constructs tf.SequenceExamples. """Constructs tf.SequenceExamples.
Args: Args:
...@@ -217,11 +228,17 @@ def make_sequence_example(dataset_name, ...@@ -217,11 +228,17 @@ def make_sequence_example(dataset_name,
'image/timestamp': sequence_int64_feature(image_timestamps), 'image/timestamp': sequence_int64_feature(image_timestamps),
} }
print("Source IDs", image_source_ids)
# Add optional fields. # Add optional fields.
if image_format is not None: if image_format is not None:
context_dict['image/format'] = context_bytes_feature([image_format]) context_dict['image/format'] = context_bytes_feature([image_format])
if image_source_ids is not None: if image_source_ids is not None:
feature_list['image/source_id'] = sequence_bytes_feature(image_source_ids) if (use_strs_for_source_id):
feature_list['image/source_id'] = sequence_strings_feature(
image_source_ids)
else:
feature_list['image/source_id'] = sequence_bytes_feature(image_source_ids)
if bboxes is not None: if bboxes is not None:
bbox_ymin, bbox_xmin, bbox_ymax, bbox_xmax = boxes_to_box_components(bboxes) bbox_ymin, bbox_xmin, bbox_ymax, bbox_xmax = boxes_to_box_components(bboxes)
feature_list['region/bbox/xmin'] = sequence_float_feature(bbox_xmin) feature_list['region/bbox/xmin'] = sequence_float_feature(bbox_xmin)
......
...@@ -122,7 +122,8 @@ class SeqExampleUtilTest(tf.test.TestCase): ...@@ -122,7 +122,8 @@ class SeqExampleUtilTest(tf.test.TestCase):
bboxes = [ bboxes = [
np.array([[0., 0., 0., 0.], np.array([[0., 0., 0., 0.],
[0., 0., 1., 1.]], dtype=np.float32), [0., 0., 1., 1.]], dtype=np.float32),
np.zeros([0, 4], dtype=np.float32) np.zeros([0, 4], dtype=np.float32),
np.array([], dtype=np.float32)
] ]
label_strings = [ label_strings = [
np.array(labels), np.array(labels),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment