【问题标题】:Generating words from trained RNN model: "Variable already exists, disallowed. Did you mean to set reuse=True in VarScope? "从经过训练的 RNN 模型生成单词:“变量已经存在,不允许。你的意思是在 VarScope 中设置 reuse=True 吗?”
【发布时间】:2017-08-24 20:52:37
【问题描述】:

所以我在 jupytor notebook 中实现了一个 RNN 词生成器模型。 当我尝试使用经过训练的模型生成一些单词时:

    with open(os.path.join(cfgs['save_dir'], 'config.pkl'), 'rb') as f:
       saved_args = cPickle.load(f)

    with open(os.path.join(cfgs['save_dir'], 'words_vocab.pkl'), 'rb') as f:
       words, vocab = cPickle.load(f)

    with tf.Session() as sess:
       model = Model(saved_args, True)
       tf.global_variables_initializer().run()
       saver = tf.train.Saver(tf.global_variables())
       ckpt = tf.train.get_checkpoint_state(cfgs['save_dir'])
       if ckpt and ckpt.model_checkpoint_path:
           saver.restore(sess, ckpt.model_checkpoint_path)
           print(model.sample(sess, words, vocab, cfgs['n'], cfgs['prime'], cfgs['sample'], cfgs['pick'], cfgs['width']))

第一次可以运行,但是如果我再次运行代码就会出现错误:

    ValueError: Variable rnnlm/softmax_w already exists, disallowed. Did you mean to set reuse=True in VarScope? 

现在我必须关闭 ipynb 文件,然后运行代码以获取新示例。 怎么改代码来避免这种情况?

【问题讨论】:

    标签: machine-learning tensorflow deep-learning ipython-notebook rnn


    【解决方案1】:

    您可以多次调用 model.sample 函数而不会出现问题,但其他一切(创建会话、构建模型、加载检查点)只应运行一次。如果您重构代码,那么您将不会再看到该错误消息。

    【讨论】:

      猜你喜欢
      • 2018-05-22
      • 2018-01-15
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 2018-02-07
      • 2019-03-05
      相关资源
      最近更新 更多