Skip to content

Commit 0894eda

Browse files
authored
Merge pull request #952 from zsdonghao/master
TensorLayer 2.0.0-alpha Release
2 parents aa9e52e + 2742ca3 commit 0894eda

File tree

303 files changed

+18281
-15458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+18281
-15458
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ update_tl.py
128128

129129
# Data Files and ByteCode files
130130
*.gz
131-
*.npz
131+
*.npz

.travis.yml

+17-13
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,28 @@ addons:
1313
branches:
1414
only:
1515
- master
16-
- TensorLayer-1.x
16+
- TensorLayer-2.x
1717
- /^\d+\.\d+(\.\d+)?(\S*)?$/
1818

1919
python:
2020
- "3.6"
2121
- "3.5"
22-
- "2.7"
22+
# - "2.7" # TensorLayer 2.0 does not support python2 now
2323

2424
env:
2525

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

3839
global:
3940

@@ -62,7 +63,7 @@ matrix:
6263
install:
6364
- |
6465
if [[ -v _DOC_AND_YAPF_TEST ]]; then
65-
pip install tensorflow
66+
pip install tensorflow==2.0.0a0
6667
pip install yapf
6768
pip install -e .[doc]
6869
else
@@ -100,7 +101,8 @@ deploy:
100101
on:
101102
tags: true
102103
python: '3.6'
103-
condition: '$_TF_VERSION = 1.11.0'
104+
condition: '$_TF_VERSION = 2.0.0a0'
105+
# condition: '$_TF_VERSION = 1.11.0'
104106

105107
# Documentation: https://docs.travis-ci.com/user/deployment/releases/
106108
- provider: releases
@@ -113,4 +115,6 @@ deploy:
113115
on:
114116
tags: true
115117
python: '3.6'
116-
condition: '$_TF_VERSION = 1.11.0'
118+
condition: '$_TF_VERSION = 2.0.0a0'
119+
# condition: '$_TF_VERSION = 1.11.0'
120+

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ To release a new version, please update the changelog as followed:
9090
### Contributors
9191
@zsdonghao: #931
9292

