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 a ConvNet on MNIST using K-FAC. 16 17See convnet.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 convnet 30 31FLAGS = None 32 33 34def main(argv): 35 _ = argv 36 37 if FLAGS.num_towers > 1: 38 convnet.train_mnist_multitower( 39 FLAGS.data_dir, num_epochs=200, num_towers=FLAGS.num_towers) 40 else: 41 convnet.train_mnist_single_machine(FLAGS.data_dir, num_epochs=200) 42 43 44if __name__ == "__main__": 45 parser = argparse.ArgumentParser() 46 parser.add_argument( 47 "--data_dir", 48 type=str, 49 default="/tmp/mnist", 50 help="Directory to store dataset in.") 51 parser.add_argument( 52 "--num_towers", 53 type=int, 54 default=1, 55 help="Number of CPUs to split minibatch across.") 56 FLAGS, unparsed = parser.parse_known_args() 57 tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) 58