TensorFlow 1.4 - CUDA 8
Driver:
- Version: 384.81
- Release Date: 2017.9.25
- Operating System: Linux 64-bit Ubuntu 16.04
# CUDA Drivers
# http://www.nvidia.com/download/driverResults.aspx/124729/en-us| from __future__ import print_function | |
| from keras.datasets imporrt imdb | |
| (x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=20000) | |
| x_train = sequence.pad_sequences(x_train, maxlen=80) | |
| word_index = keras.datasets.imdb.get_word_index() | |
| # or items() in Python 3 | |
| inverted_word_index = {index:word for (word, index) in word_index.iteritems()} |
TensorFlow 1.4 - CUDA 8
Driver:
# CUDA Drivers
# http://www.nvidia.com/download/driverResults.aspx/124729/en-us| diff --git a/keras/utils/generic_utils.py b/keras/utils/generic_utils.py | |
| index 6a97448..d1db340 100644 | |
| --- a/keras/utils/generic_utils.py | |
| +++ b/keras/utils/generic_utils.py | |
| @@ -292,7 +292,7 @@ class Progbar(object): | |
| self.seen_so_far = current | |
| now = time.time() | |
| - info = ' - %.0fs' % (now - self.start) | |
| + info = ' - %.0f ms' % (1e3 * (now - self.start)) |
| CUDA_VISIBLE_DEVICES=0 \ | |
| /usr/local/cuda/bin/nvprof \ | |
| -o model_$(git rev-parse --short HEAD)_$(date +%Y%m%d-%H%M%S).sqlite \ | |
| python train.py |
| # https://github.com/bzamecnik/ideas/blob/master/key_coloring.md | |
| import numpy as np | |
| def key_distance(pitch_class, key): | |
| """ | |
| Distance between a pitch class and tonic of a key | |
| which roughly approximates dissonance. | |
| Eg. in key of C the pitch classes sorted from most consonant |
| # https://github.com/fchollet/keras/pull/8286 | |
| # | |
| # An example how pass additional substitutions to the training function | |
| # via TensorFlow feed_dict argument to tf.Session.run(). | |
| # | |
| # Note that `feed_dict` keys are `tf.Placeholder`s and values can be | |
| # ordinary numpy arrays or other Python values. | |
| # | |
| # We pass additional arguments to model.compile() -> K.function() as **kwargs. | |
| # The trick is that the feed_dict is passed as a reference, ie. even though |
| # Is it possible to utilize Keras callbacks to encapsulate the logic? Yes. | |
| # | |
| # We decouple feeding inputs from StagingArea.put() - both can be called in | |
| # a separate Session.run(). Thus it's not needed to hack Keras inputs too much. | |
| # Instead in one run() we assign a numpy array to a Variable (via feed_dict) | |
| # and in another run() we perform StagingArea.put(). | |
| # | |
| # We make a callback StagingAreaCallback which perform the initial assign and put() | |
| # in its on_epoch_begin() method. Then in each on_batch_begin() it just runs an | |
| # assign. Then get() and put() is ran by Keras in the training function. |
| # GTX 980 Ti | |
| # plain: 68.50 images/sec | |
| # pipeline: 68.71 images/sec | |
| import math | |
| import tensorflow as tf | |
| from keras.datasets import mnist | |
| from keras.models import Model | |
| from keras.layers import Dense, Input, Conv2D, MaxPooling2D, Dropout, Flatten | |
| from keras.utils import to_categorical |
| # It works! | |
| # | |
| # GTX 980 Ti | |
| # plain model: ~14370 images/sec | |
| # prefetch model: ~14670 images/sec | |
| # | |
| # In nvprof we can see that that HtoD memcpy is really async! | |
| # What remains is just sync feed_dict to move from numpy to a CPU Variable. | |
| import math |
| import numpy as np | |
| import tensorflow as tf | |
| from tensorflow.python.ops.data_flow_ops import StagingArea | |
| dataset_range = tf.contrib.data.Dataset.range(10) | |
| iter = dataset_range.make_one_shot_iterator() | |
| next_item = iter.get_next() | |
| area = StagingArea(dtypes=[tf.int64]) | |
| area_put = area.put([next_item]) |