InvalidArgumentError: Input to reshape is a tensor with 1 values, but the requested shape has 784 [Op:Reshape]

In Week4 assignment, I successfully trained the model and see the generated 31 images

I selected 16 images and then run the sample code you have for zipping those images

from PIL import Image
from zipfile import ZipFile

denormalized_images = grading_images * 255
denormalized_images = tf.dtypes.cast(denormalized_images, dtype = tf.uint8)

file_paths = []

for this_image in range(0,16):
  i = tf.reshape(denormalized_images[this_image], [28,28])
  im = Image.fromarray(i.numpy())
  im = im.convert("L")
  filename = "hand" + str(this_image) + ".png"
  file_paths.append(filename)
  im.save(filename)

with ZipFile('my-signs.zip', 'w') as zip:
  for file in file_paths:
    zip.write(file)

But this gives me error in this line i = tf.reshape(denormalized_images[this_image], [28,28]) and says that

InvalidArgumentError: Input to reshape is a tensor with 1 values, but the requested shape has 784 [Op:Reshape]

What am I missing?

Hi,

the error says the input is not the right for tf.reshape.

obviously you are not filling anything is this paragraph but check the size of fake images (numpy) generated from the model, it should be such that it can reshape to 28 by 28. And also did you choose the best 16 looking images in the “Please fill in the empty list (2nd parameter) with 16 indices indicating the images you want to submit to the grader.”?

Please give me another hint, I can not find the error

Hi,

Its been a long time since this error came first. I think the whole problem has to do with the reshaping of the image from 28 by 28 pixels to flattened vector of 784 or vice versa. What the error saying in your case by the way?