Home

Awesome

Guided Attention for FCN

About

Chainer implementation of <a href='https://arxiv.org/abs/1802.10171'>Tell Me Where To Look</a>. This is an experiment to apply Guided Attention Inference Network(GAIN) as presented in the paper to Fully Convolutional Networks(FCN) used for segmentation purposes. The trained FCN8s model is fine tuned using guided attention.

GAIN

GAIN is based on supervising the attention maps that is produced when we train the network for the task of interest.

Image

FCN

Fully Convolutional Networks is a network architecture that consists of convolution layers followed by deconvolutions to give the segmentation output

Image

Approach

Image

Loss Curves

For classification training

Image

Segmentation Loss during GAIN updates

Image

Qualitative Results

| Original Image | PreTrained GCAMs | Post GAIN GCAMs |

Image

Image

Image

Image

Quantitative Results

For FCN8s

ImplementationAccuracyAccuracy ClassMean IUFWAVACCModel File
Original91.221277.614665.512684.5445fcn8s_from_caffe.npz
Experimental90.596280.409964.686983.9952To make public soon

How to use

pip install chainer
pip install chainercv
pip install cupy
pip install fcn

Training

<s> For training the classifier, <a href='https://drive.google.com/uc?id=0B9P1L--7Wd2vWG5MeUEwWmxudU0'>download</a>. the pretrained FCN8s chainer model </s>

python3 train_classifier.py --device 0

This will automatically download the pretrained file and train the classifier on it. You might run into an error of " xxx.txt file not found " while running this script. To solve this, at the place where your fcn library is installed, get the missing file from the <a href='https://github.com/wkentaro/fcn'>fcn</a> repository over github, and take care to put the exisiting file by making the same directory structure as asked in the error message. For more details, refer to this <a href='https://github.com/wkentaro/fcn/issues/111'>issue</a>

For GAIN updates,

python3 train_GAIN.py --modelfile <path to the trained model with trained classifier> --device 0

The accuracy of original implementation is computed with (evaluate.py <path to the trained fcn8 model>) which has been borrowed from wkentaro's <a href='https://github.com/wkentaro/fcn'>implementation</a>

Visualization

visualize.py 

required arguements -

 --pretrained <path to the model file with trained classifier but not trained through GAIN method>
 --trained <path to the model trained with GAIN>

optional arguements -

  --device=-1 <device to assign to model, default uses cpu>
  --whole=False < whether to test on whole valid dataset>
  --shuffle=False <shuffles fataset loader>
  --no=10 <if whole is False, then no of images to visualize>

To Do

Using GAIN for other models

I have attempted to make GAIN as modular as possible so that it can be used on some other model as well. All you would need to do is make GAIN class( which itself inherits chainer.Chain) as parent class to your model. Each GAIN model needs to have a few particular instance variables in order to be able to function. GAIN module has methods to instantiate every single one of them. I would advice you to lookup models/fcn8.py as well as GAIN.py to have an idea about them.

Credits

The original FCN module and the fcn package is courtesy of <a href='https://github.com/wkentaro/fcn'>wkentaro</a>

Citation

If you find this code useful in your research, please consider citing:

@misc{Alok2018,
Author = {Bishoyi, Alok Kumar},
Title = {Guided Attention Inference Network},
Year = {2018},
Publisher = {GitHub},
journal = {Github repository},
howpublished = {\url{https://github.com/alokwhitewolf/Guided-Attention-Inference-Network}},
}