From a47e3ffe0e6b3d20c4926bef7d5f547e4cf7409b Mon Sep 17 00:00:00 2001 From: bit1002lst <563052165@qq.com> Date: Sun, 10 Sep 2017 15:23:56 +0800 Subject: [PATCH] Update create_coco_tf_record.py added a loop of loading image to convert all image --- create_coco_tf_record.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/create_coco_tf_record.py b/create_coco_tf_record.py index 3275684..acce823 100644 --- a/create_coco_tf_record.py +++ b/create_coco_tf_record.py @@ -40,7 +40,7 @@ FLAGS = flags.FLAGS -def load_coco_dection_dataset(imgs_dir, annotations_filepath, shuffle_img = True ): +def load_coco_dection_dataset(imgs_dir, coco, shuffle_img = True ): """Load data from dataset by pycocotools. This tools can be download from "http://mscoco.org/dataset/#download" Args: imgs_dir: directories of coco images @@ -49,7 +49,7 @@ def load_coco_dection_dataset(imgs_dir, annotations_filepath, shuffle_img = True Return: coco_data: list of dictionary format information of each image """ - coco = COCO(annotations_filepath) + # coco = COCO(annotations_filepath) img_ids = coco.getImgIds() # totally 82783 images cat_ids = coco.getCatIds() # totally 90 catagories, however, the number of categories is not continuous, \ # [0,12,26,29,30,45,66,68,69,71,83] are missing, this is the problem of coco dataset. @@ -137,16 +137,20 @@ def main(_): else: raise ValueError("you must either convert train data or val data") # load total coco data - coco_data = load_coco_dection_dataset(imgs_dir,annotations_filepath,shuffle_img=FLAGS.shuffle_imgs) - total_imgs = len(coco_data) - # write coco data to tf record - with tf.python_io.TFRecordWriter(FLAGS.output_filepath) as tfrecord_writer: - for index, img_data in enumerate(coco_data): - if index % 100 == 0: - print("Converting images: %d / %d" % (index, total_imgs)) - example = dict_to_coco_example(img_data) - tfrecord_writer.write(example.SerializeToString()) + coco = COCO(annotations_filepath) + tfrecord_writer = tf.python_io.TFRecordWriter(FLAGS.output_filepath) + for i in range(41): + coco_data = load_coco_dection_dataset(imgs_dir,coco,shuffle_img=FLAGS.shuffle_imgs) + total_imgs = len(coco_data) + # tfrecord_writer = tf.python_io.TFRecordWriter(FLAGS.output_filepath) + # write coco data to tf record + # with tf.python_io.TFRecordWriter(FLAGS.output_filepath) as tfrecord_writer: + for index, img_data in enumerate(coco_data): + if index % 100 == 0: + print("Converting images: %d / %d" % (index, total_imgs)) + example = dict_to_coco_example(img_data) + tfrecord_writer.write(example.SerializeToString()) if __name__ == "__main__": - tf.app.run() \ No newline at end of file + tf.app.run()