CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Value error when testing with image

Open aench2023 opened this issue 9 years ago • 11 comments

Hi,

I am getting the following error, when I try predicting with an image:

ValueError: Value::Create: The shape '[4 x 32 x 32]' of sequence #0 is not compatible with the sample shape '[3 x 32 x 32]'.

aench2023 avatar Sep 13 '17 07:09 aench2023

Are you sending in 4-channel images instead of 3-channel images?

cha-zhang avatar Sep 14 '17 04:09 cha-zhang

I am not sure...what is the difference between an 4 channel image and 3 channel image, should I convert the images to 3 channel..

aench2023 avatar Sep 14 '17 04:09 aench2023

Some images are RGB (3 channel), some are RGBA (4 channel). You need to get rid of the 4th channel before sending it into eval.

cha-zhang avatar Sep 14 '17 04:09 cha-zhang

Thanks! Do you have sample code?...

aench2023 avatar Sep 14 '17 05:09 aench2023

How do you feed your data? Via Numpy? Just slice the numpy array.

cha-zhang avatar Sep 14 '17 05:09 cha-zhang

I am using the following statement myimg = np.array(PIL.Image.open(urlopen(url)), dtype=np.float32) this is the first I am working with python, could you give a suggestion as to how to slice the myimg array, thanks!

aench2023 avatar Sep 14 '17 05:09 aench2023

Then I suggest you check this example: https://github.com/Microsoft/CNTK/blob/master/Examples/Image/FeatureExtraction/FeatureExtraction.py This manual might also be helpful: https://github.com/Microsoft/CNTK/blob/master/Manual/Manual_How_to_feed_data.ipynb

cha-zhang avatar Sep 14 '17 05:09 cha-zhang

BTW, PIL.Image.convert can do the conversion to RGB mode. You may still need to convert to BGR before sending into CNTK for eval.

cha-zhang avatar Sep 14 '17 05:09 cha-zhang

Thank you so much! Should I also convert the images that I use for training to RGB mode and BGR?

aench2023 avatar Sep 14 '17 13:09 aench2023

Whatever format your input training data format was, you need to replicate the same format for testing/evaluating.

sayanpa avatar Sep 18 '17 17:09 sayanpa

Hope this has been resolved. Close due to inactivity.

cha-zhang avatar Oct 13 '17 00:10 cha-zhang