0
因此,我在jupytor笔记本中实现了一个RNN字生成器模型。 当我试图使用训练的模型生成一些话:从经过训练的RNN模型生成单词:“变量已存在,不允许。是否在VarScope中设置reuse = True?”
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文件,然后运行代码以获取新样本。 如何更改代码以避免这种情况?