Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Keras模型上,验证数据给定的fit()函数的形状不匹配?_Python_Tensorflow_Keras_Keras Layer - Fatal编程技术网

Python 在Keras模型上,验证数据给定的fit()函数的形状不匹配?

Python 在Keras模型上,验证数据给定的fit()函数的形状不匹配?,python,tensorflow,keras,keras-layer,Python,Tensorflow,Keras,Keras Layer,我有一个数据集(MNIST btw),分为训练和测试,两者的形状完全相同。我在训练部分训练卷积自动编码器,并使用另一个进行验证,如下面的fit()函数调用所示 如果我删除validation\u data=(x\u test,x\u test) 但我必须使用验证_数据,问题是当我使用它们时,在第一个历元之后,当在列车数据上计算损失并需要计算测试数据时,我得到一个错误: 纪元1/5 896/1000[===============================>…]-预计到达时间:0s-损失:

我有一个数据集(MNIST btw),分为训练和测试,两者的形状完全相同。我在训练部分训练卷积自动编码器,并使用另一个进行验证,如下面的fit()函数调用所示

如果我删除
validation\u data=(x\u test,x\u test)
但我必须使用验证_数据,问题是当我使用它们时,在第一个历元之后,当在列车数据上计算损失并需要计算测试数据时,我得到一个错误:

纪元1/5 896/1000[===============================>…]-预计到达时间:0s-损失: 0.6677-------------------------------------------------------------InvalidArgumentError回溯(最近的调用) 最后)

InvalidArgumentError:张量必须为4-D,最后一个尺寸为1、3或4,而不是 [1,3,3,8,8,1] [[Node:conv2d\u 3/kernel\u 0\u 1=ImageSummary[T=DT\u FLOAT,bad\u color=Tensor, 最大图像数=3

我如何解决这个问题

(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])`

好的,我找到了问题所在。 显然,在将write_images设置为true的情况下使用tenorboard回调时。
将卷积层的可视化写入图像时出现问题。因为存在维度不匹配。据我所知,在验证数据可用的情况下,会写入此类调试数据。如果将写入图像设置为false,则一切正常。

好的,我找到了问题所在。 显然,在将write_images设置为true的情况下使用tenorboard回调时。 将卷积层的可视化写入图像时存在问题。因为存在维度不匹配。据我所知,在验证数据可用的情况下,会写入此类调试数据。如果将write_图像设置为false,则一切正常