MCPcopy Create free account
hub / github.com/google-research/language / caption_example

Function caption_example

language/capwap/utils/io_utils.py:75–98  ·  view source on GitHub ↗

Convert image caption data into an Example proto. Args: image: A ImageMetadata instance. Returns: example: An Example proto with serialized tensor data.

(image)

Source from the content-addressed store, hash-verified

73
74
75def caption_example(image):
76 """Convert image caption data into an Example proto.
77
78 Args:
79 image: A ImageMetadata instance.
80
81 Returns:
82 example: An Example proto with serialized tensor data.
83 """
84 # Collect image object information from metadata.
85 image_features, positions = read_object(image.objects, image.image_id)
86
87 # Serialize multi-dimensional tensor data.
88 captions_proto = tf.make_tensor_proto(np.array(image.captions))
89 features_proto = tf.make_tensor_proto(image_features)
90 positions_proto = tf.make_tensor_proto(positions)
91
92 # Create final features dict.
93 features = dict(
94 image_id=int64_feature(image.image_id),
95 captions=bytes_feature(captions_proto.SerializeToString()),
96 object_features=bytes_feature(features_proto.SerializeToString()),
97 object_positions=bytes_feature(positions_proto.SerializeToString()))
98 return tf.train.Example(features=tf.train.Features(feature=features))
99
100
101def vqa_example(image):

Callers

nothing calls this directly

Calls 3

read_objectFunction · 0.85
int64_featureFunction · 0.85
bytes_featureFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…