93+
94+
## [2.0.0-alpha] - 2019-05-04
95+
96+
### Changed
97+
* update for TensorLayer 2.0.0 alpha version (PR #952)
98+
* support TensorFlow 2.0.0-alpha
99+
* support both static and dynamic model building
100+
101+
### Dependencies Update
102+
- tensorflow>=1.6,<1.13 => tensorflow>=2.0.0-alpha (PR #952)
103+
- h5py>=2.9 (PR #952)
104+
- cloudpickle>=0.8.1 (PR #952)
105+
- remove matplotlib
106+
107+
### Contributors
108+
- @zsdonghao
109+
- @JingqingZ
110+
- @ChrisWu1997
111+
- @warshallrho
112+
93113
## [1.11.1] - 2018-11-15
94114

95115
### Changed

CONTRIBUTING.md

+149-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# TensorLayer Contributor Guideline
22

3+
## Welcome to contribute!
4+
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).
5+
6+
## Checklist
7+
* Continuous integration
8+
* Build from sources
9+
* Unittest
10+
* Documentation
11+
* General intro to TensorLayer2
12+
* How to contribute a new `Layer`
13+
* How to contribute a new `Model`
14+
* How to contribute a new example/tutorial
15+
316
## Continuous integration
417

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

2538
```bash
2639
# First clone the repository and change the current directory to the newly cloned repository
27-
git clone https://github.com/tensorlayer/tensorlayer.git
28-
cd tensorlayer
40+
git clone https://github.com/zsdonghao/tensorlayer2.git
41+
cd tensorlayer2
2942

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

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

46-
# for a machine **without** an NVIDIA GPU
47-
pip install -e .[all_cpu_dev] --upgrade
59+
# basic installation
60+
pip install .
61+
62+
# advanced: for a machine **without** an NVIDIA GPU
63+
pip install -e ".[all_cpu_dev]"
4864

49-
# for a machine **with** an NVIDIA GPU
50-
pip install -e .[all_gpu_dev] --upgrade
65+
# advanced: for a machine **with** an NVIDIA GPU
66+
pip install -e ".[all_gpu_dev]"
5167
```
5268

53-
Launching the unittest:
69+
## Unittest
70+
71+
Launching the unittest for the whole repo:
5472

5573
```bash
74+
# install pytest
75+
pip install pytest
76+
77+
# run pytest
5678
pytest
5779
```
80+
81+
Running your unittest code on your implemented module only:
82+
83+
```bash
84+
# install coverage
85+
pip install coverage
86+
87+
cd /path/to/your/unittest/code
88+
# For example: cd tests/layers/
89+
90+
# run unittest
91+
coverage run --source myproject.module -m unittest discover
92+
# For example: coverage run --source tensorlayer.layers -m unittest discover
93+
94+
# generate html report
95+
coverage html
96+
```
97+
98+
## Documentation
99+
Even though you follow [numpydoc](https://numpydoc.readthedocs.io/en/latest/) document style when writing your code,
100+
this does not ensure those lines appear on TensorLayer online documentation.
101+
You need further modify corresponding RST files in `docs/modules`.
102+
103+
For example, to add your implemented new pooling layer into documentation, modify `docs/modules/layer.rst`. First, insert layer name under Layer list
104+
```rst
105+
Layer list
106+
----------
107+
108+
.. autosummary::
109+
110+
NewPoolingLayer
111+
```
112+
113+
Second, find pooling layer part and add:
114+
```rst
115+
.. -----------------------------------------------------------
116+
.. Pooling Layers
117+
.. -----------------------------------------------------------
118+
119+
Pooling Layers
120+
------------------------
121+
122+
New Pooling Layer
123+
^^^^^^^^^^^^^^^^^^^^^^^^^^
124+
.. autoclass:: NewPoolingLayer
125+
```
126+
127+
Finally, test with local documentation:
128+
```bash
129+
cd ./docs
130+
131+
make clean
132+
make html
133+
# then view generated local documentation by ./html/index.html
134+
```
135+
136+
## General intro to TensorLayer2
137+
* TensorLayer2 is built on [TensorFlow2](https://www.tensorflow.org/alpha), so TensorLayer2 is purely eager, no sessions, no globals.
138+
* TensorLayer2 supports APIs to build static models and dynamic models. Therefore, all `Layers` should be compatible with the two modes.
139+
```python
140+
# An example of a static model
141+
# A static model has inputs and outputs with fixed shape.
142+
inputs = tl.layers.Input([32, 784])
143+
dense1 = tl.layers.Dense(n_units=800, act=tf.nn.relu, in_channels=784, name='dense1')(inputs)
144+
dense2 = tl.layers.Dense(n_units=10, act=tf.nn.relu, in_channels=800, name='dense2')(dense1)
145+
model = tl.models.Model(inputs=inputs, outputs=dense2)
146+
147+
# An example of a dynamic model
148+
# A dynamic model has more flexibility. The inputs and outputs may be different in different runs.
149+
class CustomizeModel(tl.models.Model):
150+
def __init__(self):
151+
super(CustomizeModel, self).__init__()
152+
self.dense1 = tl.layers.Dense(n_units=800, act=tf.nn.relu, in_channels=784, name='dense1')
153+
self.dense2 = tl.layers.Dense(n_units=10, act=tf.nn.relu, in_channels=800, name='dense2')
154+
155+
# a dynamic model allows more flexibility by customising forwarding.
156+
def forward(self, x, bar=None):
157+
d1 = self.dense1(x)
158+
if bar:
159+
return d1
160+
else:
161+
d2 = self.dense2(d1)
162+
return d1, d2
163+
164+
model = CustomizeModel()
165+
```
166+
* More examples can be found in [examples](examples/) and [tests/layers](tests/layers/). Note that not all of them are completed.
167+
168+
## How to contribute a new `Layer`
169+
* A `NewLayer` should be a derived from the base class [`Layer`](tensorlayer/layers/core.py).
170+
* Member methods to be overrided:
171+
- `__init__(self, args1, args2, inputs_shape=None, name=None)`: The constructor of the `NewLayer`, which should
172+
- Call `super(NewLayer, self).__init__(name)` to construct the base.
173+
- Define member variables based on the args1, args2 (or even more).
174+
- 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).
175+
- Logging by `logging.info(...)`.
176+
- `__repr__(self)`: Return a printable representation of the `NewLayer`.
177+
- `build(self, inputs_shape)`: Build the `NewLayer` by defining weights.
178+
- `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).
179+
* Unittest:
180+
- Unittest should be done before a pull request. Unittest code can be written in [tests/](tests/)
181+
* Documents:
182+
- Please write a description for each class and method in RST format. The description may include the functionality, arguments, references, examples of the `NewLayer`.
183+
* Examples: [`Dense`](tensorlayer/layers/dense/base_dense.py), [`Dropout`](tensorlayer/layers/dropout.py), [`Conv`](tensorlayer/layers/convolution/simplified_conv.py).
184+
185+
## How to contribute a new `Model`
186+
* 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).
187+
* A static `NewModel` should have fixed inputs and outputs. Please check the example [`VGG_Static`](tensorlayer/models/vgg.py)
188+
* A dynamic `NewModel` has more flexiblility. Please check the example [`VGG16`](tensorlayer/models/vgg16.py)
189+
190+
## How to contribute a new example/tutorial
191+
* A new example/tutorial should implement a complete workflow of deep learning which includes (but not limited)
192+
- `Models` construction based on `Layers`.
193+
- Data processing and loading.
194+
- Training and testing.
195+
- Forward feeding by calling the models.
196+
- Loss function.
197+
- Back propagation by `tf.GradientTape()`.
198+
- Model saving and restoring.
199+
* 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)

Makefile

+7-24
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,23 @@ default:
55
@echo "\tmake install3 # install tensorlayer in current workspace with pip3"
66

77
lint:
8-
pylint example/*.py
8+
pylint examples/*.py
99
pylint tensorlayer
1010

1111
test:
12-
python3 tests/test_yapf_format.py
13-
# python3 tests/test_pydocstyle.py
14-
python3 tests/test_mnist_simple.py
15-
python3 tests/test_reuse_mlp.py
16-
python3 tests/test_layers_basic.py
17-
python3 tests/test_layers_convolution.py
18-
python3 tests/test_layers_core.py
19-
python3 tests/test_layers_extend.py
20-
python3 tests/test_layers_flow_control.py
21-
python3 tests/test_layers_importer.py
22-
python3 tests/test_layers_merge.py
23-
python3 tests/test_layers_normalization.py
24-
python3 tests/test_layers_pooling.py
25-
python3 tests/test_layers_recurrent.py
26-
python3 tests/test_layers_shape.py
27-
python3 tests/test_layers_spatial_transformer.py
28-
python3 tests/test_layers_special_activation.py
29-
python3 tests/test_layers_stack.py
30-
python3 tests/test_layers_super_resolution.py
31-
python3 tests/test_layers_time_distributed.py
12+
python3 tests/models/test_model_core.py
13+
python3 tests/layers/test_layernode.py
14+
python3 tests/files/test_utils_saveload.py
3215

3316
format:
34-
autoflake -i example/*.py
17+
autoflake -i examples/*.py
3518
autoflake -i tensorlayer/*.py
3619
autoflake -i tensorlayer/**/*.py
3720

38-
isort -rc example
21+
isort -rc examples
3922
isort -rc tensorlayer
4023

41-
yapf -i example/*.py
24+
yapf -i examples/*.py
4225
yapf -i tensorlayer/*.py
4326
yapf -i tensorlayer/**/*.py
4427

0 commit comments

Comments
 (0)