sadeepj / crfasrnn_keras

CRF-RNN Keras/Tensorflow version
http://crfasrnn.torr.vision
MIT License
603 stars 169 forks source link

Could the ‘crfrnn’ layer be used on gray image with two classes? #9

Closed Codefordl closed 7 years ago

Codefordl commented 7 years ago

I am trying to use fully convolutional network on medical image segmentation these days.Our datasets are all gray images,and we need divide them into two classes. In the last layer of our network ,we use ‘sigmoid’ activation to get the final shape ‘[height,width,1]’.when we directly added the 'crfrnn' layer into our network as the new last layer,we got wrong results.The program ran without any error. It seems the value of results don't range from 0 to 1. Could the ‘crfrnn’ layer be used on gray image with two classes? if yes,how to modify the code? Look forward to your reply.

sadeepj commented 7 years ago

@Codefordl

1) Using a greyscale image: Theoretically it's possible, but the current implementation handles only RGB images. You could modify the code to work on grey images. But as a quick hack, you could just repeat the grey channel three times and feed the result as an RGB image.

2) Using only two classes: Again, theoretically this is possible. Just feed unaries with shape [height, width, 2], where the second channel is 1.0 - first_channel (assuming first_channel is sigmoid output and hence all values are between 0.0 and 1.0). You would also have to modify the compatibility transform weight matrix (See https://github.com/sadeepj/crfasrnn_keras/blob/b990ae92285141aff1a04436b46ca819599414d9/crfrnn_layer.py#L68) to be the following:

[[-1.0,   0.0],
 [ 0.0,  -1.0]]
Codefordl commented 7 years ago

I really appreciate your help.Your advice is simple and useful.But it is not clear to me the meaning You would also have to modify the compatibility transform weight matrix (See crfasrnn_keras/crfrnn_layer.py Line 68 in b990ae9 self.compatibility_matrix = self.add_weight(name='compatibility_matrix', ) to be the following: [[-1.0, 0.0], [ 0.0, -1.0]] which words would be replaced by‘[[-1.0, 0.0],[ 0.0, -1.0]]’?