Exemplo n.º 1
0
def _create_image_with_prefix(name, prefix):
    """Create multiple accessors for image based data."""
    msu.create_bytes_context_feature(name + "_format",
                                     IMAGE_FORMAT_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_bytes_context_feature(name + "_colorspace",
                                     IMAGE_COLORSPACE_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_int_context_feature(name + "_channels",
                                   IMAGE_CHANNELS_KEY,
                                   prefix=prefix,
                                   module_dict=globals())
    msu.create_int_context_feature(name + "_height",
                                   IMAGE_HEIGHT_KEY,
                                   prefix=prefix,
                                   module_dict=globals())
    msu.create_int_context_feature(name + "_width",
                                   IMAGE_WIDTH_KEY,
                                   prefix=prefix,
                                   module_dict=globals())
    msu.create_bytes_feature_list(name + "_encoded",
                                  IMAGE_ENCODED_KEY,
                                  prefix=prefix,
                                  module_dict=globals())
    msu.create_float_context_feature(name + "_frame_rate",
                                     IMAGE_FRAME_RATE_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_bytes_list_context_feature(name + "_class_label_string",
                                          IMAGE_CLASS_LABEL_STRING_KEY,
                                          prefix=prefix,
                                          module_dict=globals())
    msu.create_int_list_context_feature(name + "_class_label_index",
                                        IMAGE_CLASS_LABEL_INDEX_KEY,
                                        prefix=prefix,
                                        module_dict=globals())
    msu.create_int_list_context_feature(name + "_object_class_index",
                                        IMAGE_OBJECT_CLASS_INDEX_KEY,
                                        prefix=prefix,
                                        module_dict=globals())
    msu.create_int_feature_list(name + "_timestamp",
                                IMAGE_TIMESTAMP_KEY,
                                prefix=prefix,
                                module_dict=globals())
Exemplo n.º 2
0
def _create_region_with_prefix(name, prefix):
    """Create multiple accessors for region based data."""
    msu.create_int_feature_list(name + "_num_regions",
                                REGION_NUM_REGIONS_KEY,
                                prefix=prefix,
                                module_dict=globals())
    msu.create_int_feature_list(name + "_is_annotated",
                                REGION_IS_ANNOTATED_KEY,
                                prefix=prefix,
                                module_dict=globals())
    msu.create_int_list_feature_list(name + "_is_occluded",
                                     REGION_IS_OCCLUDED_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_int_list_feature_list(name + "_is_generated",
                                     REGION_IS_GENERATED_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_int_feature_list(name + "_timestamp",
                                REGION_TIMESTAMP_KEY,
                                prefix=prefix,
                                module_dict=globals())
    msu.create_int_feature_list(name + "_unmodified_timestamp",
                                REGION_UNMODIFIED_TIMESTAMP_KEY,
                                prefix=prefix,
                                module_dict=globals())
    msu.create_bytes_list_feature_list(name + "_label_string",
                                       REGION_LABEL_STRING_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_int_list_feature_list(name + "_label_index",
                                     REGION_LABEL_INDEX_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_float_list_feature_list(name + "_label_confidence",
                                       REGION_LABEL_CONFIDENCE_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_bytes_list_feature_list(name + "_class_string",
                                       REGION_CLASS_STRING_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_int_list_feature_list(name + "_class_index",
                                     REGION_CLASS_INDEX_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_float_list_feature_list(name + "_class_confidence",
                                       REGION_CLASS_CONFIDENCE_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_bytes_list_feature_list(name + "_track_string",
                                       REGION_TRACK_STRING_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_int_list_feature_list(name + "_track_index",
                                     REGION_TRACK_INDEX_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_float_list_feature_list(name + "_track_confidence",
                                       REGION_TRACK_CONFIDENCE_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_ymin",
                                       REGION_BBOX_YMIN_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_xmin",
                                       REGION_BBOX_XMIN_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_ymax",
                                       REGION_BBOX_YMAX_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_xmax",
                                       REGION_BBOX_XMAX_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_point_x",
                                       REGION_POINT_X_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_point_y",
                                       REGION_POINT_Y_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_3d_point_x",
                                       REGION_3D_POINT_X_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_3d_point_y",
                                       REGION_3D_POINT_Y_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_3d_point_z",
                                       REGION_3D_POINT_Z_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_bytes_list_context_feature(name + "_parts",
                                          REGION_PARTS_KEY,
                                          prefix=prefix,
                                          module_dict=globals())
    msu.create_float_list_context_feature(
        name + "_embedding_dimensions_per_region",
        REGION_EMBEDDING_DIMENSIONS_PER_REGION_KEY,
        prefix=prefix,
        module_dict=globals())
    msu.create_bytes_context_feature(name + "_embedding_format",
                                     REGION_EMBEDDING_FORMAT_KEY,
                                     prefix=prefix,
                                     module_dict=globals())
    msu.create_float_list_feature_list(name + "_embedding_floats",
                                       REGION_EMBEDDING_FLOAT_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_bytes_list_feature_list(name + "_embedding_encoded",
                                       REGION_EMBEDDING_ENCODED_KEY,
                                       prefix=prefix,
                                       module_dict=globals())
    msu.create_float_list_feature_list(name + "_embedding_confidence",
                                       REGION_EMBEDDING_CONFIDENCE_KEY,
                                       prefix=prefix,
                                       module_dict=globals())

    # pylint: disable=undefined-variable
    def get_prefixed_bbox_at(index, sequence_example, prefix):
        return np.stack(
            (get_bbox_ymin_at(index, sequence_example, prefix=prefix),
             get_bbox_xmin_at(index, sequence_example, prefix=prefix),
             get_bbox_ymax_at(index, sequence_example, prefix=prefix),
             get_bbox_xmax_at(index, sequence_example, prefix=prefix)), 1)

    def add_prefixed_bbox(values, sequence_example, prefix):
        add_bbox_ymin(values[:, 0], sequence_example, prefix=prefix)
        add_bbox_xmin(values[:, 1], sequence_example, prefix=prefix)
        add_bbox_ymax(values[:, 2], sequence_example, prefix=prefix)
        add_bbox_xmax(values[:, 3], sequence_example, prefix=prefix)

    def get_prefixed_bbox_size(sequence_example, prefix):
        return get_bbox_ymin_size(sequence_example, prefix=prefix)

    def has_prefixed_bbox(sequence_example, prefix):
        return has_bbox_ymin(sequence_example, prefix=prefix)

    def clear_prefixed_bbox(sequence_example, prefix):
        clear_bbox_ymin(sequence_example, prefix=prefix)
        clear_bbox_xmin(sequence_example, prefix=prefix)
        clear_bbox_ymax(sequence_example, prefix=prefix)
        clear_bbox_xmax(sequence_example, prefix=prefix)

    def get_prefixed_point_at(index, sequence_example, prefix):
        return np.stack(
            (get_bbox_point_y_at(index, sequence_example, prefix=prefix),
             get_bbox_point_x_at(index, sequence_example, prefix=prefix)), 1)

    def add_prefixed_point(values, sequence_example, prefix):
        add_bbox_point_y(values[:, 0], sequence_example, prefix=prefix)
        add_bbox_point_x(values[:, 1], sequence_example, prefix=prefix)

    def get_prefixed_point_size(sequence_example, prefix):
        return get_bbox_point_y_size(sequence_example, prefix=prefix)

    def has_prefixed_point(sequence_example, prefix):
        return has_bbox_point_y(sequence_example, prefix=prefix)

    def clear_prefixed_point(sequence_example, prefix):
        clear_bbox_point_y(sequence_example, prefix=prefix)
        clear_bbox_point_x(sequence_example, prefix=prefix)

    def get_prefixed_3d_point_at(index, sequence_example, prefix):
        return np.stack(
            (get_bbox_3d_point_x_at(index, sequence_example, prefix=prefix),
             get_bbox_3d_point_y_at(index, sequence_example, prefix=prefix),
             get_bbox_3d_point_z_at(index, sequence_example, prefix=prefix)),
            1)

    def add_prefixed_3d_point(values, sequence_example, prefix):
        add_bbox_3d_point_x(values[:, 0], sequence_example, prefix=prefix)
        add_bbox_3d_point_y(values[:, 1], sequence_example, prefix=prefix)
        add_bbox_3d_point_z(values[:, 2], sequence_example, prefix=prefix)

    def get_prefixed_3d_point_size(sequence_example, prefix):
        return get_bbox_3d_point_x_size(sequence_example, prefix=prefix)

    def has_prefixed_3d_point(sequence_example, prefix):
        return has_bbox_3d_point_x(sequence_example, prefix=prefix)

    def clear_prefixed_3d_point(sequence_example, prefix):
        clear_bbox_3d_point_x(sequence_example, prefix=prefix)
        clear_bbox_3d_point_y(sequence_example, prefix=prefix)
        clear_bbox_3d_point_z(sequence_example, prefix=prefix)

    # pylint: enable=undefined-variable
    msu.add_functions_to_module(
        {
            "get_" + name + "_at":
            functools.partial(get_prefixed_bbox_at, prefix=prefix),
            "add_" + name:
            functools.partial(add_prefixed_bbox, prefix=prefix),
            "get_" + name + "_size":
            functools.partial(get_prefixed_bbox_size, prefix=prefix),
            "has_" + name:
            functools.partial(has_prefixed_bbox, prefix=prefix),
            "clear_" + name:
            functools.partial(clear_prefixed_bbox, prefix=prefix),
        },
        module_dict=globals())
    msu.add_functions_to_module(
        {
            "get_" + name + "_point_at":
            functools.partial(get_prefixed_point_at, prefix=prefix),
            "add_" + name + "_point":
            functools.partial(add_prefixed_point, prefix=prefix),
            "get_" + name + "_point_size":
            functools.partial(get_prefixed_point_size, prefix=prefix),
            "has_" + name + "_point":
            functools.partial(has_prefixed_point, prefix=prefix),
            "clear_" + name + "_point":
            functools.partial(clear_prefixed_point, prefix=prefix),
        },
        module_dict=globals())
    msu.add_functions_to_module(
        {
            "get_" + name + "_3d_point_at":
            functools.partial(get_prefixed_3d_point_at, prefix=prefix),
            "add_" + name + "_3d_point":
            functools.partial(add_prefixed_3d_point, prefix=prefix),
            "get_" + name + "_3d_point_size":
            functools.partial(get_prefixed_3d_point_size, prefix=prefix),
            "has_" + name + "_3d_point":
            functools.partial(has_prefixed_3d_point, prefix=prefix),
            "clear_" + name + "_3d_point":
            functools.partial(clear_prefixed_3d_point, prefix=prefix),
        },
        module_dict=globals())
Exemplo n.º 3
0
# The encoded bytes for storing media directly in the SequenceExample.
CLIP_ENCODED_MEDIA_BYTES_KEY = "clip/encoded_media_bytes"
# The start time for the encoded media if not preserved during encoding.
CLIP_ENCODED_MEDIA_START_TIMESTAMP_KEY = "clip/encoded_media_start_timestamp"
# The start time, in microseconds, for the start of the clip in the media.
CLIP_START_TIMESTAMP_KEY = "clip/start/timestamp"
# The end time, in microseconds, for the end of the clip in the media.
CLIP_END_TIMESTAMP_KEY = "clip/end/timestamp"
# A list of label indices for this clip.
CLIP_LABEL_INDEX_KEY = "clip/label/index"
# A list of label strings for this clip.
CLIP_LABEL_STRING_KEY = "clip/label/string"
# A list of label confidences for this clip.
CLIP_LABEL_CONFIDENCE_KEY = "clip/label/confidence"
msu.create_bytes_context_feature("example_id",
                                 EXAMPLE_ID_KEY,
                                 module_dict=globals())
msu.create_bytes_context_feature("example_dataset_name",
                                 EXAMPLE_DATASET_NAME_KEY,
                                 module_dict=globals())
msu.create_bytes_context_feature("clip_media_id",
                                 CLIP_MEDIA_ID_KEY,
                                 module_dict=globals())
msu.create_bytes_context_feature("clip_alternative_media_id",
                                 ALTERNATIVE_CLIP_MEDIA_ID_KEY,
                                 module_dict=globals())
msu.create_bytes_context_feature("clip_encoded_media_bytes",
                                 CLIP_ENCODED_MEDIA_BYTES_KEY,
                                 module_dict=globals())
msu.create_bytes_context_feature("clip_data_path",
                                 CLIP_DATA_PATH_KEY,
Exemplo n.º 4
0
Tests for media_sequence_util.py.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf

from mediapipe.util.sequence import media_sequence_util as msu

# run this code at the module level to procedurally define functions for test
# cases.
msu.create_bytes_context_feature("string_context",
                                 "string_feature",
                                 module_dict=msu.__dict__)
msu.create_float_context_feature("float_context",
                                 "float_feature",
                                 module_dict=msu.__dict__)
msu.create_int_context_feature("int64_context",
                               "int64_feature",
                               module_dict=msu.__dict__)
msu.create_bytes_list_context_feature("string_list_context",
                                      "string_vector_feature",
                                      module_dict=msu.__dict__)
msu.create_float_list_context_feature("float_list_context",
                                      "float_vector_feature",
                                      module_dict=msu.__dict__)
msu.create_int_list_context_feature("int64_list_context",
                                    "int64_vector_feature",