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

keras InvalidArgumentError: Incompatible shapes: [10,1] vs. [10,60,60,3600] #14268

Closed
molo32 opened this issue Nov 3, 2020 · 3 comments
Closed
Assignees
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@molo32
Copy link

molo32 commented Nov 3, 2020

I am trying to train an anime face dataset on an autoencoder. but at the time of training it gives me this error.

InvalidArgumentError: Incompatible shapes: [10,1] vs. [10,60,60,3600]

I have a folder with 63,565 color images of anime faces and each image has a different size.

what am I doing wrong?


# importing libraries 
!mkdir /content/anime
!mv /content/images /content/anime
from keras.preprocessing.image import ImageDataGenerator 
from keras.models import Sequential 
train_datagen = ImageDataGenerator() 
  
 




import keras
from keras import layers

# This is the size of our encoded representations
encoding_dim = 32  # 32 floats -> compression of factor 24.5, assuming the input is 784 floats




ancho=60
alto=60
n_pixels=alto*ancho


train_generator = train_datagen.flow_from_directory("/content/anime", 
                              target_size =(ancho, alto), 
                     batch_size =10)

# This is our input image
input_img = keras.Input(shape=(n_pixels,3))

# "encoded" is the encoded representation of the input
encoded = layers.Dense(encoding_dim, activation='relu')(input_img)
# "decoded" is the lossy reconstruction of the input
decoded = layers.Dense(n_pixels, activation='sigmoid')(encoded)


# This model maps an input to its reconstruction
autoencoder = keras.Model(input_img, decoded)

# This model maps an input to its encoded representation
encoder = keras.Model(input_img, encoded)




# This is our encoded (32-dimensional) input
encoded_input = keras.Input(shape=(encoding_dim,))#la salid del encoder osea la entrada del decoder
# Retrieve the last layer of the autoencoder model
decoder_layer = autoencoder.layers[-1]
# Create the decoder model
decoder = keras.Model(encoded_input, decoder_layer(encoded_input))


autoencoder.compile(optimizer='adam', loss='mse')
from keras.datasets import mnist
import numpy as np
autoencoder.fit(train_generator,
                epochs=10,
                batch_size=10)


Epoch 1/10
WARNING:tensorflow:Model was constructed with shape (None, 3600, 3) for input Tensor("input_1:0", shape=(None, 3600, 3), dtype=float32), but it was called on an input with incompatible shape (None, None, None, None).
WARNING:tensorflow:Model was constructed with shape (None, 3600, 3) for input Tensor("input_1:0", shape=(None, 3600, 3), dtype=float32), but it was called on an input with incompatible shape (None, None, None, None).
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-13-1b5b29a94954> in <module>()
      5 autoencoder.fit(train_generator,
      6                 epochs=10,
----> 7                 batch_size=10)

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:  Incompatible shapes: [10,1] vs. [10,60,60,3600]
     [[node mean_squared_error/SquaredDifference (defined at <ipython-input-13-1b5b29a94954>:7) ]] [Op:__inference_train_function_2136]

Function call stack:
train_function
@saikumarchalla saikumarchalla added the type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. label Nov 10, 2020
@sushreebarsa sushreebarsa self-assigned this Oct 18, 2021
@sushreebarsa
Copy link
Contributor

sushreebarsa commented Oct 18, 2021

@molo32
In order to expedite the trouble-shooting process, please provide a code snippet to reproduce the issue reported here. Could you please try to execute your code using TF v2.6.0 and let us know if the issue still persists ? Please refer to a similar issue as well. Thanks!

@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

4 participants