Convert a model in .h5 format

Hi @loubnabnl I read your article and after that I trained the model in keras this error pop up:
NotImplementedError: Saving the model to HDF5 format requires the model to be a Functional model or a Sequential model. It does not work for subclassed models, because such models are defined via the body of a Python method, which isn't safely serializable. Consider saving to the Tensorflow SavedModel format (by setting save_format="tf") or using save_weights.

So it doesn’t let me save the model into a “.h5” file or tensorflowLight.

Can you please help me with it? How can I do the conversation in one of these two file?

I’m using a VisualTransformer.

How are you trying to save the model?

@philschmid in these 3 ways:

model_directory = “drive/MyDrive/Tirocinio/1ris_vit-stanford-dog-dataset”

tokenizer = ViTFeatureExtractor.from_pretrained(model_directory)
model = ViTForImageClassification.from_pretrained(model_directory)

pytorch_path = “drive/MyDrive/Tirocinio/ViT_model_pytorch”
model_pytorch = ViTForImageClassification.from_pretrained(pytorch_path)

h5_path = “drive/MyDrive/Tirocinio/ViT_model_tf”
model_h5 = ViTForImageClassification.from_pretrained(h5_path, from_tf=True)

The point is that I want to save the model into an unique “.h5” file.