# Cannot load a saved (fine-tuned) model?

**URL:** <https://discuss.huggingface.co/t/cannot-load-a-saved-fine-tuned-model/9307>\
**Category:** 🤗Transformers\
**Created:** [August 17, 2021, 8:02pm UTC](https://discuss.huggingface.co/t/cannot-load-a-saved-fine-tuned-model/9307 "2021-08-17T20:02:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![olaffson](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/olaffson/32/2416_2.png) [@olaffson](https://discuss.huggingface.co/u/olaffson)\
**Post date:** [August 17, 2021, 8:02pm UTC](https://discuss.huggingface.co/t/cannot-load-a-saved-fine-tuned-model/9307/1 "2021-08-17T20:02:19Z")

</div>

Hello there,

I am facing a rather annoying issue. I fine-tuned a Bert model for classification and saved the resulting model to disk. However, I am unable to subsequently load the model.

This is essentially what I do:

```auto
tokenizer = AutoTokenizer.from_pretrained('C:\\Users\\bert-sentiment')
#tokenize text...
model = TFAutoModelForSequenceClassification.from_pretrained('C:\\Users\\bert-sentiment',
                                                                  num_labels =3,
                                                                  ignore_mismatched_sizes = True)
#fine tune model...
model.fit()
model.save_pretrained('C:\\Users\\mydir')

```

mydir contains two files `tf_model.h5` and `config.json`. However, when I tried to load the model by simply running

```
mymodel = TFAutoModelForSequenceClassification.from_pretrained("C:\\Users\\mydir")

```

I get the error

`OSError: Unable to load weights from h5 file. If you tried to load a TF 2.0 model from a PyTorch checkpoint, please set from_pt=True.`

☹ do you know what the issue could be?  
Thanks!

---

<div class="post-metadata">

**Author:** ![olaffson](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/olaffson/32/2416_2.png) [@olaffson](https://discuss.huggingface.co/u/olaffson)\
**Post date:** [August 18, 2021, 1:25pm UTC](https://discuss.huggingface.co/t/cannot-load-a-saved-fine-tuned-model/9307/2 "2021-08-18T13:25:11Z")

</div>

Strange bug. I re-generated the saved models and then loading worked fine. Perhaps some corruption at saving time?
