简体   繁体   中英

Can't pass validation_data to a model with several inputs in Keras

I've got a model with two inputs and a single output:

...
model = models.Model([l_in_wv, l_in_ng], [l_out])
model.compile(optimizer="Adam", loss=loss_fn, metrics=[...], sample_weight_mode="temporal")
model.fit([tokens_wv_j, tokens_ng_j], anno_onehot, validation_split=0.2  verbose=1, epochs=20, batch_size=400, sample_weight=sample_weights, callbacks=[checkpoint])

It trains fine as long as I don't try to pass a separate dataset as validation_data , eg

model.fit([tokens_wv_j, tokens_ng_j], anno_onehot, validation_data=[[tokens_wv_j_val, tokens_ng_j_val], anno_j_val], verbose=1, epochs=20, batch_size=400, sample_weight=sample_weights, callbacks=[checkpoint])

If I try to do this, the model instantly raises this error

ValueError: Error when checking target: expected l_out to have 3 dimensions, but got array with shape (131943, 50)

I've tried changing the way I pass the dataset to ([tokens_wv_j_val, tokens_ng_j_val], anno_j_val) or ((tokens_wv_j_val, tokens_ng_j_val), anno_j_val) or even (tokens_wv_j_val, tokens_ng_j_val, anno_j_val) (which is obviously wrong, because in this case the third array is considered sample_weights ) , but all options only result in a slightly different error message. Is this feature supported? The documentation on multiple-input models tells nothing about it.

好吧....如果训练有效,您只需要确保这些形状匹配即可,除了拳头尺寸(批量大小):

  • tokens_wv_j.shape[1:] = tokens_wv_j_val.shape[1:]
  • tokens_ng_j.shape[1:] = tokens_ng_j_val.shape[1:]
  • anno_onehot.shape[1:] = anno_j_val.shape[1:]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM