Session tensorflow中的恢复模型

Session tensorflow中的恢复模型,session,tensorflow,save,restore,Session,Tensorflow,Save,Restore,我正在使用tensorflow实现一个神经网络,为了保存我的模型,我写了以下几行: 首先保存:saver.save(sess,'logs/model\u%d.ckpt'%epoch\u i) 然后恢复: restore = True if restore == True : saver = tf.train.import_meta_graph('logs/model_55.ckpt.meta') saver.restore(sess, "logs/model_55.ckpt")

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

首先保存:
saver.save(sess,'logs/model\u%d.ckpt'%epoch\u 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.")
模型恢复良好,因为在显示“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\u variables\u initializer().run()