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
Tensorflow keras LSTM功能API多输入_Tensorflow_Keras_Lstm_Multiple Input - Fatal编程技术网

Tensorflow keras LSTM功能API多输入

Tensorflow keras LSTM功能API多输入,tensorflow,keras,lstm,multiple-input,Tensorflow,Keras,Lstm,Multiple Input,我试图使用两个输入来训练LSTM模型:价格和情绪,在规范化这两个数据:trainX和trainS后,我按照keras文档训练模式 print(trainX.shape) print(trainS.shape) (22234, 1, 51) --> 51 is because these datasets are time sequence, and I look back for 51 hours of the history price data (22285, 1) 代码基本上遵循多

我试图使用两个输入来训练LSTM模型:价格和情绪,在规范化这两个数据:trainX和trainS后,我按照keras文档训练模式

print(trainX.shape)
print(trainS.shape)
(22234, 1, 51) --> 51 is because these datasets are time sequence, and I look back for 51 hours of the history price data
(22285, 1)
代码基本上遵循多输入文件: 但是当我适合这个模型时,我犯了错误

Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[[0., 0., 0., ..., 0., 0., 0.]],

       [[0., 0., 0., ..., 0., 0., 0.]],

       [[0., 0., 0., ..., 0., 0., 0.]],

       ...,

       [[0., 0., 0., ..., 0., 0., 0.]],

       [[0., 0., 0., ....


model fit调用必须传递np.Array列表,以使其批大小相同,并且剩余维度必须与为输入/目标定义的维度匹配

i、 你需要打电话

model.fit([input0, input1], [output0, output1])

所有这些都需要具有相同的形状[0]

我注意到您的代码中有以下内容:

main_input = Input(shape=(trainX.shape[0],)

这是不正确的。您希望输入的形状为
trainX.shape[1://code>。无需定义批量大小,但您必须定义其他维度。

但如果我在main_输入中使用trainX.shape[1:],则会出现错误:将形状转换为TensorShape:int()参数时出错必须是字符串、类似字节的对象或数字,而不是“tuple”
shape=
参数需要一个可以表示为
(int,)的元组
或作为现有元组的切片,如
trainX.shape[1://code>。i、 括号用于构造元组,因此如果元组上有一个切片,则不要添加额外的括号。您的意思是:Input(shape=trainX.shape[1:],dtype='int32',name='main_Input')?但它仍然有错误:输入0与层lstm_27不兼容:预期ndim=3,发现ndim=4。此外,我还有一个问题:[输出0,输出1]我应该在这里输入什么?也许需要花时间一步一步地阅读教程。您可能不希望trainX的ndim=4(除非它是图像)。
main_input = Input(shape=(trainX.shape[0],)