question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I’m having the similar trouble as in #26. Not sure if I’m doing something wrong or if there’s a fix. I’m using my own image dataset all scaled to 96x96. Stack trace below.

Image: PNG 96x96 96x96+0+0 8-bit sRGB 7.2KB 0.000u 0:00.000

Traceback (most recent call last):
  File "main.py", line 99, in <module>
    tf.app.run()
  File "/home/ubuntu/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "main.py", line 82, in main
    dcgan.train(FLAGS)
  File "/home/ubuntu/GANs/model.py", line 186, in train
    sample_inputs = np.array(sample).astype(np.float32)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:28 (1 by maintainers)

github_iconTop GitHub Comments

26reactions
Zhangtdcommented, Nov 30, 2017

I had the same problem before. It is because there are grey scale images in my data. I solved this by:

from PIL import Image
img = Image.open(img_name).convert('RGB')
# your own image operations 

Simply converting grey scale image to RGB image is OK.

21reactions
empireshadescommented, Apr 27, 2017

I was able to fix this issue by:

  1. Ensuring that all images in my dataset were the exact same size.
cd data/mypics
# Create dir to store images that aren't the same size`
mkdir misshaped
# Identify misshaped images using Imagemagick's 'identify' tool 
and move to above dir. (Replace with your desired resolution)
identify * | grep -v "600x450" | awk '{ print $1 }' | xargs -I {} bash -c "mv {} misshaped"
  1. Ensuring that all images had the same number of colors. In my case I was using color JPGs and I found a handful of Grayscale images.
identify -format "%i %[colorspace]\n" IMG_*.jpg | grep -v sRGB
IMG_4959.jpg Gray
IMG_4960.jpg Gray
IMG_4961.jpg Gray
IMG_4962.jpg Gray
IMG_7356.jpg Gray
IMG_7630.jpg Gray

After I took care of these, it worked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: could not broadcast input array from shape ...
At least one item in your list is either not three dimensional, or its second or third dimension does not match the other...
Read more >
Valueerror: could not broadcast input array from shape
The error message "Valueerror: could not broadcast input array from shape" basically means that pandas won't be able to remove two data frames...
Read more >
Could Not Broadcast Input Array From Shape (27839,1) Into ...
ValueError : could not broadcast input array from shape 96964 into shape in main dcgan.trainFLAGS File /home/ubuntu/GANs/model.py line is 400x300x3 and JPEG but ......
Read more >
ValueError could not broadcast input array from shape 360 ...
In the above error it shows could not broadcast input array from shape (360,270,3) into shape (360,280,3), means you are tying to exchange ......
Read more >
Python Error ""ValueError: could not broadcast input array ...
Your data generator retrieves your labels as categorical and based on the error, I assume you have 4 classes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found