Skip to content

Commit

Permalink
Merge pull request #952 from zsdonghao/master
Browse files Browse the repository at this point in the history
TensorLayer 2.0.0-alpha Release
  • Loading branch information
zsdonghao committed May 4, 2019
2 parents aa9e52e + 2742ca3 commit 0894eda
Show file tree
Hide file tree
Showing 303 changed files with 18,281 additions and 15,458 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -128,4 +128,4 @@ update_tl.py

# Data Files and ByteCode files
*.gz
*.npz
*.npz
30 changes: 17 additions & 13 deletions .travis.yml
Expand Up @@ -13,27 +13,28 @@ addons:
branches:
only:
- master
- TensorLayer-1.x
- TensorLayer-2.x
- /^\d+\.\d+(\.\d+)?(\S*)?$/

python:
- "3.6"
- "3.5"
- "2.7"
# - "2.7" # TensorLayer 2.0 does not support python2 now

env:

# Backward Compatibility in insured for release less than 1 year old.
# https://pypi.org/project/tensorflow/#history
matrix:
- _TF_VERSION=1.12.0 # Remove on Oct 22, 2019
- _TF_VERSION=1.11.0 # Remove on Sep 28, 2019
- _TF_VERSION=1.10.1 # Remove on Aug 24, 2019
- _TF_VERSION=1.9.0 # Remove on Jul 10, 2019
- _TF_VERSION=1.8.0 # Remove on Apr 28, 2019
- _TF_VERSION=1.7.1 # Remove on May 08, 2019
- _TF_VERSION=1.7.0 # Remove on Mar 29, 2019
- _TF_VERSION=1.6.0 # Remove on Mar 01, 2019
- _TF_VERSION=2.0.0a0
# - _TF_VERSION=1.12.0 # Remove on Oct 22, 2019
# - _TF_VERSION=1.11.0 # Remove on Sep 28, 2019
# - _TF_VERSION=1.10.1 # Remove on Aug 24, 2019
# - _TF_VERSION=1.9.0 # Remove on Jul 10, 2019
# - _TF_VERSION=1.8.0 # Remove on Apr 28, 2019
# - _TF_VERSION=1.7.1 # Remove on May 08, 2019
# - _TF_VERSION=1.7.0 # Remove on Mar 29, 2019
# - _TF_VERSION=1.6.0 # Remove on Mar 01, 2019

global:

Expand Down Expand Up @@ -62,7 +63,7 @@ matrix:
install:
- |
if [[ -v _DOC_AND_YAPF_TEST ]]; then
pip install tensorflow
pip install tensorflow==2.0.0a0
pip install yapf
pip install -e .[doc]
else
Expand Down Expand Up @@ -100,7 +101,8 @@ deploy:
on:
tags: true
python: '3.6'
condition: '$_TF_VERSION = 1.11.0'
condition: '$_TF_VERSION = 2.0.0a0'
# condition: '$_TF_VERSION = 1.11.0'

# Documentation: https://docs.travis-ci.com/user/deployment/releases/
- provider: releases
Expand All @@ -113,4 +115,6 @@ deploy:
on:
tags: true
python: '3.6'
condition: '$_TF_VERSION = 1.11.0'
condition: '$_TF_VERSION = 2.0.0a0'
# condition: '$_TF_VERSION = 1.11.0'

20 changes: 20 additions & 0 deletions CHANGELOG.md
Expand Up @@ -90,6 +90,26 @@ To release a new version, please update the changelog as followed:
### Contributors
@zsdonghao: #931


## [2.0.0-alpha] - 2019-05-04

