Skip to content

Commit ffe4277

Browse files
authored
Merge pull request #336 from tensorlayer/fixdoc
remove unused arguments.
2 parents 1788549 + f30a5ee commit ffe4277

File tree

14 files changed

+162
-513
lines changed

14 files changed

+162
-513
lines changed

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TensorLayer is a deep learning and reinforcement learning library on top of [Ten
2424

2525
# News
2626
* [18 Jan] [《深度学习:一起玩转TensorLayer》](http://www.broadview.com.cn/book/5059) (Deep Learning using TensorLayer)
27-
* [17 Dec] Experimentally release APIs for distributed training (by [TensorPort](https://tensorport.com)). See [tiny example](https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_mnist_distributed.py).
27+
* [17 Dec] Release experimental APIs for distributed training (by [TensorPort](https://tensorport.com)). See [tiny example](https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_mnist_distributed.py).
2828
* [17 Nov] Release data augmentation APIs for object detection, see [tl.prepro](http://tensorlayer.readthedocs.io/en/latest/modules/prepro.html#object-detection).
2929
* [17 Nov] Support [Convolutional LSTM](https://arxiv.org/abs/1506.04214), see [ConvLSTMLayer](http://tensorlayer.readthedocs.io/en/latest/modules/layers.html#conv-lstm-layer).
3030
* [17 Nov] Support [Deformable Convolution](https://arxiv.org/abs/1703.06211), see [DeformableConv2dLayer](http://tensorlayer.readthedocs.io/en/latest/modules/layers.html#d-deformable-conv).
@@ -41,13 +41,15 @@ TensorLayer is a deep learning and reinforcement learning library on top of [Ten
4141

4242
# Installation
4343

44-
TensorLayer has package pre-requisites including TensorFlow, numpy, matplotlib and nltk (optional). For GPU support, CUDA and cuDNN are required. Please check [documentation](http://tensorlayer.readthedocs.io/en/latest/user/installation.html) for detailed instructions. The simplest way to install TensorLayer in your python program is:
44+
TensorLayer has pre-requisites including TensorFlow, numpy, matplotlib and nltk (optional). For GPU support, CUDA and cuDNN are required.
45+
The simplest way to install TensorLayer is:
4546

4647
```bash
4748
[for master version] pip install git+https://github.com/zsdonghao/tensorlayer.git (Recommended)
4849
[for stable version] pip install tensorlayer
4950
```
5051

52+
Please check [documentation](http://tensorlayer.readthedocs.io/en/latest/user/installation.html) for detailed instructions.
5153

5254

5355
# Examples and Tutorials
@@ -121,18 +123,21 @@ TensorLayer provides two set of Convolutional layer APIs, see [(Professional)](h
121123
-->
122124

123125

124-
# Library Features
126+
# Features
125127

126-
As deep learning practitioners, we have been looking for a library that can serve for various development phases. This library shall be easy for beginners by providing rich neural network reference implementations. Later, it can be extended to address *real-world problems* by controlling training backends to exhibit low-level cognitive behaviours. In the end, it shall be able to serve in challenging *production environments*. TensorLayer is developed with the following goals:
128+
## Design Philosophy
127129

128-
- *Simplicity* : TensorLayer lifts the low-level dataflow abstraction of TensorFlow to **high-level** deep learning modules.
129-
A user often find it easy to bootstrap with TensorLayer, and then dive into low-level implementation only if need.
130+
As deep learning practitioners, we have been looking for a library that can serve for various development phases. This library is easy for beginners by offering rich neural network
131+
examples and tutorials. Later, its APIs can be extended to address *real-world problems* by allowing users to carefully manipulating TensorFlow. In the end, it is able to serve in challenging *production environments*. TensorLayer is a novel library that aims to satisfy development requirements throughout these phases. It has three key features:
132+
133+
- *Simplicity* : TensorLayer lifts the low-level dataflow abstraction of TensorFlow to **high-level** deep learning modules. It also
134+
provides users with massive examples and tutorials to help bootstrap.
130135
- *Transparency* : TensorLayer provides access to the **native APIs** of TensorFlow. This helps users achieve flexible controls within the training engine.
131-
- *Performance* : TensorLayer provides **zero-cost** abstraction (see Benchmark below). It can run on distributed and heterogeneous TensorFlow platforms with full power.
136+
- *Performance* : TensorLayer provides **zero-cost** abstraction. It can run on distributed and heterogeneous TensorFlow platforms with full power.
132137

133-
## Low Runtime Overhead
138+
## Negligible Overhead
134139

135-
TensorLayer has negligible overhead. We show this by benchmarking classic deep learning
140+
TensorLayer has negligible performance overhead. We benchmark classic deep learning
136141
models using TensorLayer and native TensorFlow implementations
137142
on a Titan X Pascal GPU. Here are the training speeds of respective tasks:
138143

@@ -141,14 +146,18 @@ on a Titan X Pascal GPU. Here are the training speeds of respective tasks:
141146
| TensorLayer | 2528 images/s | 18063 words/s | 58167 words/s |
142147
| TensorFlow | 2530 images/s | 18075 words/s | 58181 words/s |
143148

144-
## Comparing TensorLayer with Keras and TFLearn
149+
## Compared with Keras and TFLearn
145150

146-
A frequent question regarding TensorLayer is what is the different with other libraries like Keras and Tflearn.
147-
These libraries are comfortable to start with. They provide imperative abstractions to lower adoption barrier;
148-
but in turn mask the underlying engine from users. Though good for bootstrap,
149-
it becomes hard to leverage the advanced features of TensorFlow, which is quite necessary in tackling real-world problems.
151+
Similar to TensorLayer, Keras and TFLearn are also popular TensorFlow wrapper libraries.
152+
These libraries are comfortable to start with. They provide high-level abstractions;
153+
but in turn mask the underlying engine features from users. Though good for bootstrap,
154+
it becomes hard to manipulate the low-level powerful features of TensorFlow, which we find quite necessary
155+
in tackling many real-world problems.
150156
Without compromise in simplicity, TensorLayer APIs are generally more flexible and transparent.
151-
Users often find it easy to start with the examples and tutorials of TensorLayer, then dive into the TensorFlow low-level APIs only if need through the transparent API design.
157+
Users often find it easy to start with the examples and tutorials of TensorLayer, and
158+
then dive into the TensorFlow low-level APIs only if need through the transparent API design.
159+
TensorLayer does not intend to create library lock-in. Users can easily import models from Keras, TFSlim and TFLearn into
160+
a TensorLayer environment.
152161

153162

154163
# Documentation
@@ -229,7 +238,7 @@ We provide many helper functions (like `fit()` , `test()`) that is similar to Ke
229238

230239
# Academic and Industry Users
231240

232-
TensorLayer is in an active development stage and has received numerous contributions from an open community.
241+
TensorLayer is in an active development stage and has an open community.
233242
It has been widely used by researchers from Imperial College London, Carnegie Mellon University, Stanford University,
234243
Tsinghua University, UCLA, Linköping University and etc.,
235244
as well as engineers from Google, Microsoft, Alibaba, Tencent, Penguins Innovate, ReFULE4, Bloomberg, GoodAILab and many others.

docs/modules/visualize.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ to visualize the model, activations etc. Here we provide more functions for data
1717
frame
1818
images2d
1919
tsne_embedding
20-
20+
draw_weights
2121

2222
Save and read images
2323
----------------------
@@ -65,3 +65,7 @@ Images by matplotlib
6565
Visualize embeddings
6666
--------------------
6767
.. autofunction:: tsne_embedding
68+
69+
Visualize weights
70+
--------------------
71+
.. autofunction:: draw_weights

example/tutorial_mnist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def main_test_layers(model='relu'):
144144
print(" val acc: %f" % (val_acc / n_batch))
145145
try:
146146
# You can visualize the weight of 1st hidden layer as follow.
147-
tl.vis.W(network.all_params[0].eval(), second=10, saveable=True, shape=[28, 28], name='w1_' + str(epoch + 1), fig_idx=2012)
147+
tl.vis.draw_weights(network.all_params[0].eval(), second=10, saveable=True, shape=[28, 28], name='w1_' + str(epoch + 1), fig_idx=2012)
148148
# You can also save the weight of 1st hidden layer to .npz file.
149149
# tl.files.save_npz([network.all_params[0]] , name='w1'+str(epoch+1)+'.npz')
150150
except:
@@ -370,7 +370,7 @@ def main_test_stacked_denoise_AE(model='relu'):
370370
print(" val acc: %f" % (val_acc / n_batch))
371371
try:
372372
# visualize the 1st hidden layer during fine-tune
373-
tl.vis.W(network.all_params[0].eval(), second=10, saveable=True, shape=[28, 28], name='w1_' + str(epoch + 1), fig_idx=2012)
373+
tl.vis.draw_weights(network.all_params[0].eval(), second=10, saveable=True, shape=[28, 28], name='w1_' + str(epoch + 1), fig_idx=2012)
374374
except:
375375
print("You should change vis.W(), if you want to save the feature images for different dataset")
376376

tensorlayer/cost.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def li_regularizer(scale, scope=None):
513513
logging.info('Scale of 0 disables regularizer.')
514514
return lambda _, name=None: None
515515

516-
def li(weights, name=None):
516+
def li(weights):
517517
"""Applies li regularization to weights."""
518518
with tf.name_scope('li_regularizer') as scope:
519519
my_scale = ops.convert_to_tensor(scale, dtype=weights.dtype.base_dtype, name='scale')
@@ -526,7 +526,7 @@ def li(weights, name=None):
526526
return li
527527

528528

529-
def lo_regularizer(scale, scope=None):
529+
def lo_regularizer(scale):
530530
"""Lo regularization removes the neurons of current layer. The `o` represents `outputs`
531531
Returns a function that can be used to apply group lo regularization to weights.
532532
The implementation follows `TensorFlow contrib <https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/layers/python/layers/regularizers.py>`__.
@@ -535,8 +535,6 @@ def lo_regularizer(scale, scope=None):
535535
----------
536536
scale : float
537537
A scalar multiplier `Tensor`. 0.0 disables the regularizer.
538-
scope: str
539-
An optional scope name for this function.
540538
541539
Returns
542540
-------
@@ -576,7 +574,7 @@ def lo(weights, name='lo_regularizer'):
576574
return lo
577575

578576

579-
def maxnorm_regularizer(scale=1.0, scope=None):
577+
def maxnorm_regularizer(scale=1.0):
580578
"""Max-norm regularization returns a function that can be used to apply max-norm regularization to weights.
581579
582580
More about max-norm, see `wiki-max norm <https://en.wikipedia.org/wiki/Matrix_norm#Max_norm>`_.
@@ -586,8 +584,6 @@ def maxnorm_regularizer(scale=1.0, scope=None):
586584
----------
587585
scale : float
588586
A scalar multiplier `Tensor`. 0.0 disables the regularizer.
589-
scope: str
590-
An optional scope name for this function.
591587
592588
Returns
593589
---------
@@ -627,7 +623,7 @@ def mn(weights, name='max_regularizer'):
627623
return mn
628624

629625

630-
def maxnorm_o_regularizer(scale, scope):
626+
def maxnorm_o_regularizer(scale):
631627
"""Max-norm output regularization removes the neurons of current layer.
632628
Returns a function that can be used to apply max-norm regularization to each column of weight matrix.
633629
The implementation follows `TensorFlow contrib <https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/layers/python/layers/regularizers.py>`__.
@@ -636,8 +632,6 @@ def maxnorm_o_regularizer(scale, scope):
636632
----------
637633
scale : float
638634
A scalar multiplier `Tensor`. 0.0 disables the regularizer.
639-
scope: str
640-
An optional scope name for this function.
641635
642636
Returns
643637
---------
@@ -677,7 +671,7 @@ def mn_o(weights, name='maxnorm_o_regularizer'):
677671
return mn_o
678672

679673

680-
def maxnorm_i_regularizer(scale, scope=None):
674+
def maxnorm_i_regularizer(scale):
681675
"""Max-norm input regularization removes the neurons of previous layer.
682676
Returns a function that can be used to apply max-norm regularization to each row of weight matrix.
683677
The implementation follows `TensorFlow contrib <https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/layers/python/layers/regularizers.py>`__.
@@ -686,8 +680,6 @@ def maxnorm_i_regularizer(scale, scope=None):
686680
----------
687681
scale : float
688682
A scalar multiplier `Tensor`. 0.0 disables the regularizer.
689-
scope: str
690-
An optional scope name for this function.
691683
692684
Returns
693685
---------
@@ -725,6 +717,3 @@ def mn_i(weights, name='maxnorm_i_regularizer'):
725717
return standard_ops_fn(my_scale, standard_ops.reduce_sum(standard_ops.reduce_max(standard_ops.abs(weights), 1)), name=scope)
726718

727719
return mn_i
728-
729-
730-
#

tensorlayer/db.py

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -418,119 +418,3 @@ def __str__(self):
418418
_s = "[TensorDB] Info:\n"
419419
_t = _s + " " + str(self.db)
420420
return _t
421-
422-
# def save_bulk_data(self, data=None, filename='filename'):
423-
# """ Put bulk data into TensorDB.datafs, return file ID.
424-
# When you have a very large data, you may like to save it into GridFS Buckets
425-
# instead of Collections, then when you want to load it, XXXX
426-
#
427-
# Parameters
428-
# -----------
429-
# data : serialized data.
430-
# filename : string, GridFS Buckets.
431-
#
432-
# References
433-
# -----------
434-
# - MongoDB find, xxxxx
435-
# """
436-
# s = time.time()
437-
# f_id = self.datafs.put(data, filename=filename)
438-
# print("[TensorDB] save_bulk_data: {} took: {}s".format(filename, round(time.time()-s, 2)))
439-
# return f_id
440-
#
441-
# def save_collection(self, data=None, collect_name='collect_name'):
442-
# """ Insert data into MongoDB Collections, return xx.
443-
#
444-
# Parameters
445-
# -----------
446-
# data : serialized data.
447-
# collect_name : string, MongoDB collection name.
448-
#
449-
# References
450-
# -----------
451-
# - MongoDB find, xxxxx
452-
# """
453-
# s = time.time()
454-
# rl = self.db[collect_name].insert_many(data)
455-
# print("[TensorDB] save_collection: {} took: {}s".format(collect_name, round(time.time()-s, 2)))
456-
# return rl
457-
#
458-
# def find(self, args={}, collect_name='collect_name'):
459-
# """ Find data from MongoDB Collections.
460-
#
461-
# Parameters
462-
# -----------
463-
# args : dictionary, arguments for finding.
464-
# collect_name : string, MongoDB collection name.
465-
#
466-
# References
467-
# -----------
468-
# - MongoDB find, xxxxx
469-
# """
470-
# s = time.time()
471-
#
472-
# pc = self.db[collect_name].find(args) # pymongo.cursor.Cursor object
473-
# flist = pc.distinct('f_id')
474-
# fldict = {}
475-
# for f in flist: # you may have multiple Buckets files
476-
# # fldict[f] = pickle.loads(self.datafs.get(f).read())
477-
# # s2 = time.time()
478-
# tmp = self.datafs.get(f).read()
479-
# # print(time.time()-s2)
480-
# fldict[f] = pickle.loads(tmp)
481-
# # print(time.time()-s2)
482-
# # exit()
483-
# # print(round(time.time()-s, 2))
484-
# data = [fldict[x['f_id']][x['id']] for x in pc]
485-
# data = np.asarray(data)
486-
# print("[TensorDB] find: {} get: {} took: {}s".format(collect_name, pc.count(), round(time.time()-s, 2)))
487-
# return data
488-
489-
490-
class DBLogger:
491-
""" """
492-
493-
def __init__(self, db, model):
494-
self.db = db
495-
self.model = model
496-
497-
def on_train_begin(self, logs={}):
498-
print("start")
499-
500-
def on_train_end(self, logs={}):
501-
print("end")
502-
503-
def on_epoch_begin(self, epoch, logs={}):
504-
self.epoch = epoch
505-
self.et = time.time()
506-
return
507-
508-
def on_epoch_end(self, epoch, logs={}):
509-
self.et = time.time() - self.et
510-
print("ending")
511-
print(epoch)
512-
logs['epoch'] = epoch
513-
logs['time'] = datetime.utcnow()
514-
logs['stepTime'] = self.et
515-
logs['acc'] = np.asscalar(logs['acc'])
516-
print(logs)
517-
518-
w = self.model.Params
519-
fid = self.db.save_params(w, logs)
520-
logs.update({'params': fid})
521-
self.db.valid_log(logs)
522-
523-
def on_batch_begin(self, batch, logs={}):
524-
self.t = time.time()
525-
self.losses = []
526-
self.batch = batch
527-
528-
def on_batch_end(self, batch, logs={}):
529-
self.t2 = time.time() - self.t
530-
logs['acc'] = np.asscalar(logs['acc'])
531-
#logs['loss']=np.asscalar(logs['loss'])
532-
logs['step_time'] = self.t2
533-
logs['time'] = datetime.utcnow()
534-
logs['epoch'] = self.epoch
535-
logs['batch'] = self.batch
536-
self.db.train_log(logs)

tensorlayer/files.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def load_mnist_labels(path, filename):
117117
return X_train, y_train, X_val, y_val, X_test, y_test
118118

119119

120-
def load_cifar10_dataset(shape=(-1, 32, 32, 3), path='data', plotable=False, second=3):
120+
def load_cifar10_dataset(shape=(-1, 32, 32, 3), path='data', plotable=False):
121121
"""Load CIFAR-10 dataset.
122122
123123
It consists of 60000 32x32 colour images in 10 classes, with
@@ -137,8 +137,6 @@ def load_cifar10_dataset(shape=(-1, 32, 32, 3), path='data', plotable=False, sec
137137
The path that the data is downloaded to, defaults is ``data/cifar10/``.
138138
plotable : boolean
139139
Whether to plot some image examples, False as default.
140-
second : int
141-
If ``plotable`` is True, it is the display time.
142140
143141
Examples
144142
--------
@@ -1791,4 +1789,4 @@ def npz_to_W_pdf(path=None, regx='w1pre_[0-9]+\.(npz)'):
17911789
for f in file_list:
17921790
W = load_npz(path, f)[0]
17931791
logging.info("%s --> %s" % (f, f.split('.')[0] + '.pdf'))
1794-
visualize.W(W, second=10, saveable=True, name=f.split('.')[0], fig_idx=2012)
1792+
visualize.draw_weights(W, second=10, saveable=True, name=f.split('.')[0], fig_idx=2012)

0 commit comments

Comments
 (0)