This repository contains the reference implementation for our proposed Convolutional CRFs.

Overview

ConvCRF

This repository contains the reference implementation for our proposed Convolutional CRFs in PyTorch (Tensorflow planned). The two main entry-points are demo.py and benchmark.py. Demo.py performs ConvCRF inference on a single input image while benchmark.py compares ConvCRF with FullCRF. Both scripts output plots similar to the one shown below.

Example Output

Requirements

Plattform: Linux, python3 >= 3.4 (or python2 >= 2.7), pytorch 0.4 (or pytorch 0.3 + pyinn), cuda, cudnn

Python Packages: numpy, imageio, cython, scikit-image, matplotlib

To install those python packages run pip install -r requirements.txt or pip install numpy imageio cython scikit-image matplotlib. I recommand using a python virtualenv.

Optional Packages: pyinn, pydensecrf

Pydensecrf is required to run FullCRF, which is only needed for the benchmark. To install pydensecrf, follow the instructions here or simply run pip install git+https://github.com/lucasb-eyer/pydensecrf.git. Warning Running pip install git+ downloads and installs external code from the internet.

PyINN allows us to write native cuda operations and compile them on-the-fly during runtime. PyINN is used for our initial ConvCRF implementation and required for PyTorch 0.3 users. PyTorch 0.4 introduces an Im2Col layer, making it possible to implement ConvCRFs entirely in PyTorch. PyINN can be used as alternative backend. Run pip install git+https://github.com/szagoruyko/pyinn.git@master to install PyINN.

Execute

Demo: Run python demo.py data/2007_001288_0img.png data/2007_001288_5labels.png to perform ConvCRF inference on a single image. Try python demo.py --help to see more options.

Benchmark: Run python benchmark.py data/2007_001288_0img.png data/2007_001288_5labels.png to compare the performance of ConvCRFs to FullCRFs. This script will also tell you how much faster ConvCRFs are. On my system ConvCRF7 is more then 40 and ConvCRF5 more then 60 times faster.

Citation

If you benefit from this project, please consider citing our paper.

TODO

  • Build a native PyTorch 0.4 implementation of ConvCRF
  • Provide python 2 implementation
  • Build a Tensorflow implementation of ConvCRF
