sagieppel / Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation

68 stars 40 forks source link

TRIAN.PY ISSUES #10

Open leishi2018 opened 5 years ago

leishi2018 commented 5 years ago

Hello, I have a problem about this. My test pictures is a RGB three chanels,and Labels is PNG .

ValueError: could not broadcast input array from shape (456,607,4) into shape (456,607)

leishi2018 commented 5 years ago

ValueError Traceback (most recent call last)

in () ----> 1 main()#Run script 2 print("Finished") in main(argv) 37 #..............Start Training loop: Main Training.................................................................... 38 for itr in range(MAX_ITERATION): ---> 39 Images, GTLabels =TrainReader.ReadAndAugmentNextBatch() # Load augmeted images and ground true labels for training 40 feed_dict = {image: Images,GTLabel:GTLabels, keep_prob: 0.5} 41 sess.run(train_op, feed_dict=feed_dict) # Train one cycle ~/tensorflow_train/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation-master/Data_Reader.py in ReadAndAugmentNextBatch(self) 133 Images[f]=Img 134 if self.ReadLabels: --> 135 Labels[f,:,:,0]=Label 136 137 #.......................Return aumented images and labels........................................................... ValueError: could not broadcast input array from shape (456,607,4) into shape (456,607)
sagieppel commented 5 years ago

Seem like your annotation image have depth of 4 and not 1, The Label should be 2d image where the value of each pixel is its class number.

leishi2018 commented 5 years ago

Ok, thanks,I have solve this problem. but, my loss is always nan,and, my test photos are some flowers.

sagieppel commented 5 years ago

Possibly the number of classes you put in NUM_CLASSES is lower then the one actually appear in your annotations. Check the max number that appear in your annotation.

leishi2018 commented 5 years ago

My annotation of photos are only white(object) and black(background).so, NUM_CLASSES is 2.

------------------ 原始邮件 ------------------ 发件人: "sagieppel"notifications@github.com; 发送时间: 2018年12月16日(星期天) 晚上6:33 收件人: "sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation"Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation@noreply.github.com; 抄送: "火焰舞者"523997174@qq.com; "Author"author@noreply.github.com; 主题: Re:[sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation]TRIAN.PY ISSUES (#10)

Possibly the number of classes you put in NUM_CLASSES is lower then the one actually appear in your annotations. Check the max number that appear in your annotation.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

leishi2018 commented 5 years ago

NUM_CLASSES is 2 that is ok. when I change it the program will take an error.

leishi2018 commented 5 years ago

Why do you use BGR substract pixels mean, that lead to the negative value of bgr. and the value of self.conv1_1 are all the zero. So, my Net.Prob is Nan

sagieppel commented 5 years ago

Is the value of the white region in label map 1 or 255? If its 255 that is the error. The highest value of the label map is the number of classes.

Substracting mean is standart normalization it cant lead to all zeros. Also having all zeros in first layer will not lead to nan results.

leishi2018 commented 5 years ago

can you tell me how to set the number class.

------------------ 原始邮件 ------------------ 发件人: "sagieppel"notifications@github.com; 发送时间: 2018年12月18日(星期二) 上午6:35 收件人: "sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation"Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation@noreply.github.com; 抄送: "火焰舞者"523997174@qq.com; "Author"author@noreply.github.com; 主题: Re:[sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation]TRIAN.PY ISSUES (#10)

Is the value of the white region in label map 1 or 255? If its 255 that is the error. The highest value of the label map is the number of classes.

Substracting mean is standart normalization it cant lead to all zeros. Also having all zeros in first layer will not lead to nan results.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

leishi2018 commented 5 years ago

I have change white from 255 to 1 and black to 0. but my loss are always nan image_0561

image_0561

sagieppel commented 5 years ago

The image above (the black one) has a maximum pixel value of 48 and depth of three. If you have two class the only allowed value are 0 and 1. And the image must be 2d (depth of 0) You can check it yourself by running:

import scipy.misc as misc Label=misc.imread(LabelFileName) print("Label Max Value "+str(Label.max())) print("Label shape "+str(Label.shape))

A simple way to convert your label map to 2d and remove values above 1 is: import numpy as np import scipy.misc as misc Label=misc.imread(LabelFileName) LabelFixed=(Label[:,:,0]==1).astype(np.uint8) print("Fixed Label Max Value "+str(Label.max())) print("Fixed Label shape "+str(LabelFixed.shape)) misc.imsave(LabelFileName,LabelFixed)

leishi2018 commented 5 years ago

Thank you for your code, my data can be used,but some steps later it comes that

and my labels dont have this shape(327x383x3) of photo. my labels(60 photos) are all ok by use your code for checking.

------------------ 原始邮件 ------------------ 发件人: "sagieppel"notifications@github.com; 发送时间: 2018年12月19日(星期三) 凌晨5:22 收件人: "sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation"Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation@noreply.github.com; 抄送: "火焰舞者"523997174@qq.com; "Author"author@noreply.github.com; 主题: Re:[sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation]TRIAN.PY ISSUES (#10)

The image above (the black one) has a maximum pixel value of 48 and depth of three. If you have two class the only allowed value is 0 and 1. And the image must be 2d depth of 0 You can check it yourself by using:

import scipy.misc as misc Label=misc.imread(LabelFileName) misc.imshow((Label==1).astype(float)) print("Label Max Value "+str(Label.max())) print("Label shape "+str(Label.shape))

A simple way to convert your label to 2d and remove values above 1 is: import numpy as np import scipy.misc as misc Label=misc.imread(LabelFileName) LabelFixed=(Label[:,:,0]==1).astype(np.uint8) print("Fixed Label Max Value "+str(Label.max())) print("Fixed Label shape "+str(LabelFixed.shape)) misc.imsave(LabelFileName,LabelFixed)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

leishi2018 commented 5 years ago

Hi, thank you. mine can work. because one Label is wrong.

------------------ 原始邮件 ------------------ 发件人: "sagieppel"notifications@github.com; 发送时间: 2018年12月19日(星期三) 凌晨5:22 收件人: "sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation"Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation@noreply.github.com; 抄送: "火焰舞者"523997174@qq.com; "Author"author@noreply.github.com; 主题: Re:[sagieppel/Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation]TRIAN.PY ISSUES (#10)

The image above (the black one) has a maximum pixel value of 48 and depth of three. If you have two class the only allowed value is 0 and 1. And the image must be 2d depth of 0 You can check it yourself by using:

import scipy.misc as misc Label=misc.imread(LabelFileName) misc.imshow((Label==1).astype(float)) print("Label Max Value "+str(Label.max())) print("Label shape "+str(Label.shape))

A simple way to convert your label to 2d and remove values above 1 is: import numpy as np import scipy.misc as misc Label=misc.imread(LabelFileName) LabelFixed=(Label[:,:,0]==1).astype(np.uint8) print("Fixed Label Max Value "+str(Label.max())) print("Fixed Label shape "+str(LabelFixed.shape)) misc.imsave(LabelFileName,LabelFixed)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.