Help ! I am facing this problem in loading my model

this is code for my model all over : import tensorflow as tf
import os
import datetime

IMG_SIZE = 224
INPUT_SHAPE = [None, IMG_SIZE, IMG_SIZE, 3]
OUTPUT_SHAPE = len(unique)
MODEL_URL = “mobilenet_v2 | Kaggle

def create_model(input_shape=INPUT_SHAPE, output_shape=OUTPUT_SHAPE, model_url=MODEL_URL):
model = tf.keras.Sequential([
hub.KerasLayer(MODEL_URL),
tf.keras.layers.Dense(units=OUTPUT_SHAPE, activation=“softmax”)
])

model.compile(
    loss=tf.keras.losses.CategoricalCrossentropy(),
    optimizer=tf.keras.optimizers.Adam(),
    metrics=["accuracy"]
)

model.build(INPUT_SHAPE)

return model

def train_model():
model = create_model()
tensorboard = create_tensorboard_callback()
model.fit(x=train_data,
epochs=100,
validation_data=validation_data,
validation_freq=1,
callbacks=[tensorboard, early_stopping])
return model

def save_model(model, suffix=None):
modeldir = os.path.join(“/content/drive/MyDrive/plant/plant/models”,
datetime.datetime.now().strftime(“%Y%m%d-%h%M%s”))
model_path = modeldir + “-” + suffix + “.keras”
print(f"Saving the model to: {model_path}…")
model.save(model_path)
return model_path

def load_model(model_path):
loaded_model = tf.keras.models.load_model(model_path)
return loaded_model

Training the model

model = train_model()

Saving the model

saved_model_path = save_model(model, suffix=“1000-images-mobilenetv2_Adam”)

Loading the model

loaded_model = load_model(saved_model_path)

Displaying the summary of the loaded model

loaded_model.summary()

Problem : Traceback (most recent call last):
File “C:\Users\HP\OneDrive\Desktop\New folder\first_step\app.py”, line 24, in
model = load_model(‘1000-images-mobilenetv2_Adam.keras’) # Load your trained deep learning model
File “C:\Users\HP\OneDrive\Desktop\New folder\first_step\app.py”, line 21, in load_model
custom_objects={“KerasLayer”:hub.KerasLayer(“mobilenet_v2 | Kaggle”)})
File “C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_hub\keras_layer.py”, line 165, in init
self._func = load_module(handle, tags, self._load_options)
File “C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_hub\keras_layer.py”, line 467, in load_module
return module_v2.load(handle, tags=tags, options=set_load_options)
File “C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_hub\module_v2.py”, line 113, in load
raise ValueError("Trying to load a model of incompatible/unknown type. "
ValueError: Trying to load a model of incompatible/unknown type. ‘C:\Users\HP\AppData\Local\Temp\tfhub_modules\87c08e811d90a898c320e6626614764b3f4e562b’ contains neither ‘saved_model.pb’ nor ‘saved_model.pbtxt’.

I would guess that parts of your path-setting code isn’t working.

  • Where is the “.keras” part of the path?
  • Where is the “to:” in this text output?

image

that is just naming convention for model, I don’t think and also try without it having any problem

Have you read the Keras documentation for loading and saving models? There are some requirements for the filepath specification.

I tryied a lot but nothing is working filling lost in it

@Sanket_Gode, sorry but I don’t know what your message means.