Tbertin
Tbertin

Reputation: 645

Restore models in tensorflow

I'm using tensorflow to implement a neural network and in order to save my model i've written the followings lines :

First to save : saver.save(sess, 'logs/model_%d.ckpt' % epoch_i)

Then to restore :

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.")

The model is well restored because there is no error before the display of 'Model restored' but just after, i've the following error :

    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"]()]]

I've no idea of the the issue raised by this error, has someone a solution ?

I've put names to each operation in the graph and also tried with several syntax, nothing seems to work...

Thanks a lot for your help !

Upvotes: 1

Views: 284

Answers (1)

Diana
Diana

Reputation: 377

try initializing your variables before restoring tf.global_variables_initializer().run()

Upvotes: 2

Related Questions