keras转tensorflow后,报错:Attempting to use uninitialized value batch_normalization_14/moving_mean

keras turn tensorflow, use tensorflow model predicts that error:

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value batch_normalization_14/moving_mean

[[Node: batch_normalization_14/moving_mean/read = Identity[T=DT_FLOAT, _class=["loc:@batch_normalization_14/cond/FusedBatchNorm/Switch_3"], _device="/job:localhost/replica:0/task:0/device:GPU:0"](batch_normalization_14/moving_mean)]]

[[Node: predictions/Softmax/_5 = _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_576_predictions/Softmax", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

Solution:

After sess, add sess initialization: sess.run (tf.global_variables_initializer ())

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

 

Development: If keras reported under similar wrong, then add the following code:

keras.backend.get_session().run(tf.initialize_all_variables())

 

Guess you like

Origin blog.csdn.net/weixin_41770169/article/details/93191941