我正在尝试在自动编码器上训练动漫人脸数据集。 但是在训练时却给了我这个错误。
InvalidArgumentError: Incompatible shapes: [10,1] vs. [10,60,60,3600]
我有一个文件夹,其中包含63565张动漫面孔的彩色图像,并且每张图像的尺寸都不同。
我在做什么错了?
# 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