2017-05-26 6 views
1

私は列車とテストに分割された1つのデータセット(MNIST btw)を持っていますが、どちらもまったく同じ形状です。私は列車の部分で畳み込みオートエンコーダーを訓練し、fit()関数呼び出しで以下に示すようにバリデーションのために他のものを使用します。損失が得るとき、私は、最初のエポックの後、それらを使用する場合Kerasモデルのfit()関数に有効な検証データの形状ミスマッチ?

は、コードが(列データのすなわち、鉄道模型と良い結果を提供します)完璧に動作し、私はvalidation_data=(x_test,x_test) を削除しかし、私はvalidation_dataを使用する必要がある場合は、問題があります列車データで計算され、テストデータの計算が必要な場合は、エラーが表示されます。

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

どのように解決できますか?

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

答えて

0

[OK]をクリックすると、問題の原因がわかりました。 明らかに、write_imagesがtrueに設定されたテナーボードコールバックを使用している場合。 畳み込みレイヤの視覚化を画像として書き込む際に問題があります。ディメンションの不一致があるためです。私が理解しているように、そのようなデバッグデータは、検証データが利用可能な場合に書き出されます。 write_imagesをfalseに設定すると、すべて正常に動作します。

関連する問題