(argv)
| 96 | |
| 97 | |
| 98 | def main(argv): |
| 99 | if len(argv) > 1: |
| 100 | raise app.UsageError("Too many command-line arguments.") |
| 101 | |
| 102 | tf.logging.set_verbosity(tf.logging.INFO) |
| 103 | if not FLAGS.output_dir: |
| 104 | FLAGS.output_dir = os.path.dirname(FLAGS.generation_file) |
| 105 | tf.io.gfile.makedirs(FLAGS.output_dir) |
| 106 | |
| 107 | # Load generations. |
| 108 | vocab = text_utils.Vocab.load(FLAGS.vocab_path) |
| 109 | captions = load_synthetic_captions(FLAGS.generation_file, vocab) |
| 110 | images = [] |
| 111 | for image_id, captions in captions.items(): |
| 112 | metadata = image_utils.ImageMetadata( |
| 113 | image_id=image_id, captions=captions, objects=FLAGS.features) |
| 114 | images.append(metadata) |
| 115 | |
| 116 | # Dump to sharded TFRecords. |
| 117 | io_utils.convert_to_tfrecords( |
| 118 | dataset=images, |
| 119 | num_shards=FLAGS.num_shards, |
| 120 | basename=os.path.join(FLAGS.output_dir, "train"), |
| 121 | example_fn=io_utils.caption_example) |
| 122 | |
| 123 | |
| 124 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected
searching dependent graphs…