Comments
  • Sir ,tks for the cpu version,however,i think there have some small problems in your code

    Sir ,tks for the cpu version,however,i think there have some small problems in your code

    I try to run the newest code and always report errors. Finally i find that there some little mistake in the code after multiple tests 1st demo.py line97 should change to 'if args.cpu:' 2nd convcrf.py line523 should delete the 'raise ValueError' However,i don't know if i am right or not:) since i am a rookie and even did not fully understand your paper and all the codes

    opened by huixiancheng 0
  • Support running on CPU

    Support running on CPU

    Since you already provide a pure-PyTorch implementation that does not require PyINN, the code does not actually require CUDA. This PR removes the use_gpu assertions from the implementation and adds a --cpu flag both to the demo and benchmark script. (Side note: pydensecrf is actually faster on CPU, so in practice ConvCRF is only useful on GPU, but running on CPU is still useful for testing purposes.)

    opened by f0k 0
  • KeyError: 'final_softmax'

    KeyError: 'final_softmax'

    Hello, when I run the convcrf.py, arise error: Traceback (most recent call last): File "F:/googledownload/ConvCRF-master/convcrf/convcrf.py", line 620, in tcrf = GaussCRF(conf, [10, 10], None).cuda() File "F:/googledownload/ConvCRF-master/convcrf/convcrf.py", line 169, in init final_softmax=conf['final_softmax'], KeyError: 'final_softmax'

    have you met such problem? how to solve it?

    opened by tanjia123456 0
  • RuntimeError: non-empty 3D or 4D (batch mode) tensor expected for input

    RuntimeError: non-empty 3D or 4D (batch mode) tensor expected for input

    from convcrf import convcrf
    
    config = convcrf.default_conf
    shape = [3,416,416]
    nclasses = 15
    
    crf = convcrf.GaussCRF(config, shape, nclasses)
    crf.cuda()
    
    img = torch.randn(1,3,416,416).cuda()
    un = torch.randn(1,15,416,416).cuda()
    un = torch.softmax(un,dim=1)
    
    pred = crf.forward(un, img)
    

    ERROR: Traceback (most recent call last):

    File "", line 1, in pred = crf.forward(un, img)

    File "...\anaconda3\lib\site-packages\convcrf-1.0-py3.7.egg\convcrf\convcrf.py", line 202, in forward compats, conf['merge'])

    File "...\anaconda3\lib\site-packages\convcrf-1.0-py3.7.egg\convcrf\convcrf.py", line 574, in add_pairwise_energies pyinn=self.pyinn)

    File "...\anaconda3\lib\site-packages\convcrf-1.0-py3.7.egg\convcrf\convcrf.py", line 311, in init gaussian = self._create_convolutional_filters(feats)

    File "...\anaconda3\lib\site-packages\convcrf-1.0-py3.7.egg\convcrf\convcrf.py", line 353, in _create_convolutional_filters count_include_pad=False)

    RuntimeError: non-empty 3D or 4D (batch mode) tensor expected for input

    opened by GitSwar90 0
  • Confusion regarding ordering of log and softmax in inference code

    Confusion regarding ordering of log and softmax in inference code

    Hi Marvin,

    Great project! I am trying to utilize it in my own research and went through your convcrf.py code. I have a doubt around this line where if I am not wrong, if default_conf["logsoftmax"] is True you take softmax followed by log using the log_softmax function (docs) but if it's False you take the log followed by the softmax. Can you please clarify on this?

    Thanks

    opened by umangksinha 0
  • About training in deep network.

    About training in deep network.

    Hi, @MarvinTeichmann Thanks for your work, I have two questions about the ConvCRF.

    1. I run demo.py and got a perfect result, but how the weights of Gaussian Kernels been updated?
    2. I put the ConvCRF as a module into a deep network, and train the whole network by BP for semantic segmentation, No error but the loss is so unstable and the mIoU is too low. How should I choose the training protocol?

    Thanks a lot.

    opened by wangq95 0
  • Question about comparative experiment

    Question about comparative experiment

    Hello

    ConvCRF is an amazing work.

    I have a question about the experiment on ConvCRF and CRFasRNN. In general, DenseCRF can increase MIoU by 3%, Which means that even without end-to-end jointly fine tuning, the CNN-DenseCRF system can achieve a better MIoU than the unary (CNN). But I notice that in this paper, MIoU of FCN-ResNet101-CRFasRNN is about 69, lower than the raw MIoU of its unary module FCN-ResNet101 (about 71).

    What happends to DenseCRF that makes its accuracy declining so hard?

    opened by AlexTansley 0
Owner
Marvin Teichmann
Germany Phd student. Working on Deep Learning and Computer Vision projects.
Marvin Teichmann
PyTorch implementation of CVPR 2020 paper (Reference-Based Sketch Image Colorization using Augmented-Self Reference and Dense Semantic Correspondence) and pre-trained model on ImageNet dataset

