Git Product home page Git Product logo

convcrf's Introduction

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

convcrf's People

Contributors

f0k avatar marvinteichmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

convcrf's Issues

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?

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

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?

On the difference compared to the original paper

Hi Marvin,

Interesting work!

I would like to ask some questions.

  1. It appears that there is a difference in the mean field iterations presented in your paper (section 3.1) compared to the original paper (also section 3.1). More specifically, in the original paper, the output of each iteration is softmax(- unary - message_passing) while in your paper it is softmax(unary + message_passing) (note the additive inversion).

  2. In your implementation, I could not understand this part:

        if not i == num_iter - 1 or self.final_softmax:
                if self.conf['softmax']:
                    prediction = exp_and_normalize(prediction, dim=1)

According to the algorithm, prediction should be normalized at every iteration. In the code, though, it is not normalized for the last iteration, or when self.final_softmax = False, or when self.conf['softmax'] = False.

Could you please explain these two issues?

Thank you in advance!
Best regards.

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

The size of tensor a (512) must match the size of tensor b (20) at non-singleton dimension 1

same input as example, but got this error:

convcrf/convcrf.py", line 598, in inference
    prediction = (self.unary_weight - self.weight) * lg_unary + \
RuntimeError: The size of tensor a (512) must match the size of tensor b (20) at non-singleton dimension 1

the input image and unary size are:

image vs unary input size: torch.Size([1, 3, 512, 1024]) vs torch.Size([1, 20, 512, 1024])

Prediction different in iterations

Can you someone explain why the prediction used to compute the message at the first iteration is the output from logsoftmax and for the other iterations is softmax? In the inference function.

The relationship with FullCRF

hi~ I'm digging in your work for weeks and it's really awesome! Now I wanna ask if I set the conv size as the input size, does it mean that the convCRF is equivalent to FullyCRF in this case?

The meaning of these parameters?

I am currently training CONV-CRF, but I have not found the corresponding formula for these parameters in your paper? I don't know their specific meaning:
'pos_feats': {
'sdims': 3,
'compat': 3,
},
'col_feats': {
'sdims': 80,
'schan': 13, # schan depend on the input scale.
# use schan = 13 for images in [0, 255]
# for normalized images in [-0.5, 0.5] try schan = 0.1
'compat': 10,
'use_bias': True

About End-to-end training

Thanks for your code. Do you have the code for end-to-end training? I wonder how to use ConvCRF in end-to-end training.

typeerror

Hi Marvin,when I just run 'python demo.py data/2007_001288_0img.png data/2007_001288_5labels.png
', the error occured as following:

TypeError: avg_pool2d(): argument 'padding' must be tuple of ints, but found element of type float at pos 1
could you help me ?thanks very much.

Can I use ConvCRF in grayscale images?

I haven't seen a demo for grayscale images or images having higher dimensions, so I wonder if it is implemented for images with dimension not equalling to 3. Thank you!

how to use for text sequence labelling problem?

hi,

thanks for your good work. Is it possible to modify the code to use for text sequence labelling problems such as "named entity recognition" where CRFs are commonly used in combination with NNETs. Any pointers would be great.

Thanks

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.

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

Another Question about speed test and GPU-memory test

Hi, Marvin:

I notice that in your paper, you post the speed of ConvCRF with different receptive field size from 3 to 13. Here is my question, why there's no more larger conv-size than size-13 ? And is the speed posted in table.1 indicate that the time cost for just one iteration?

Applying Issue

Hi, I'm quite interested in CRF like models in segmentation and contour detection tasks. I think the ConvCRF is suitable for contour detection much, so I link it to the end of my naive CNN model, but when I set the hyperparameters as listed in the paper, the final prediction of ConvCRF would not change in 200 epochs. While I increase the learning rate to 1e-3, the prediction would generally be the same as the unary. By the way, I just apply the default_config and change the trainable mark to True. Is there any other detail I need to add? Thx for ur great work:)

Why log on input data?

Does anyone know why is it used the log on the input data (or logsoftmax) instead of just softmax?

about the training curve

Hi @MarvinTeichmann , thanks a lot for your sharing valuable code!

I have a question about the learning curve, from the Fig. 4b, after equipped with the CRF module (epoch 100), the Train mIoU has a large jump, but seems to stay constant after that. Does this mean the CRF module learns nothing? Or maybe the network quickly converged from epoch 100 to epoch 101? Maybe I should check how the parameters of the CRF module changed from epoch 100 to epoch 250.

About speed comparison?

Thanks for your excellent work!
I noticed convcrf is run on gpu, while fullcrf is run on cpu. Is it unfair to compare two algorithms on different platforms?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.