|
| 1 | +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# ============================================================================== |
| 15 | +"""Convert a dataset to TFRecords format, which can be easily integrated into |
| 16 | +a TensorFlow pipeline. |
| 17 | +
|
| 18 | +Usage: |
| 19 | +```shell |
| 20 | +python tf_convert_data.py \ |
| 21 | + --dataset_name=pascalvoc \ |
| 22 | + --dataset_dir=/tmp/pascalvoc \ |
| 23 | + --output_name=pascalvoc \ |
| 24 | + --output_dir=/tmp/ |
| 25 | +``` |
| 26 | +""" |
| 27 | +import tensorflow as tf |
| 28 | + |
| 29 | +from dataset import pascalvoc_to_tfrecords |
| 30 | + |
| 31 | +FLAGS = tf.app.flags.FLAGS |
| 32 | + |
| 33 | +tf.app.flags.DEFINE_string( |
| 34 | + 'dataset_name', 'bdd100k', |
| 35 | + 'The name of the dataset to convert.') |
| 36 | +tf.app.flags.DEFINE_string( |
| 37 | + 'dataset_dir', "h:/Data/BDD100K/bdd/images/100k/", |
| 38 | + 'Directory where the original dataset is stored.') |
| 39 | +tf.app.flags.DEFINE_string( |
| 40 | + 'output_name', 'bdd100k_val', |
| 41 | + 'Basename used for TFRecords output files.') |
| 42 | +tf.app.flags.DEFINE_string( |
| 43 | + 'output_dir', './dataset/bdd100k_TfRecord', |
| 44 | + 'Output directory where to store TFRecords files.') |
| 45 | + |
| 46 | + |
| 47 | +def main(_): |
| 48 | + if not FLAGS.dataset_dir: |
| 49 | + raise ValueError('You must supply the dataset directory with --dataset_dir') |
| 50 | + print('Dataset directory:', FLAGS.dataset_dir) |
| 51 | + print('Output directory:', FLAGS.output_dir) |
| 52 | + |
| 53 | + if FLAGS.dataset_name == 'pascalvoc'or FLAGS.dataset_name == "bdd100k": |
| 54 | + pascalvoc_to_tfrecords.run(FLAGS.dataset_dir, FLAGS.output_dir, FLAGS.output_name) |
| 55 | + else: |
| 56 | + raise ValueError('Dataset [%s] was not recognized.' % FLAGS.dataset_name) |
| 57 | + |
| 58 | +if __name__ == '__main__': |
| 59 | + tf.app.run() |
| 60 | + |
0 commit comments