Unable to import tensorflow_hub - Been stuck on this all evening

Hi all,

I’m new to machine learning, not having any professional or academic experience with it, but having fun learning about what is possible with image processing. I was really excited to use the hub for style transfer model, however I am unable to import it with the error code persisting despite checking previous forum posts and trying my best to troubleshoot. Would really love some suggestions!

import tensorflow_hub as hub

**

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

**

Here’s my current versions, on windows 10. if other info is missing let me know and I will fetch it, again I’m new to this. I was able to install tensorflow_hub just fine but error came on import.

I’ve tried starting in a new kernel from scratch re installing everything, also tried to downgrade my tf version to 2.15 to see if it was a compatibility issue but I was unable to successfully install another version

tensorflow version 2.16.0rc0
Successfully installed tensorflow_hub-0.16.1 tf-keras-2.15.0
Python version: 3.12.2

thanks in advance for any help or suggestions!

HI r_both, welcome to the TF Forum!

You users need to match the version of tf-keras with the one of TF that you are using.

in your case, since you are using tf 2.16, your tf-keras should also be 2.16 (tf-keras · PyPI) as well

worked! thanks so much

1 Like