Error during implementing script AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'register load context function'

Hi all,
I am getting the following error, tried to search for solution and all solutions i found didn’t work

AttributeError: module ‘tensorflow.compat.v2.internal’ has no attribute ‘register_load_context_function’

Traceback (most recent call last):
File “D:\test\main_.py”, line 1, in
from CAPTCHA_object_detection import *
File “D:\test\CAPTCHA_object_detection.py”, line 10, in
import tensorflow as tf
File “C:\Python39\lib\site-packages\tensorflow_init_.py”, line 469, in
_keras._load()
File “C:\Python39\lib\site-packages\tensorflow\python\util\lazy_loader.py”, line 41, in load
module = importlib.import_module(self.name)
File "C:\Python39\lib\importlib_init
.py", line 127, in import_module
return bootstrap.gcd_import(name[level:], package, level)
File "C:\Python39\lib\site-packages\keras_init
.py", line 21, in
from keras import models
File "C:\Python39\lib\site-packages\keras\models_init
.py", line 18, in
from keras.engine.functional import Functional
File “C:\Python39\lib\site-packages\keras\engine\functional.py”, line 34, in
from keras.engine import training as training_lib
File “C:\Python39\lib\site-packages\keras\engine\training.py”, line 45, in
from keras.saving.legacy import save
File “C:\Python39\lib\site-packages\keras\saving\legacy\save.py”, line 24, in
from keras.saving.legacy.saved_model import load_context
File “C:\Python39\lib\site-packages\keras\saving\legacy\saved_model\load_context.py”, line 68, in
tf.internal.register_load_context_function(in_load_context)
AttributeError: module ‘tensorflow.compat.v2.internal’ has no attribute ‘register_load_context_function’

@Ahmed_Abdelrahman,

Welcome to the Tensorflow Forum!

Could you please share the standalone code to replicate the above issue?

Thank you!

@Ahmed_Abdelrahman,

Can you try as suggested below and let us know?

Thank you!

the mistake i did that I did not had the tensorflow_models package installed