zhixuhao / unet

unet for image segmentation
MIT License
4.6k stars 2k forks source link

Nothing comes out: just a grey, black, or white screen depending on the weight #148

Open Sequential-circuits opened 5 years ago

Sequential-circuits commented 5 years ago

I understand this software should generate black and white images separating the cells found

However, I only get plain black, white, or grey images depending on what value I put in the code below (0.5), which I obtained from another thread here: for i,item in enumerate(npyfile): if flag_multi_class: img = labelVisualize(num_class,COLOR_DICT,item) else: img=item[:,:,0] print("image=",img,np.max(img),np.min(img)) img[img>0.5]=1 img[img<=0.5]=0 print("image=",img,np.max(img),np.min(img)) io.imsave(os.path.join(save_path,"%d_predict.png"%i),img)

I also put "img = img / 255." as instructed at another thread, but also to no avail

How can I get an image such as https://raw.githubusercontent.com/zhixuhao/unet/master/img/0label.png ?

shlykov2 commented 5 years ago

same

whirlwind25 commented 5 years ago

same

voidwalker-M commented 5 years ago

I have the same question

AliceWord commented 5 years ago

comment this line in model.py: conv9 = Conv2D(2, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv9). it works for me, but i don‘t know the reason.

jnather commented 5 years ago

AliceWord thanks for the reply, but I did what you said and still only black screen despite of 50 epochs

i got an acc of 99% and loss of 0.13

passerbyWt commented 5 years ago

I changed the number of channals in Conv2D function from 64, 128,256... to 16,32,64... and it can work correctly.

loveunk commented 5 years ago

@AliceWord Previously, I encountered the same issue. I compared the model in this repository with the model in the U-Net paper and found that there is no need to have the 2 * 3 * 3 filters. After removing it, the model works.

jnather commented 5 years ago

@AliceWord Previously, I encountered the same issue. I compared the model in this repository with the model in the U-Net paper and found that there is no need the have the 2 * 3 * 3 filters. After removing it, the model works.

Sorry i'm a beginner here. how do I do that? Thanks again.

jnather commented 5 years ago

I changed the number of channals in Conv2D function from 64, 128,256... to 16,32,64... and it can work correctly.

I tried this and it didn't work

loveunk commented 5 years ago

@AliceWord Previously, I encountered the same issue. I compared the model in this repository with the model in the U-Net paper and found that there is no need the have the 2 * 3 * 3 filters. After removing it, the model works.

Sorry i'm a beginner here. how do I do that? Thanks again.

@jnather What I did is to remove/comment the following line in model.py:

conv9 = Conv2D(2, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv9)
SnakeHacker commented 5 years ago

same

manvirvirk commented 4 years ago

did any one find solution to this???

gmverdon-zelfstroom commented 4 years ago

I am experiencing this problem as well.

wadoodachaudhary commented 4 years ago

Same problem. I get 99% accuracy but only black image. I think it matches with the background which is about 99% of pixels.

alyaamer commented 4 years ago

@wadoodachaudhary , i see your comment is right , cause I'm having the same case in my dataset , where the background covers most of the image, So where you able to solve this issue Thanks

wadoodachaudhary commented 4 years ago

You have to play with loss functions. Try Dice, Pixel loss, mean iou.

husheng876 commented 4 years ago

You have to play with loss functions. Try Dice, Pixel loss, mean iou.

i have tried the dice loss function and I find which will case a new error.So the loss function should use binary loss function .And I finally solve the problem that the result is gray.

kuporu commented 4 years ago

comment this line in model.py: conv9 = Conv2D(2, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv9). it works for me, but i don‘t know the reason.

Thanks

tessa2k commented 1 year ago

You have to play with loss functions. Try Dice, Pixel loss, mean iou.

i have tried the dice loss function and I find which will case a new error.So the loss function should use binary loss function .And I finally solve the problem that the result is gray.

Thanks for your reply. I wonder whether the "binary loss function" you mentioned refers to "loss = 'binary_crossentropy' " in the original model.py.