Getting issue in updating code from Tensorflow V1 to V2

self._traceback = tf_stack.extract_stack()

I am facing issue in updating code to Tensorflow V2 i have tested the code with V1 and it’s working fine
i have moved most of my code to code V2 but now i am getting this error, the whole error is below:

2022-03-16 12:09:51.770391: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/keras/layers/legacy_rnn/rnn_cell_impl.py:702: UserWarning: tf.nn.rnn_cell.BasicLSTMCell is deprecated and will be removed in a future version. This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.
warnings.warn("tf.nn.rnn_cell.BasicLSTMCell is deprecated and will be "
/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer_v1.py:1727: UserWarning: layer.add_variable is deprecated and will be removed in a future version. Please use layer.add_weight method instead.
warnings.warn(’layer.add_variable is deprecated and ’
2022-03-16 12:09:52.936514: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-03-16 12:09:52.937664: I tensorflow/core/common_runtime/process_util.cc:146] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
2022-03-16 12:09:52.997416: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)
2022-03-16 12:09:53.082000: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2299965000 Hz
2022-03-16 12:09:53.125179: W tensorflow/core/framework/op_kernel.cc:1763] OP_REQUIRES failed at save_restore_v2_ops.cc:205 : Not found: Key model/cnn/BatchNorm/gamma not found in checkpoint
Traceback (most recent call last):
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/client/session.py”, line 1375, in _do_call
return fn(*args)
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/client/session.py”, line 1359, in _run_fn
return self._call_tf_sessionrun(options, feed_dict, fetch_list,
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/client/session.py”, line 1451, in _call_tf_sessionrun
return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
tensorflow.python.framework.errors_impl.NotFoundError: Key model/cnn/BatchNorm/gamma not found in checkpoint
[[{{node save/RestoreV2}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 1297, in restore
sess.run(self.saver_def.restore_op_name,
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/client/session.py”, line 967, in run
result = self._run(None, fetches, feed_dict, options_ptr,
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/client/session.py”, line 1190, in _run
results = self._do_run(handle, final_targets, final_fetches,
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/client/session.py”, line 1368, in _do_run
return self._do_call(_run_fn, feeds, fetches, targets, options,
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/client/session.py”, line 1394, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.NotFoundError: Key model/cnn/BatchNorm/gamma not found in checkpoint
[[node save/RestoreV2 (defined at /Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py:284) ]]

Original stack trace for ‘save/RestoreV2’:
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/predict.py”, line 7, in
encoded, predicted_text = run_model.recognize_strip(model_config_path, image)
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/run_model.py”, line 49, in recognize_strip
model, config = create_and_run_model(model_config_path, image_strip)
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/run_model.py”, line 29, in create_and_run_model
model = mappings[config.model](config, eval_path, image_strip);
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py”, line 65, in init
self._initialize_model(True, verbose=False)
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py”, line 284, in _initialize_model
self.saver = tf.train.Saver(save_relative_paths=False)
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 835, in init
self.build()
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 847, in build
self._build(self._filename, build_save=True, build_restore=True)
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 875, in _build
self.saver_def = self._builder._build_internal( # pylint: disable=protected-access
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 514, in _build_internal
restore_op = self._AddRestoreOps(filename_tensor, saveables,
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 334, in _AddRestoreOps
all_tensors = self.bulk_restore(filename_tensor, saveables, preferred_shard,
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 582, in bulk_restore
return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/ops/gen_io_ops.py”, line 1508, in restore_v2
_, _, _op, _outputs = _op_def_library._apply_op_helper(
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/framework/op_def_library.py”, line 748, in _apply_op_helper
op = g._create_op_internal(op_type_name, inputs, dtypes=None,
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/framework/ops.py”, line 3528, in _create_op_internal
ret = Operation(
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/framework/ops.py”, line 1990, in init
self._traceback = tf_stack.extract_stack()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/py_checkpoint_reader.py”, line 69, in get_tensor
return CheckpointReader.CheckpointReader_GetTensor(
RuntimeError: Key _CHECKPOINTABLE_OBJECT_GRAPH not found in checkpoint

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 1308, in restore
names_to_keys = object_graph_key_mapping(save_path)
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 1626, in object_graph_key_mapping
object_graph_string = reader.get_tensor(trackable.OBJECT_GRAPH_PROTO_KEY)
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/py_checkpoint_reader.py”, line 74, in get_tensor
error_translator(e)
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/py_checkpoint_reader.py”, line 35, in error_translator
raise errors_impl.NotFoundError(None, None, error_message)
tensorflow.python.framework.errors_impl.NotFoundError: Key _CHECKPOINTABLE_OBJECT_GRAPH not found in checkpoint

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/cle-184/Desktop/Integration-Test/StripRecognizer - MODIFIED/predict.py”, line 7, in
encoded, predicted_text = run_model.recognize_strip(model_config_path, image)
File “/home/cle-184/Desktop/Integration-Test/StripRecognizer - MODIFIED/run_model.py”, line 49, in recognize_strip
model, config = create_and_run_model(model_config_path, image_strip)
File “/home/cle-184/Desktop/Integration-Test/StripRecognizer - MODIFIED/run_model.py”, line 29, in create_and_run_model
model = mappings[config.model](config, eval_path, image_strip);
File “/home/cle-184/Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py”, line 65, in init
self._initialize_model(True, verbose=False)
File “/home/cle-184/Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py”, line 296, in _initialize_model
self.saver.restore(self.sess, restored_model)
File “/home/cle-184/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 1313, in restore
raise _wrap_restore_error_with_msg(
tensorflow.python.framework.errors_impl.NotFoundError: Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Key model/cnn/BatchNorm/gamma not found in checkpoint
[[node save/RestoreV2 (defined at /Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py:284) ]]

Original stack trace for ‘save/RestoreV2’:
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/predict.py”, line 7, in
encoded, predicted_text = run_model.recognize_strip(model_config_path, image)
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/run_model.py”, line 49, in recognize_strip
model, config = create_and_run_model(model_config_path, image_strip)
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/run_model.py”, line 29, in create_and_run_model
model = mappings[config.model](config, eval_path, image_strip);
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py”, line 65, in init
self._initialize_model(True, verbose=False)
File “/Desktop/Integration-Test/StripRecognizer - MODIFIED/models/model_class.py”, line 284, in _initialize_model
self.saver = tf.train.Saver(save_relative_paths=False)
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 835, in init
self.build()
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 847, in build
self._build(self._filename, build_save=True, build_restore=True)
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 875, in _build
self.saver_def = self._builder._build_internal( # pylint: disable=protected-access
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 514, in _build_internal
restore_op = self._AddRestoreOps(filename_tensor, saveables,
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 334, in _AddRestoreOps
all_tensors = self.bulk_restore(filename_tensor, saveables, preferred_shard,
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/training/saver.py”, line 582, in bulk_restore
return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/ops/gen_io_ops.py”, line 1508, in restore_v2
_, _, _op, _outputs = _op_def_library._apply_op_helper(
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/framework/op_def_library.py”, line 748, in _apply_op_helper
op = g._create_op_internal(op_type_name, inputs, dtypes=None,
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/framework/ops.py”, line 3528, in _create_op_internal
ret = Operation(
File “/anaconda3/envs/python3.96/lib/python3.9/site-packages/tensorflow/python/framework/ops.py”, line 1990, in init
self._traceback = tf_stack.extract_stack()

Have you checked: