Python object_detection.utils.dataset_util.read_examples_list() Examples
The following are 30
code examples of object_detection.utils.dataset_util.read_examples_list().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
object_detection.utils.dataset_util
, or try the search function
.
Example #1
Source File: create_dataset.py From object_detection_kitti with Apache License 2.0 | 6 votes |
def create_records(data_dir, to_path='data/train.tfrecord'): annotations_dir, examples_path = get_fun_paths(data_dir) writer = tf.python_io.TFRecordWriter(to_path) labels = {} examples_list = dataset_util.read_examples_list(examples_path) assert len(examples_list) > 0, examples_path for i, example in enumerate(examples_list): path = os.path.join(annotations_dir, example + '.xml') data = xml_to_dict(path) assert 'object' in data, data['filename'] labels[i] = [k['name'] for k in data['object']] try: tf_example = dict_to_tf_example(data, data_dir, label_map_dict) except Exception as e: #TODO(SS): remove me print(e) import pdb; pdb.set_trace() writer.write(tf_example.SerializeToString()) writer.close() return labels # to inspect a bit
Example #2
Source File: create_pet_tf_record.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def main(_): data_dir = FLAGS.data_dir label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) logging.info('Reading from Pet dataset.') image_dir = os.path.join(data_dir, 'images') annotations_dir = os.path.join(data_dir, 'annotations') examples_path = os.path.join(annotations_dir, 'trainval.txt') examples_list = dataset_util.read_examples_list(examples_path) # Test images are not included in the downloaded data set, so we shall perform # our own split. random.seed(42) random.shuffle(examples_list) num_examples = len(examples_list) num_train = int(0.7 * num_examples) train_examples = examples_list[:num_train] val_examples = examples_list[num_train:] logging.info('%d training and %d validation examples.', len(train_examples), len(val_examples)) train_output_path = os.path.join(FLAGS.output_dir, 'pet_train.record') val_output_path = os.path.join(FLAGS.output_dir, 'pet_val.record') create_tf_record(train_output_path, label_map_dict, annotations_dir, image_dir, train_examples) create_tf_record(val_output_path, label_map_dict, annotations_dir, image_dir, val_examples)
Example #3
Source File: create_pascal_tf_record.py From Elphas with Apache License 2.0 | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #4
Source File: create_pet_tf_record.py From MBMD with MIT License | 5 votes |
def main(_): data_dir = FLAGS.data_dir label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) logging.info('Reading from Pet dataset.') image_dir = os.path.join(data_dir, 'images') annotations_dir = os.path.join(data_dir, 'annotations') examples_path = os.path.join(annotations_dir, 'trainval.txt') examples_list = dataset_util.read_examples_list(examples_path) # Test images are not included in the downloaded data set, so we shall perform # our own split. random.seed(42) random.shuffle(examples_list) num_examples = len(examples_list) num_train = int(0.7 * num_examples) train_examples = examples_list[:num_train] val_examples = examples_list[num_train:] logging.info('%d training and %d validation examples.', len(train_examples), len(val_examples)) train_output_path = os.path.join(FLAGS.output_dir, 'pet_train.record') val_output_path = os.path.join(FLAGS.output_dir, 'pet_val.record') create_tf_record(train_output_path, label_map_dict, annotations_dir, image_dir, train_examples) create_tf_record(val_output_path, label_map_dict, annotations_dir, image_dir, val_examples)
Example #5
Source File: dataset_util_test.py From AniSeg with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #6
Source File: dataset_util_test.py From MAX-Object-Detector with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #7
Source File: create_pascal_tf_record.py From MAX-Object-Detector with Apache License 2.0 | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #8
Source File: dataset_util_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #9
Source File: create_pascal_tf_record.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #10
Source File: dataset_util_test.py From models with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #11
Source File: create_pascal_tf_record.py From models with Apache License 2.0 | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #12
Source File: dataset_util_test.py From motion-rcnn with MIT License | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #13
Source File: create_pascal_tf_record.py From object_detection_with_tensorflow with MIT License | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #14
Source File: check_imagenet_data.py From MBMD with MIT License | 5 votes |
def main(_): data_dir = FLAGS.data_dir #writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) # logging.info('Reading from Imagenet dataset.') examples_list = dataset_util.read_examples_list(FLAGS.data_list_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: print('On image %d of %d'%(idx, len(examples_list))) # logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(FLAGS.annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] if not data.has_key('object'): continue dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) # if tf_example is not None: # writer.write(tf_example.SerializeToString()) #writer.close()
Example #15
Source File: create_imagenet_tf_record.py From MBMD with MIT License | 5 votes |
def main(_): data_dir = FLAGS.data_dir writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) # logging.info('Reading from Imagenet dataset.') examples_list = dataset_util.read_examples_list(FLAGS.data_list_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: print('On image %d of %d'%(idx, len(examples_list))) # logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(FLAGS.annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] if not data.has_key('object'): continue tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) if tf_example is not None: writer.write(tf_example.SerializeToString()) writer.close()
Example #16
Source File: dataset_util_test.py From MBMD with MIT License | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #17
Source File: create_pascal_tf_record.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #18
Source File: dataset_util_test.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #19
Source File: dataset_util_test.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #20
Source File: create_pet_tf_record.py From hands-detection with MIT License | 5 votes |
def main(_): data_dir = FLAGS.data_dir label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) logging.info('Reading from Pet dataset.') image_dir = os.path.join(data_dir, 'images') annotations_dir = os.path.join(data_dir, 'annotations') examples_path = os.path.join(annotations_dir, 'trainval.txt') examples_list = dataset_util.read_examples_list(examples_path) # Test images are not included in the downloaded data set, so we shall perform # our own split. random.seed(42) random.shuffle(examples_list) num_examples = len(examples_list) num_train = int(0.7 * num_examples) train_examples = examples_list[:num_train] val_examples = examples_list[num_train:] logging.info('%d training and %d validation examples.', len(train_examples), len(val_examples)) train_output_path = os.path.join(FLAGS.output_dir, 'pet_train.record') val_output_path = os.path.join(FLAGS.output_dir, 'pet_val.record') create_tf_record(train_output_path, label_map_dict, annotations_dir, image_dir, train_examples) create_tf_record(val_output_path, label_map_dict, annotations_dir, image_dir, val_examples)
Example #21
Source File: create_pascal_tf_record.py From hands-detection with MIT License | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #22
Source File: dataset_util_test.py From hands-detection with MIT License | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #23
Source File: create_knots_tf_record.py From active-learning-detect with MIT License | 5 votes |
def get_examples_list(data_dir, prefix, setName): examples_path = os.path.join(data_dir, 'ImageSets', 'Main', prefix + setName+ '.txt') examples_list = dataset_util.read_examples_list(examples_path) return examples_list
Example #24
Source File: create_pet_tf_record.py From moveo_ros with MIT License | 5 votes |
def main(_): data_dir = FLAGS.data_dir label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) logging.info('Reading from Pet dataset.') image_dir = os.path.join(data_dir, 'images') annotations_dir = os.path.join(data_dir, 'annotations') examples_path = os.path.join(annotations_dir, 'trainval.txt') examples_list = dataset_util.read_examples_list(examples_path) # Test images are not included in the downloaded data set, so we shall perform # our own split. random.seed(42) random.shuffle(examples_list) num_examples = len(examples_list) num_train = int(0.7 * num_examples) train_examples = examples_list[:num_train] val_examples = examples_list[num_train:] logging.info('%d training and %d validation examples.', len(train_examples), len(val_examples)) train_output_path = os.path.join(FLAGS.output_dir, 'pet_train.record') val_output_path = os.path.join(FLAGS.output_dir, 'pet_val.record') create_tf_record(train_output_path, label_map_dict, annotations_dir, image_dir, train_examples) create_tf_record(val_output_path, label_map_dict, annotations_dir, image_dir, val_examples)
Example #25
Source File: create_pascal_tf_record.py From moveo_ros with MIT License | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #26
Source File: dataset_util_test.py From moveo_ros with MIT License | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #27
Source File: create_pascal_tf_record.py From container_detection with GNU General Public License v3.0 | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['cont_train', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()
Example #28
Source File: dataset_util_test.py From DOTA_models with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #29
Source File: dataset_util_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 5 votes |
def test_read_examples_list(self): example_list_data = """example1 1\nexample2 2""" example_list_path = os.path.join(self.get_temp_dir(), 'examples.txt') with tf.gfile.Open(example_list_path, 'wb') as f: f.write(example_list_data) examples = dataset_util.read_examples_list(example_list_path) self.assertListEqual(['example1', 'example2'], examples)
Example #30
Source File: create_pascal_tf_record.py From ros_tensorflow with Apache License 2.0 | 5 votes |
def main(_): if FLAGS.set not in SETS: raise ValueError('set must be in : {}'.format(SETS)) if FLAGS.year not in YEARS: raise ValueError('year must be in : {}'.format(YEARS)) data_dir = FLAGS.data_dir years = ['VOC2007', 'VOC2012'] if FLAGS.year != 'merged': years = [FLAGS.year] writer = tf.python_io.TFRecordWriter(FLAGS.output_path) label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) for year in years: logging.info('Reading from PASCAL %s dataset.', year) examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main', 'aeroplane_' + FLAGS.set + '.txt') annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir) examples_list = dataset_util.read_examples_list(examples_path) for idx, example in enumerate(examples_list): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples_list)) path = os.path.join(annotations_dir, example + '.xml') with tf.gfile.GFile(path, 'r') as fid: xml_str = fid.read() xml = etree.fromstring(xml_str) data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict, FLAGS.ignore_difficult_instances) writer.write(tf_example.SerializeToString()) writer.close()