jakeret / tf_unet

Generic U-Net Tensorflow implementation for image segmentation
GNU General Public License v3.0
1.9k stars 748 forks source link

Pixels close to edges #70

Closed vabrishami closed 6 years ago

vabrishami commented 7 years ago

Thank you for your beautiful implementation of the Unet. I have already read your paper and checked your code. It seems that you haven't implemented the part "Ensure separating of touching object". Please correct me if I am wrong. If I am correct, do you think it is easy to implement? I would be more than happy to help with that.

jakeret commented 7 years ago

What do you mean by "Ensure separating of touching object"?

vabrishami commented 7 years ago

Sorry for the lack of description. In the implementation of the UNET, they force the network to learn the border pixels. In their paper (on page 5, equation 2) they describe how they compute the weight map.

jakeret commented 7 years ago

I see, at the moment the code doesn't support a weight map. Adapting the package to support this might involve quite some work I fear

BAILOOL commented 7 years ago

Indeed, in the code, the class weights are fixed which makes it hard to balance classes for segmentation problem. Is it possible to adaptively determine weight_map based on the input image pixels? What I mean is to simply compute background and foreground pixels in the flat_labels and to adapt weight_ratio respectively based on that. I have tried to do that, but it fails due to nondeterministic values of flat_labels when initializing in _get_cost() function. Thank you in advance!

jakeret commented 7 years ago

@BAILOOL if I understand you correctly, this is not directly related to the initial question. You would like to change the class weights for every training image. Overwriting the _get_cost function is the correct way to go. I think you have to replace

class_weights = tf.constant(np.array(class_weights, dtype=np.float32))

with your adaptive approach.

DingkunLiu commented 6 years ago

I think the correct way is to set weight_map dynamically is to feed the corresponding weight map at each iteration to the placeholder. To do this, you need to add one more placeholder, modify _get_cost, train function and data provider class I think.

soroushr commented 5 years ago

@DingkunLiu I am working on something similar to what you suggested. But I don't quite understand why data provider and/or train functions should be modified. Wouldn't it be sufficient to add a placeholder and modify the loss in _get_cost()?