tensorflow: Failed precondition: Error while reading resource variable block3a_se_expand/bias from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/block3a_se_expand/bias/N10tensorflow3VarE does not exist. [[{{node block3a_se_expand/BiasAdd/ReadVariableOp}}]] [[dense_1/Softmax/_1903]]
I have three trained models which is using in one script . First model (.h5) is loaded using following piece of code
from keras_retinanet import models
def get_session():
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
return tf.compat.v1.Session(config=config)
keras.backend.tensorflow_backend.set_session(get_session())
first_model = models.load_model(first_model_path, backbone_name='resnet50')
The first model loaded and predicted successfully. After first model operation, second model (.hdf5) loaded using following code block
from tensorflow.keras.models import load_model
second_model =load_model(second_model_path)
Second model loaded successfully and but while prediction , getting the following error.
2020-04-15 12:01:36.207346: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set. If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU. To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile. 2020-04-15 12:01:36.310985: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7 2020-04-15 12:01:43.026476: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10 Traceback (most recent call last): File "ppe_detection.py", line 105, in <module> predicted , x = predict_helmet(processed_roi,helmet_model) File "/samjith/project/safety-monitoring/classify/helmet/helmet_classy.py", line 17, in predict_helmet helmet_score = helmet_model.predict([x])[0][0] File "/home/samjith/anaconda3/envs/keras-retina/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 1078, in predict callbacks=callbacks) File "/home/samjith/anaconda3/envs/keras-retina/lib/python3.7/site-packages/tensorflow/python/keras/engine/training_arrays.py", line 363, in model_iteration batch_outs = f(ins_batch) File "/home/samjith/anaconda3/envs/keras-retina/lib/python3.7/site-packages/tensorflow/python/keras/backend.py", line 3292, in __call__ run_metadata=self.run_metadata) File "/home/samjith/anaconda3/envs/keras-retina/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1458, in __call__ run_metadata_ptr) tensorflow.python.framework.errors_impl.FailedPreconditionError: 2 root error(s) found. (0) Failed precondition: Error while reading resource variable block3b_expand_conv/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/block3b_expand_conv/kernel/N10tensorflow3VarE does not exist. [[{{node block3b_expand_conv/Conv2D/ReadVariableOp}}]] [[dense_1/Softmax/_1903]] (1) Failed precondition: Error while reading resource variable block3b_expand_conv/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/block3b_expand_conv/kernel/N10tensorflow3VarE does not exist. [[{{node block3b_expand_conv/Conv2D/ReadVariableOp}}]] 0 successful operations. 0 derived errors ignored.
I have gone through this github link. But the error still remains.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (4 by maintainers)
I have fixed this by changing the
loadfunction. If you are loading your model from.h5or.pbchange it from this:
model = tf.saved_model.load(self.filename, [tf.saved_model.SERVING])to this:
Each model will have its own session and graph. The default session and graph within this context cannot load the new weights to the already-existing graph. This could be solved in TF 1 with session, but I don’t see how to solve this in TF 2 yet without disabling eager execution.
Try: