Skip to content

Commit df3e2cb

Browse files
author
Jonathan DEKHTIAR
authored
Layer API Refactoring (#675)
* Layer API Refactoring * private method decorator added * Input Layers added * Lazy Import on ROI pooling * @zsdonghao change proposal added * UTF-8 header added * gitignore updated * Python2 error correction * Changelog Updated * Python Headers Uniformized + Codacy Error Fix + LSTMStateTuple missing import
1 parent d184728 commit df3e2cb

Some content is hidden

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

76 files changed

+1183
-1173
lines changed

.gitignore

Lines changed: 117 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,126 @@
1-
*.gz
2-
*.npz
3-
*.pyc
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+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
427
*~
528

6-
.DS_Store
7-
.idea
8-
.spyproject/
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
949
.pytest_cache/
1050

51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
60+
# Flask stuff:
61+
instance/
62+
.webassets-cache
63+
64+
# Scrapy stuff:
65+
.scrapy
66+
67+
# Sphinx documentation
68+
docs/_build/
69+
70+
# PyBuilder
71+
target/
72+
73+
# Jupyter Notebook
74+
.ipynb_checkpoints
75+
76+
# pyenv
77+
.python-version
78+
79+
# celery beat schedule file
80+
celerybeat-schedule
81+
82+
# SageMath parsed files
83+
*.sage.py
84+
85+
# Environments
86+
.env
87+
.venv
88+
env/
1189
venv/
12-
build/
90+
ENV/
91+
env.bak/
92+
venv.bak/
93+
venv_/
94+
venv2/
95+
venv3/
96+
97+
# Spyder project settings
98+
.spyderproject
99+
.spyproject
100+
101+
# Rope project settings
102+
.ropeproject
103+
104+
# mkdocs documentation
105+
/site
106+
107+
# mypy
108+
.mypy_cache/
109+
110+
111+
# IDE Specific directories
112+
.DS_Store
113+
.idea
114+
.vscode/
115+
116+
# TensorLayer Directories
13117
data/
14-
dist/
15-
docs/_build
16-
tensorlayer.egg-info
17-
tensorlayer/__pycache__
118+
lib_win/
18119

120+
# Custom Scripts
19121
update_tl.bat
20122
update_tl.py
21-
.vscode/
123+
124+
# Data Files and ByteCode files
125+
*.gz
126+
*.npz

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ To release a new version, please update the changelog as followed:
7979
- CircleCI added to build and upload Docker Containers for each PR merged and tag release (by @DEKHTIARJonathan in #648)
8080
- Decorator:
8181
- `tl.decorators` API created including `deprecated_alias` and `private_method` (by @DEKHTIARJonathan in #660)
82+
- `tl.decorators` API enriched with `protected_method` (by @DEKHTIARJonathan in #675)
8283
- Docker:
8384
- Containers for each release and for each PR merged on master built (by @DEKHTIARJonathan in #648)
8485
- Containers built in the following configurations (by @DEKHTIARJonathan in #648):
@@ -125,13 +126,18 @@ To release a new version, please update the changelog as followed:
125126
- All the tests are now using a DEBUG level verbosity when run individualy (by @DEKHTIARJonathan in #660)
126127
- `tf.identity` as activation is **ignored**, thus reducing the size of the graph by removing useless operation (by @DEKHTIARJonathan in #667)
127128
- argument dictionaries are now checked and saved within the `Layer` Base Class (by @DEKHTIARJonathan in #667)
129+
- `Layer` Base Class now presenting methods to update faultlessly `all_layers`, `all_params`, and `all_drop` (by @DEKHTIARJonathan in #675)
130+
- Input Layers have been removed from `tl.layers.core` and added to `tl.layers.inputs` (by @DEKHTIARJonathan in #675)
131+
- Input Layers are now considered as true layers in the graph (they represent a placeholder), unittests have been updated (by @DEKHTIARJonathan in #675)
132+
- Layer API is simplified, with automatic feeding `prev_layer` into `self.inputs` (by @DEKHTIARJonathan in #675)
128133

129134
### Deprecated
130135
- `tl.layers.TimeDistributedLayer` argurment `args` is deprecated in favor of `layer_args` (by @DEKHTIARJonathan in #667)
131136

132137
### Removed
133138
- `assert()` calls remove and replaced by `raise AssertionError()` (by @DEKHTIARJonathan in #667)
134139
- `tl.identity` is removed, not used anymore and deprecated for a long time (by @DEKHTIARJonathan in #667)
140+
- All Code specific to `TF.__version__ < "1.6"` have been removed (by @DEKHTIARJonathan in #675)
135141

136142
### Fixed
137143
- Issue #498 - Deprecation Warning Fix in `tl.layers.RNNLayer` with `inspect` (by @DEKHTIARJonathan in #574)
@@ -143,10 +149,10 @@ To release a new version, please update the changelog as followed:
143149
- Deprecation warning fixed in `tl.layers.binary._compute_threshold()` (by @DEKHTIARJonathan in #658)
144150
- All references to `tf.logging` replaced by `tl.logging` (by @DEKHTIARJonathan in #661)
145151
- Duplicated code removed when bias was used (by @DEKHTIARJonathan in #667)
152+
- `tensorlayer.third_party.roi_pooling.roi_pooling.roi_pooling_ops` is now lazy loaded to prevent systematic error raised (by @DEKHTIARJonathan in #675)
146153
- Tutorial:
147154
- `tutorial_word2vec_basic.py` saving issue #476 fixed (by @DEKHTIARJonathan in #635)
148155
- All tutorials tested and errors have been fixed (by @DEKHTIARJonathan in #635)
149-
150156
### Security
151157

152158
### Dependencies Update

tensorlayer/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""Deep learning and Reinforcement learning library for Researchers and Engineers"""
4+
45
from __future__ import absolute_import
56

67
import os

tensorlayer/cli/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
#! /usr/bin/python
2+
# -*- coding: utf-8 -*-
13
"""The tensorlayer.cli module provides a command-line tool for some common tasks."""

tensorlayer/cli/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#! /usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
14
import argparse
25

36
from tensorlayer.cli import train

tensorlayer/cli/train.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/usr/bin/env python
2-
# encoding: utf-8
1+
#! /usr/bin/python
2+
# -*- coding: utf-8 -*-
33
"""
44
tl train
55
========

tensorlayer/cost.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! /usr/bin/python
12
# -*- coding: utf-8 -*-
23

34
import numbers

tensorlayer/decorators/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /usr/bin/python
2+
# -*- coding: utf-8 -*-
13
"""
24
TensorLayer provides rich layer implementations trailed for
35
various benchmarks and domain-specific problems. In addition, we also
@@ -8,6 +10,7 @@
810
"""
911

1012
from .deprecation import deprecated_alias
11-
from .private_method import private_method
13+
from .method_decorator import private_method
14+
from .method_decorator import protected_method
1215

13-
__all__ = ['deprecated_alias', 'private_method']
16+
__all__ = ['deprecated_alias', 'private_method', 'protected_method']
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#! /usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
import inspect
5+
6+
7+
def private_method(func):
8+
"""decorator for making an instance method private"""
9+
10+
def func_wrapper(*args, **kwargs):
11+
"""decorator wrapper function"""
12+
outer_frame = inspect.stack()[1][0]
13+
if 'self' not in outer_frame.f_locals or outer_frame.f_locals['self'] is not args[0]:
14+
raise RuntimeError('%s.%s is a private method' % (args[0].__class__.__name__, func.__name__))
15+
16+
return func(*args, **kwargs)
17+
18+
return func_wrapper
19+
20+
21+
def protected_method(func):
22+
"""decorator for making an instance method private"""
23+
24+
def func_wrapper(*args, **kwargs):
25+
"""decorator wrapper function"""
26+
outer_frame = inspect.stack()[1][0]
27+
28+
caller = inspect.getmro(outer_frame.f_locals['self'].__class__)[:-1]
29+
target = inspect.getmro(args[0].__class__)[:-1]
30+
31+
share_subsclass = False
32+
33+
for cls_ in target:
34+
print("cls_:", cls_)
35+
if issubclass(caller[0], cls_) or caller[0] is cls_:
36+
share_subsclass = True
37+
break
38+
39+
if ('self' not in outer_frame.f_locals or
40+
outer_frame.f_locals['self'] is not args[0]) and (not share_subsclass):
41+
raise RuntimeError('%s.%s is a protected method' % (args[0].__class__.__name__, func.__name__))
42+
43+
return func(*args, **kwargs)
44+
45+
return func_wrapper

tensorlayer/decorators/private_method.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)