Skip to content

Commit

Permalink
Merge pull request #1 from torrvision/master
Browse files Browse the repository at this point in the history
Update from original
  • Loading branch information
bittnt committed Mar 31, 2016
2 parents 3ddb109 + 39ded56 commit 54eba6b
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 105 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<b>Live demo:</b> [http://crfasrnn.torr.vision](http://crfasrnn.torr.vision)

This package contains code for the "CRF-RNN" semantic image segmentation method, published in the ICCV 2015 paper [Conditional Random Fields as Recurrent Neural Networks](http://www.robots.ox.ac.uk/~szheng/papers/CRFasRNN.pdf). Our software is built on top of the [Caffe](http://caffe.berkeleyvision.org/) deep learning library. The current version was developed by:
This package contains code for the "CRF-RNN" semantic image segmentation method, published in the ICCV 2015 paper [Conditional Random Fields as Recurrent Neural Networks](http://www.robots.ox.ac.uk/~szheng/papers/CRFasRNN.pdf). This paper was initially described in an [arXiv tech report](http://arxiv.org/abs/1502.03240). Our software is built on top of the [Caffe](http://caffe.berkeleyvision.org/) deep learning library. The current version was developed by:

[Sadeep Jayasumana](http://www.robots.ox.ac.uk/~sadeep/),
[Shuai Zheng](http://kylezheng.org/),
Expand Down Expand Up @@ -102,6 +102,35 @@ That's it! Enjoy our software!
###1.3 Run the demo
Matlab and Python scripts for running the demo are available in the matlab-scripts and python-scripts directories, respectively. You can choose either of them. Note that you should change the paths in the scripts according your environment.

####For Python fans:
First you need to download the model. In Linux, this is:
```
sh download_trained_model.sh
```
Atlernatively, you can also get the model by directly clicking the link in python-scripts/README.md.

Get into the python-scripts folder, and then type:
```
python crfasrnn_demo.py
```
You will get an output.png image.

To use your own images, just replace "input.jpg" in the crfasrnn_demo.py file.

####For Matlab fans:
First you need to download the model. In Linux, this is:
```
sh download_trained_model.sh
```
Atlernatively, you can also get the model by directly clicking the link in matlab-scripts/README.md.

Get into the matlab-scripts folder, load your matlab, then run the crfrnn_demo.m.

To use your own images, just replace "input.jpg" in the crfrnn_demo.m file.

You can also find part of our model in [MatConvNet](http://www.vlfeat.org/matconvnet/pretrained/).


# LICENSE
CRF-RNN feature in Caffe is implemented for the paper:
Shuai Zheng, Sadeep Jayasumana, Bernardino Romera-Paredes, Vibhav Vineet, Zhizhong Su, Dalong Du, Chang Huang, Philip H. S. Torr.
Expand Down
78 changes: 0 additions & 78 deletions caffe-crfrnn/Makefile.config

This file was deleted.

Binary file removed matlab-scripts/2007_000033.png
Binary file not shown.
5 changes: 5 additions & 0 deletions matlab-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ sha1: bfda5c5149d566aa56695789fa9a08e7a7f3070a

This model is for the ICCV paper titled "Conditional Random Fields as Recurrent Neural Networks".

With this model, you should get 73.0 mean-IOU score on a reduced validation set(346 Images http://www.robots.ox.ac.uk/~szheng/Res_CRFRNN/seg12valid.txt) on PASCAL VOC 2012. Notice that without this CRF-RNN layer, our end-to-end-trained FCN-8s model gives 69.85 mean-IOU score (mean pix. accuracy:92.94, pixel accuracy: 78.80) on the this reduced validation set of PASCAL VOC 2012.

The input is expected in BGR color channel order, with the following per-channel mean substracted:
B: 104.00698793 G: 116.66876762 R: 122.67891434

Demo website is <http://crfasrnn.torr.vision>.

This model was trained by
Expand Down
30 changes: 18 additions & 12 deletions matlab-scripts/crfrnn_demo.m
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
clear all;
close all;
%This is a software bundle "CRF-RNN", which is published in a ICCV paper titled "Conditional Random Fields as Recurrent Neural Networks". This is implemented as part of the Caffe library, written in C++/C. The current version is maintained by:
% This package contains code for the "CRF-RNN" semantic image segmentation method, published in the
% ICCV 2015 paper Conditional Random Fields as Recurrent Neural Networks. Our software is built on
% top of the Caffe deep learning library.
%
% Contact:
% Shuai Zheng (szheng@robots.ox.ac.uk), Sadeep Jayasumana (sadeep@robots.ox.ac.uk), Bernardino Romera-Paredes (bernard@robots.ox.ac.uk)
%
%Shuai Zheng : szheng@robots.ox.ac.uk Sadeep Jayasumana : sadeep@robots.ox.ac.uk Bernardino Romera Paredes :
% Supervisor:
% Philip Torr (philip.torr@eng.ox.ac.uk)
%
%Supervisor: Philip Torr : philip.torr@eng.ox.ac.uk
%
%For more information about CRF-RNN please vist the project website http://crfasrnn.torr.vision.
% For more information about CRF-RNN please vist the project website http://crfasrnn.torr.vision.
%

caffe_path = '../caffe-crfrnn/';

model_def_file = 'TVG_CRFRNN_COCO_VOC.prototxt';
model_file = 'TVG_CRFRNN_COCO_VOC.caffemodel';

use_gpu = 1;
if exist(model_file, 'file') ~= 2
error('You need a network model file. Please download our default model by running ./download_trained_model.sh');
end

use_gpu = 1; % Set this to 0 if you don't have a GPU.

addpath(fullfile(caffe_path, 'matlab/caffe'));

caffe('reset');
caffe('set_device', 0);% change here if you have a powerful GPU in different device, nvidia-smi will help you check the device information.
caffe('set_device', 0); % Change here if you have a powerful GPU in different device, nvidia-smi will help you check the device information.

tvg_matcaffe_init(use_gpu, model_def_file, model_file);
[~, map] = imread('2007_000033.png']);

im = imread('input.jpg');

Expand All @@ -46,5 +52,5 @@
pred = pred';
pred = pred(1:h, 1:w);

imwrite(pred, map, ['output.png'], 'png');

load map.mat
imwrite(pred, map, 'output.png', 'png');
2 changes: 1 addition & 1 deletion matlab-scripts/download_trained_model.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wget http://goo.gl/j7PrPZ
wget -O TVG_CRFRNN_COCO_VOC.caffemodel http://goo.gl/j7PrPZ
Binary file added matlab-scripts/map.mat
Binary file not shown.
7 changes: 6 additions & 1 deletion python-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ license: Non-commercial, for commercial use, please contact crfasrnn@gmail.com
sha1: bfda5c5149d566aa56695789fa9a08e7a7f3070a
---

This model is for the ICCV paper titled "Conditional Random Fields as Recurrent Neural Networks".
This model is for the ICCV paper titled "Conditional Random Fields as Recurrent Neural Networks".

With this model, you should get 73.0 mean-IOU score on a reduced validation set(346 Images http://www.robots.ox.ac.uk/~szheng/Res_CRFRNN/seg12valid.txt) on PASCAL VOC 2012. Notice that without this CRF-RNN layer, our end-to-end-trained FCN-8s model gives 69.85 mean-IOU score (mean pix. accuracy:92.94, pixel accuracy: 78.80) on the this reduced validation set of PASCAL VOC 2012.

The input is expected in BGR color channel order, with the following per-channel mean substracted:
B: 104.00698793 G: 116.66876762 R: 122.67891434

Demo website is <http://crfasrnn.torr.vision>.

Expand Down
25 changes: 14 additions & 11 deletions python-scripts/crfasrnn_demo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# -*- coding: utf-8 -*-
"""
This is a software bundle "CRF-RNN", which is published in a ICCV paper titled "Conditional Random Fields as Recurrent Neural Networks". This is implemented as part of the Caffe library, written in C++/C. The current version is maintained by:
This package contains code for the "CRF-RNN" semantic image segmentation method, published in the
ICCV 2015 paper Conditional Random Fields as Recurrent Neural Networks. Our software is built on
top of the Caffe deep learning library.
Contact:
Shuai Zheng (szheng@robots.ox.ac.uk), Sadeep Jayasumana (sadeep@robots.ox.ac.uk), Bernardino Romera-Paredes (bernard@robots.ox.ac.uk)
Shuai Zheng : szheng@robots.ox.ac.uk Sadeep Jayasumana : sadeep@robots.ox.ac.uk Bernardino Romera Paredes :
Supervisor:
Philip Torr (philip.torr@eng.ox.ac.uk)
Supervisor: Philip Torr : philip.torr@eng.ox.ac.uk
For more information about CRF-RNN please vist the project website http://crfasrnn.torr.vision.
For more information about CRF-RNN, please vist the project website http://crfasrnn.torr.vision.
"""

caffe_root = '../caffe-crfrnn/'
import sys
sys.path.insert(0,caffe_root+'python')
sys.path.insert(0, caffe_root + 'python')

import os
import cPickle
Expand All @@ -27,12 +31,12 @@

MODEL_FILE = 'TVG_CRFRNN_COCO_VOC.prototxt'
PRETRAINED = 'TVG_CRFRNN_COCO_VOC.caffemodel'
IMAGE_FILE = '2007_000032.jpg'
IMAGE_FILE = 'input.jpg'


#caffe.set_mode_gpu()
net = caffe.Segmenter(MODEL_FILE, PRETRAINED)
input_image = 255*caffe.io.load_image(IMAGE_FILE)
input_image = 255 * caffe.io.load_image(IMAGE_FILE)


width = input_image.shape[0]
Expand Down Expand Up @@ -72,7 +76,7 @@
192,192,0]

mean_vec = np.array([103.939, 116.779, 123.68], dtype=np.float32)
reshaped_mean_vec = mean_vec.reshape(1,1,3);
reshaped_mean_vec = mean_vec.reshape(1, 1, 3);

# Rearrange channels to form BGR
im = image[:,:,::-1]
Expand All @@ -86,10 +90,9 @@
im = np.pad(im, pad_width=((0, pad_h), (0, pad_w), (0, 0)), mode = 'constant', constant_values = 0)
# Get predictions
segmentation = net.predict([im])
segmentation2 = segmentation[0:cur_h,0:cur_w]
segmentation2 = segmentation[0:cur_h, 0:cur_w]
output_im = PILImage.fromarray(segmentation2)
output_im.putpalette(pallete)


plt.imshow(output_im)
plt.savefig('output.png')
2 changes: 1 addition & 1 deletion python-scripts/download_trained_model.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wget http://goo.gl/j7PrPZ TVG_CRFRNN_COCO_VOC.caffemodel
wget -O TVG_CRFRNN_COCO_VOC.caffemodel http://goo.gl/j7PrPZ

0 comments on commit 54eba6b

Please sign in to comment.