Convert image caption data into an Example proto. Args: image: A ImageMetadata instance. Returns: example: An Example proto with serialized tensor data.
(image)
| 73 | |
| 74 | |
| 75 | def 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 | |
| 101 | def vqa_example(image): |
nothing calls this directly
no test coverage detected
searching dependent graphs…