No module named tf

Please I need help

My app Here is giving an error of no module named tf which I quite weird since I already installed tensorflow

ValueError: Unknown layer: Functional

File "/home/user/app/app.py", line 31, in <module>
    model = load_model('cat_and_dog_classifier.h5')File "/home/user/.local/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 184, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)

the reason for this error is cause of use of different versions of Keras & TensorFlow… like in for training the model the version might have ‘2.3.0’ for Tensorflow & ‘2.4.3’ for Keras and now while accessing the saved model(.h5) are using another version of Keras & TensorFlow.

So for the solution it is best to re-trained model from scratch with upgraded versions or downgrades your TF&Keras to the same version as on which model is trained.

You may even use following code if you are using older TF and trying to unpack h5 file packed by newer TF

your_model = tf.keras.models.load_model(
    path_to_h5,
    custom_objects={'Functional':tf.keras.models.Model})

Follow below discussion for more details (hope it would be helpful):