Closed pianoza closed 7 years ago
Hi!
I'm currently working on a deadline and will be too busy to look into this for the next couple weeks. Let me give you a few pointers though:
A segfault usually comes from wrong use of the API: if you'd use the C++ code in the same way, it'd segfault too. Your image is non-square, so my guess would be some shape in a wrong order somewhere. Another quick guess: is the ndarray C-contiguous? Someone recently contributed an example of non-RGB-image data, which I turned into a tutorial-style notebook. You could cross-check with it to maybe find the mistake.
In any case, if you find the mistake before I get to it, please let me know so I may add safeguards into the PyDenseCRF API for future users of it not to fall into the same pitfall.
Of course, it might also be a bug with the wrapper, which may take some time to find.
Hi,
I found my mistake: the shape of the probs
and the image.shape
were not the same, I had one of the axes swapped in the probs
. I think it would be cool to have an assert in the function, but anyways thanks, your comment was helpful!
Thank you for posting an update! I will definitely add an assert as soon as I get some down time!
FYI, I added a little more protection from this in the above commit, thanks again for your feedback!
Hi @pianoza , I recently also want to use pydensecrf to deal with 3D data. Can you share me your solution? From the commit of lucasb, as below, I still can not know how to use densecrf on 3D data. Thanks.
SHAPE, NLABELS = (69, 51, 72), 5
probs = np.random.randn(NLABELS, 68, 50).astype(np.float32) # WRONG shape here
probs /= probs.sum(axis=0, keepdims=True)
d = dcrf.DenseCRF(np.prod(SHAPE), NLABELS)
d.setUnaryEnergy(unary_from_softmax(probs)) # THIS SHOULD THROW and not crash later
feats = create_pairwise_gaussian(sdims=(1.0, 1.0, 1.0), shape=SHAPE)
d.addPairwiseEnergy(feats, compat=3, kernel=dcrf.FULL_KERNEL, normalization=dcrf.NORMALIZE_SYMMETRIC)
Q = d.inference(5)
new_image = np.argmax(Q, axis=0).reshape(SHAPE)
Hi @Thatfreesky, The way I used it for a 3D data was exactly the same as in my first comment.
Hi @Thatfreesky, The way I used it for a 3D data was exactly the same as in my first comment.
Hi @pianoza and @Thatfreesky I'm trying to use it as a 3D dense CRF as in this paper from the same authors https://www.sciencedirect.com/science/article/pii/S1361841516301839
I want to apply it to 3D RGB images to get a temporal correlation o videos and I'm having troubles cause the 3D version doesn't exist in a python library
I wanna know if that's what you're trying to do as well and if you can help me through it
Thank you
Hi, I'm trying to run pydensecrf for 3D case, but getting segmentation fault when I call inference. Here's how I'm running it (not sure if this is the correct way):
..and here is the backtrace:
Could you please help me to figure out what am I doing wrong?