J'ai 1 jeu de données (MNIST btw), divisé en train et test, les deux ont exactement la même forme. J'entraîne un Autoencoder convolutif sur la partie train et j'utilise l'autre pour la validation comme indiqué ci-dessous dans l'appel de la fonction fit().Forme Mistmatch sur les données de validation givent à la fonction fit() sur le modèle Keras?
Le code fonctionne parfaitement (c.-à-train modèle sur les données de train et donne de bons résultats) si je retire le validation_data=(x_test,x_test)
Mais je dois utiliser validation_data, le problème est quand je les utilise, après la première époque, lorsque la perte obtient calculé sur les données du train et doit être calculé pour les données de test, je reçois une erreur:
Epoch 1/5 896/1000 [=========================>....] - ETA: 0s - loss: 0.6677--------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last)
InvalidArgumentError: Tensor must be 4-D with last dim 1, 3, or 4, not [1,3,3,8,8,1] [[Node: conv2d_3/kernel_0_1 = ImageSummary[T=DT_FLOAT, bad_color=Tensor, max_images=3
Comment puis-je résoudre cela?
(x_train, _), (x_test, _) = mnist.load_data()
print("+++++++++++++++shape of x_train " , x_train.shape)
x_train = x_train.astype('float32')/255.
x_test = x_test.astype('float32')/255.
# adapt this if using `channels_first` image data format
x_train = np.reshape(x_train, (len(x_train), 28, 28, 1))
# adapt this if using `channels_first` image data format
x_test = np.reshape(x_test, (len(x_test), 28, 28, 1))
#TODO remove after i have solved the problem with the dim mismatch when using the validation dataset
x_train = x_train[range(1000),:,:,:]
x_test = x_test[range(1000),:,:,:]
# execute this in terminal to start tensorboard and let it watch the given logfile
# tensorboard --logdir=/tmp/autoencoder
tensorboardPath = os.path.join(os.getcwd(),"tensorboard")
tensorBoard = TensorBoard(log_dir=tensorboardPath,write_graph=True,write_images=True,histogram_freq=1, embeddings_freq=1, embeddings_layer_names=None)
checkpointer = ModelCheckpoint(filepath=os.path.join(os.getcwd(),"tensorboard"), verbose=1, save_best_only=True)
autoencoder.fit(x_train, x_train,
epochs=5,
batch_size=128,
shuffle=True,
validation_data=(x_test,x_test),
callbacks=[tensorBoard, checkpointer])`