Izak Hirschman
Izak Hirschman

Reputation: 71

Getting "Unable to load weights from pytorch checkpoint file" when loading model from transformers

When trying load model:

from transformers import TrOCRProcessor,VisionEncoderDecoderModel

model=VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-handwritten')

Getting:

OSError: Unable to load weights from pytorch checkpoint file for '/home/user/.cache/huggingface/hub/models--microsoft--trocr-base-handwritten/snapshots/69659a277424eb381574e4952f3b3fa3440a419b/pytorch_model.bin' at '/home/user/.cache/huggingface/hub/models--microsoft--trocr-base-handwritten/snapshots/69659a277424eb381574e4952f3b3fa3440a419b/pytorch_model.bin'. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

Tried downgrading torch with no success, setting from_tf=True and everthing that in here: https://github.com/huggingface/transformers/issues/4336

Upvotes: 4

Views: 13135

Answers (1)

Izak Hirschman
Izak Hirschman

Reputation: 71

I managed to find the solution all I needed to do is delete the model's folder(69659a277424eb381574e4952f3b3fa3440a419b in my case) from hugging face trocr in:

/home/user/.cache/huggingface/hub/models--microsoft--trocr-base-handwritten/snapshots/69659a277424eb381574e4952f3b3fa3440a419b

and when I restarted the process the model was downloaded again with no problems.

Upvotes: 3

Related Questions