Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation icon indicating copy to clipboard operation
Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation copied to clipboard

TRIAN.PY ISSUES

Open leishi2018 opened this issue 6 years ago • 13 comments

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 avatar Dec 14 '18 08:12 leishi2018

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)

leishi2018 avatar Dec 14 '18 08:12 leishi2018

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.

sagieppel avatar Dec 14 '18 14:12 sagieppel

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

leishi2018 avatar Dec 16 '18 05:12 leishi2018

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.

sagieppel avatar Dec 16 '18 10:12 sagieppel

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

------------------ 原始邮件 ------------------ 发件人: "sagieppel"[email protected]; 发送时间: 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; 抄送: "火焰舞者"[email protected]; "Author"[email protected]; 主题: 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 avatar Dec 17 '18 02:12 leishi2018

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

leishi2018 avatar Dec 17 '18 02:12 leishi2018

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

leishi2018 avatar Dec 17 '18 11:12 leishi2018

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.

sagieppel avatar Dec 17 '18 22:12 sagieppel

can you tell me how to set the number class.

------------------ 原始邮件 ------------------ 发件人: "sagieppel"[email protected]; 发送时间: 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; 抄送: "火焰舞者"[email protected]; "Author"[email protected]; 主题: 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 avatar Dec 18 '18 06:12 leishi2018

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

image_0561

leishi2018 avatar Dec 18 '18 12:12 leishi2018

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)

sagieppel avatar Dec 18 '18 21:12 sagieppel

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"[email protected]; 发送时间: 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; 抄送: "火焰舞者"[email protected]; "Author"[email protected]; 主题: 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 avatar Dec 19 '18 12:12 leishi2018

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

------------------ 原始邮件 ------------------ 发件人: "sagieppel"[email protected]; 发送时间: 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; 抄送: "火焰舞者"[email protected]; "Author"[email protected]; 主题: 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 avatar Dec 20 '18 04:12 leishi2018