Reference-Based-Sketch-Image-Colorization-ImageNet This is a PyTorch implementation of CVPR 2020 paper (Reference-Based Sketch Image Colorization usin

Yuzhi ZHAO 11 Jul 28, 2022
This repo contains the implementation of the algorithm proposed in Off-Belief Learning, ICML 2021.

Off-Belief Learning Introduction This repo contains the implementation of the algorithm proposed in Off-Belief Learning, ICML 2021. Environment Setup

Facebook Research 32 Jan 5, 2023
A PyTorch implementation of Mugs proposed by our paper "Mugs: A Multi-Granular Self-Supervised Learning Framework".

Mugs: A Multi-Granular Self-Supervised Learning Framework This is a PyTorch implementation of Mugs proposed by our paper "Mugs: A Multi-Granular Self-

Sea AI Lab 62 Nov 8, 2022
Convolutional neural network web app trained to track our infant’s sleep schedule using our Google Nest camera.

Machine Learning Sleep Schedule Tracker What is it? Convolutional neural network web app trained to track our infant’s sleep schedule using our Google

g-parki 7 Jul 15, 2022
This repository implements and evaluates convolutional networks on the Möbius strip as toy model instantiations of Coordinate Independent Convolutional Networks.

Orientation independent Möbius CNNs This repository implements and evaluates convolutional networks on the Möbius strip as toy model instantiations of

Maurice Weiler 59 Dec 9, 2022
This repository contains the code for our fast polygonal building extraction from overhead images pipeline.

Polygonal Building Segmentation by Frame Field Learning We add a frame field output to an image segmentation neural network to improve segmentation qu

Nicolas Girard 186 Jan 4, 2023
This repository contains the source code of our work on designing efficient CNNs for computer vision

Efficient networks for Computer Vision This repo contains source code of our work on designing efficient networks for different computer vision tasks:

Sachin Mehta 386 Nov 26, 2022
This repository contains the entire code for our work "Two-Timescale End-to-End Learning for Channel Acquisition and Hybrid Precoding"

Two-Timescale-DNN Two-Timescale End-to-End Learning for Channel Acquisition and Hybrid Precoding This repository contains the entire code for our work

QiyuHu 3 Mar 7, 2022
Implementation of Geometric Vector Perceptron, a simple circuit for 3d rotation equivariance for learning over large biomolecules, in Pytorch. Idea proposed and accepted at ICLR 2021

Geometric Vector Perceptron Implementation of Geometric Vector Perceptron, a simple circuit with 3d rotation equivariance for learning over large biom

Phil Wang 59 Nov 24, 2022
Implementation of 'lightweight' GAN, proposed in ICLR 2021, in Pytorch. High resolution image generations that can be trained within a day or two

512x512 flowers after 12 hours of training, 1 gpu 256x256 flowers after 12 hours of training, 1 gpu Pizza 'Lightweight' GAN Implementation of 'lightwe

Phil Wang 1.5k Jan 2, 2023
An implementation for the loss function proposed in Decoupled Contrastive Loss paper.

Decoupled-Contrastive-Learning This repository is an implementation for the loss function proposed in Decoupled Contrastive Loss paper. Requirements P

Ramin Nakhli 71 Dec 4, 2022
Implementation of the method proposed in the paper "Neural Descriptor Fields: SE(3)-Equivariant Object Representations for Manipulation"

Neural Descriptor Fields (NDF) PyTorch implementation for training continuous 3D neural fields to represent dense correspondence across objects, and u

null 167 Jan 6, 2023
Pytorch implementation of the popular Improv RNN model originally proposed by the Magenta team.

Pytorch Implementation of Improv RNN Overview This code is a pytorch implementation of the popular Improv RNN model originally implemented by the Mage

Sebastian Murgul 3 Nov 11, 2022
Torch-ngp - A pytorch implementation of the hash encoder proposed in instant-ngp

HashGrid Encoder (WIP) A pytorch implementation of the HashGrid Encoder from ins

hawkey 1k Jan 1, 2023
Implementation of a memory efficient multi-head attention as proposed in the paper, "Self-attention Does Not Need O(n²) Memory"

Memory Efficient Attention Pytorch Implementation of a memory efficient multi-head attention as proposed in the paper, Self-attention Does Not Need O(

Phil Wang 180 Jan 5, 2023
Implementation of the Transformer variant proposed in "Transformer Quality in Linear Time"

FLASH - Pytorch Implementation of the Transformer variant proposed in the paper Transformer Quality in Linear Time Install $ pip install FLASH-pytorch

Phil Wang 209 Dec 28, 2022
CoSMA: Convolutional Semi-Regular Mesh Autoencoder. From Paper "Mesh Convolutional Autoencoder for Semi-Regular Meshes of Different Sizes"

Mesh Convolutional Autoencoder for Semi-Regular Meshes of Different Sizes Implementation of CoSMA: Convolutional Semi-Regular Mesh Autoencoder arXiv p

Fraunhofer SCAI 10 Oct 11, 2022
The source code for the Cutoff data augmentation approach proposed in this paper: "A Simple but Tough-to-Beat Data Augmentation Approach for Natural Language Understanding and Generation".

Cutoff: A Simple Data Augmentation Approach for Natural Language This repository contains source code necessary to reproduce the results presented in

Dinghan Shen 49 Dec 22, 2022
Code and data of the Fine-Grained R2R Dataset proposed in paper Sub-Instruction Aware Vision-and-Language Navigation

Fine-Grained R2R Code and data of the Fine-Grained R2R Dataset proposed in the EMNLP2020 paper Sub-Instruction Aware Vision-and-Language Navigation. C

YicongHong 34 Nov 15, 2022