HZCTony / U-net-with-multiple-classification

44 stars 13 forks source link

two questions #2

Open mqray opened 5 years ago

mqray commented 5 years ago

I found you did some modification in data.py, including:

def adjustData(img,mask,flag_multi_class,num_class):
    if(flag_multi_class):
        #print(type(img))
        img = img / 255.
        mask = mask[:,:,:,0] if(len(mask.shape) == 4) else mask[:,:,0]
        mask[(mask!=0.)&(mask!=255.)&(mask!=128.)] = 0.
        new_mask = np.zeros(mask.shape + (num_class,))
        new_mask[mask == 255.  , 0] = 1
        new_mask[mask == 128.,   1] = 1
        new_mask[mask == 0.,     2] = 1
        mask = new_mask

I know that your dataset contain three classes, but I don't know how to fix it to enable my dataset which contain more than 10 classes. Besides, I found that in your model2.py, that the input shape is (2586,256,1). I'm confused that whether your input image's shape is (256,256,3). I'm confused, please help me, thank you.

mqray commented 5 years ago

What's more, I guess that the function called labelVisualize in data.py may wrong.

def labelVisualize(num_class, color_dict, img):
    img_out = np.zeros(img[:,:,0].shape + (3,))
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            index_of_class = np.argmax(img[i,j])
            img_out[i,j] = color_dict[index_of_class]
    return img_out

I guess that this may just make each pixel can be labelled by the correspondingly pixel value, but this loop may can't work. I'm confused, please help me...

mqray commented 5 years ago

Besides, when we use flow_from_directory, the class mode was ser as grayscale. Notice that in your dataset, the photos' mode is rgb, I guess maybe the color_mode should change. In this situation, more changes will happen.

Yes you should change. Maybe I forgot to set it as grayscale cause I did some test for rgb before.

HZCTony commented 5 years ago

I found you did some modification in data.py, including:

def adjustData(img,mask,flag_multi_class,num_class):
    if(flag_multi_class):
        #print(type(img))
        img = img / 255.
        mask = mask[:,:,:,0] if(len(mask.shape) == 4) else mask[:,:,0]
        mask[(mask!=0.)&(mask!=255.)&(mask!=128.)] = 0.
        new_mask = np.zeros(mask.shape + (num_class,))
        new_mask[mask == 255.  , 0] = 1
        new_mask[mask == 128.,   1] = 1
        new_mask[mask == 0.,     2] = 1
        mask = new_mask

I know that your dataset contain three classes, but I don't know how to fix it to enable my dataset which contain more than 10 classes. Besides, I found that in your model2.py, that the input shape is (2586,256,1). I'm confused that whether your input image's shape is (256,256,3). I'm confused, please help me, thank you.

First, in my opinion , you should define what are the colors of your binary images of different classes. you should check two things: 1) how many classes (you said 10) do you have? change the last dimension for one-hot vector (maybe you should set it to 11(10 classes + 1 none ))

2) set every grayscale value corresponding to the certain index value of the last dimension. For example,

new_mask[mask == 255. , 0] = 1 <----- means that if the grayscale value of a labelled image equals to 255, the value of index 0 (equals to first class) will become 1. Every pixel has only a "1" value in the last dimension (This is one-hot vector).

3) Yes, my input images is (256,256,3). However, flow_from_directory should set the color_mode as grayscale. It doesn't matter how many channels do you prepare as inputs. The inputs should all become (256,256,1) due to grayscale transformation.

Hope I can resolve your questions.