Tensorflow implementation of CrfRnn layer according to Conditional Random Fields as Recurrent Neural Networks.
This is a minor repackaging of this repo, which itself is based on the work of this repo.
Note this repo does not contain the kernel for the lattice dimensional filter. See Setup below.
- Clone this repository and add the parent directory to your
PYTHONPATH
cd /path/to/parent_dir
git clone https://github.com/jackd/crfrnn
export PYTHONPATH=$PYTHONPATH:/path/to/parent_dir
- Get the source code for the kernel.
git clone --recursive https://github.com/MiguelMonteiro/CRFasRNNLayer
- change the number of channels to an appropriate value (to run the examples, this must be 21).
- build (you may need to manually install cmake). Note you'll need to change
INPUT_CHANNELS
to the number of classes. - Copy
lattice_filter.so
to./lattice_filter/lattice_filter.so
Building the kernel requires CMake 3.9 or above. Ubuntu 16.04 ships with 3.5, so you may need to manually install the latest version. Following the instrucitons here:
sudo apt remove cmake
sudo apt purge cmake
version=3.11
build=2
mkdir ~/temp
cd ~/temp
wget https://cmake.org/files/v$version/cmake-$version.$build.tar.gz
tar -xzvf cmake-$version.$build.tar.gz
cd cmake-$version.$build/
./bootstrap
make -j4
sudo make install
# Test
cmake --version
To run the demo:
- Follow Setup instructions above.
- Download pretrained model weights here.
- Move weights to
./example/keras/crfrnn_keras_model.h5
. - Run the
run_demo.py
script.
cd /path/to/parent_dir/crfrnn/example/keras
mv ~/Downloads/crfrnn_keras_model.h5 ./crfrnn_keras_model.h5
./run_demo.py
As per the original repo, if you use this code/model for your research, please cite the following paper:
@inproceedings{crfasrnn_ICCV2015,
author = {Shuai Zheng and Sadeep Jayasumana and Bernardino Romera-Paredes and Vibhav Vineet and
Zhizhong Su and Dalong Du and Chang Huang and Philip H. S. Torr},
title = {Conditional Random Fields as Recurrent Neural Networks},
booktitle = {International Conference on Computer Vision (ICCV)},
year = {2015}
}