# Model saved into an unique .h5 file (or TensorflowLight)

**URL:** <https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825>\
**Category:** 🤗Transformers\
**Created:** [July 25, 2022, 10:12am UTC](https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825 "2022-07-25T10:12:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgrnd4](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dgrnd4](https://discuss.huggingface.co/u/dgrnd4)\
**Post date:** [July 25, 2022, 10:12am UTC](https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825/1 "2022-07-25T10:12:02Z")

</div>

Hi there, I saved the model using the following code, that load a pre-trained model, save the model, and then load/save the model in the TF version:

```auto
from transformers import AutoModelForImageClassification
model = AutoModelForImageClassification.from_pretrained('google/vit-base-patch16-224')
model.save_pretrained("my_model")

from transformers import TFAutoModelForImageClassification

tf_model = TFAutoModelForImageClassification.from_pretrained("my_model", from_pt=True)
tf_model.save_pretrained("my_model_tf")

```

In my\_model\_tf there are 2 different file:

1. config.json, that contains the “characteristics” of the model
2. tf\_model.h5, that contains the weights of the model

When i try to load tf\_model.h5, I have the following Error:

`ValueError: No model config found in the file at <tensorflow.python.platform.gfile.GFile object at 0x7f83009fb110>`

**There is a way to only obtain an UNIQUE .h5 file that contains the whole model?**

---

<div class="post-metadata">

**Author:** ![Rocketknight1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rocketknight1/32/21055_2.png) [@Rocketknight1](https://discuss.huggingface.co/u/Rocketknight1)\
**Post date:** [July 26, 2022, 1:13pm UTC](https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825/2 "2022-07-26T13:13:17Z")

</div>

Hi @dgrnd4! There are some complexities here - our models are implemented by subclassing, which gives users a lot of flexibility but means that it is impossible to save a full implementation of the model, even as a `SavedModel`. However, you can save specific concrete functions, which is probably what you want to do if you want to create a model artifact for inference or TFLite conversion. You can see the documentation [here](https://www.tensorflow.org/guide/saved_model#specifying_signatures_during_export). For this use-case, I recommend directly using TF/Keras methods like `model.save` to give you more low-level control over the exported signatures, and you will probably also want to set a signature that corresponds to the exact input tensors and shapes you want to use for your TFLite model.

Also, good luck if you’re attempting a TFLite conversion! We don’t officially support it, but I suspect some of our models will convert okay,

---

<div class="post-metadata">

**Author:** ![dgrnd4](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dgrnd4](https://discuss.huggingface.co/u/dgrnd4)\
**Post date:** [July 26, 2022, 4:17pm UTC](https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825/3 "2022-07-26T16:17:18Z")

</div>

Hi @Rocketknight1 thanks for the reply.

What I was thinking is to create a KERAS model so that at the end I can use the model.save(“model.h5”) function to save everything in one file.

What do you mean with **“save specific concrete functions”**? The documentation that you send me is about the model already “converted” in TensorFlow so the model that I have right now is impossible to use with this function because an object.

PROBABLY I’m wrong, so I’m sorry in advice 😅

---

<div class="post-metadata">

**Author:** ![Rocketknight1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rocketknight1/32/21055_2.png) [@Rocketknight1](https://discuss.huggingface.co/u/Rocketknight1)\
**Post date:** [July 26, 2022, 4:26pm UTC](https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825/4 "2022-07-26T16:26:00Z")

</div>

Ah, it might be my fault! What is the ultimate goal here, exactly? Are you trying to convert your model to TFLite? Or do you just want to save the model and reload it again with `from_pretrained()`?

---

<div class="post-metadata">

**Author:** ![dgrnd4](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dgrnd4](https://discuss.huggingface.co/u/dgrnd4)\
**Post date:** [July 26, 2022, 4:27pm UTC](https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825/5 "2022-07-26T16:27:37Z")

</div>

yes, @Rocketknight1 you’re right. My purpose is to convert my model folder (config.json + model.h5) to only one file in the format “.h5” or “TFLite”.

This is my [project](https://colab.research.google.com/drive/1Maye5rC2Fe6MqdKX9C5KxuYfrisUBkhX?usp=sharing) if you want to look at it!

So from now, if you look at the section “Load Model” of my colab file, I have the model saved in 3 different ways: from here, how can I convert it into an unique TFLite or h5 file?

---

<div class="post-metadata">

**Author:** ![dgrnd4](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@dgrnd4](https://discuss.huggingface.co/u/dgrnd4)\
**Post date:** [July 27, 2022, 8:58am UTC](https://discuss.huggingface.co/t/model-saved-into-an-unique-h5-file-or-tensorflowlight/20825/6 "2022-07-27T08:58:07Z")

</div>

Hi @Rocketknight1, maybe I get the solution!

Do you know how can I “extract” concrete functions from my model?
