在张量流中恢复模型

Restore models in 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.")

模型还原的很好,因为在显示'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()