Skip to content

Commit dc6fb7e

Browse files
authored
Docs for dorefa, ternary weight net (#443)
* update docs for model compression * fixed typo
1 parent 4aa66e3 commit dc6fb7e

File tree

8 files changed

+33
-12
lines changed

8 files changed

+33
-12
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ Examples can be found [in this folder](https://github.com/zsdonghao/tensorlayer/
8585
- VGG 19 (ImageNet). Classification task, see [tutorial_vgg19.py](https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_vgg19.py).
8686
- InceptionV3 (ImageNet). Classification task, see [tutorial\_inceptionV3_tfslim.py](https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_inceptionV3_tfslim.py).
8787
- SqueezeNet (ImageNet). Classification task, see [tutorial_squeezenet.py](https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_squeezenet.py)
88-
- BinaryNet (MNIST). Classification task, see [tutorial_binarynet_mnist_cnn.py](https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_binarynet_mnist_cnn.py)
88+
- BinaryNet. Model compression, see [mnist](https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_binarynet_mnist_cnn.py) [cifar10](https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_binarynet_cifar10_tfrecord.py).
89+
- Tenary Weight Network. Model compression, see [mnist](https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_tenaryweight_mnist_cnn.py) [cifar10](https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_tenaryweight_cifar10_tfrecord.py).
90+
- DoReFa-Net. Model compression, see [mnist](https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_dorefanet_mnist_cnn.py) [cifar10](https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_dorefanet_cifar10_tfrecord.py).
8991
- Wide ResNet (CIFAR) by [ritchieng](https://github.com/ritchieng/wideresnet-tensorlayer).
9092
- More CNN implementations of [TF-Slim](https://github.com/tensorflow/models/tree/master/research/slim) can be connected to TensorLayer via SlimNetsLayer.
9193
- [Spatial Transformer Networks](https://arxiv.org/abs/1506.02025) by [zsdonghao](https://github.com/zsdonghao/Spatial-Transformer-Nets).

docs/modules/layers.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ Layer list
334334

335335
BinaryDenseLayer
336336
BinaryConv2d
337+
TenaryDenseLayer
338+
TenaryConv2d
339+
DorefaDenseLayer
340+
DorefaConv2d
337341
SignLayer
338342
ScaleLayer
339343

@@ -834,17 +838,30 @@ Binarized Dense
834838
^^^^^^^^^^^^^^^^^
835839
.. autoclass:: BinaryDenseLayer
836840

837-
838841
Binarized Conv2d
839842
^^^^^^^^^^^^^^^^^^
840843
.. autoclass:: BinaryConv2d
841844

845+
Tenary Dense
846+
^^^^^^^^^^^^^^^^^^
847+
.. autoclass:: TenaryDenseLayer
848+
849+
Tenary Conv2d
850+
^^^^^^^^^^^^^^^^^^
851+
.. autoclass:: TenaryConv2d
852+
853+
Dorefa Dense
854+
^^^^^^^^^^^^^^^^^^
855+
.. autoclass:: DorefaDenseLayer
856+
857+
Dorefa Conv2d
858+
^^^^^^^^^^^^^^^^^^
859+
.. autoclass:: DorefaConv2d
842860

843861
Sign
844862
^^^^^^^^^^^^^^
845863
.. autoclass:: SignLayer
846864

847-
848865
Scale
849866
^^^^^^^^^^^^^^
850867
.. autoclass:: ScaleLayer

docs/user/example.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Computer Vision
2222
- VGG 19 (ImageNet). Classification task, see `tutorial_vgg19.py <https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_vgg19.py>`_.
2323
- InceptionV3 (ImageNet). Classification task, see `tutorial_inceptionV3_tfslim.py <https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_inceptionV3_tfslim.py>`_.
2424
- SqueezeNet (ImageNet). Classification task, see `tutorial_squeezenet.py <https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_squeezenet.py>`_.
25-
- BinaryNet (MNIST). Classification task, see `tutorial_binarynet_mnist_cnn.py <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_binarynet_mnist_cnn.py>`_.
25+
- BinaryNet. Model compression, see `mnist <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_binarynet_mnist_cnn.py>`__ `cifar10 <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_binarynet_cifar10_tfrecord.py>`__.
26+
- Tenary Weight Network. Model compression, see `mnist <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_tenaryweight_mnist_cnn.py>`__ `cifar10 <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_tenaryweight_cifar10_tfrecord.py>`__.
27+
- DoReFa-Net. Model compression, see `mnist <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_dorefanet_mnist_cnn.py>`__ `cifar10 <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_dorefanet_cifar10_tfrecord.py>`__.
2628
- Wide ResNet (CIFAR) by `ritchieng <https://github.com/ritchieng/wideresnet-tensorlayer>`_.
2729
- More CNN implementations of `TF-Slim <https://github.com/tensorflow/models/tree/master/research/slim>`_ can be connected to TensorLayer via SlimNetsLayer.
2830
- `Spatial Transformer Networks <https://arxiv.org/abs/1506.02025>`_ by `zsdonghao <https://github.com/zsdonghao/Spatial-Transformer-Nets>`__.

tensorlayer/layers/binary.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def __init__(
350350

351351
n_in = int(self.inputs.get_shape()[-1])
352352
self.n_units = n_units
353-
logging.info("BinaryDenseLayer %s: %d %s" % (self.name, self.n_units, act.__name__))
353+
logging.info("TenaryDenseLayer %s: %d %s" % (self.name, self.n_units, act.__name__))
354354
with tf.variable_scope(name):
355355
W = tf.get_variable(name='W', shape=(n_in, n_units), initializer=W_init, dtype=LayersConfig.tf_dtype, **W_init_args)
356356
# W = tl.act.sign(W) # dont update ...
@@ -468,7 +468,7 @@ def __init__(
468468
self.inputs = prev_layer.outputs
469469
if act is None:
470470
act = tf.identity
471-
logging.info("BinaryConv2d %s: n_filter:%d filter_size:%s strides:%s pad:%s act:%s" % (self.name, n_filter, str(filter_size), str(strides), padding,
471+
logging.info("TenaryConv2d %s: n_filter:%d filter_size:%s strides:%s pad:%s act:%s" % (self.name, n_filter, str(filter_size), str(strides), padding,
472472
act.__name__))
473473

474474
if len(strides) != 2:
@@ -500,7 +500,7 @@ def __init__(
500500

501501

502502
class DorefaDenseLayer(Layer):
503-
"""The :class:`DorefaDenseLayer` class is a binary fully connected layer, which weights are 'bitW' bits and the output of the previous layer
503+
"""The :class:`DorefaDenseLayer` class is a binary fully connected layer, which weights are 'bitW' bits and the output of the previous layer
504504
are 'bitA' bits while inferencing.
505505
506506
Note that, the bias vector would not be binarized.
@@ -511,7 +511,7 @@ class DorefaDenseLayer(Layer):
511511
Previous layer.
512512
bitW : int
513513
The bits of this layer's parameter
514-
bitA : int
514+
bitA : int
515515
The bits of the output of previous layer
516516
n_units : int
517517
The number of units of this layer.
@@ -561,7 +561,7 @@ def __init__(
561561

562562
n_in = int(self.inputs.get_shape()[-1])
563563
self.n_units = n_units
564-
logging.info("BinaryDenseLayer %s: %d %s" % (self.name, self.n_units, act.__name__))
564+
logging.info("DorefaDenseLayer %s: %d %s" % (self.name, self.n_units, act.__name__))
565565
with tf.variable_scope(name):
566566
W = tf.get_variable(name='W', shape=(n_in, n_units), initializer=W_init, dtype=LayersConfig.tf_dtype, **W_init_args)
567567
# W = tl.act.sign(W) # dont update ...
@@ -588,7 +588,7 @@ def __init__(
588588

589589

590590
class DorefaConv2d(Layer):
591-
"""The :class:`DorefaConv2d` class is a binary fully connected layer, which weights are 'bitW' bits and the output of the previous layer
591+
"""The :class:`DorefaConv2d` class is a binary fully connected layer, which weights are 'bitW' bits and the output of the previous layer
592592
are 'bitA' bits while inferencing.
593593
594594
Note that, the bias vector would not be binarized.
@@ -599,7 +599,7 @@ class DorefaConv2d(Layer):
599599
Previous layer.
600600
bitW : int
601601
The bits of this layer's parameter
602-
bitA : int
602+
bitA : int
603603
The bits of the output of previous layer
604604
n_filter : int
605605
The number of filters.
@@ -684,7 +684,7 @@ def __init__(
684684
self.inputs = prev_layer.outputs
685685
if act is None:
686686
act = tf.identity
687-
logging.info("BinaryConv2d %s: n_filter:%d filter_size:%s strides:%s pad:%s act:%s" % (self.name, n_filter, str(filter_size), str(strides), padding,
687+
logging.info("DorefaConv2d %s: n_filter:%d filter_size:%s strides:%s pad:%s act:%s" % (self.name, n_filter, str(filter_size), str(strides), padding,
688688
act.__name__))
689689

690690
if len(strides) != 2:

0 commit comments

Comments
 (0)