Python 3.x 如何将函数映射到Tensorflow中的预批处理(';BatchDataset';)张量

Python 3.x 如何将函数映射到Tensorflow中的预批处理(';BatchDataset';)张量,python-3.x,tensorflow,machine-learning,keras,Python 3.x,Tensorflow,Machine Learning,Keras,我正在根据时间序列数据制作数据窗口(输入、输出窗口对)。我已经将我的时间序列转换为tf数据集,其中每个批次的时间步数等于我需要的总窗口大小 def make_dataset(data=train_df[0]): ds = tf.keras.preprocessing.timeseries_dataset_from_array( data=data, targets=None, sequence_length=total_window_si

我正在根据时间序列数据制作数据窗口(输入、输出窗口对)。我已经将我的时间序列转换为tf数据集,其中每个批次的时间步数等于我需要的总窗口大小

 def make_dataset(data=train_df[0]):
    ds = tf.keras.preprocessing.timeseries_dataset_from_array(
        data=data,
        targets=None,
        sequence_length=total_window_size,
        sequence_stride=1,
        shuffle=True,
        batch_size=32
    )

    return ds

返回的形状示例:

for example in tensor.take(1):
  print(f'shape: {example.shape}')

shape: (32, 48, 18)
我现在需要做的是将时间维度拆分为我的输入-输出对,我有一个函数来执行此操作,但是,当我尝试将此函数映射到上述函数中的“ds”时,我得到以下错误:

'BatchDataset' object is not subscriptable
我希望有人能帮助我理解我哪里出了问题?我对tensorflow很陌生。。。下面是我的代码,在这个示例中,“input slice”和“label_slice”分别为0和24。因此,我的目标是将我的批次分成长度为24的输入-输出对

def split_window(features):
  inputs = features[:, input_slice, :]
  labels = features[:, labels_slice, :]

  inputs.set_shape([None, input_width, None])
  labels.set_shape([None, label_width, None])

  return inputs, labels
 def make_dataset(data=train_df[0]):
    data = np.array(data, dtype=np.float32)
    ds = tf.keras.preprocessing.timeseries_dataset_from_array(
        data=data,
        targets=None,
        sequence_length=total_window_size,
        sequence_stride=1,
        shuffle=True,
        batch_size=32
    )

    ds = ds.map(split_window(ds))

    return ds
tensor = make_dataset()
tensor

'BatchDataset' object is not subscriptable