keras 在tensorflow 中作为输出的有限形状

7bsow1i6  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(170)

我尝试使用keras随机生成时间序列数据,如下所示:

import tensorflow as tf 
import pandas as pd
import random
input_data = [random.uniform(10,100) for _ in range(350000)]
targets = [random.uniform(10,100) for _ in range(350000)]
dataset = tf.keras.utils.timeseries_dataset_from_array(
    input_data, targets, sequence_length=10000)
for batch in dataset:
  inputs, targets = batch
  break

但最后的形状是减少和未来作为:

<tf.Tensor: shape=(128, 10000), dtype=float32, numpy=
array([[22.922523, 44.253967, 41.80049 , ..., 60.444836, 14.977458,
        17.970036],
       [44.253967, 41.80049 , 34.09485 , ..., 14.977458, 17.970036,
        68.27751 ],
       [41.80049 , 34.09485 , 37.27845 , ..., 17.970036, 68.27751 ,
        98.05703 ],
       ...,
       [13.941159, 51.48634 , 61.248505, ..., 98.093346, 67.3885  ,
        34.01148 ],
       [51.48634 , 61.248505, 77.34204 , ..., 67.3885  , 34.01148 ,
        27.165142],
       [61.248505, 77.34204 , 54.856853, ..., 34.01148 , 27.165142,
        97.55085 ]], dtype=float32)>

如何增加数组的大小,或者有什么限制吗?

t9aqgxwy

t9aqgxwy1#

VARIABLE更改为所需的样本数(batch_size)。如果需要整个数据,则可以将batch_size=None

dataset = tf.keras.utils.timeseries_dataset_from_array(
input_data, targets, batch_size=VARIABLE, sequence_length=10000)

相关问题