VikParuchuri / surya

OCR, layout analysis, reading order, table recognition in 90+ languages
https://www.datalab.to
GNU General Public License v3.0
14.35k stars 899 forks source link

Does not run without internet #227

Closed rh920 closed 6 days ago

rh920 commented 1 month ago

I want to use surya-ocr offline. I have downloaded models DETECTOR_MODEL_CHECKPOINT and RECOGNITION_MODEL_CHECKPOINT and updated OCR (text recognition) script as shown bellow. However, the script still attemps to download vikp/surya_rec2

from PIL import Image
from surya.ocr import run_ocr
from surya.model.detection.model import load_model as load_det_model, load_processor as load_det_processor
from surya.model.recognition.model import load_model as load_rec_model
from surya.model.recognition.processor import load_processor as load_rec_processor

DETECTOR_MODEL_CHECKPOINT = './models/surya_det3'
RECOGNITION_MODEL_CHECKPOINT = './models/surya_rec2'

image = Image.open(IMAGE_PATH)
langs = ["en"] # Replace with your languages - optional but recommended
det_processor, det_model = load_det_processor(DETECTOR_MODEL_CHECKPOINT), load_det_model(DETECTOR_MODEL_CHECKPOINT)
rec_model, rec_processor = load_rec_model(RECOGNITION_MODEL_CHECKPOINT), load_rec_processor()

predictions = run_ocr([image], [langs], det_model, det_processor, rec_model, rec_processor)

I found that in surya.model.recognition.processor.load_processor there is a class named SuryaProcessor, that uses RECOGNITION_MODEL_CHECKPOINT. I suggest modifying load_processor to accept RECOGNITION_MODEL_CHECKPOINT as an input argument to specify the model path.

Alternatively, if there is a better solution to ensure the script runs without internet access, I would appreciate your guidance.

xiaoyao9184 commented 3 weeks ago

This project uses Hugging Face's cached models and can operate in offline mode by setting HF_HUB_OFFLINE environment variable, which will prevent models from being downloaded.

To use offline mode, you need to pre-download the models. You can do this by running the project to download the models or by using the huggingface-cli download command (recommended).

The downloaded cache follows a dedicated folder structure; see manage-cache for details. You can also change the default cache location by setting the XDG_CACHE_HOME environment variable.

xiaoyao9184 commented 2 weeks ago

After further try, it not only downloads models online but also fetches fonts from GitHub. If you want to run it completely offline, you can use the Docker image I created, which includes a Compose example.

rh920 commented 2 weeks ago

After further try, it not only downloads models online but also fetches fonts from GitHub. If you want to run it completely offline, you can use the Docker image I created, which includes a Compose example.

Thanks a lot. There was range of docker compose file in your repository. Do you know anything about finetuning recognition model?

xiaoyao9184 commented 2 weeks ago

After further try, it not only downloads models online but also fetches fonts from GitHub. If you want to run it completely offline, you can use the Docker image I created, which includes a Compose example.

Thanks a lot. There was range of docker compose file in your repository. Do you know anything about finetuning recognition model?

No, I haven't actually done it.