Metadata-Version: 1.1
Name: tfdeploy
Version: 0.1.7
Summary: Deploy tensorflow graphs for faster evaluation and export to tensorflow-less environments running
numpy.
Home-page: https://github.com/riga/tfdeploy
Author: Marcel Rieger, Benjamin Fischer
Author-email: UNKNOWN
License: MIT
Description: Deploy `tensorflow <https://www.tensorflow.org>`__ graphs for *faster*
        evaluation and export to *tensorflow-less* environments running
        `numpy <http://www.numpy.org>`__.
        
        Evaluation usage
        ''''''''''''''''
        
        .. code:: python
        
            import tfdeploy as td
            import numpy as np
        
            model = tfdeploy.Model("/path/to/model.pkl")
            inp, outp = mode.get("input", "output")
        
            batch = numpy.random.rand(10000, 784)
            result = outp.eval({inp: batch})
        
        Installation
        ''''''''''''
        
        Via `pip <https://pypi.python.org/pypi/tfdeploy>`__
        
        .. code:: bash
        
            pip install tfdeploy
        
        or by simply copying the file into your project.
        
        Why?
        ----
        
        Working with tensorflow is awesome. Model definition and training is
        simple yet powerful, and the range of built-in features is just
        striking.
        
        However, when it comes down to model deployment and evaluation things
        get a bit more cumbersome than they should be. You either export your
        graph to a new file *and* `save your trained
        variables <https://www.tensorflow.org/versions/master/how_tos/variables/index.html#saving-variables>`__
        in a separate file, or you make use of tensorflow's `serving
        system <https://www.tensorflow.org/versions/master/tutorials/tfserve/index.html>`__.
        Wouldn't it be great if you could just export your model to a simple
        numpy-based callable? Of course it would. And this is exactly what
        tfdeploy does for you.
        
        To boil it down, tfdeploy
        
        -  is lightweight. A single file with < 150 lines of core code. Just
           copy it to your project.
        -  `way faster <#performance>`__ then using tensorflow's
           ``Tensor.eval``.
        -  **does not need tensorflow** during evaluation.
        -  only depends on numpy.
        -  can load one or more models from a single file.
        -  does not support GPUs.
        
        How?
        ----
        
        The central class is ``tfdeploy.Model``. The following two examples
        demonstrate how a model can be created from a tensorflow graph, saved to
        and loaded from disk, and eventually evaluated.
        
        Convert your graph
        ''''''''''''''''''
        
        .. code:: python
        
            import tensorflow as tf
            import tfdeploy as td
        
            # build your graph
            sess = tf.Session()
        
            # use names for input and output layers
            x = tf.placeholder("float", shape=[None, 784], name="input")
            W = tf.Variable(tf.truncated_normal([784, 100], stddev=0.05))
            b = tf.Variable(tf.zeros([100]))
            y = tf.nn.softmax(tf.matmul(x, W) + b, name="output")
        
            sess.run(tf.initialize_all_variables())
        
            # ... training ...
        
            # create a tfdeploy model and save it to disk
            model = td.Model()
            model.add(y, sess) # y and all its ops and related tensors are added recursively
            model.save("model.pkl")
        
        Load the model and evaluate (without tensorflow)
        ''''''''''''''''''''''''''''''''''''''''''''''''
        
        .. code:: python
        
            import numpy as np
            import tfdeploy as td
        
            model = td.Model("model.pkl")
        
            # shorthand to x and y
            x, y = model.get("input", "output")
        
            # evaluate
            batch = np.random.rand(10000, 784)
            result = y.eval({x: batch})
        
        Write your own ``Operation``
        ''''''''''''''''''''''''''''
        
        tfdeploy supports [STRIKEOUT:most of the] all math ``Operation``'s
        `implemented in
        tensorflow <https://www.tensorflow.org/versions/master/api_docs/python/math_ops.html>`__
        (nn Ops are currently added). However, if you miss one (in that case,
        submit a PR or an issue ;) ) or if you're using custom ops, you might
        want to extend tfdeploy:
        
        .. code:: python
        
            import tensorflow as tf
            import tfdeploy as td
        
            # ... write you model here ...
        
            # let's assume your final tensor "y" relies on an op of type "InvertedSoftmax"
            # before creating the td.Model, you should add that op to tfdeploy
        
            class InvertedSoftmax(td.Operation):
                @staticmethod
                def func(a):
                    e = np.exp(-a)
                    return np.divide(e, np.sum(e, axis=-1, keepdims=True))
        
            # this is equivalent to
        
            @td.Operation.factory
            def InvertedSoftmax(a):
                e = np.exp(-a)
                return np.divide(e, np.sum(e, axis=-1, keepdims=True))
        
            # now, we're good to go
            model = td.Model()
            model.add(y, sess)
            model.save("model.pkl")
        
        Performance
        -----------
        
        tfdeploy is lightweight (1 file, < 150 lines of core code) and fast.
        Internal operations are nearly overhead-free. All mathematical
        operations use numpy vectorization.
        
        iPython shell:
        
        .. code:: bash
        
            > ipython -i tests/perf.py
        
            In [1]: %timeit -n100 test_tf()
            100 loops, best of 3: 109 ms per loop
        
            In [2]: %timeit -n100 test_td()
            100 loops, best of 3: 60.5 ms per loop
        
        Development
        -----------
        
        -  Source hosted at `GitHub <https://github.com/riga/tfdeploy>`__
        -  Report issues, questions, feature requests on `GitHub
           Issues <https://github.com/riga/tfdeploy/issues>`__
        
        Authors
        -------
        
        -  `Marcel R. <https://github.com/riga>`__
        -  `Benjamin F. <https://github.com/bfis>`__
        
        License
        -------
        
        The MIT License (MIT)
        
        Copyright (c) 2016 Marcel R.
        
        Permission is hereby granted, free of charge, to any person obtaining a
        copy of this software and associated documentation files (the
        "Software"), to deal in the Software without restriction, including
        without limitation the rights to use, copy, modify, merge, publish,
        distribute, sublicense, and/or sell copies of the Software, and to
        permit persons to whom the Software is furnished to do so, subject to
        the following conditions:
        
        The above copyright notice and this permission notice shall be included
        in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
        OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
        MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
        IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
        CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
        TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
        SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Keywords: tensorflow,deploy,export,dump,numpy,model,predict,evaluate,function,method
Platform: UNKNOWN
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Information Technology
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
