"benchmark/latency_throughput/bench_serving.py" did not exist on "19818b9c2f8df06436412f61d192d065bc2f976e"
download_and_convert_data.py 3.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
r"""Downloads and converts a particular dataset.

Usage:
```shell

$ python download_and_convert_data.py \
21
22
    --dataset_name=flowers \
    --dataset_dir=/tmp/flowers
23
24
25
26
27
28

$ python download_and_convert_data.py \
    --dataset_name=cifar10 \
    --dataset_dir=/tmp/cifar10

$ python download_and_convert_data.py \
29
30
31
32
33
34
35
    --dataset_name=mnist \
    --dataset_dir=/tmp/mnist

$ python download_and_convert_data.py \
    --dataset_name=visualwakewords \
    --dataset_dir=/tmp/visualwakewords

36
37
38
39
40
41
42
43
44
45
46
```
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf

from datasets import download_and_convert_cifar10
from datasets import download_and_convert_flowers
from datasets import download_and_convert_mnist
47
from datasets import download_and_convert_visualwakewords
48

49
FLAGS = tf.compat.v1.app.flags.FLAGS
50

51
tf.compat.v1.app.flags.DEFINE_string(
52
53
    'dataset_name',
    None,
54
55
    'The name of the dataset to convert, one of "flowers", "cifar10", "mnist", "visualwakewords"'
    )
56

57
tf.compat.v1.app.flags.DEFINE_string(
58
59
60
61
    'dataset_dir',
    None,
    'The directory where the output TFRecords and temporary files are saved.')

62
63
64
65
66
67
68
69
70
71
tf.flags.DEFINE_float(
    'small_object_area_threshold', 0.005,
    'For --dataset_name=visualwakewords only. Threshold of fraction of image '
    'area below which small objects are filtered')

tf.flags.DEFINE_string(
    'foreground_class_of_interest', 'person',
    'For --dataset_name=visualwakewords only. Build a binary classifier based '
    'on the presence or absence of this object in the image.')

72
73
74
75
76
77
78

def main(_):
  if not FLAGS.dataset_name:
    raise ValueError('You must supply the dataset name with --dataset_name')
  if not FLAGS.dataset_dir:
    raise ValueError('You must supply the dataset directory with --dataset_dir')

79
  if FLAGS.dataset_name == 'flowers':
80
    download_and_convert_flowers.run(FLAGS.dataset_dir)
81
82
  elif FLAGS.dataset_name == 'cifar10':
    download_and_convert_cifar10.run(FLAGS.dataset_dir)
83
84
  elif FLAGS.dataset_name == 'mnist':
    download_and_convert_mnist.run(FLAGS.dataset_dir)
85
86
87
88
  elif FLAGS.dataset_name == 'visualwakewords':
    download_and_convert_visualwakewords.run(
        FLAGS.dataset_dir, FLAGS.small_object_area_threshold,
        FLAGS.foreground_class_of_interest)
89
90
  else:
    raise ValueError(
91
        'dataset_name [%s] was not recognized.' % FLAGS.dataset_name)
92
93

if __name__ == '__main__':
94
  tf.compat.v1.app.run()