Python 如何使用多输入的KERA生成序列数据?

Python 如何使用多输入的KERA生成序列数据?,python,tensorflow,keras,generator,autoregressive-models,Python,Tensorflow,Keras,Generator,Autoregressive Models,我正在为keras中的序列对序列问题编写VAE。解码器是一个自回归模型,所以我有两个不同的输入,一个用于编码器,另一个用于解码器(移位1,但这不是问题)。 我还想做数据扩充,所以我决定使用fit_generator()方法,但在返回两个输入时遇到了一些问题 我试图返回两个输入向量的列表,如下所示 类数据生成器(序列): 定义初始化(。。。。 定义uu获取项目uu(自身,索引): 数据=创建_数据() 返回[数据,数据] 或者像这样的字典 返回{“编码器输入名称”:“数据,解码器输入名称”:数据

我正在为keras中的序列对序列问题编写VAE。解码器是一个自回归模型,所以我有两个不同的输入,一个用于编码器,另一个用于解码器(移位1,但这不是问题)。 我还想做数据扩充,所以我决定使用fit_generator()方法,但在返回两个输入时遇到了一些问题

我试图返回两个输入向量的列表,如下所示

类数据生成器(序列):
定义初始化(。。。。
定义uu获取项目uu(自身,索引):
数据=创建_数据()
返回[数据,数据]
或者像这样的字典

返回{“编码器输入名称”:“数据,解码器输入名称”:数据}
其中数据是形状的numpy张量(批量大小、最大序列长度、输入尺寸)

我不能只使用同一个输入层,因为稍后两个输入会有点不同,正如我所说的,解码器输入将被一个不同的第一个元素和其他原因移位

当我返回列表[数据,数据]或出现以下错误时:

ValueError: 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
batch_size = x.shape[0]
AttributeError: 'str' object has no attribute 'shape'
当我返回字典时,出现以下错误:

ValueError: 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
batch_size = x.shape[0]
AttributeError: 'str' object has no attribute 'shape'
我如何解决这个问题

多谢各位

编辑

我将
\uuu getitem\uu
的输出更改为
[inpuut_1,input_2],][/code>成功了。

您应该从生成器/序列实例返回一个元组。元组的第一个元素是输入数组列表(如果您的模型有一个输入层,则只有一个数组),第二个元素是输出数组列表(如果模型有一个输出层,则仅一个阵列)

因此,
\uuu getitem\uuu
应该返回如下内容:

def __getitem__(self, index):
    # ...
    return  [inp_arr1, inp_arr2, ...], [out_arr1, out_arr2, ...]  # IMPORTANT: this is a tuple

我没有输出对象,所以我必须返回[inp_1,inp_2],][@MarioBonsembiante你的意思是你的模型没有输出???!那么是的,可能是
[inp_1,inp_2],没有
[inp_1,inp_2],][/code>。我试过
[input_1,input_2],][/code>,它成功了。谢谢!