Implementation of Convolutional Feature Masking (CFM)
Implementation of Convolutional Feature Masking (CFM)
Created by Franck FOTSO
CFM, which stands for Convolutional Feature Masking. This project is an attempt to implement the segmentation approach Convolutional Feature Masking for Joint Object and Stuff Segmentation). In the paper, they propose to use the shape information via masking convolutional features. The CNN features are masked out from the convolutional maps and used to train classifiers for recognition. We have setup an end-end framework suitable for data pre-processing, training, test, evalutation and visualization. There are several proposals involved in this project: Selective Search, Multiscale Combinatorial Group (MCG) and Convolutional Oriented Boundaries (COB).
Our main goals are:
We have used the VOC2012 dataset, parsed as SBD (Semantic Boundaries Dataset). In addition, we also used the MCG and COB proposals related.
Required files are available here:
Those datasets were used to train model over CNN nets: AlexNet, ZF & VGG16. We have explored many CNN nets in the way to see how flexible this approach is. Futhermore, we have provided all prototxt required so that you can test this project in a wide range of Nvidia GPU card ( > 2 Gb)
OS: Ubuntu 16.04 64 bit
GPU: Nvidia GTX 950M 4G
Cuda 8.0
CuDNN 3.0.8
Python 2.7.12
OpenCV 3.1.0
To install this project, please follow the steps below:
Download the repository:
$ cd /opt
$ sudo git clone --recursive https://github.com/franckfotso/segm_cfm.git
$ cd segm_cfm
Install all externals repositories required:
$ cd /externals/caffe-segm
Adjust Makefile.config, then
$ sudo mkdir build
$ cd build
$ cmake ..
$ make -j4
$ make install
$ cd ../..
Install selective_search tool. Prequequisites: Boost.NumPy
$ cd /externals/selective_search_py
$ wget http://cs.brown.edu/~pff/segment/segment.zip; unzip segment.zip; rm segment.zip
$ mkdir build
$ cd build
$ cmake..
$ make -j 4
$ cd ../..
Note: if you face any troubles, please have a look here selective_search for python 2.7
Install project’s libs
$ cd libs
$ make
$ cd ..
Install python’s packages required:
for req in $(cat requirements.txt); do pip install $req; done
Get the data and models required:
Download the data and uncompress in ‘/opt/segm_cfm/data’
Download the models and uncompress in ‘/opt/segm_cfm/data/models’
WARNING: Be aware that some commands above are time consuming & high computing.
Parse the groundtruth data (from pascal_voc segmentation format):
$ cd /opt/segm_cfm
$ python tools/parse_segm_data.py --dataset voc_2012 \
--gt_set trainval --in_seg_cls data/voc_2012/SegmentationClass \
--in_seg_inst data/voc_2012/SegmentationObject --num_proc 4 \
--out_seg_dir data/sbd_voc2012/SEGM-RAW
For help use the command: python tools/parse_segm_data.py —help
Parse the groundtruth data (from bsd segmentation format):
$ cd /opt/segm_cfm
$ python tools/parse_gt_data.py --dataset bsd_voc2012 \
--gt_set train --in_seg_cls data/bsd_voc2012/cls \
--in_seg_inst data/bsd_voc2012/inst --num_proc 4 \
--out_seg_dir data/bsd_voc2012/SEGM-RAW
$ python tools/parse_gt_data.py --dataset bsd_voc2012 \
--gt_set val --in_seg_cls data/bsd_voc2012/cls \
--in_seg_inst data/bsd_voc2012/inst --num_proc 4 \
--out_seg_dir data/bsd_voc2012/SEGM-RAW
For help use the command: python tools/parse_gt_data.py —help
Parse the proposals so that they can be easily handled by our project:
$ cd /opt/segm_cfm
$ python tools/parse_pr_data.py --dataset bsd_voc2012 \
--gt_set train --in_pr_dir data/bsd_voc2012/MCG-RAW.init \
--pr_meth mcg --top_k 1000 --num_proc 4 \
--out_pr_dir data/bsd_voc2012/MCG-RAW.parsed
Let's generate also MCG proposals for demo dataset
$ python tools/parse_pr_data.py --dataset demo \
--gt_set test --in_pr_dir data/bsd_voc2012/MCG-RAW.init \
--pr_meth mcg --top_k 1000 --num_proc 4 \
--out_pr_dir data/demo/MCG-RAW.parsed
For help use the command: python tools/parse_pr_data.py —help
(Optional) Generate ‘selective_search’ proposals:
$ cd /opt/segm_cfm
$ python tools/generate_data.py --dataset bsd_voc2012 \
--gt_set train --pr_meth selective_search --num_proc 4 \
--mode accurate --output_im data/bsd_voc2012/SS-IMG \
--data MASK --output_mat data/bsd_voc2012/SS-RAW
$ python tools/generate_data.py --dataset bsd_voc2012 \
--gt_set train --pr_meth selective_search --num_proc 4 \
--mode accurate --output_im data/bsd_voc2012/SS-IMG \
--data MAT --output_mat data/bsd_voc2012/SS-RAW
Let's do the same for the demo dataset
$ python tools/generate_data.py --dataset demo \
--gt_set test --pr_meth selective_search --num_proc 4 \
--mode accurate --output_im data/demo/SS-IMG \
--data MASK --output_mat data/demo/SS-RAW
$ python tools/generate_data.py --dataset demo \
--gt_set test --pr_meth selective_search --num_proc 4 \
--mode accurate --output_im data/demo/SS-IMG \
--data MAT --output_mat data/demo/SS-RAW
For help use the command: python tools/generate_data.py —help
Training: bsd_voc2012, AlexNet, selective_search | MCG
$ cd /opt/segm_cfm
Using selective_search proposals
$ python tools/train_net.py --gpu_id 0 --dataset bsd_voc2012 \
--gt_set train --task CFM --solver models/AlexNet/solver_CFM_T{1|2|3|4}.prototxt \
--weights pretrained/AlexNet/bvlc_alexnet.caffemodel \
--in_gt_dir data/bsd_voc2012/SEGM-RAW \
--in_pr_dir data/bsd_voc2012/SS-RAW.parsed \
--iters 30000 --cache_im_dir cache/bsd_voc2012_train_ss
Using MCG proposals
$ python tools/train_net.py --gpu_id 0 --dataset bsd_voc2012 \
--gt_set train --task CFM --solver models/AlexNet/solver_CFM_T{1|2|3|4}.prototxt \
--weights pretrained/AlexNet/bvlc_alexnet.caffemodel \
--in_gt_dir data/bsd_voc2012/SEGM-RAW \
--in_pr_dir data/bsd_voc2012/MCG-RAW.parsed \
--iters 30000 --cache_im_dir cache/bsd_voc2012_train_mcg
For help use the command: python tools/train_net.py —help
Training: bsd_voc2012, VGG16, selective_search | MCG
$ cd /opt/segm_cfm
Using selective_search proposals
$ python tools/train_net.py --gpu_id 0 --dataset bsd_voc2012 \
--gt_set train --task CFM --solver models/VGG16/solver_CFM_T{1|2|3|4}.prototxt \
--weights pretrained/VGG16/VGG16.v2.caffemodel \
--in_gt_dir data/bsd_voc2012/SEGM-RAW \
--in_pr_dir data/bsd_voc2012/MCG-RAW.parsed \
--iters 30000 --cache_im_dir cache/bsd_voc2012_train_ss
Using MCG proposals
$ python tools/train_net.py --gpu_id 0 --dataset bsd_voc2012 \
--gt_set train --task CFM --solver models/VGG16/solver_CFM_T{1|2|3|4}.prototxt \
--weights pretrained/VGG16/VGG16.v2.caffemodel \
--in_gt_dir data/bsd_voc2012/SEGM-RAW \
--in_pr_dir data/bsd_voc2012/MCG-RAW.parsed \
--iters 30000 --cache_im_dir cache/bsd_voc2012_train_mcg
For help use the command: python tools/train_net.py —help
Testing: demo, T4, AlexNet, selective_search | MCG
$ cd /opt/segm_cfm
Using selective_search proposals
$ python tools/demo.py --gpu_id 0 --net AlexNet \
--gt_set test --task CFM --dataset demo \
--proto models/AlexNet/AlexNet_CFM_T4_test.prototxt \
--weights outputs/bsd_voc2012/train_mcg/AlexNet_segm_cfm_T4_iter_30000.caffemodel \
--in_pr_dir data/demo/SS-RAW.parsed --kwargs 'cfm_t:T4'
Using MCG proposals
$ python tools/demo.py --gpu_id 0 --net AlexNet \
--gt_set test --task CFM --dataset demo \
--proto models/AlexNet/AlexNet_CFM_T4_test.prototxt \
--weights outputs/bsd_voc2012/train_mcg/AlexNet_segm_cfm_T4_iter_30000.caffemodel \
--in_pr_dir data/demo/MCG-RAW.parsed --kwargs 'cfm_t:T4'
For help use the command: python tools/demo.py —help
Testing: demo, VGG16, T4, selective_search | MCG
$ cd /opt/segm_cfm
Using selective_search proposals
$ python tools/demo.py --gpu_id 0 --net VGG16 \
--gt_set test --task CFM --dataset demo \
--proto models/VGG16/VGG16_CFM_T4_test.prototxt \
--weights outputs/bsd_voc2012/train_mcg/VGG16_segm_cfm_T4_iter_30000.caffemodel \
--in_pr_dir data/demo/SS-RAW.parsed --kwargs 'cfm_t:T4'
Using MCG proposals
$ python tools/demo.py --gpu_id 0 --net VGG16 \
--gt_set test --task CFM --dataset demo \
--proto models/VGG16/VGG16_CFM_T4_test.prototxt \
--weights outputs/bsd_voc2012/train_mcg/VGG16_segm_cfm_T4_iter_30000.caffemodel \
--in_pr_dir data/demo/MCG-RAW.parsed --kwargs 'cfm_t:T4'
For help use the command: python tools/demo.py —help
All results related to demo dataset will be saved at ‘/opt/segm_cfm/data/demo/out’
Please feel free to leave suggestions or comments to Franck FOTSO (romyny9096@gmail.com)