def gen_tfrecords(img_dir, label_file, output_dir, net, shuffle=False): tfrecord_file = "{}/{}_bbox_landmark.tfrecord".format(output_dir, net) if tf.gfile.Exists(tfrecord_file): print( "Dataset (tfrecord) files already exist. Exiting without recreating them." ) return labels = read_label_file2(label_file) if shuffle: tfrecord_file = tfrecord_file + "_shuffle" random.shuffle(labels) with tf.python_io.TFRecordWriter(tfrecord_file) as tfrecord_writer: for i, data_unit in enumerate(labels): if (i + 1) % 100 == 0: sys.stdout.write('\r>> {}/{} images has been converted'.format( i + 1, len(labels))) sys.stdout.flush() filename = data_unit['filename'] img_path = os.path.join(img_dir, filename) image_data, height, width = _process_image_withoutcoder(img_path) example = _convert_to_example_simple(data_unit, image_data) tfrecord_writer.write(example.SerializeToString()) print('\nFinished converting the MTCNN dataset (tfrecords)!')
def _add_to_tfrecord(filename, image_example, tfrecord_writer): """Loads data from image and annotations files and add them to a TFRecord. Args: dataset_dir: Dataset directory; name: Image name to add to the TFRecord; tfrecord_writer: The TFRecord writer to use for writing. """ print('---',filename) # filename = os.path.join('../data', filename) image_data, height, width = _process_image_withoutcoder(filename) example = _convert_to_example_simple(image_example, image_data) tfrecord_writer.write(example.SerializeToString())
def _add_to_tfrecord(filename, image_example, tfrecord_writer): """Loads data from image and annotations files and add them to a TFRecord. Args: dataset_dir: Dataset directory; name: Image name to add to the TFRecord; tfrecord_writer: The TFRecord writer to use for writing. """ # print('---', filename) # imaga_data:array to string # height:original image's height # width:original image's width # image_example dict contains image's info image_data, height, width = _process_image_withoutcoder(filename) example = _convert_to_example_simple(image_example, image_data) tfrecord_writer.write(example.SerializeToString())
def _add_to_tfrecord(filename, image_example, tfrecord_writer): """Loads data from image and annotations files and add them to a TFRecord. Args: dataset_dir: Dataset directory; name: Image name to add to the TFRecord; tfrecord_writer: The TFRecord writer to use for writing. """ print('---', filename) #imaga_data:array to string #height:original image's height #width:original image's width #image_example dict contains image's info image_data, height, width = _process_image_withoutcoder(filename) example = _convert_to_example_simple(image_example, image_data) tfrecord_writer.write(example.SerializeToString())
def _add_to_tfrecord(filename, image_example, tfrecord_writer): #从图片和注释中加载数据,并添加他们到tfrecord image_data, height, width = _process_image_withoutcoder(filename) example = _convert_to_example_simple(image_example, image_data) tfrecord_writer.write(example.SerializeToString())
def _add_to_tfrecord(filename, image_example, tfrecord_writer): print('---', filename) image_data, height, width = _process_image_withoutcoder(filename) example = _convert_to_example_simple(image_example, image_data) tfrecord_writer.write(example.SerializeToString())