# Load fine tuned model in tensorflow

**URL:** <https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932>\
**Category:** Intermediate\
**Created:** [August 3, 2021, 9:37am UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932 "2021-08-03T09:37:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](https://discuss.huggingface.co/u/ahmedlone123)\
**Post date:** [August 3, 2021, 9:37am UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/1 "2021-08-03T09:37:30Z")

</div>

I fine-tuned a pre-trained model(wav2vec) in hugging face using the transformers library and converted it from PyTorch to Tensorflow. I want to load this fine-tuned model in Tensorlfow but I can’t seem to find any tutorials showcasing how to. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [August 3, 2021, 10:59am UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/2 "2021-08-03T10:59:49Z")

</div>

```auto
from transformers import TFWav2Vec2ForXxx

TFWav2Vec2ForXxx.from_pretrained(model_name_or_path)

```

where `model_name_or_path` is the folder where you stored that model, or the name of the repo you pushed it to on the Hugging Face Hub.

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](https://discuss.huggingface.co/u/ahmedlone123)\
**Post date:** [August 3, 2021, 1:12pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/3 "2021-08-03T13:12:46Z")

</div>

How would i load this model in tensorflow , wouldn’t this be loading it using huggingface ?

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [August 3, 2021, 4:06pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/4 "2021-08-03T16:06:25Z")

</div>

The TensorFlow library does not offer an implementation of the Wav2Vec2 model, so I’m not sure how you would like to be loading it without using Transformers.

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](https://discuss.huggingface.co/u/ahmedlone123)\
**Post date:** [August 3, 2021, 4:17pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/5 "2021-08-03T16:17:04Z")

</div>

[https://tfhub.dev/vasudevgupta7/wav2vec2/1](https://tfhub.dev/vasudevgupta7/wav2vec2/1)  
well there is this

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [August 3, 2021, 4:19pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/6 "2021-08-03T16:19:39Z")

</div>

This is one particular model, not the architecture. Since the person that added it to the TF Hub is a core contributor to Transformers, it’s probably the same code as in the library behind it.

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](https://discuss.huggingface.co/u/ahmedlone123)\
**Post date:** [August 3, 2021, 4:23pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/7 "2021-08-03T16:23:44Z")

</div>

okay thank you i am going to try to retrain the model in pure tenserflow

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [August 3, 2021, 4:35pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/8 "2021-08-03T16:35:59Z")

</div>

I’m not sure you need to, you can save the model loaded as above in any pure TF format you want. As you would when retraining the model in pure TensorFlow.

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](https://discuss.huggingface.co/u/ahmedlone123)\
**Post date:** [August 3, 2021, 4:45pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/9 "2021-08-03T16:45:59Z")

</div>

Well my main goal is to be able to load the wav2vec model inside tensorflow and after training a pytroch model inside hugging face and converting it to tensorflow I get a h5 file and a seperate config file .

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/6/6001b7642c88ac00cf2800bde4fbca8108c31cf5.png)

when I try to load it like this it gives me this error but when I try running this notebook:

[https://colab.research.google.com/github/vasudevgupta7/gsoc-wav2vec2/blob/main/notebooks/wav2vec2\_saved\_model\_finetuning.ipynb](https://colab.research.google.com/github/vasudevgupta7/gsoc-wav2vec2/blob/main/notebooks/wav2vec2_saved_model_finetuning.ipynb)

which is the wav2vec model the guy upload to tensorflow this part works :

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/b/b2a57f68f2f05d54d7a039b3c7d7a0dba348fbaf.png)

soo Idk what’s wrong with this .  
Thank you for being patient with me

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [August 3, 2021, 4:56pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/10 "2021-08-03T16:56:03Z")

</div>

As I said, first load it inside a `TFWav2Vec2ForXxx` model (I’m not sure exactly which model you used, replaced the Xxx to the proper name). You can do this with

```auto
TFWav2Vec2ForXxx.from_pretrained(path_to_pytorch_model, from_pt=True)

```

This model will be a Keras model. You can save it using Keras, so should be able to then load it with Keras.

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](https://discuss.huggingface.co/u/ahmedlone123)\
**Post date:** [August 3, 2021, 4:56pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/11 "2021-08-03T16:56:48Z")

</div>

okay thank you i will try this i am sorry for wasting ur time

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](https://discuss.huggingface.co/u/ahmedlone123)\
**Post date:** [August 3, 2021, 5:15pm UTC](https://discuss.huggingface.co/t/load-fine-tuned-model-in-tensorflow/8932/12 "2021-08-03T17:15:32Z")

</div>

I tried it :

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/3/383b0b668820c835c8f949fc455ae00db1ce333a.png)

I tried this way too :

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/7/7b29529600372d04616ad46363bd30ca71a8d5e6.png)