### Changed
* update for TensorLayer 2.0.0 alpha version (PR #952)
* support TensorFlow 2.0.0-alpha
* support both static and dynamic model building

### Dependencies Update
- tensorflow>=1.6,<1.13 => tensorflow>=2.0.0-alpha (PR #952)
- h5py>=2.9 (PR #952)
- cloudpickle>=0.8.1 (PR #952)
- remove matplotlib

### Contributors
- @zsdonghao
- @JingqingZ
- @ChrisWu1997
- @warshallrho

## [1.11.1] - 2018-11-15

### Changed
Expand Down
156 changes: 149 additions & 7 deletions CONTRIBUTING.md
@@ -1,5 +1,18 @@
# TensorLayer Contributor Guideline

## Welcome to contribute!
You are more than welcome to contribute to TensorLayer! If you have any improvement, please send us your [pull requests](https://help.github.com/en/articles/about-pull-requests). You may implement your improvement on your [fork](https://help.github.com/en/articles/working-with-forks).

## Checklist
* Continuous integration
* Build from sources
* Unittest
* Documentation
* General intro to TensorLayer2
* How to contribute a new `Layer`
* How to contribute a new `Model`
* How to contribute a new example/tutorial

## Continuous integration

We appreciate contributions
Expand All @@ -24,8 +37,8 @@ to apply those tools before submitting your PR.

```bash
# First clone the repository and change the current directory to the newly cloned repository
git clone https://github.com/tensorlayer/tensorlayer.git
cd tensorlayer
git clone https://github.com/zsdonghao/tensorlayer2.git
cd tensorlayer2

# Install virtualenv if necessary
pip install virtualenv
Expand All @@ -43,15 +56,144 @@ venv\Scripts\activate.bat

# ============= IF TENSORFLOW IS NOT ALREADY INSTALLED ============= #

# for a machine **without** an NVIDIA GPU
pip install -e .[all_cpu_dev] --upgrade
# basic installation
pip install .

# advanced: for a machine **without** an NVIDIA GPU
pip install -e ".[all_cpu_dev]"

# for a machine **with** an NVIDIA GPU
pip install -e .[all_gpu_dev] --upgrade
# advanced: for a machine **with** an NVIDIA GPU
pip install -e ".[all_gpu_dev]"
```

Launching the unittest:
## Unittest

Launching the unittest for the whole repo:

```bash
# install pytest
pip install pytest

# run pytest
pytest
```

Running your unittest code on your implemented module only:

```bash
# install coverage
pip install coverage

cd /path/to/your/unittest/code
# For example: cd tests/layers/

# run unittest
coverage run --source myproject.module -m unittest discover
# For example: coverage run --source tensorlayer.layers -m unittest discover

# generate html report
coverage html
```

## Documentation
Even though you follow [numpydoc](https://numpydoc.readthedocs.io/en/latest/) document style when writing your code,
this does not ensure those lines appear on TensorLayer online documentation.
You need further modify corresponding RST files in `docs/modules`.

For example, to add your implemented new pooling layer into documentation, modify `docs/modules/layer.rst`. First, insert layer name under Layer list
```rst
Layer list
----------
.. autosummary::
NewPoolingLayer
```

Second, find pooling layer part and add:
```rst
.. -----------------------------------------------------------
.. Pooling Layers
.. -----------------------------------------------------------
Pooling Layers
------------------------
New Pooling Layer
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: NewPoolingLayer
```

Finally, test with local documentation:
```bash
cd ./docs

make clean
make html
# then view generated local documentation by ./html/index.html
```

## General intro to TensorLayer2
* TensorLayer2 is built on [TensorFlow2](https://www.tensorflow.org/alpha), so TensorLayer2 is purely eager, no sessions, no globals.
* TensorLayer2 supports APIs to build static models and dynamic models. Therefore, all `Layers` should be compatible with the two modes.
```python
# An example of a static model
# A static model has inputs and outputs with fixed shape.
inputs = tl.layers.Input([32, 784])
dense1 = tl.layers.Dense(n_units=800, act=tf.nn.relu, in_channels=784, name='dense1')(inputs)
dense2 = tl.layers.Dense(n_units=10, act=tf.nn.relu, in_channels=800, name='dense2')(dense1)
model = tl.models.Model(inputs=inputs, outputs=dense2)

# An example of a dynamic model
# A dynamic model has more flexibility. The inputs and outputs may be different in different runs.
class CustomizeModel(tl.models.Model):
def __init__(self):
super(CustomizeModel, self).__init__()
self.dense1 = tl.layers.Dense(n_units=800, act=tf.nn.relu, in_channels=784, name='dense1')
self.dense2 = tl.layers.Dense(n_units=10, act=tf.nn.relu, in_channels=800, name='dense2')

# a dynamic model allows more flexibility by customising forwarding.
def forward(self, x, bar=None):
d1 = self.dense1(x)
if bar:
return d1
else:
d2 = self.dense2(d1)
return d1, d2

model = CustomizeModel()
```
* More examples can be found in [examples](examples/) and [tests/layers](tests/layers/). Note that not all of them are completed.

## How to contribute a new `Layer`
* A `NewLayer` should be a derived from the base class [`Layer`](tensorlayer/layers/core.py).
* Member methods to be overrided:
- `__init__(self, args1, args2, inputs_shape=None, name=None)`: The constructor of the `NewLayer`, which should
- Call `super(NewLayer, self).__init__(name)` to construct the base.
- Define member variables based on the args1, args2 (or even more).
- If the `inputs_shape` is provided, call `self.build(inputs_shape)` and set `self._built=True`. Note that sometimes only `in_channels` should be enough to build the layer like [`Dense`](tensorlayer/layers/dense/base_dense.py).
- Logging by `logging.info(...)`.
- `__repr__(self)`: Return a printable representation of the `NewLayer`.
- `build(self, inputs_shape)`: Build the `NewLayer` by defining weights.
- `forward(self, inputs, **kwargs)`: Forward feeding the `NewLayer`. Note that the forward feeding of some `Layers` may be different during training and testing like [`Dropout`](tensorlayer/layers/dropout.py).
* Unittest:
- Unittest should be done before a pull request. Unittest code can be written in [tests/](tests/)
* Documents:
- Please write a description for each class and method in RST format. The description may include the functionality, arguments, references, examples of the `NewLayer`.
* Examples: [`Dense`](tensorlayer/layers/dense/base_dense.py), [`Dropout`](tensorlayer/layers/dropout.py), [`Conv`](tensorlayer/layers/convolution/simplified_conv.py).

## How to contribute a new `Model`
* A `NewModel` should be derived from the base class [`Model`](tensorlayer/models/core.py) (if dynamic) or an instance of [`Model`](tensorlayer/models/core.py) (if static).
* A static `NewModel` should have fixed inputs and outputs. Please check the example [`VGG_Static`](tensorlayer/models/vgg.py)
* A dynamic `NewModel` has more flexiblility. Please check the example [`VGG16`](tensorlayer/models/vgg16.py)

## How to contribute a new example/tutorial
* A new example/tutorial should implement a complete workflow of deep learning which includes (but not limited)
- `Models` construction based on `Layers`.
- Data processing and loading.
- Training and testing.
- Forward feeding by calling the models.
- Loss function.
- Back propagation by `tf.GradientTape()`.
- Model saving and restoring.
* Examples: [MNIST](examples/basic_tutorials/tutorial_mnist_mlp_static.py), [CIFAR10](examples/basic_tutorials/tutorial_cifar10_cnn_static.py), [FastText](examples/text_classification/tutorial_imdb_fasttext.py)
31 changes: 7 additions & 24 deletions Makefile
Expand Up @@ -5,40 +5,23 @@ default:
@echo "\tmake install3 # install tensorlayer in current workspace with pip3"

lint:
pylint example/*.py
pylint examples/*.py
pylint tensorlayer

test:
python3 tests/test_yapf_format.py
# python3 tests/test_pydocstyle.py
python3 tests/test_mnist_simple.py
python3 tests/test_reuse_mlp.py
python3 tests/test_layers_basic.py
python3 tests/test_layers_convolution.py
python3 tests/test_layers_core.py
python3 tests/test_layers_extend.py
python3 tests/test_layers_flow_control.py
python3 tests/test_layers_importer.py
python3 tests/test_layers_merge.py
python3 tests/test_layers_normalization.py
python3 tests/test_layers_pooling.py
python3 tests/test_layers_recurrent.py
python3 tests/test_layers_shape.py
python3 tests/test_layers_spatial_transformer.py
python3 tests/test_layers_special_activation.py
python3 tests/test_layers_stack.py
python3 tests/test_layers_super_resolution.py
python3 tests/test_layers_time_distributed.py
python3 tests/models/test_model_core.py
python3 tests/layers/test_layernode.py
python3 tests/files/test_utils_saveload.py

format:
autoflake -i example/*.py
autoflake -i examples/*.py
autoflake -i tensorlayer/*.py
autoflake -i tensorlayer/**/*.py

isort -rc example
isort -rc examples
isort -rc tensorlayer

yapf -i example/*.py
yapf -i examples/*.py
yapf -i tensorlayer/*.py
yapf -i tensorlayer/**/*.py

Expand Down

0 comments on commit 0894eda

Please sign in to comment.