Tensorflow 高效的 Cyclegan 历史池

Tensorflow efficient Cyclegan history pool

CycleGAN paper 中提到了判别器的历史池。因此我们保留 last e.g.来自生成器的 50 个样本并将它们提供给鉴别器。没有历史就很简单,我们可以利用 tf.data.Dataset 和迭代器将数据插入网络。但是有了history pool,我就没弄明白怎么用了tf.data.Datasetapi。 训练循环中的代码类似于

fx, fy = sess.run(model_ops['fakes'], feed_dict={
    self.cur_x: cur_x,
    self.cur_y: cur_y,
})

cur_x, cur_y = sess.run([self.X_feed.feed(), self.Y_feed.feed()])
feeder_dict = {
    self.cur_x: cur_x,
    self.cur_y: cur_y,
    self.prev_fake_x: x_pool.query(fx, step),
    self.prev_fake_y: y_pool.query(fy, step),
}
# self.cur_x, self.cur_y, self.prev_fake_x, self.prev_fake_y are just placeholders
# x_pool and y_pool are simple wrappers for random sampling from the history pool and saving new images to the pool
for _ in range(dis_train):
    sess.run(model_ops['train']['dis'], feed_dict=feeder_dict)
for _ in range(gen_train):
    sess.run(model_ops['train']['gen'], feed_dict=feeder_dict)

令我困扰的是代码的低效性,例如无法像 tf.data API 的预取那样在训练期间预加载下一批,但我看不到任何使用 tf.data API 的方式。 它是否提供某种历史池,我可以将其与预取和一般优化数据加载模型一起使用? 此外,当我在鉴别器训练操作和生成器训练操作之间有一定比例时,也会出现类似的问题。 例如,如果我想要 运行 每 1 步鉴别器进行 2 步生成器训练操作,是否可以使用相同的数据来完成?因为使用 tf.data API,每次调用 sess.run 时都会从迭代器中抽取新样本。

有什么方法可以正确有效地实施吗?

所以,我发现 TFGAN tensorflow contrib 存储库中已经实现了历史池。