python-对于无限数据集,每个时代使用的数据是相同的吗?

2021-01-08 21点热度 0人点赞 0条评论

在TensorFlow中,假设我有一个来自Generator的数据集:

dataset = tf.data.Dataset.from_generator(gen...)
这个发电机产生无限无反诉
数据(就像无限的非循环小数)。
model.fit(dataset, steps_per_epoch=10000, epochs=5)

现在,在这5个培训阶段,使用的数据是相同的吗?也就是说,总是发电机的前10000个项目?而不是0-9999代表第1个时期,10000-19999代表第2个时期,等等。

initial_epoch 参数呢?如果我把它设为1,模型会从10000项训练吗?

model.fit(dataset, steps_per_epoch=10000, epochs=5, initial_epoch=1)
更新:
这个简单的测试显示每次都将重置数据集模型.fit()
被调用
def gen():
    i = 1
    while True:
        yield np.array([[i]]), np.array([[0]])
        i += 1

ds = tf.data.Dataset.from_generator(gen, output_types=(tf.int32, tf.int32)).batch(3)

x = Input(shape=(1, 1))
model = Model(inputs=x, outputs=x)

model.compile('adam', loss=lambda true, pred: tf.reduce_mean(pred))
for i in range(10):
    model.fit(ds, steps_per_epoch=5, epochs=1)

输出:

1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 9ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 2ms/step - loss: 8.0000

一次通话5个时间段:

model.fit(ds, steps_per_epoch=5, epochs=5)

输出:

Epoch 1/5
1/5 [=====>........................] - ETA: 0s - loss: 2.0000
5/5 [==============================] - 0s 9ms/step - loss: 8.0000
Epoch 2/5
1/5 [=====>........................] - ETA: 0s - loss: 17.0000
5/5 [==============================] - 0s 2ms/step - loss: 23.0000
Epoch 3/5
1/5 [=====>........................] - ETA: 0s - loss: 32.0000
5/5 [==============================] - 0s 2ms/step - loss: 38.0000
Epoch 4/5
1/5 [=====>........................] - ETA: 0s - loss: 47.0000
5/5 [==============================] - 0s 2ms/step - loss: 53.0000
Epoch 5/5
1/5 [=====>........................] - ETA: 0s - loss: 62.0000
5/5 [==============================] - 0s 2ms/step - loss: 68.0000
查看隐藏内容需要支付:¥1
查看

未经允许不得转载!python-对于无限数据集,每个时代使用的数据是相同的吗?

本文地址:https://ans.52learn.online/2161

ANS52LEARN

DO BEST