Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidArgumentError: Input to reshape is a tensor with 313600 values, but the requested shape requires a multiple of 4608 #6249

Closed
kazoo-kmt opened this issue Dec 11, 2016 · 9 comments

Comments

@kazoo-kmt
Copy link

When I implemented this (https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py) by TensorFlow, I had an issue on reshaping. When I tried to flatten 12 * 12 * 32 tensor, I had an error message saying
tensorflow.python.framework.errors.InvalidArgumentError: Input to reshape is a tensor with 313600 values, but the requested shape requires a multiple of 4608 [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](dropout/mul, Reshape_1/shape)]]

I tried to match the input shape, but the error message said "a tensor with 313600 values" which I had no idea where this came from. Therefore, I thought this might be an issue on TensorFlow.

All the code and error message are uploaded here. http://stackoverflow.com/questions/40955223/tensorflow-python-framework-errors-invalidargumenterror-input-to-reshape-is-a-t

What related GitHub issues or StackOverflow threads have you found by searching the web for your problem?

http://stackoverflow.com/questions/38397258/error-tensorflow-cnn-dimension
#2048

Environment info

Operating System: macOS Sierra 10.12.1
Python 3.5.1

Installed version of CUDA and cuDNN:
(please attach the output of ls -l /path/to/cuda/lib/libcud*):
No such file or directory

If installed from binary pip package, provide:

  1. A link to the pip package you installed: pip install tensorflow
  2. The output from python -c "import tensorflow; print(tensorflow.__version__)".
    0.11.0rc1

If installed from source, provide

  1. The commit hash (git rev-parse HEAD)
  2. The output of bazel version

If possible, provide a minimal reproducible example (We usually don't have time to read hundreds of lines of your code)

What other attempted solutions have you tried?

I tried the following solutions and I confirmed that I defined the target image for reshaping/flattening.
http://stackoverflow.com/questions/38397258/error-tensorflow-cnn-dimension
#2048

Logs or other output that would be helpful

(If logs are large, please upload as attachment or provide link).
I wrote all the code and errors here.
http://stackoverflow.com/questions/40955223/tensorflow-python-framework-errors-invalidargumenterror-input-to-reshape-is-a-t

@michaelisard
Copy link

I'm sorry that nobody has answered on stackoverflow yet, but that is really the correct forum for this kind of usage question. Have you tried printing out the values of intermediate tensors e.g. h_conv1, h_conv2, h_pool, h_drop1? That should show you the shapes of all of them and help you understand where the tensor of size 313600 is coming from.

@kazoo-kmt
Copy link
Author

Thanks. if I type h_flat after h_flat = tf.reshape(h_drop1, [-1, 12*12*32]), the output is <tf.Tensor 'Reshape_4:0' shape=(?, 4608) dtype=float32>. Or, if I type h_flat.get_shape(), then the output is TensorShape([Dimension(None), Dimension(4608)]).

@kazoo-kmt
Copy link
Author

The error was from a shape mismatch. After I changed conv2 to'VALID' from 'SAME', it worked.

@FypTeamFast2019TumorDetection
Copy link

FypTeamFast2019TumorDetection commented Sep 9, 2018

We answered this problem which is also related to architecture Understand this in following link
https://stackoverflow.com/questions/46465925/input-to-reshape-is-a-tensor-with-37632-values-but-the-requested-shape-has-1505/52240509#52240509
Let us know if you face any issue

@freedom9393
Copy link

In my case, an image size and my model's input shape were different. Please check your image size again and again. Cuz, I've spent pretty long time on fixing this problem

@Srinikethan-R
Copy link

The error was from a shape mismatch. After I changed conv2 to'VALID' from 'SAME', it worked.

where can I find conv2 ?

@jeevan-tt
Copy link

Epoch 1/25

InvalidArgumentError Traceback (most recent call last)
in ()
----> 1 cnn.fit(x = training_set, validation_data = test_set, epochs = 25)

8 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 ctx.ensure_initialized()
59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:

InvalidArgumentError: Input to reshape is a tensor with 3936256 values, but the requested shape requires a multiple of 6272
[[node sequential_5/flatten_4/Reshape (defined at :1) ]] [Op:__inference_train_function_3715]

Function call stack:
train_function

@pawarhrishi21
Copy link

pawarhrishi21 commented Dec 17, 2020

Epoch 1/25

InvalidArgumentError Traceback (most recent call last)
in ()
----> 1 cnn.fit(x = training_set, validation_data = test_set, epochs = 25)

8 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 ctx.ensure_initialized()
59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:

InvalidArgumentError: Input to reshape is a tensor with 3936256 values, but the requested shape requires a multiple of 6272
[[node sequential_5/flatten_4/Reshape (defined at :1) ]] [Op:__inference_train_function_3715]

Function call stack:
train_function
@jeevan-tt
Facing the same error, Still cannot figure out the problem. Did you resolve the error?

@MahyarFardin
Copy link

MahyarFardin commented Feb 18, 2022

Hi the reason for this error is because of the shape of input check all of your input it may seem that all of them have the same shape but you may find some of them in wired shapes like 28283*3 as you see the third dimension is unusable.

Solves

when you use image flow define your shape as (28,28)

some times you may define input shape to all of the layers recall that you should define it only for the first layer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants