lucasb-eyer / pydensecrf

Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
MIT License
1.95k stars 417 forks source link

Issue with inference method #13

Closed sqy12 closed 8 years ago

sqy12 commented 8 years ago

Just like what I've described before. Here attached the example code and the images. You can put them in the same folder and have a try. I'm using 3D images. The test image is the labeled image after training a random forest regressor and testing the origin image. What I want to do is to perform a post process of the labeled image to reduce the noise and increase the classification rate and dice metric. origin.nii.gz test.nii.gz Issue.txt You need to change the 'Issue.txt' to 'Issue.py' as GitHub doesn't allow me to upload a Python file.

Thanks a lot.

lucasb-eyer commented 8 years ago

For the record, this is about this comment in #12, that the inference method crashes.

I'll have a look soon.

sqy12 commented 8 years ago

Hello, it has been a while. Do you have any images that I can use to run the inference example in your repository?

lucasb-eyer commented 8 years ago

No, I didn't get to it yet, sorry! Life is currently a little hectic for me, but I didn't forget about it.

sqy12 commented 8 years ago

Nah, I mean I want to have a try of you inference_example.py file. Could you please provide me some sample 2D images(image and annotation) as my images are all 3D images and not working?

fengjunlv commented 8 years ago

second this. Sample images (rgb and label) would be greatly helpful. I tried some images and the result is always all-zero.

sqy12 commented 8 years ago

You can probably find some sample images and annotation images from here. http://graphics.stanford.edu/projects/densecrf/textonboost/

But I'm now facing some new issues on running the example file.

sqy12 commented 8 years ago

The images are in the code size folder.

fengjunlv commented 8 years ago

@sqy12 I found them. Thanks.

sqy12 commented 8 years ago

@fengjunlv No worries. Do you have any issues on running the example? I've got an

AttributeError: 'NoneType' object has no attribute 'max'

on line number 25.

lucasb-eyer commented 8 years ago

I'll add the original sample images Philip used in the C++ examples to this repo and try them out myself to see if I get the same errors as you.

fengjunlv commented 8 years ago

@sqy12 I haven't tried them yet. I am thinking of simpler initial label such as a a surrounding rectangle like what densecut has used. Maybe this algorithm is not suitable for this type of input.

lucasb-eyer commented 8 years ago

I have moved the examples to the examples/ folder and added Philip's original example images. You can also see the output I get when running the inference.py example.

@sqy12 what exactly are you running when you get that AttributeError. I still need to try the images you have provided, I hope to get to that tomorrow or otherwise soon.

lucasb-eyer commented 8 years ago

And for the recor, python utils_example.py im1.png anno1.png runs just fine, too.

sqy12 commented 8 years ago

@lucasb-eyer Thanks. I can see that actually works. Just got a little problem of importing matplotlib. But I still have no idea why inference method doesn't work in my case.

sqy12 commented 8 years ago

From the exit code, I think the problem could be out of memory.

sqy12 commented 8 years ago

Probably not the problem of memory. Does it matter if the image is not RGB based but intensity based?

sqy12 commented 8 years ago

It works now. But I'm not sure if you algorithm works for a images labeled within range [0,1,2,4].

lucasb-eyer commented 8 years ago

Few things:

  1. "it works now" cool! so what was the problem? Maybe others will have the same.
  2. Does this mean we can close this issue?
  3. It's not my algorithm, but Philip Krähenbühl's :)
  4. The algorithm doesn't really know about your label values, it's up to you to turn them into meaningful energies. It definitely does work well with multiple labels.
sqy12 commented 8 years ago

To be honest, I've no idea what the problem is. I just cropped the image data to a smaller one and had a try. And then it works. I think this issue could be closed.

Actually I think in the algorithm you are required to set the number of classes which I believe is the number of labels. The number of labels should be for in my case [0,1,2,4]. But the highest number in the computed result array is 3. Is there any specific parameter that I need to change for a 3D image? And I'm using an intensity image instead of RGB image.

lucasb-eyer commented 8 years ago

Oh, I see what you mean now, thanks for getting back! That's an assumption the compute_unary function makes. You could either write your custom version based on it, but my guess is the simplest thing for you to do would be something like arr[arr == 4] = 3.

sqy12 commented 8 years ago

Hello, could you please explain how the M is used in your example? M = 21 # 21 Classes to match the C++ example
It seems like you example annotation is ranged from 0 to 94, which I thought would be 95 classes? And the computed map is ranged from 1 to 2. Is that possible to keep the labels stay the same like from [0,1,2,3] to [0,1,2,3], which parameter that I should change to do this? And it seems like labels of the computed map always starts from 1.

lucasb-eyer commented 8 years ago

Thanks, that was a bad example! And if the C++ example did this, it is a bad example too. I've updated the example in the commit you see linked here so that it computes the actual number of labels/classes present in the image.

For keeping the labels in their original range, please read the documentation of skimage's relabel_sequential that we're using in the example; you can use one of the returned values for "back-transformation".

But please do not keep updating an issue with unrelated other issues, prefer to open a new issue. This is a list of issues, not a forum/board thread.