Use CRF as post-process in image segmentation
tanjia123456 opened this issue · comments
Hello, thank you for your code.
I have a question to ask you, my network output is y_ pred: (10242,36) 10242 is the number of pixels, 36 is the number of categories, y_ PRED can be expressed as the probability that each pixel belongs to a certain class. Y_ true: (10242,36) one hot. How do you use CRF for post-processing?
I think you can find a solution at https://github.com/lucasb-eyer/pydensecrf.
If you refer to 2-D images, just see https://github.com/ZJULearning/RMI/blob/master/crf/crf.py
Ok, My output isn't a picture, juse a martrix? is it ok?
Ok, My output isn't a picture, juse a martrix? is it ok?
It is totally ok. Just follow the content in the picture and the steps in https://github.com/lucasb-eyer/pydensecrf.
Possibly like:
d = dcrf.DenseCRF(10242,36) # npoints, nlabels
feats = np.array(...) # Get the pairwise features from somewhere.
print(feats.shape) # -> (7, 10242) = (feature dimensionality, npoints)
print(feats.dtype) # -> dtype('float32')
dcrf.addPairwiseEnergy(feats)
Q = d.inference(5) # or other inference steps
map = np.argmax(Q, axis=0).reshape((10242,36))
OK! thank you very much, I will try it by myself.