pyNetBuilder is a modular pytonic interface with builtin modules for generating popular caffe networks.
A neural network is a Directed acyclic graph (DAG) of layers. The caffe layers and the network is represented using prototxt format. As we go deeper, and add more layers or build more complex DAG's using basic layers, writing the prototxt files becomes tedious. This tool aims to provide a pytonic interface to generate prototxt files.
pyNetBuilder builds on top of caffe's NetSpec class to stich together a network. NetSpec "provides a way to write nets directly in Python, using a natural, functional style." Here is a basic example of writing nets in caffe. pyNetBuilder is to provide generic wrappers to attach blocks of layers to NetSpec in form of Legos.
A lego is a basic neural network building block. It has:
BaseLegoFunction: This is a classes which can attach all the core caffe layers using functional style. The default parameters for layers can be added / updated in the default.config file. For example you can attach a convolutional layer to a netspec object as follows:
from lego.base import BaseLegoFunction
conv_params = dict(name='conv1', num_output=64, kernel_size=7,
use_global_stats='True', pad=3, stride=2)
conv = BaseLegoFunction('Convolution',params).attach(netspec, [netspec.data])
Hybrid - These are combinations of core legos. Example - ShortcutLego (resnets), FireLego (squeezenet), InceptionLego (google). Example - you can attach a ShortcutLego (residual networks) to a netspec object as follows:
from lego.hybrid import ShortcutLego
params = dict(name='resnet_block', num_output=256,
shortcut='identity', main_branch='bottleneck',
stride=1, use_global_stats=false,)
block = ShortcutLego(params).attach(netspec, [last_layer])
To generate a network, you can pass a network specification through a series of legos and the modules will get attached to the Netspec object.
The apps folder is a collection of python scripts which uses the pynetbuilder modules to create standard caffe network prototxt files from popluar papers. Currently apps for following networks are provided (other contributions are welcome):
Contributions to pynetbuilder are welcome.
BaseLego
class and write your hybrid lego inside the hybrid module. If your hybrid legos are more generic (example ssd-for object detection) you can create another module inside pynetbuilder.legos.yourlegos
and add the hybrid lego's inside the module.Code licensed under the [BSD 2 clause license] (https://github.com/BVLC/caffe/blob/master/LICENSE). See LICENSE file for terms.
pynetbuilder was written by Jay Mahadeokar from the Yahoo Vision and ML team. Special thanks to Jack Culpepper, Huy Nguyen, Pierre Garrigues, Sachin Farfade, Clayton Mellina and other members of the team for inputs and review.