├── tf_mnist_mlp.py ├── neon_mnist_mlp.py ├── README.md └── LICENSE /tf_mnist_mlp.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 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 | # ============================================================================== 15 | 16 | """A very simple MNIST classifier. 17 | See extensive documentation at 18 | https://www.tensorflow.org/get_started/mnist/beginners 19 | """ 20 | from __future__ import absolute_import 21 | from __future__ import division 22 | from __future__ import print_function 23 | 24 | import argparse 25 | import sys 26 | 27 | from tensorflow.examples.tutorials.mnist import input_data 28 | 29 | import tensorflow as tf 30 | 31 | FLAGS = None 32 | 33 | 34 | def main(_): 35 | # Import data 36 | mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True) 37 | 38 | # Create the model 39 | x = tf.placeholder(tf.float32, [None, 784]) 40 | W1 = tf.Variable(tf.random_normal_initializer()([784, 100])) 41 | b1 = tf.Variable(tf.random_normal_initializer()([100])) 42 | W2 = tf.Variable(tf.random_normal_initializer()([100, 10])) 43 | b2 = tf.Variable(tf.random_normal_initializer()([10])) 44 | y = tf.matmul(tf.nn.relu(tf.matmul(x, W1) + b1), W2) + b2 45 | 46 | y_ = tf.placeholder(tf.float32, [None, 10]) 47 | train_step = tf.train.MomentumOptimizer(0.1, 0.9).minimize( 48 | tf.reduce_mean( 49 | tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))) 50 | 51 | sess = tf.InteractiveSession() 52 | tf.global_variables_initializer().run() 53 | # Train 54 | for _ in range(4690): 55 | batch_xs, batch_ys = mnist.train.next_batch(128) 56 | sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) 57 | 58 | # Test trained model 59 | accuracy = tf.reduce_mean( 60 | tf.cast( 61 | tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)), 62 | tf.float32)) 63 | print(sess.run(accuracy, feed_dict={x: mnist.test.images, 64 | y_: mnist.test.labels})) 65 | 66 | if __name__ == '__main__': 67 | parser = argparse.ArgumentParser() 68 | parser.add_argument('--data_dir', type=str, default='/tmp/mnist_data', 69 | help='Directory for storing input data') 70 | FLAGS, unparsed = parser.parse_known_args() 71 | tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) 72 | -------------------------------------------------------------------------------- /neon_mnist_mlp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # ---------------------------------------------------------------------------- 3 | # Copyright 2015-2016 Nervana Systems Inc. 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ---------------------------------------------------------------------------- 16 | """ 17 | Train a small multi-layer perceptron with fully connected layers on MNIST data. 18 | 19 | This example has some command line arguments that enable different neon 20 | features. 21 | 22 | Examples: 23 | 24 | python examples/mnist_mlp.py -b gpu -e 10 25 | 26 | Run the example for 10 epochs using the NervanaGPU backend 27 | 28 | python examples/mnist_mlp.py --eval_freq 1 29 | 30 | After each training epoch, process the validation/test data 31 | set through the model and display the cost. 32 | 33 | python examples/mnist_mlp.py --serialize 1 -s checkpoint.pkl 34 | 35 | After every iteration of training, dump the model to a pickle 36 | file named "checkpoint.pkl". Changing the serialize parameter 37 | changes the frequency at which the model is saved. 38 | 39 | python examples/mnist_mlp.py --model_file checkpoint.pkl 40 | 41 | Before starting to train the model, set the model state to 42 | the values stored in the checkpoint file named checkpoint.pkl. 43 | 44 | """ 45 | 46 | from neon.callbacks.callbacks import Callbacks 47 | from neon.data import MNIST 48 | from neon.initializers import Gaussian 49 | from neon.layers import GeneralizedCost, Affine 50 | from neon.models import Model 51 | from neon.optimizers import GradientDescentMomentum 52 | from neon.transforms import (Rectlin, Logistic, CrossEntropyBinary, 53 | Misclassification) 54 | from neon.util.argparser import NeonArgparser 55 | from neon import logger as neon_logger 56 | 57 | 58 | def main(args): 59 | # load up the mnist data set 60 | dataset = MNIST(path=args.data_dir) 61 | 62 | # initialize model object 63 | mlp = Model( 64 | layers=[ 65 | Affine(nout=100, init=Gaussian(loc=0.0, scale=0.01), 66 | activation=Rectlin()), 67 | Affine(nout=10, init=Gaussian(loc=0.0, scale=0.01), 68 | activation=Logistic(shortcut=True))]) 69 | 70 | # setup optimizer 71 | optimizer = GradientDescentMomentum( 72 | 0.1, momentum_coef=0.9, stochastic_round=args.rounding) 73 | 74 | # configure callbacks 75 | callbacks = Callbacks(mlp, eval_set=dataset.valid_iter, **args.callback_args) 76 | 77 | # run fit 78 | # setup cost function as CrossEntropy 79 | mlp.fit( 80 | dataset.train_iter, 81 | optimizer=optimizer, 82 | num_epochs=args.epochs, 83 | cost=GeneralizedCost(costfunc=CrossEntropyBinary()), 84 | callbacks=callbacks) 85 | error_rate = mlp.eval(dataset.valid_iter, metric=Misclassification()) 86 | neon_logger.display('Classification accuracy = %.4f' % (1 - error_rate)) 87 | 88 | 89 | if __name__ == '__main__': 90 | main(NeonArgparser(__doc__).parse_args()) 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MNIST in Neon and TensorFlow 2 | 3 | This repository includes implementations of a deep learning model using two 4 | different frameworks: Intel Nervana 5 | [Neon](http://neon.nervanasys.com/docs/latest/index.html) and Google 6 | [TensorFlow](https://www.tensorflow.org/). 7 | 8 | These implementations are intended to illustrate the differences in the 9 | programming models presented by the two frameworks. 10 | 11 | # The Problem 12 | 13 | The model solves an old problem from the machine learning community: assign a 14 | 28 × 28 pixel grayscale image of a handwritten digit to the correct one 15 | of ten classes. 16 | 17 | The model is trained and tested on 70,000 images from the [MNIST 18 | database](https://en.wikipedia.org/wiki/MNIST_database). 19 | 20 | # The Implementations 21 | 22 | ## Parsing Arguments 23 | 24 | The Neon implementation uses a [`NeonArgparser`](http://neon.nervanasys.com/docs/latest/generated/neon.util.argparser.NeonArgparser.html) instance to parse command-line arguments: 25 | 26 | ``` 27 | if __name__ == '__main__': 28 | main(NeonArgparser(__doc__).parse_args()) 29 | ``` 30 | 31 | The TensorFlow implementation uses an [`ArgumentParser`](https://docs.python.org/2/library/argparse.html#argumentparser-objects) instance. The 32 | `data_dir` argument specifies the location of cached training data (if any). 33 | 34 | It then calls our `main()` function, providing command-line arguments. 35 | 36 | ``` 37 | 38 | if __name__ == '__main__': 39 | parser = argparse.ArgumentParser() 40 | parser.add_argument('--data_dir', type=str, default='/tmp/mnist_data', 41 | help='Directory for storing input data') 42 | FLAGS, unparsed = parser.parse_known_args() 43 | tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) 44 | ``` 45 | 46 | ## Preparing Data 47 | 48 | The Neon implementation uses an [`MNIST`](http://neon.nervanasys.com/docs/latest/datasets.html#mnist) instance to aquire data sets. The 49 | [`MNIST`](http://neon.nervanasys.com/docs/latest/datasets.html#mnist) instance handles downloading the MNIST database into a local cache. 50 | 51 | ``` 52 | dataset = MNIST(path=args.data_dir) 53 | ``` 54 | 55 | The TensorFlow implementation uses an [`mnist.input_data`](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/tutorials/mnist/?hl=fr) instance. 56 | 57 | ``` 58 | mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True) 59 | ``` 60 | 61 | ## Defining the Model 62 | 63 | The Neon implementation defines the model as two [`Affine`](http://neon.nervanasys.com/docs/latest/layers.html#compound-layers) layers with 64 | [`Gaussian`](http://neon.nervanasys.com/docs/latest/initializers.html) initialization. The first layer has a [rectified linear](http://neon.nervanasys.com/docs/latest/activations.html) activation, 65 | and the second a [`Logistic`](http://neon.nervanasys.com/docs/latest/activations.html) activation. 66 | 67 | The model is instantiated directly with these two layers. 68 | 69 | ``` 70 | mlp = Model( 71 | layers=[ 72 | Affine(nout=100, init=Gaussian(loc=0.0, scale=0.01), 73 | activation=Rectlin()), 74 | Affine(nout=10, init=Gaussian(loc=0.0, scale=0.01), 75 | activation=Logistic(shortcut=True))]) 76 | ``` 77 | 78 | The TensorFlow implementation defines the model as a collection of 79 | 80 | * [`placeholder`](https://www.tensorflow.org/api_docs/python/tf/placeholder)s, 81 | * [`Variable`](https://www.tensorflow.org/api_docs/python/tf/Variable)s initialized using [`random_normal_initializer`](https://www.tensorflow.org/api_docs/python/tf/random_normal_initializer), 82 | * [matrix multiplication](https://www.tensorflow.org/api_docs/python/tf/matmul) operations, and 83 | * [rectified linear](https://www.tensorflow.org/api_docs/python/tf/nn/relu) activations. 84 | 85 | These objects are actually references into a graph representation of the model. 86 | This representation expresses the dependencies between the outputs, various 87 | intermediate values, inputs, and the matrix operations on them. 88 | 89 | ``` 90 | x = tf.placeholder(tf.float32, [None, 784]) 91 | W1 = tf.Variable(tf.random_normal_initializer()([784, 100])) 92 | b1 = tf.Variable(tf.random_normal_initializer()([100])) 93 | W2 = tf.Variable(tf.random_normal_initializer()([100, 10])) 94 | b2 = tf.Variable(tf.random_normal_initializer()([10])) 95 | y = tf.matmul(tf.nn.relu(tf.matmul(x, W1) + b1), W2) + b2 96 | ``` 97 | 98 | ## Defining the Optimizer 99 | 100 | The Neon implementation defines the optimizer as an instance of [`GradientDescentMomentum`](http://neon.nervanasys.com/docs/latest/optimizers.html#stochastic-gradient-descent) 101 | 102 | ``` 103 | optimizer = GradientDescentMomentum( 104 | 0.1, momentum_coef=0.9, stochastic_round=args.rounding) 105 | ``` 106 | 107 | The TensorFlow implementation defines the optimizer as a collection of 108 | 109 | * [`placeholder`](https://www.tensorflow.org/api_docs/python/tf/placeholder)s for the actual and expected outputs, and 110 | * operations including [`reduce_mean`](https://www.tensorflow.org/api_docs/python/tf/reduce_mean) and [`softmax_cross_entropy_with_logits`](https://www.tensorflow.org/versions/master/api_docs/python/tf/nn/softmax_cross_entropy_with_logits) (the cost function) 111 | 112 | Again, these objects are references into a graph representation of the 113 | optimizer. 114 | 115 | ``` 116 | y_ = tf.placeholder(tf.float32, [None, 10]) 117 | train_step = tf.train.MomentumOptimizer(0.1, 0.9).minimize( 118 | tf.reduce_mean( 119 | tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))) 120 | ``` 121 | 122 | ## Fitting the Model 123 | 124 | The Neon implementation fits the model to the training set by passing the 125 | optimizer to its `fit()` method. The cost function is specified here using a 126 | [`GeneralizedCost`](http://neon.nervanasys.com/docs/latest/generated/neon.layers.layer.GeneralizedCost.html) layer and 127 | [`CrossEntropyBinary`](http://neon.nervanasys.com/docs/latest/generated/neon.transforms.cost.CrossEntropyBinary.html) function. The number of training epochs is 128 | derived from the command line arguments. 129 | 130 | ``` 131 | mlp.fit( 132 | dataset.train_iter, 133 | optimizer=optimizer, 134 | num_epochs=args.epochs, 135 | cost=GeneralizedCost(costfunc=CrossEntropyBinary()), 136 | callbacks=callbacks) 137 | ``` 138 | 139 | The TensorFlow implementation fits the model to the training set by 140 | 141 | 1. registering a default 142 | [`session`](https://www.tensorflow.org/programmers_guide/graphs#executing_a_graph_in_a_tfsession) in the context of which to execute the graph. 143 | 144 | 2. initializing global variables 145 | 146 | 3. acquiring a batch of training data and 147 | 148 | 4. running the optimizer with the batch mapped to placeholders in the model. 149 | 150 | 5. repeating steps 3. and 4. 151 | 152 | ``` 153 | sess = tf.InteractiveSession() 154 | tf.global_variables_initializer().run() 155 | for _ in range(4690): 156 | batch_xs, batch_ys = mnist.train.next_batch(128) 157 | sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) 158 | ``` 159 | 160 | ## Displaying Accuracy 161 | 162 | The Neon implementation evaluates the accuracy of the model on the validation set by calling its `eval()` method and passing the [`Misclassification`](http://neon.nervanasys.com/docs/latest/generated/neon.transforms.cost.Misclassification.html) metric. 163 | 164 | ``` 165 | error_rate = mlp.eval(dataset.valid_iter, metric=Misclassification()) 166 | neon_logger.display('Classification accuracy = %.4f' % (1 - error_rate)) 167 | ``` 168 | 169 | The TensorFlow implementation defines an accuracy measurement as a collection of 170 | 171 | * [`placeholder`]()s for the actual and expected outputs, and 172 | * operations including [`equal`](https://www.tensorflow.org/versions/r1.3/api_docs/python/tf/equal) and [`reduce_mean`](https://www.tensorflow.org/api_docs/python/tf/reduce_mean) 173 | 174 | These objects are actually references into a graph representation of the 175 | accuracy formula. It evaluates the accuracy by running this graph with the test 176 | set mapped to placeholders. 177 | 178 | ``` 179 | accuracy = tf.reduce_mean( 180 | tf.cast( 181 | tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)), 182 | tf.float32)) 183 | print(sess.run(accuracy, feed_dict={x: mnist.test.images, 184 | y_: mnist.test.labels})) 185 | ``` 186 | 187 | # Running 188 | 189 | To run the Neon implementation, [follow instructions for installing Neon](http://neon.nervanasys.com/docs/latest/installation.html). Then, simply enter 190 | 191 | ``` 192 | (.venv2) :neon-tf-mnist $ python neon_mnist_mlp.py 193 | ``` 194 | 195 | To run the TensorFlow implementation, [follow instructions for installing TensorFlow](https://www.tensorflow.org/install/). Then simply enter 196 | 197 | ``` 198 | (tensorflow) :neon-tf-mnist $ python tf_mnist_mlp.py 199 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------