在TensorFlow中还原模型

特伯丁

我正在使用tensorflow来实现神经网络,为了保存模型,我编写了以下几行:

首先保存: saver.save(sess, 'logs/model_%d.ckpt' % epoch_i)

然后还原:

restore = True
if restore == True :
   saver = tf.train.import_meta_graph('logs/model_55.ckpt.meta')
   saver.restore(sess, "logs/model_55.ckpt")
   print("Model restored.")

模型已很好地还原,因为在显示“模型还原”之前没有错误,但是在此之后,我出现以下错误:

    tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power
         [[Node: beta1_power/read = Identity[T=DT_FLOAT, _class=["loc:@triplet/dense1/bias"], _device="/job:localhost/replica:0/task:0/device:GPU:0"](beta1_power)]]
         [[Node: sqrt2_1/_385 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_28263_sqrt2_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

    During handling of the above exception, another exception occurred:

[...]

        raise type(e)(node_def, op, message)
    tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power
         [[Node: beta1_power/read = Identity[T=DT_FLOAT, _class=["loc:@triplet/dense1/bias"], _device="/job:localhost/replica:0/task:0/device:GPU:0"](beta1_power)]]
         [[Node: sqrt2_1/_385 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_28263_sqrt2_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

    Caused by op 'beta1_power/read', defined at:

[...]


    FailedPreconditionError (see above for traceback): Attempting to use uninitialized value beta1_power
         [[Node: beta1_power/read = Identity[T=DT_FLOAT, _class=["loc:@triplet/dense1/bias"], _device="/job:localhost/replica:0/task:0/device:GPU:0"](beta1_power)]]
         [[Node: sqrt2_1/_385 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_28263_sqrt2_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

    Traceback (most recent call last):

[...]

    tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power
         [[Node: beta1_power/read = Identity[T=DT_FLOAT, _class=["loc:@triplet/dense1/bias"], _device="/job:localhost/replica:0/task:0/device:GPU:0"](beta1_power)]]
         [[Node: sqrt2_1/_385 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_28263_sqrt2_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

我不知道此错误引发的问题,有人可以解决吗?

我已经在图中的每个操作中添加了名称,还尝试了几种语法,但似乎没有任何效果...

非常感谢你的帮助 !

戴安娜

在还原之前尝试初始化变量 tf.global_variables_initializer().run()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章