tensorflow rnn模型路径 [英] tensorflow rnn model path

查看:66
本文介绍了tensorflow rnn模型路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Tensorflow训练了语言模型,如教程

I have trained the language model using Tensorflow as given in thie tutorial

为了训练,我使用了以下命令.

For training I used the following command.

 bazel-bin/tensorflow/models/rnn/ptb/ptb_word_lm   --data_path=./simple-examples/data/  --model small

培训成功,最后进行了以下操作.

The training was successful with the following o/p at the end.

Epoch: 13 Train Perplexity: 37.196
Epoch: 13 Valid Perplexity: 124.502
Test Perplexity: 118.624

但是我仍然对训练模型的存储位置以及如何使用感到困惑.

But I am still confused with, where the training model is stored and how to use it.

推荐答案

该演示代码可能不包含保存模型的功能.您可能需要显式使用tf.train.Saver在检查点之间保存和还原变量.

The demo code probably did not include the ability to save a model; you might want to explicitly use tf.train.Saver to save and restore variables to and from checkpoints.

请参见 doc 根据文档,这非常简单.在下面的示例中,我保存了 模型中的所有变量.相反,您可以按照选择要保存的变量例子.

It's pretty straightforward according to the doc. In below example, I saved all the variables in the model. Instead, you can choose which variable(s) to save by following the examples.

# ... 
tf.initialize_all_variables().run()
####################################################
# Add ops to save and restore all the variables.
####################################################
saver = tf.train.Saver()

for i in range(config.max_max_epoch):
  lr_decay = config.lr_decay ** max(i - config.max_epoch, 0.0)
  m.assign_lr(session, config.learning_rate * lr_decay)

  print("Epoch: %d Learning rate: %.3f" % (i + 1, session.run(m.lr)))
  train_perplexity = run_epoch(session, m, train_data, m.train_op,
                               verbose=True)
  print("Epoch: %d Train Perplexity: %.3f" % (i + 1, train_perplexity))
  valid_perplexity = run_epoch(session, mvalid, valid_data, tf.no_op())
  print("Epoch: %d Valid Perplexity: %.3f" % (i + 1, valid_perplexity))

  ####################################################
  # Save the variables to disk.
  ####################################################
  save_path = saver.save(session, "/tmp/model.epoch.%03d.ckpt" % (i + 1))
  print("Model saved in file: %s" % save_path)
  # ....

就我而言,每个检查点文件的磁盘大小为18.61M(--model small).

In my case, each checkpoint file has a disk size of 18.61M (--model small).

关于如何使用该模型,只需按照 doc 进行操作即可从保存的文件中恢复检查点.然后由您决定如何使用它.

Regarding how to use the model, just follow the doc to restore the checkpoints from saved files. Then it's at your will how to use it.

这篇关于tensorflow rnn模型路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