Unverified Commit d5e826e3 authored by Steven Hickson's avatar Steven Hickson Committed by GitHub
Browse files

Merge branch 'master' into master

parents e1ac09e1 fc37f117
......@@ -39,6 +39,8 @@
/research/video_prediction/ @cbfinn
/research/fivo/ @dieterichlawson
/samples/ @MarkDaoust
/samples/languages/java/ @asimshankar
/tutorials/embedding/ @zffchen78 @a-dai
/tutorials/image/ @sherrym @shlens
/tutorials/image/cifar10_estimator/ @tfboyd @protoget
/tutorials/rnn/ @lukaszkaiser @ebrevdo
# TensorFlow Official Models
The TensorFlow official models are a collection of example models that use TensorFlow's high-level APIs. They are intended to be well-maintained, tested, and kept up to date with the latest stable TensorFlow API. They should also be reasonably optimized for fast performance while still being easy to read.
The TensorFlow official models are a collection of example models that use TensorFlow's high-level APIs. They are intended to be well-maintained, tested, and kept up to date with the latest TensorFlow API. They should also be reasonably optimized for fast performance while still being easy to read.
The master branch of the models are **in development**, and they target the [nightly binaries](https://github.com/tensorflow/tensorflow#installation) built from the [master branch of TensorFlow](https://github.com/tensorflow/tensorflow/tree/master).
**Stable versions** of the official models targeting releases of TensorFlow are available as tagged branches or [downloadable releases](https://github.com/tensorflow/models/releases). Model repository version numbers match the target TensorFlow release, such that [branch r1.4.0](https://github.com/tensorflow/models/tree/r1.4.0) and [release v1.4.0](https://github.com/tensorflow/models/releases/tag/v1.4.0) are compatible with [TensorFlow v1.4.0](https://github.com/tensorflow/tensorflow/releases/tag/v1.4.0).
If you are on a version of TensorFlow earlier than v1.4, please [update your installation](https://www.tensorflow.org/install/).
Currently the models are compatible with TensorFlow 1.4. If you are on an earlier version please [update your installation](https://www.tensorflow.org/install/).
---
......
......@@ -33,7 +33,7 @@ def read32(bytestream):
def check_image_file_header(filename):
"""Validate that filename corresponds to images for the MNIST dataset."""
with tf.gfile.Open(filename) as f:
with tf.gfile.Open(filename, 'rb') as f:
magic = read32(f)
num_images = read32(f)
rows = read32(f)
......@@ -49,7 +49,7 @@ def check_image_file_header(filename):
def check_labels_file_header(filename):
"""Validate that filename corresponds to labels for the MNIST dataset."""
with tf.gfile.Open(filename) as f:
with tf.gfile.Open(filename, 'rb') as f:
magic = read32(f)
num_items = read32(f)
if magic != 2049:
......@@ -58,12 +58,12 @@ def check_labels_file_header(filename):
def download(directory, filename):
"""Download (and unzip) a file from the MNIST dataset, if it doesn't already exist."""
if not tf.gfile.Exists(directory):
tf.gfile.MakeDirs(directory)
"""Download (and unzip) a file from the MNIST dataset if not already done."""
filepath = os.path.join(directory, filename)
if tf.gfile.Exists(filepath):
return filepath
if not tf.gfile.Exists(directory):
tf.gfile.MakeDirs(directory)
# CVDF mirror of http://yann.lecun.com/exdb/mnist/
url = 'https://storage.googleapis.com/cvdf-datasets/mnist/' + filename + '.gz'
zipped_filepath = filepath + '.gz'
......
......@@ -96,6 +96,11 @@ def model_fn(features, labels, mode, params):
})
if mode == tf.estimator.ModeKeys.TRAIN:
optimizer = tf.train.AdamOptimizer(learning_rate=1e-4)
# If we are running multi-GPU, we need to wrap the optimizer.
if params.get('multi_gpu'):
optimizer = tf.contrib.estimator.TowerOptimizer(optimizer)
logits = model(image, training=True)
loss = tf.losses.softmax_cross_entropy(onehot_labels=labels, logits=logits)
accuracy = tf.metrics.accuracy(
......@@ -122,16 +127,53 @@ def model_fn(features, labels, mode, params):
})
def validate_batch_size_for_multi_gpu(batch_size):
"""For multi-gpu, batch-size must be a multiple of the number of
available GPUs.
Note that this should eventually be handled by replicate_model_fn
directly. Multi-GPU support is currently experimental, however,
so doing the work here until that feature is in place.
"""
from tensorflow.python.client import device_lib
local_device_protos = device_lib.list_local_devices()
num_gpus = sum([1 for d in local_device_protos if d.device_type == 'GPU'])
if not num_gpus:
raise ValueError('Multi-GPU mode was specified, but no GPUs '
'were found. To use CPU, run without --multi_gpu.')
remainder = batch_size % num_gpus
if remainder:
err = ('When running with multiple GPUs, batch size '
'must be a multiple of the number of available GPUs. '
'Found {} GPUs with a batch size of {}; try --batch_size={} instead.'
).format(num_gpus, batch_size, batch_size - remainder)
raise ValueError(err)
def main(unused_argv):
model_function = model_fn
if FLAGS.multi_gpu:
validate_batch_size_for_multi_gpu(FLAGS.batch_size)
# There are two steps required if using multi-GPU: (1) wrap the model_fn,
# and (2) wrap the optimizer. The first happens here, and (2) happens
# in the model_fn itself when the optimizer is defined.
model_function = tf.contrib.estimator.replicate_model_fn(
model_fn, loss_reduction=tf.losses.Reduction.MEAN)
data_format = FLAGS.data_format
if data_format is None:
data_format = ('channels_first'
if tf.test.is_built_with_cuda() else 'channels_last')
mnist_classifier = tf.estimator.Estimator(
model_fn=model_fn,
model_fn=model_function,
model_dir=FLAGS.model_dir,
params={
'data_format': data_format
'data_format': data_format,
'multi_gpu': FLAGS.multi_gpu
})
# Train the model
......@@ -169,39 +211,52 @@ def main(unused_argv):
mnist_classifier.export_savedmodel(FLAGS.export_dir, input_fn)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--batch_size',
type=int,
default=100,
help='Number of images to process in a batch')
parser.add_argument(
'--data_dir',
type=str,
default='/tmp/mnist_data',
help='Path to directory containing the MNIST dataset')
parser.add_argument(
'--model_dir',
type=str,
default='/tmp/mnist_model',
help='The directory where the model will be stored.')
parser.add_argument(
'--train_epochs', type=int, default=40, help='Number of epochs to train.')
parser.add_argument(
'--data_format',
type=str,
default=None,
choices=['channels_first', 'channels_last'],
help='A flag to override the data format used in the model. channels_first '
'provides a performance boost on GPU but is not always compatible '
'with CPU. If left unspecified, the data format will be chosen '
'automatically based on whether TensorFlow was built for CPU or GPU.')
parser.add_argument(
'--export_dir',
type=str,
help='The directory where the exported SavedModel will be stored.')
class MNISTArgParser(argparse.ArgumentParser):
def __init__(self):
super(MNISTArgParser, self).__init__()
self.add_argument(
'--multi_gpu', action='store_true',
help='If set, run across all available GPUs.')
self.add_argument(
'--batch_size',
type=int,
default=100,
help='Number of images to process in a batch')
self.add_argument(
'--data_dir',
type=str,
default='/tmp/mnist_data',
help='Path to directory containing the MNIST dataset')
self.add_argument(
'--model_dir',
type=str,
default='/tmp/mnist_model',
help='The directory where the model will be stored.')
self.add_argument(
'--train_epochs',
type=int,
default=40,
help='Number of epochs to train.')
self.add_argument(
'--data_format',
type=str,
default=None,
choices=['channels_first', 'channels_last'],
help='A flag to override the data format used in the model. '
'channels_first provides a performance boost on GPU but is not always '
'compatible with CPU. If left unspecified, the data format will be '
'chosen automatically based on whether TensorFlow was built for CPU or '
'GPU.')
self.add_argument(
'--export_dir',
type=str,
help='The directory where the exported SavedModel will be stored.')
if __name__ == '__main__':
parser = MNISTArgParser()
tf.logging.set_verbosity(tf.logging.INFO)
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
......@@ -62,11 +62,12 @@ class Tests(tf.test.TestCase):
self.assertEqual(predictions['probabilities'].shape, (10,))
self.assertEqual(predictions['classes'].shape, ())
def mnist_model_fn_helper(self, mode):
def mnist_model_fn_helper(self, mode, multi_gpu=False):
features, labels = dummy_input_fn()
image_count = features.shape[0]
spec = mnist.model_fn(features, labels, mode, {
'data_format': 'channels_last'
'data_format': 'channels_last',
'multi_gpu': multi_gpu
})
if mode == tf.estimator.ModeKeys.PREDICT:
......@@ -91,6 +92,9 @@ class Tests(tf.test.TestCase):
def test_mnist_model_fn_train_mode(self):
self.mnist_model_fn_helper(tf.estimator.ModeKeys.TRAIN)
def test_mnist_model_fn_train_mode_multi_gpu(self):
self.mnist_model_fn_helper(tf.estimator.ModeKeys.TRAIN, multi_gpu=True)
def test_mnist_model_fn_eval_mode(self):
self.mnist_model_fn_helper(tf.estimator.ModeKeys.EVAL)
......
......@@ -133,7 +133,8 @@ def main(argv):
# Note that the number of examples used during evaluation is
# --eval_steps * --batch_size.
# So if you change --batch_size then change --eval_steps too.
estimator.evaluate(input_fn=eval_input_fn, steps=FLAGS.eval_steps)
if FLAGS.eval_steps:
estimator.evaluate(input_fn=eval_input_fn, steps=FLAGS.eval_steps)
if __name__ == "__main__":
......
......@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
#
# DO NOT MODIFY THIS FILE. Add tests to be executed in test_models.sh
# Usage: docker_test.sh [--docker-image <DOCKER_IMG_NAME>]
#
......@@ -22,7 +22,7 @@
# --docker-image flag), the default latest tensorflow docker
# will be used.
#
# The script obeys the following required environment variables unless superceded by
# The script obeys the following required environment variables unless superceded by
# the docker image flag:
# PYTHON_VERSION: (PYTHON2 | PYTHON3)
......@@ -35,9 +35,9 @@ EXIT=0
export WORKSPACE=${PWD}
if [ "$PYTHON_VERSION" = "PYTHON3" ]; then
DOCKER_IMG_NAME="tensorflow/tensorflow:1.4.0-py3"
DOCKER_IMG_NAME="tensorflow/tensorflow:nightly-py3"
else
DOCKER_IMG_NAME="tensorflow/tensorflow:1.4.0"
DOCKER_IMG_NAME="tensorflow/tensorflow:nightly"
if [ "$PYTHON_VERSION" != "PYTHON2" ]; then
echo "WARNING: Python version was not specified. Using Python2 by default."
sleep 5
......@@ -56,6 +56,9 @@ fi
# Specify which test is to be run
COMMAND="./official/testing/test_models.sh"
# Check the recency of the desired image
${DOCKER_BINARY} pull ${DOCKER_IMG_NAME}
# RUN
${DOCKER_BINARY} run \
-v ${WORKSPACE}:/workspace \
......
# Coming Soon!
This directory will soon be populated with TensorFlow models and data
processing code for identifying exoplanets in astrophysical light curves.
For full details, see the following paper:
*Identifying Exoplanets With Deep Learning: A Five Planet Resonant Chain Around
Kepler-80 And An Eighth Planet Around Kepler-90*
Christopher J Shallue and Andrew Vanderburg
To appear in the Astronomical Journal
Preprint available at https://www.cfa.harvard.edu/~avanderb/kepler90i.pdf
Contact: Chris Shallue (@cshallue)
# Brain Coder
*Authors: Daniel Abolafia, Quoc Le, Mohammad Norouzi*
*Authors: Daniel Abolafia, Mohammad Norouzi, Quoc Le*
Brain coder is a code synthesis experimental environment. We provide code that reproduces the results from our recent paper [Code Synthesis with Priority Queue Training](https://openreview.net/forum?id=r1AoGNlC-). See single_task/README.md for details on how to build and reproduce those experiments.
Brain coder is a code synthesis experimental environment. We provide code that reproduces the results from our recent paper [Neural Program Synthesis with Priority Queue Training](https://arxiv.org/abs/1801.03526). See single_task/README.md for details on how to build and reproduce those experiments.
## Installation
......
......@@ -10,6 +10,7 @@ else that may be specific to a particular run.
import ast
import itertools
from six.moves import xrange
class Config(dict):
......
......@@ -7,6 +7,7 @@ from __future__ import print_function
from math import exp
from math import sqrt
import numpy as np
from six.moves import xrange
import tensorflow as tf
from common import config_lib # brain coder
......
......@@ -12,6 +12,8 @@ import random
from absl import logging
import numpy as np
import six
from six.moves import xrange
import tensorflow as tf
......@@ -137,7 +139,7 @@ def stack_pad(tensors, pad_axes=None, pad_to_lengths=None, dtype=np.float32,
same_axes = dict(enumerate(max_lengths))
if pad_axes is None:
pad_axes = []
if isinstance(pad_axes, (int, long)):
if isinstance(pad_axes, six.integer_types):
if pad_to_lengths is not None:
max_lengths[pad_axes] = pad_to_lengths
del same_axes[pad_axes]
......
# Experiments for ICLR 2018 paper.
[Code Synthesis with Priority Queue Training](https://openreview.net/forum?id=r1AoGNlC-).
[Neural Program Synthesis with Priority Queue Training](https://arxiv.org/abs/1801.03526).
Runs policy gradient (REINFORCE), priority queue training, genetic algorithm,
and uniform random search.
......
......@@ -11,6 +11,7 @@ import random
from absl import logging
import numpy as np
from six.moves import xrange
from common import bf # brain coder
from common import reward as r # brain coder
......
......@@ -14,6 +14,7 @@ import random
from absl import flags
from absl import logging
import numpy as np
from six.moves import xrange
from common import bf # brain coder
from common import utils # brain coder
......@@ -469,4 +470,3 @@ class Individual(list):
def random_individual(genome_size):
return lambda: Individual(np.random.choice(GENES, genome_size).tolist())
......@@ -18,6 +18,7 @@ from time import sleep
from absl import flags
from absl import logging
import numpy as np
from six.moves import xrange
import tensorflow as tf
from common import utils # brain coder
......@@ -321,4 +322,3 @@ def run_random_search(max_num_programs, checkpoint_dir, task_eval_fn,
solution_found=found_solution, generations=num_programs_seen,
num_programs=num_programs_seen, max_generations=max_num_programs,
max_num_programs=max_num_programs)
......@@ -15,6 +15,7 @@ import time
from absl import logging
import numpy as np
from six.moves import xrange
import tensorflow as tf
from common import rollout as rollout_lib # brain coder
......@@ -1294,4 +1295,3 @@ def process_episodes(
batch_targets = np.array([], dtype=np.float32)
return (batch_targets, batch_returns)
......@@ -8,6 +8,7 @@ from collections import Counter
from absl import logging
import numpy as np
from six.moves import xrange
import tensorflow as tf
from common import utils # brain coder
......
......@@ -8,6 +8,7 @@ import ast
from collections import namedtuple
import os
import re
from six.moves import xrange
import tensorflow as tf
......@@ -152,4 +153,3 @@ class Results(object):
r for shard_results in results_per_shard for r in shard_results]
return aggregate, shard_stats
......@@ -8,6 +8,7 @@ import contextlib
import os
import shutil
import tempfile
from six.moves import xrange
import tensorflow as tf
from single_task import results_lib # brain coder
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment