【问题标题】:TensorFlow shuffle() does not shuffle datasetTensorFlow shuffle() 不会打乱数据集
【发布时间】:2021-02-25 01:42:58
【问题描述】:

我使用的是 TensorFlow 2.3.1,下面的代码没有打乱数据。

我有时间序列数据,我想构建特征和预测目标。

代码:

data_len = len(calls['Calls'])

# Load data as TensorFlow dataset
dataset = tf.data.Dataset.from_tensor_slices(calls['Calls'])

# Create data windows and shifting values. Drop incomplete arrays
dataset = dataset.window(5, shift=1, drop_remainder=True)

# Convert into tensors for each window
dataset = dataset.flat_map(lambda window: window.batch(5))

# Split into features and target
dataset = dataset.map(lambda window: (window[:-1], window[-1:]))

# Shuffle data
dataset.shuffle(buffer_size=data_len)

dataset.batch(2).prefetch(1)

# Print output
for x, y in dataset:
    print('x = {}'.format(x.numpy()))
    print('y = {}'.format(y.numpy()))

结果:

x = [1659 4928 3961 3663]
y = [2452]
x = [4928 3961 3663 2452]
y = [2195]
x = [3961 3663 2452 2195]
y = [3796]
x = [3663 2452 2195 3796]
y = [2997]
x = [2452 2195 3796 2997]
y = [2598]
x = [2195 3796 2997 2598]
y = [2605]
x = [3796 2997 2598 2605]
y = [2603]
x = [2997 2598 2605 2603]
y = [2332]
x = [2598 2605 2603 2332]
y = [2025]
x = [2605 2603 2332 2025]

【问题讨论】:

  • 我在生成的范围数据上尝试了相同的代码......同样的问题。另外,我更新到 tf 2.4.1,但问题仍然存在。 ``` # 调用长度 data_len = 10 # 将数据加载为 TensorFlow 数据集 dataset = tf.data.Dataset.range(10) ``

标签: tensorflow shuffle


【解决方案1】:

发现问题。

我没有将批处理和改组分配回数据集。

还是谢谢。

【讨论】:

    猜你喜欢
    • 2017-10-22
    • 2019-01-16
    • 1970-01-01
    • 2018-08-24
    • 2018-10-30
    • 2020-01-19
    • 2019-11-18
    • 2021-07-06
    • 2018-12-15
    相关资源
    最近更新 更多