相关疑难解决方法(0)

Tensorflow:如何保存/恢复模型?

在Tensorflow中训练模型后:

  1. 你如何保存训练有素的模型?
  2. 你以后如何恢复这个保存的模型?

python model machine-learning tensorflow

516
推荐指数
20
解决办法
32万
查看次数

tensorflow:保存和恢复会话

我试图从答案中实现一个建议: Tensorflow:如何保存/恢复模型?

我有一个对象,它tensorflow以一种sklearn风格包装模型.

import tensorflow as tf
class tflasso():
    saver = tf.train.Saver()
    def __init__(self,
                 learning_rate = 2e-2,
                 training_epochs = 5000,
                    display_step = 50,
                    BATCH_SIZE = 100,
                    ALPHA = 1e-5,
                    checkpoint_dir = "./",
             ):
        ...

    def _create_network(self):
       ...


    def _load_(self, sess, checkpoint_dir = None):
        if checkpoint_dir:
            self.checkpoint_dir = checkpoint_dir

        print("loading a session")
        ckpt = tf.train.get_checkpoint_state(self.checkpoint_dir)
        if ckpt and ckpt.model_checkpoint_path:
            self.saver.restore(sess, ckpt.model_checkpoint_path)
        else:
            raise Exception("no checkpoint found")
        return

    def fit(self, train_X, train_Y , load = True):
        self.X = …
Run Code Online (Sandbox Code Playgroud)

python scikit-learn tensorflow

8
推荐指数
1
解决办法
1万
查看次数