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

Segmentation Fault at Permutohedral.cpp #2

Closed sonerdemiray closed 8 years ago

sonerdemiray commented 8 years ago

First of all, thank you for the wrapper :)

I'm getting a segmentation fault error when I call the inference method.

I did a traceback with gdb; It is the Permutohedral's code causing the error.

Program received signal SIGSEGV, Segmentation fault. Permutohedral::sseCompute (this=, out=0x76e5750, in=0x76e5750, value_size=263169, reverse=false) at densecrf/src/permutohedral.cpp:551 551 values[ osse_value_size+k ] += w \ sse_val[k];

Do you have any guess about the reason?

Thank you in advance.

Soner

swehrwein commented 8 years ago

Just a shot in the dark, but I had a similar segfault. If you're calling the general Make sure you're giving the data term as a numpy array of shape (n_labels, n_points), and if you're using addPairwiseEnergy, the features should have shape (feature_dimensions, n_points). When I passed the same data in but transposed, I got a segfault that looked similar to yours. I think the README example has been clarified about the smoothness term but the data term example is has it transposed. HTH, Scott

sonerdemiray commented 8 years ago

Hi Scott,

Thank you for your reply.

Apparently I noticed that I did two mistakes in the code.

1) Looking to the sample usage, I thought that the Unary array must be flattened as (n_points, n_labels) although it has to be flattened as (n_labels, n_points) as you mentioned.

2) I was transposing the data term, but I noticed that I'm doing it in wrong channel order. I fixed it.

Thank you again for your response. It helped a lot :)

Soner

Soner

lucasb-eyer commented 8 years ago

@swehrwein thanks for the help!

I need to improve the README. @sonerdemiray Did you use the generic (non-2D) case? Do you have a suggestion on improving the README?

sonerdemiray commented 8 years ago

Hi Lucas,

I didn't try the generic case yet but that would be great if you add the information Scott's supplied about flattening order of Unary array as (n_labels, n_points).

And I think the line "U = U.reshape((-1,3)) # Needs to be flat." should be changed as
"U = U.reshape((3,-1)) # Needs to be flat." in the documentation's sample usage to be consistent with the working case.

The rest of the documentation is quite perfect.

That would be also great if you supply a sample usage of MatrixCompatibility mode. Because this is a powerful feature.

Thank you again for sharing the work. :)

Soner

lucasb-eyer commented 8 years ago

Thanks again, I fixed the readme.

Using MatrixCompatibility is as easy as passing a 2D numpy array for the compat argument of addPairwiseGaussian. That's in theory; in practice I haven't tested it simply because I don't really know about that feature. If you encounter any problem trying it, feel free to open a new issue and I'll see how I can help. If you end up with a simple, self-contained example, I'd happily accept PRs.