简体   繁体   English

TensorFlow:恢复模型

[英]TensorFlow: Restoring a model

I'm trying to save my model at the end of triaining and restore it every time the training begins. 我正在尝试在三级练习结束时保存我的模型,并在每次训练开始时将其还原。 I just followed what this link did. 我只是关注此链接的作用

    saver = tf.train.Saver()
    with tf.Session(graph=graph) as session:
        # Initializate the weights and biases
        tf.global_variables_initializer().run()
        new_saver = tf.train.import_meta_graph('model.meta')
        new_saver.restore(sess,tf.train.latest_checkpoint('./'))
        W1 = session.run(W)
        print(W1)

        for curr_epoch in range(num_epochs):
            train_cost = train_ler = 0
            start = time.time()
            for batch in range(num_batches_per_epoch):
                ...Some training...

        W2 = session.run(W)
        print(W2)
        save_path = saver.save(session, "models/model")

But it gives error below: 但是它在下面给出了错误:

--->  new_saver.restore(session, tf.train.latest_checkpoint('./'))
SystemError: <built-in function TF_Run> returned a result with an error set

Can anyone help me please? 谁能帮我吗? Many thanks! 非常感谢!

If you're gonna load with ./ you have to make sure, that your console (that you use to start the python program) is actually set on that directory (models/). 如果要加载./,则必须确保控制台(用于启动python程序)实际上已在该目录(models /)上设置。 But in that case, it will save your new data in a new directory. 但是在这种情况下,它将把您的新数据保存在新目录中。 So load with ./models/ instead 所以加载./models/

(Also you don't need to initiate variables, the restore does that for you.) (此外,您不需要初始化变量,还原可以为您完成此操作。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM