「tensorflow」 Variable was uninitialized

Initialize:

1
2
3
4
5
import tensorflow as tf
import numpy as np

dir = './model/tf_savedmodel'
zeros = tf.constant(np.zeros([1, 640, 960, 3]), dtype=float)

Work:

1
2
model = tf.saved_model.load(dir)
output = model.signatures['serving_default'](zeros)
1
2
model = tf.saved_model.load(dir)
output = model(zeros)

Failed:

1
2
model = tf.saved_model.load(dir).signatures['serving_default']
output = model(zeros)
1
2
3
4
5
tensorflow.python.framework.errors_impl.FailedPreconditionError:  Error while reading resource variable conv5_block17_0_bn/gamma_96932 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/conv5_block17_0_bn/gamma_96932/N10tensorflow3VarE does not exist.
[[{{node StatefulPartitionedCall/fusion_network/conv5_block17_0_bn/ReadVariableOp}}]] [Op:__inference_signature_wrapper_21102]

Function call stack:
signature_wrapper