带有TPU的tf.keras:使用验证时,多个输入会引发错误

时间:2019-07-20 07:48:07

标签: tensorflow keras tpu

我正在尝试在Google colab中的TPU上训练RNN模型。当我有一个输入和多个输出时,它工作正常,但是当我添加另一个输入时,它与火车数据集一起工作,但对验证却不起作用-即使我将火车数据集用作验证数据集,也是如此?

我想知道为什么会这样-因为数据集的形状应该相同。

如果有人能指出为什么会引发错误

  

“ ValueError:图层BarcodeType的输入0与   层:输入形状的预期轴-1的值为51200,但   收到形状为[128,320000]“的输入   应该是一样的吗?

这是生成数据集的代码:

def train_input_fn(batch_size, textChars, textWords, barcodeY, barcodeTypeY, cvcY):

    # Convert the inputs to a Dataset.
    #dataset = tf.data.Dataset.from_tensor_slices((X_placeholder, {"barcode": barcodeY_placeholder, "cvc": cvcY_placeholder })) #"barcodeType": barcodeTypeY.astype('int32'), 
    dataset = tf.data.Dataset.from_tensor_slices(({"text_input": textChars, "textWord_input": textWords}, {"barcode": barcodeY, "cvc": cvcY, "barcodeType": barcodeTypeY.astype('int32') }))
# Shuffle, repeat, and batch the examples.
    dataset = dataset.cache()
    dataset = dataset.shuffle(1024)
    dataset = dataset.repeat()
    dataset = dataset.batch(batch_size, drop_remainder=True)
# Return the dataset.
    return dataset

这是第二个输入(引发错误的输入)的前几层的外观:

textWord_input (InputLayer)     [(128, 200)]         0                                            
__________________________________________________________________________________________________
leaky_re_lu_4 (LeakyReLU)       (128, 36, 256)       0           bidirectional_2[0][0]            
__________________________________________________________________________________________________
embedding_1 (Embedding)         (128, 200, 500)      4322000     textWord_input[0][0]             
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (128, 36, 256)       1024        leaky_re_lu_4[0][0]              
__________________________________________________________________________________________________
bidirectional_3 (Bidirectional) (128, 200, 256)      644096      embedding_1[0][0]

这是我得到的错误:

Epoch 1/10000
5/6 [========================>.....] - ETA: 5s - loss: 3.8790 - barcode_loss: 0.6839 - cvc_loss: 0.6946 - barcodeType_loss: 2.5005 - barcode_acc: 0.8019 - cvc_acc: 0.7826 - barcodeType_acc: 0.8883 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-22-b63a2ed1735e> in <module>()
     15     #validation_data=validation_data, #validationCVC, validationStore
     16     #validation_steps=int(validationX.shape[0]/batch_size),
---> 17     callbacks=[checkpoint, earlyStopping] #TensorBoardColabCallback(tbc)
     18 )

19 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
    157                 ' incompatible with the layer: expected axis ' + str(axis) +
    158                 ' of input shape to have value ' + str(value) +
--> 159                 ' but received input with shape ' + str(shape))
    160     # Check shape.
    161     if spec.shape is not None:

ValueError: Input 0 of layer barcodeType is incompatible with the layer: expected axis -1 of input shape to have value 51200 but received input with shape [128, 320000]

0 个答案:

没有答案