mlp_mnist_main.py revision aaac4ac3e9d1d8c48db9e4010459a417a07553d2
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.use_estimator: 37 if FLAGS.num_towers != 1: 38 raise ValueError("Only 1 device supported in tf.estimator example.") 39 mlp.train_mnist_estimator(FLAGS.data_dir, num_epochs=200) 40 elif FLAGS.num_towers > 1: 41 mlp.train_mnist_multitower( 42 FLAGS.data_dir, num_epochs=200, num_towers=FLAGS.num_towers) 43 else: 44 mlp.train_mnist(FLAGS.data_dir, num_epochs=200) 45 46 47if __name__ == "__main__": 48 parser = argparse.ArgumentParser() 49 parser.add_argument( 50 "--data_dir", 51 type=str, 52 default="/tmp/mnist", 53 help="Directory to store dataset in.") 54 parser.add_argument( 55 "--num_towers", 56 type=int, 57 default=1, 58 help="Number of CPUs to split minibatch across.") 59 parser.add_argument( 60 "--use_estimator", 61 action="store_true", 62 help="Use tf.estimator API to train.") 63 FLAGS, unparsed = parser.parse_known_args() 64 tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) 65