jakeret / tf_unet

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

How to label my data #223

Closed abderhasan closed 5 years ago

abderhasan commented 5 years ago

My data is composed of 2-classes. I have labeled the classes 1 (foreground) and 2 (background). Pixels were labeled here for semantic segmentation.

In image_util.py lines 64 and 65, when I did the following:

labels[..., 1] = label labels[..., 2] = ~label

I got an error that the index of labels is out of range.

Should I change the labels as above, or keeping it as follows is considered correct?

labels[..., 0] = label labels[..., 1] = ~label

So, what I'm trying to ask is, should the label IDs in image_util.py be similar to my original label IDs (i.e. 1 and 2)?

Thanks.

jakeret commented 5 years ago

The implementation expects a one-hot encoding. In case of a binary segmentation (foreground & background) the input should be 1 if its a foreground pixel and 0 otherwise.

In your case you would have to do something like

labels[..., 0] = label==1
labels[..., 1] = label==2
abderhasan commented 5 years ago

Great! Thanks a lot.

abderhasan commented 5 years ago

Sorry, just a quick question. In my case, the foreground was given the label "1" and the background the label "2". So, should it be this way?

labels[..., 0] = label==2 labels[..., 1] = label==1

Thanks.