我制作了一个模型(模型 1),它以 31 个不同的数组作为输入。它由 31 个输入层组成,这些输入层在下一层一起计算(使用连接层)。这种多输入模型工作得很好。
但是,我想添加更多信息。因此,我添加了一个模型(模型 2),该模型将一个数组作为输入,然后将两个模型(1 和 2)的结果输入一个连接层,该层作为最后一个模型(模型 3)的输入进行回归。
但是现在最后一个模型的拟合方法不起作用。
history = modelConcatenate.fit(x=[trainSet, train.drop(trait, axis=1).iloc[:, 44479:].values],
y=train[trait[i]].values,
validation_data=([testSet, test.drop(trait, axis=1).iloc[:, 44479:].values],
test[trait[i]].values),
epochs=200, callbacks=[history], verbose=0, batch_size=10)
trainSet 是 31 个数组(第一个模型的输入)的数组,train 包含模型 2 的输入。
训练时出现以下错误:
ValueError Traceback (most recent call last)
<ipython-input-16-a7f53b631b76> in <module>
----> 1 evaluationMulti(cnn=False)
<ipython-input-14-0cc8c088dbd1> in evaluationMulti(cnn)
74 validation_data=([testSet, test.drop(trait, axis=1).iloc[:, 44479:].values],
75 test[trait[i]].values),
---> 76 epochs=200, callbacks=[history], verbose=0, batch_size=10)
77 end = time.time()
78 print("tempsd'entrainement: ", end-start)
/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
725 max_queue_size=max_queue_size,
726 workers=workers,
--> 727 use_multiprocessing=use_multiprocessing)
728
729 def evaluate(self,
/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/engine/training_arrays.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs)
641 steps=steps_per_epoch,
642 validation_split=validation_split,
--> 643 shuffle=shuffle)
644
645 if validation_data:
/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, batch_size, check_steps, steps_name, steps, validation_split, shuffle, extract_tensors_from_dataset)
2469 feed_input_shapes,
2470 check_batch_axis=False, # Don't enforce the batch size.
-> 2471 exception_prefix='input')
2472
2473 # Get typespecs for the input data and sanitize it if necessary.
/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
502 elif isinstance(data, (list, tuple)):
503 if isinstance(data[0], (list, tuple)):
--> 504 data = [np.asarray(d) for d in data]
505 elif len(names) == 1 and isinstance(data[0], (float, int)):
506 data = [np.asarray(data)]
/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/engine/training_utils.py in <listcomp>(.0)
502 elif isinstance(data, (list, tuple)):
503 if isinstance(data[0], (list, tuple)):
--> 504 data = [np.asarray(d) for d in data]
505 elif len(names) == 1 and isinstance(data[0], (float, int)):
506 data = [np.asarray(data)]
/usr/lib/python3/dist-packages/numpy/core/numeric.py in asarray(a, dtype, order)
536
537 """
--> 538 return array(a, dtype, copy=False, order=order)
539
540
ValueError: could not broadcast input array from shape (804,3482) into shape (804)
804 是训练集的大小,3482 是第一个模型的第一个数组的大小。我不明白为什么使用 31 个输入的数组对模型 1 有效,但现在使用 2 个输入的数组却不行。