I have created a model from mobilenetv2 model on TensorFlow hub,
I use model.save() to save the model
and use:
my_reloaded_model = tf.keras.models.load_model(
("./model/model_flower.h5"),
custom_objects={'KerasLayer':hub.KerasLayer}
)
to load model.
My program works fine but after about a week when I run the program again it generates an error like this:
TypeError: Error when deserializing class 'KerasLayer' using config={'name': 'keras_layer_1', 'trainable': False, 'dtype': 'float32', 'batch_input_shape': [None, 224, 224, 3], 'handle': 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4'}.
Exception encountered: Trying to load a model of incompatible/unknown type. 'C:\Users\Lenovo\AppData\Local\Temp\tfhub_modules\145bb06ec3b59b08fb564ab752bd5aa222bfb50a' contains neither 'saved_model.pb' nor 'saved_model.pbtxt'.
I checked on stack overflow and got one result:
Essentially what I understood from the article above, is that TensorFlow will create a temp directory to keep loaded models; however, after a few days or so, the contents of the folders (the loaded model) will be deleted. Then when you look to load a model again, TensorFlow will route to the temp dir, but the model will be deleted from the temp dir.
This makes sense and explains why if your code is running totally fine the past few days, and then all of the sudden gets this error, it probably has to do with deleting the old temp directory."
I deleted the temp folder and ran it again and it worked fine. But that's only a temporary solution, the program still stops working every 1 week or so. I don't want to have to delete that temporary folder every once in a while.
Do you have any solution?
I want my program to work for a long time, not having to fix it every time.