Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghang1989 committed Nov 17, 2017
1 parent 80a12ef commit d539ddf
Show file tree
Hide file tree
Showing 56 changed files with 2,646 additions and 1,171 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
*.DS_Store
*.swp
*.pyc
version.py
build/
data/
docs/src/
docs/html/
encoding/_ext/
encoding.egg-info/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Hang Zhang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# PyTorch-Encoding-Layer
# PyTorch-Encoding

## [Documentation](http://hangzh.com/PyTorch-Encoding/)

- Please visit the [**Docs**](http://hangzh.com/PyTorch-Encoding/) for detail instructions of installation and usage.

- [**Link**](http://hangzh.com/PyTorch-Encoding/experiments/texture.html) to the Deep TEN texture classification experiments and pre-trained models.

## Citation

**Deep TEN: Texture Encoding Network** [[arXiv]](https://arxiv.org/pdf/1612.02844.pdf)
[Hang Zhang](http://hangzh.com/), [Jia Xue](http://jiaxueweb.com/), [Kristin Dana](http://eceweb1.rutgers.edu/vision/dana.html)
Expand All @@ -11,9 +19,3 @@ month = {July},
year = {2017}
}
```

## [Documentation](http://hangzh.com/PyTorch-Encoding/)

- Please visit the [**Docs**](http://hangzh.com/PyTorch-Encoding/) for detail instructions of installation and usage.

- [**Link**](http://hangzh.com/PyTorch-Encoding/experiments/texture.html) to the experiments and pre-trained models.
30 changes: 17 additions & 13 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
from torch.utils.ffi import create_extension

lib_path = os.path.join(os.path.dirname(torch.__file__), 'lib')
this_file = os.path.dirname(os.path.realpath(__file__))
cwd = os.path.dirname(os.path.realpath(__file__))

# build kernel library
# clean the build files
clean_cmd = ['bash', 'clean.sh']
subprocess.check_call(clean_cmd)

# build CUDA library
os.environ['TORCH_BUILD_DIR'] = lib_path
if platform.system() == 'Darwin':
os.environ['TH_LIBRARIES'] = os.path.join(lib_path,'libTH.1.dylib')
Expand All @@ -28,21 +32,21 @@
os.environ['THC_LIBRARIES'] = os.path.join(lib_path,'libTHC.so.1')
ENCODING_LIB = os.path.join(lib_path, 'libENCODING.so')

clean_cmd = ['bash', 'clean.sh']
subprocess.check_call(clean_cmd)

build_all_cmd = ['bash', 'encoding/make.sh']
subprocess.check_call(build_all_cmd, env=dict(os.environ))

# build FFI
sources = ['encoding/src/encoding_lib.cpp']
headers = ['encoding/src/encoding_lib.h']
headers = [
'encoding/src/encoding_lib.h',
]
defines = [('WITH_CUDA', None)]
with_cuda = True

include_path = [os.path.join(lib_path, 'include'),
os.path.join(os.environ['HOME'],'pytorch/torch/lib/THC'),
os.path.join(lib_path,'include/ENCODING'),
os.path.join(this_file,'encoding/src/')]
os.path.join(cwd,'encoding/kernel/include'),
os.path.join(cwd,'encoding/src/')]

def make_relative_rpath(path):
if platform.system() == 'Darwin':
Expand All @@ -58,11 +62,11 @@ def make_relative_rpath(path):
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
include_dirs = include_path,
extra_link_args = [
make_relative_rpath(lib_path),
ENCODING_LIB,
],
include_dirs = include_path,
extra_link_args = [
make_relative_rpath(lib_path),
ENCODING_LIB,
],
)

if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions docs/source/_static/img/cvpr17.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/img/figure1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/img/myimage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/img/upconv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/source/dilated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Dilated Networks

We provide correct dilated pre-trained ResNet and DenseNet for semantic segmentation.
For dilation of ResNet, we replace the stride of 2 Conv3x3 at begining of certain stage and update the dilation of the conv layers afterwards.
For dilation of DenseNet, we provide DilatedAvgPool2d that handles the dilation of the transition layers, then update the dilation of the conv layers afterwards.
For dilation of DenseNet, we provide :class:`encoding.nn.DilatedAvgPool2d` that handles the dilation of the transition layers, then update the dilation of the conv layers afterwards.
All provided models have been verified.


Expand Down
27 changes: 6 additions & 21 deletions docs/source/encoding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
My NN Layers
============


Modules
-------

Expand All @@ -21,22 +22,16 @@ Modules
.. autoclass:: Inspiration
:members:

:hidden:`DilatedAvgPool2d`
:hidden:`UpsampleConv2d`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: DilatedAvgPool2d
:members:

:hidden:`GramMatrix`
~~~~~~~~~~~~~~~~~~~~

.. autoclass:: GramMatrix
.. autoclass:: UpsampleConv2d
:members:

:hidden:`Aggregate`
~~~~~~~~~~~~~~~~~~~
:hidden:`DilatedAvgPool2d`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: Aggregate
.. autoclass:: DilatedAvgPool2d
:members:

Functions
Expand All @@ -54,13 +49,3 @@ Functions

.. autofunction:: scaledL2

:hidden:`residual`
~~~~~~~~~~~~~~~~~~~

.. autofunction:: residual


:hidden:`assign`
~~~~~~~~~~~~~~~~~~~

.. autofunction:: assign
38 changes: 19 additions & 19 deletions docs/source/experiments/style.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MSG-Net Style Transfer Example
==============================

.. image:: https://raw.githubusercontent.com/zhanghang1989/MSG-Net/master/images/figure1.jpg
.. image:: ../_static/img/figure1.jpg
:width: 55%
:align: left

Expand Down Expand Up @@ -47,7 +47,7 @@ Stylize Images Using Pre-trained Model

python camera_demo.py demo --model models/9styles.model

.. image:: https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/myimage.gif
.. image:: ../_static/img/myimage.gif

- Test the model::

Expand All @@ -66,14 +66,14 @@ Stylize Images Using Pre-trained Model

.. raw:: html

<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/1.jpg" width="260px" /> <img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/2.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/3.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/4.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/5.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/6.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/7.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/8.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/9.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/1.jpg" width="220px" /> <img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/2.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/3.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/4.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/5.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/6.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/7.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/8.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/9.jpg" width="220px" />

Train Your Own MSG-Net Model
----------------------------
Expand All @@ -96,7 +96,7 @@ Train Your Own MSG-Net Model


Neural Style
-------------
------------
`Image Style Transfer Using Convolutional Neural Networks <http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Gatys_Image_Style_Transfer_CVPR_2016_paper.pdf>`_ by Leon A. Gatys, Alexander S. Ecker, and Matthias Bethge::

python main.py optim --content-image images/content/venice-boat.jpg --style-image images/9styles/candy.jpg
Expand All @@ -110,12 +110,12 @@ Neural Style

.. raw:: html

<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g1.jpg" width="260px" /> <img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g2.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g3.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g4.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g5.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g6.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g7.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g8.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g9.jpg" width="260px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g1.jpg" width="220px" /> <img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g2.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g3.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g4.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g5.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g6.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g7.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g8.jpg" width="220px" />
<img src ="https://raw.githubusercontent.com/zhanghang1989/PyTorch-Style-Transfer/master/images/g9.jpg" width="220px" />

4 changes: 2 additions & 2 deletions docs/source/experiments/texture.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Deep TEN: Deep Texture Encoding Network Example
===============================================

.. image:: http://hangzh.com/figure/cvpr17.svg
.. image:: ../_static/img/cvpr17.svg
:width: 100%
:align: left

Expand Down Expand Up @@ -39,7 +39,7 @@ Test Pre-trained Model
Train Your Own Model
--------------------

- Example training command::
- Example training command for training above model::

python main.py --dataset minc --model encodingnet --batch-size 64 --lr 0.01 --epochs 60

Expand Down
41 changes: 41 additions & 0 deletions docs/source/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,44 @@ Other Functions

.. autofunction:: dilatedavgpool2d

:hidden:`upsample`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: upsample


:hidden:`dropout`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: dropout


:hidden:`relu`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: relu


:hidden:`view_each`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: view_each


:hidden:`multi_each`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: multi_each


:hidden:`sum_each`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: sum_each


:hidden:`cat_each`
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: cat_each

5 changes: 4 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Encoding Documentation

Created by `Hang Zhang <http://hangzh.com/>`_

PyTorch-Encoding is an optimized PyTorch package with CUDA backend, including Encoding Layer, Multi-GPU Synchronized Batch Normalization and useful util functions. Example systems are also provided in `experiments section <experiments/texture.html>`_. We hope this software will accelerate your research, please cite our `papers <notes/compile.html>`_.
- An optimized PyTorch package with CUDA backend, including Encoding Layer :class:`encoding.nn.Encoding`, Multi-GPU Synchronized Batch Normalization :class:`encoding.nn.BatchNorm2d` and other customized modules and functions.

- **Example Systems** for Semantic Segmentation (coming), CIFAR-10 Classification, `Texture Recognition <experiments/texture.html>`_ and `Style Transfer <experiments/style.html>`_ are provided in experiments section.


.. toctree::
:glob:
Expand Down
6 changes: 6 additions & 0 deletions docs/source/nn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Other NN Layers
Customized Layers
-----------------

:hidden:`GramMatrix`
~~~~~~~~~~~~~~~~~~~~

.. autoclass:: GramMatrix
:members:

:hidden:`Normalize`
~~~~~~~~~~~~~~~~~~~

Expand Down
30 changes: 17 additions & 13 deletions docs/source/notes/compile.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
Install PyTorch-Encoding
========================
Installing PyTorch-Encoding
===========================

- Install PyTorch from Source to the ``$HOME`` directory:
* Please follow the `PyTorch instructions <https://github.com/pytorch/pytorch#from-source>`_ (recommended).
* Or you can simply clone a copy to ``$HOME`` directory::

Install from Source
-------------------

* Please follow the `PyTorch instructions <https://github.com/pytorch/pytorch#from-source>`_ to install PyTorch from Source to the ``$HOME`` directory (recommended). Or you can simply clone a copy to ``$HOME`` directory::

git clone https://github.com/pytorch/pytorch $HOME/pytorch

- Install this package:
* Clone the repo::
* Install this package

- Clone the repo::

git clone https://github.com/zhanghang1989/PyTorch-Encoding && cd PyTorch-Encoding-Layer
git clone https://github.com/zhanghang1989/PyTorch-Encoding && cd PyTorch-Encoding

* On Linux::
- On Linux::

python setup.py install
python setup.py install

* On Mac OSX::
- On Mac OSX::

MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install

- Reference:
Reference
---------

.. note::
If using the code in your research, please cite our paper.
Expand Down
Loading

0 comments on commit d539ddf

Please sign in to comment.