【问题标题】:How do I restore the Generator of a GAN from a Tensorflow Model?如何从 Tensorflow 模型中恢复 GAN 的生成器?
【发布时间】:2019-06-19 22:06:12
【问题描述】:

我正在尝试使用 Tensorflow 模型(元图和检查点)恢复经过训练的生成对抗网络生成器

我是 tensorflow 和 python 的新手,所以我不确定我所做的是否有意义。已经尝试从元文件导入元图并从检查点恢复变量,但我确定下一步该做什么。我的目标是从最后一个检查点恢复经过训练的生成器,然后使用它从噪声输入中生成新数据。

这是包含模型文件的驱动器的链接: https://drive.google.com/drive/folders/1MaELMC4aOroSQlMJ32J3_ff3wxiBT_Fq?usp=sharing

到目前为止,我已经尝试了以下方法,它似乎正在加载图表:


# import the graph from the file
imported_graph = tf.train.import_meta_graph("../../models/model-9.meta")

# list all the tensors in the graph
for tensor in tf.get_default_graph().get_operations():
    print (tensor.name)

# run the session
with tf.Session() as sess:
    # restore the saved vairable
    imported_graph.restore(sess, "../../models/model-9")

但是,我不确定下一步该做什么。是否可以使用这些文件只运行经过训练的生成器?我怎样才能访问它?

【问题讨论】:

    标签: python tensorflow neural-network generative-adversarial-network


    【解决方案1】:

    在 Tensorflow 2 文档中,他们保存了生成器和鉴别器。但是,他们没有解释如何只恢复生成器。

    checkpoint_dir = './training_checkpoints'
    checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
    checkpoint = tf.train.Checkpoint(generator_optimizer=generator_optimizer,
                                     discriminator_optimizer=discriminator_optimizer,
                                     generator=generator,
                                     discriminator=discriminator)
    

    然后用恢复

    checkpoint.restore(tf.train.latest_checkpoint(checkpoint_dir))
    

    来自https://www.tensorflow.org/tutorials/generative/dcgan#save_checkpoints

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 2016-05-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      相关资源
      最近更新 更多