0

I was working on Sequential model for plant disease detection problem.
Initially I used an image_list=[] and converted images to array using img_to_array(image)
My next step was to use test_train_split but before that I need to convert this list to array hence I used this:
im_list=np.array(image_list,dtype=np.float16)/255.0
But this line throws "ValueError: could not broadcast input array from shape (64,64,3) into shape (64,64)."
I understand it's an image list but generally it should convert a 3-D list to array as I tried with a sample list which it converted successfully. I don't get why this wouldn't work!!
::[UPDATE]::
PS: If the answers posted on the similar post doesn't help your issue. ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)

and if you cannot modify the dimensions or implement .astype() as stated in that post!!. Try using the below function:

if len(img.shape)>2 and img.shape[2]==4:
        img=cv2.cvtColor(img,cv2.COLOR_BGRA2BGR)

This generally happens when there's a 'PNG' image in the dataset.
Sample Trial:

li=np.random.rand(10,10,2)
lii=np.array(li,dtype=np.float16)

Variable Explorer:

enter image description here

Terminal Window:
enter image description here

  • What do you mean, "you tried the answers"? The link answers tell us that one or more of your images has a different shape from the others. Did you identify that array? It's likely that you have a mix of color and b/w images. – hpaulj Jun 19 '20 at 07:09
  • @hpaulj I wrote a small snippet that checks if ndim(arr)==3, if not, it should print the image name and exit the program. But as a matter of fact the program ran completely without any trouble for some reason. And again got stuck at ValueError. Hence I came back to update this section. – Shashank Shukla Jun 19 '20 at 08:02
  • A (64,64,1) would also give problems. The arrays in the list differ in the 3rd dimension. Examine `shape` for all those arrays. – hpaulj Jun 19 '20 at 08:09
  • @hpaulj, thanks, I did a arr.shape check and it comes out that few images have 4 channels somehow!! And I rechecked that this problem was already answered in that post. I feel so foolish rn. I'll fix up this post later on. – Shashank Shukla Jun 19 '20 at 08:53

0 Answers0