Installing TrOCR on Sagemaker Jupyter Notebook

Hello,

I am trying to run TrOCR in my Sagemaker Jupyter notebook by following the example code here: TrOCR

I start by running:

!pip install transformers

that runs successfully but I then run:

from transformers import TrOCRProcessor, VisionEncoderDecoderModel
import requests 
from PIL import Image

processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten") 
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")

and then I get the following error:


RuntimeError: Failed to import transformers.models.vit.feature_extraction_vit because of the following error (look up to see its traceback):
cannot import name 'HF_MODULES_CACHE' from 'transformers.utils' (/home/ec2-user/anaconda3/envs/pytorch_p38/lib/python3.8/site-packages/transformers/utils/__init__.py)

any advice on how I can resolve this runtime error?r

1 Like