Home

Awesome

Multigrid Neural Architecture

This implements the work from Multigrid Neural Architecture by Tsung-Wei Ke, Michael Maire and Stella Yu.

multigrid_cnn

We propose a multigrid extension of convolutional neural networks (CNNs). Rather than manipulating representations living on a single spatial grid, our network layers operate across scale space, on a pyramid of grids. They consume multigrid inputs and produce multigrid outputs; convolutional filters themselves have both within-scale and cross-scale extent. This aspect is distinct from simple multiscale designs, which only process the input at different scales. Viewed in terms of information flow, a multigrid network passes messages across a spatial pyramid. As a consequence, receptive field size grows exponentially with depth, facilitating rapid integration of context. Most critically, multigrid structure enables networks to learn internal attention and dynamic routing mechanisms, and use them to accomplish tasks on which modern CNNs fail.

We demonstrate the network by running our model on different tasks: 1) Classification on cifar100 & ImageNet, 2) Segmentation on cluttered Mnist data, 3) Spatial Transformation on cluttered Mnist data. The following figure shows the multigrid convolutional and multigrid residual convolutional layer used in our network.

multigrid_cnn

Prerequisites

Please make sure that following libraries are well installed.

Getting Started

> luarocks install nn
> luarocks install cutorch
> luarocks install cunn
> luarocks install cudnn
> luarocks install optim
> luarocks install hdf5
> luarocks install image
> luarocks install nccl

Set up for Environment Path

> export HOME_PREFIX=/path/to/dataset/rootdir

Prepare for dataset

> cd utils/mnist-cluttered
> th download_mnist.lua

// Generating data & labels:
// For segmentation
> th segmentation.lua
// For spatial transformer
> th spatial_transform.lua
// For pure rotation
> th rotation.lua
// For pure affine transformation
> th affine_transform.lua
// For pure translation
> th translation.lua

Make sure that all .t7 files for mnist-cluttered data are put under $HOME_PREFIX/data/mnist-cluttered/.

Training for Cifar100

> sh scripts/cifar/prnmg.sh (or vgg.sh, resnet.sh, nmg.sh, pnmg.sh, rnmg.sh, prnmg.sh)

Options:

Top-1 prediction error over cifar100:

NetworkParams(x10^6)FLOPs(x10^6)Error (%)
MG-68.34116.6332.08
MG-1120.46391.8828.39
MG-1632.58667.1329.91
MG-2144.68942.3830.03
R-MG-1220.56457.2027.84
R-MG-2244.791007.7026.79
R-MG-3269.021558.2025.29
R-MG-4293.262108.7126.32

Training for ImageNet

> sh scripts/ilsvrc/rnmg.sh (or prnmgseg.sh)

options:

Top-1 prediction error over validation set of ImageNet:

NetworkParams(x10^6)FLOPs(x10^9)val, 10-crop (%)val, single-crop (%)
ResNet-5025.64.4622.85-
WRN-34 (2.0)48.614.09-24.50
R-MG-3432.95.7622.4224.51

Segmentation/Spatial-transformation over MNIST-cluttered

> sh scripts/mnist-cluttered/unet.sh (or prnmg.mnist.sh, pnmg.mnist.sh)

Options:

Testing for segmentation/spatial-transformation:

Take segmentation for example, the fullpath of the trained models would be checkpoint/mnist-seg/MODEL_PREFIX/DATE_TIME/model_200.t7.

  1. Add the following line to scripts/mnist-cluttered/mnist-test.sh
-retrain checkpoint/mnist-seg/MODEL_PREFIX/DATE_TIME/model_200.t7
  1. Change the option -dataset mnist-spt to mnist-seg in the script.

  2. Run the script to compute the meanIU and meanAcc of the predictions. Also, the predictions would be saved to checkpoint/mnist-seg/MODEL_PREFIX/DATE_TIME/testOutput_1.h5

> sh scripts/mnist-test.sh

Spatial transformation over cluttered MNIST: spatial_transform

Generating Saliency Map

  1. Add the following line to scripts/mnist-cluttered/mnist-saliency.sh
-trainedNet checkpoint/mnist-spt/MODEL_PREFIX/DATE_TIME/model_200.t7
  1. Run the script

Saliency Map of Unet/MG: saliency_map