Welcome to Neuralnet-Pytorch’s documentation!¶
Personally, going from Theano to Pytorch is pretty much like time traveling from 90s to the modern day. However, despite a lot of bells and whistles, we still feel there are some missing elements from Pytorch which are confirmed to never be added to the library. Therefore, this library is written to supplement more features to the current magical Pytorch. All the modules in the package directly subclass the corresponding modules from Pytorch, so everything should still be familiar. For example, the following snippet in Pytorch
from torch import nn
model = nn.Sequential(
nn.Conv2d(1, 20, 5, padding=2),
nn.ReLU(),
nn.Conv2d(20, 64, 5, padding=2),
nn.ReLU()
)
can be rewritten in Neuralnet-pytorch as
import neuralnet_pytorch as nnt
model = nnt.Sequential(
nnt.Conv2d(1, 20, 5, padding='half', activation='relu'),
nnt.Conv2d(20, 64, 5, padding='half', activation='relu')
)
which is the same as the native Pytorch, or
import neuralnet_pytorch as nnt
model = nnt.Sequential(input_shape=1)
model.add_module('conv1', nnt.Conv2d(model.output_shape, 20, 5, padding='half', activation='relu'))
model.add_module('conv2', nnt.Conv2d(model.output_shape, 64, 5, padding='half', activation='relu'))
which frees you from doing a lot of manual calculations when adding one layer on top of another. Theano folks will also find some reminiscence as many functions are highly inspired by Theano.
Installation¶
Requirements¶
Pytorch¶
Neuralnet-pytorch is built on top of Pytorch, so obviously Pytorch is needed. Please refer to the official Pytorch website for installation details.
Other dependencies¶
In Neuralnet-pytorch, we use several backends to visualize training, so it is necessary to install some additional packages.
To install all dependencies in a go, simply open a Terminal session and execute
pip install matplotlib visdom tensorboardX
Install Neuralnet-pytorch¶
There are two ways to install Neuralnet-pytorch: via PyPi and Github. At the moment, the package is not available on Conda yet.
From PyPi¶
The easiest and quickest way to get Neuralnet-pytorch is to install the package from Pypi. In a Terminal session, simply type
pip install neuralnet-pytorch
From Github¶
To install the bleeding-edge version, which is highly recommended, run
pip install git+git://github.com/justanhduc/neuralnet-pytorch.git@master
We also provide a version with some fancy Cuda/C++ implementations collected on various sources. To install this version, run
pip install git+git://github.com/justanhduc/neuralnet-pytorch.git@fancy
Uninstall Neuralnet-pytorch¶
Simply use pip to uninstall the package
pip uninstall neuralnet-pytorch
Why would you want to do that anyway?
Upgrade Neuralnet-pytorch¶
Use pip with -U
or --upgrade
option
pip install -U neuralnet-pytorch
However, for maximal experience, please considering using the bleeding-edge version on Github.
Reinstall Neuralnet-pytorch¶
If you want to reinstall Neuralnet-pytorch, please uninstall and then install it again.
When reinstalling the package, we recommend to use --no-cache-dir
option as pip caches
the previously built binaries
pip uninstall neuralnet-pytorch
pip install neuralnet-pytorch --no-cache-dir
Reference Manual¶
To check if you have installed Neuralnet-pytorch correctly, try
>>> import neuralnet_pytorch as nnt
If there is any error, please check your installation again (see Installation).
The basic contents of our package are as follows.
Neuralnet Layers¶
layers
– Basic Layers¶
This section describes all the backbone modules of Neuralnet-pytorch.
Abstract Layers¶
Attributes¶
The following classes equip the plain torch
modules with more bells and whistles.
Also, some features are deeply integrated into Neuralnet-pytorch,
which enables faster and more convenient training and testing of your neural networks.
Extended Pytorch Abstract Layers¶
Quick-and-dirty Layers¶
Monitor Network Training¶
License¶
MIT License
Copyright (c) 2019 Duc Nguyen
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.
Contact¶
I am Nguyen Anh Duc, a PhD candidate in Computer Vision at Yonsei University. This package is written during my little free time when doing PhD. Most but not all the written modules are properly checked. Therefore, buggy performance is inevitable. No replacements or refunds are guaranteed for such situations. If you want to collaborate or contribute, feel free to make a PR/issue on Github or email me at adnguyen@yonsei.ac.kr.