tensorbuilder.api module
1062 | 1063 | 1064 | 1065 |from api import API 1067 | import builder 1068 | import builder_tree 1069 | import applicative 1070 | 1071 | 1072 | __all__ = ["builder", "builder_tree", "applicative", "api"] 1073 |
├── .gitignore ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── MANIFEST.in ├── README.md ├── book.json ├── docker-compose.yml ├── docs └── tensorbuilder │ ├── api │ ├── api.m.html │ ├── applicative.m.html │ ├── builder.m.html │ ├── builder_tree.m.html │ └── index.html │ ├── builder.m.html │ ├── core │ ├── concrete_classes.m.html │ ├── index.html │ └── utils.m.html │ ├── extensions │ ├── index.html │ └── patches │ │ ├── index.html │ │ └── tensorbuilder_patch.m.html │ ├── index.html │ ├── patches │ ├── custom_patch.m.html │ ├── index.html │ ├── layers_patch.m.html │ ├── rnn_utilities_patch.m.html │ ├── summaries_patch.m.html │ ├── tensorbuilder_patch │ │ ├── api_functions_patch.m.html │ │ ├── applicative_ops.m.html │ │ ├── builder_custom_ops.m.html │ │ ├── custom_layer_ops.m.html │ │ ├── index.html │ │ ├── scope_ops.m.html │ │ ├── summaries.m.html │ │ ├── tensorflow_ops.m.html │ │ └── tflearn_ops.m.html │ └── tensorflow_patch.m.html │ ├── tensordata.m.html │ ├── tensordata │ └── index.html │ └── tests │ ├── index.html │ └── test_tensorbuilder.m.html ├── examples ├── tensorbuilder_patch.py └── tflearn_patch.py ├── guide ├── README.md ├── SUMMARY.md ├── basics │ └── README.md ├── branching │ ├── README.md │ └── test.md ├── dsl │ ├── README.md │ └── test.md ├── patches │ ├── README.md │ └── test.md └── scoping │ ├── README.md │ └── test.md ├── requirements.txt ├── scripts ├── create_readme.py ├── do_pypitest ├── gen_docs ├── init ├── test_pypitest ├── update_gh_pages ├── upload_live └── upload_test ├── setup.py ├── tensorbuilder ├── README-template.md ├── __init__.py ├── builder.py ├── patches │ ├── __init__.py │ ├── custom_patch.py │ ├── layers_patch.py │ ├── rnn_utilities_patch.py │ ├── summaries_patch.py │ └── tensorflow_patch.py ├── tensordata │ └── __init__.py ├── tests │ ├── __init__.py │ └── test_tensorbuilder.py └── version.txt └── tests └── test2.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | #Ipython Notebook 62 | .ipynb_checkpoints 63 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.5 2 | Mayor rewrite to enable clean extensibility + added scoping mechanism. 3 | 4 | **scoping** 5 | 6 | You can now write code with scopes like this 7 | 8 | h = ( 9 | tb.build(x) 10 | .relu_layer(100) 11 | .then_with(tf.device, "/gpu:0")(lambda layer: 12 | layer 13 | .tanh_layer(50) 14 | .dropout() 15 | .softmax_layer(10) 16 | ) 17 | .tensors() 18 | ) 19 | 20 | It internally uses the `with` statement to do what you expect. The DSL was also expanded to support these operations and it looks more natural 21 | 22 | h = dl.pipe( 23 | x, 24 | dl.relu_layer(100), 25 | 26 | { tf.device("/gpu:0"): 27 | dl.tanh_layer(50) 28 | .dropout() 29 | .softmax_layer(10) 30 | }, 31 | dl.tensors() 32 | ) 33 | 34 | as you see scoping is done using a dictionary object. 35 | 36 | #### New methods 37 | * then_with: support scoping 38 | * with_device: shortcut for `then_with(tf.device, ...)` 39 | * with_variable_scope: shortcut for `then_with(tf.variable_scope, ...)` 40 | * linear_layer: sets `activation_fn` to `None` 41 | * flatten: taken from `tflearn` 42 | 43 | #### Bugs Fixed 44 | * `*_layer` methods where getting inserted an in-between `relu` operation because `fully_connected` has `activation_fn=tf.nn.relu` as a default parameter. 45 | 46 | #### Other changes 47 | * Builder, BuilderTree, and Applicative now inherit from BuilderBase, BuilderTree and ApplicativeBase respectively. They are also dynamically generated by a function so patches get set own set of these classes and do not pollute each other. 48 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:0.11.0rc2 2 | 3 | RUN apt-get update 4 | RUN apt-get -y install git 5 | 6 | RUN pip install prettytensor 7 | RUN pip install pandas 8 | RUN pip install plotly 9 | RUN pip install pdoc 10 | RUN pip install mako 11 | RUN pip install markdown 12 | RUN pip install decorator==4.0.9 13 | RUN pip install tflearn 14 | RUN pip install asq==1.2.1 15 | RUN pip install pytest 16 | RUN pip install pytest-sugar 17 | RUN pip install fn 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 cgarciae 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENCE 2 | include requirements.txt 3 | include README.md 4 | include CHANGELOG.md 5 | 6 | include tensorbuilder/version.txt 7 | include tensorbuilder/README-template.md 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tensor Builder 2 | TensorBuilder had a mayor refactoring and is now based on [Phi](https://github.com/cgarciae/phi). Updates to the README comming soon! 3 | 4 | ### Goals 5 | Comming Soon! 6 | 7 | ## Installation 8 | Tensor Builder assumes you have a working `tensorflow` installation. We don't include it in the `requirements.txt` since the installation of tensorflow varies depending on your setup. 9 | 10 | #### From pypi 11 | ``` 12 | pip install tensorbuilder 13 | ``` 14 | 15 | #### From github 16 | For the latest development version 17 | ``` 18 | pip install git+https://github.com/cgarciae/tensorbuilder.git@develop 19 | ``` 20 | 21 | ## Getting Started 22 | 23 | Create neural network with a [5, 10, 3] architecture with a `softmax` output layer and a `tanh` hidden layer through a Builder and then get back its tensor: 24 | 25 | ```python 26 | import tensorflow as tf 27 | from tensorbuilder import T 28 | 29 | x = tf.placeholder(tf.float32, shape=[None, 5]) 30 | keep_prob = tf.placeholder(tf.float32) 31 | 32 | h = T.Pipe( 33 | x, 34 | T.tanh_layer(10) # tanh(x * w + b) 35 | .dropout(keep_prob) # dropout(x, keep_prob) 36 | .softmax_layer(3) # softmax(x * w + b) 37 | ) 38 | ``` 39 | 40 | ## Features 41 | Comming Soon! 42 | 43 | ## Documentation 44 | Comming Soon! 45 | 46 | ## The Guide 47 | Comming Soon! 48 | 49 | ## Full Example 50 | Next is an example with all the features of TensorBuilder including the DSL, branching and scoping. It creates a branched computation where each branch is executed on a different device. All branches are then reduced to a single layer, but the computation is the branched again to obtain both the activation function and the trainer. 51 | 52 | ```python 53 | import tensorflow as tf 54 | from tensorbuilder import T 55 | 56 | x = placeholder(tf.float32, shape=[None, 10]) 57 | y = placeholder(tf.float32, shape=[None, 5]) 58 | 59 | [activation, trainer] = T.Pipe( 60 | x, 61 | [ 62 | T.With( tf.device("/gpu:0"): 63 | T.relu_layer(20) 64 | ) 65 | , 66 | T.With( tf.device("/gpu:1"): 67 | T.sigmoid_layer(20) 68 | ) 69 | , 70 | T.With( tf.device("/cpu:0"): 71 | T.tanh_layer(20) 72 | ) 73 | ], 74 | T.linear_layer(5), 75 | [ 76 | T.softmax() # activation 77 | , 78 | T 79 | .softmax_cross_entropy_with_logits(y) # loss 80 | .minimize(tf.train.AdamOptimizer(0.01)) # trainer 81 | ] 82 | ) 83 | ``` -------------------------------------------------------------------------------- /book.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": "./guide" 3 | } 4 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | volumes: 4 | data: 5 | 6 | services: 7 | tf: 8 | build: . 9 | volumes: 10 | - ./:/tensorbuilder 11 | ports: 12 | - "8885:8888" 13 | command: bash -c "python setup.py install && cd /notebooks && /run_jupyter.sh" 14 | 15 | docs: 16 | # update gh-pages => git subtree push --prefix docs/tensorbuilder origin gh-pages 17 | build: . 18 | volumes: 19 | - ./:/tensorbuilder 20 | working_dir: /tensorbuilder 21 | command: ./gen_docs 22 | 23 | test: 24 | build: . 25 | volumes: 26 | - ./:/tensorbuilder 27 | working_dir: /tensorbuilder 28 | command: py.test 29 | -------------------------------------------------------------------------------- /docs/tensorbuilder/api/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 |from api import API 1067 | import builder 1068 | import builder_tree 1069 | import applicative 1070 | 1071 | 1072 | __all__ = ["builder", "builder_tree", "applicative", "api"] 1073 |