mlp_mnist_main.py revision 0e6abfcdaf62c991ffa303454904e51ff55cf3d5
1# Copyright 2017 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# ==============================================================================
15r"""Train an MLP on MNIST using K-FAC.
16
17See mlp.py for details.
18"""
19
20from __future__ import absolute_import
21from __future__ import division
22from __future__ import print_function
23
24import argparse
25import sys
26
27import tensorflow as tf
28
29from tensorflow.contrib.kfac.examples import mlp
30
31FLAGS = None
32
33
34def main(argv):
35  _ = argv
36  if FLAGS.num_towers > 1:
37    mlp.train_mnist_multitower(
38        FLAGS.data_dir, num_epochs=200, num_towers=FLAGS.num_towers)
39  else:
40    mlp.train_mnist(FLAGS.data_dir, num_epochs=200)
41
42
43if __name__ == "__main__":
44  parser = argparse.ArgumentParser()
45  parser.add_argument(
46      "--data_dir",
47      type=str,
48      default="/tmp/mnist",
49      help="Directory to store dataset in.")
50  parser.add_argument(
51      "--num_towers",
52      type=int,
53      default=1,
54      help="Number of CPUs to split minibatch across.")
55  FLAGS, unparsed = parser.parse_known_args()
56  tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
57