Numpy - How to reshape odd array sizes?
You cannot reshape an array of n elements into an array of m elements if n and m are not equal. The operation of reshaping an array is really just the operation of obtaining a new view of the same array.
Your input array has n=1*7*7*2048=100353 elements while you're trying to reshape to an array with m=1*1*1*2048=2048 elements.
As pointed out by hpaulj, your problem lies in your input shape. From the shapes you mention, (1, 7, 7, 2048) and (1, 1, 1, 2048), it looks like your expected input should probably be extracted from a later layer (maybe after a global pooling stage) but we cannot say much more without more details on your models.
I have a TensorFlow model in which I want to pass an image to it in order for it to determine the object within the image.
However, the model is complaining of the shape of the image saying it wants it in the form (1, 1, 1, 2048) however it's receiving (1, 7, 7, 2048).
I have tried doing a numpy.reshape() on the image by doing either numpy.reshape(myObj, (1, 1, 1, 2048)) or numpy.reshape(myObj, (1, 1, 1, -1)). However, the former just complains that it can't reshape array of size 100352 to (1, 1, 1, 2048) and the latter resizes the last element of the array to the multiple of (7, 7, 2048), i.e. 100352.
How would one go about reshaping an odd array size, or is this not how Numpy shapes/reshapes work? Is there an alternative way to do what I'm asking for if not possible with Numpy?