{"id":20661032,"url":"https://github.com/ai-forever/ocr-model","last_synced_at":"2025-07-04T03:35:57.733Z","repository":{"id":41051089,"uuid":"403656157","full_name":"ai-forever/OCR-model","owner":"ai-forever","description":"An easy-to-run OCR model pipeline based on CRNN and CTC loss","archived":false,"fork":false,"pushed_at":"2023-02-06T12:20:21.000Z","size":96,"stargazers_count":42,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-28T04:55:41.725Z","etag":null,"topics":["crnn","ocr","pytorch","text-recognition"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ai-forever.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-06T14:38:28.000Z","updated_at":"2024-04-16T09:33:40.000Z","dependencies_parsed_at":"2023-01-31T03:00:16.516Z","dependency_job_id":null,"html_url":"https://github.com/ai-forever/OCR-model","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2FOCR-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2FOCR-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2FOCR-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-forever%2FOCR-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ai-forever","download_url":"https://codeload.github.com/ai-forever/OCR-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224958566,"owners_count":17398497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crnn","ocr","pytorch","text-recognition"],"created_at":"2024-11-16T19:06:53.879Z","updated_at":"2024-11-16T19:06:54.400Z","avatar_url":"https://github.com/ai-forever.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OCR model\n\nThis is a model for Optical Character Recognition based on [CRNN-arhitecture](https://arxiv.org/abs/1507.05717) and [CTC loss](https://www.cs.toronto.edu/~graves/icml_2006.pdf).\n\nOCR-model is a part of [ReadingPipeline](https://github.com/ai-forever/ReadingPipeline) repo.\n\n## Demo\n\nIn the [demo](scripts/OCR-GoogleColab.ipynb) you can find an example of using of OCR-model (you can run it in your Google Colab).\n\n## Quick setup and start\n\n- Nvidia drivers \u003e= 470, CUDA \u003e= 11.4\n- [Docker](https://docs.docker.com/engine/install/ubuntu/), [nvidia-docker](https://github.com/NVIDIA/nvidia-docker)\n\nThe provided [Dockerfile](Dockerfile) is supplied to build an image with CUDA support and cuDNN.\n\n### Preparations\n\n- Clone the repo.\n- Download and extract dataset to the `data/` folder.\n- `sudo make all` to build a docker image and create a container.\n  Or `sudo make all GPUS=device=0 CPUS=10` if you want to specify gpu devices and limit CPU-resources.\n\nIf you don't want to use Docker, you can install dependencies via requirements.txt\n\n## Configuring the model\n\nYou can change the [ocr_config.json](scripts/ocr_config.json) and set the necessary training and evaluating parameters: alphabet, image size, saving path, etc.\n\n```\n\"train\": {\n    \"datasets\": [\n        {\n            \"csv_path\": \"/workdir/data/dataset_1/train.csv\",\n            \"prob\": 0.5\n        },\n        {\n            \"csv_path\": \"/workdir/data/dataset_2/train.csv\",\n            \"prob\": 0.7\n        },\n        ...\n    ],\n    \"epoch_size\": 10000,\n    \"batch_size\": 512\n}\n```\n- `epoch_size` - the size of an epoch. If you set it to `null`, then the epoch size will be equal to the amount of samples in the all datasets.\n- It is also possible to specify several datasets for the train/validation/test, setting the probabilities for each dataset separately (the sum of `prob` can be greater than 1, since normalization occurs inside the processing).\n\n## Prepare data\n\nDatasets must be pre-processed and have a single format: each dataset must contain a folder with images (crop images with text) and csv file with annotations. The csv file should contain two columns: \"filename\" with the relative path to the images (folder-name/image-name.png), and \"text\"-column with the image transcription.\n\n| filename          | text |\n| ----------------- | ---- |\n| images/4099-0.png | is   |\n\nIf you use polygon annotations in COCO format, you can prepare a training dataset using this script:\n\n```bash\npython scripts/prepare_dataset.py \\\n    --annotation_json_path path/to/the/annotaions.json \\\n    --annotation_image_root dir/to/images/from/annotation/file \\\n    --class_names pupil_text pupil_comment teacher_comment \\\n    --bbox_scale_x 1 \\\n    --bbox_scale_y 1 \\\n    --save_dir dir/to/save/dataset \\\n    --output_csv_name data.csv\n```\n\n## Training\n\nTo train the model:\n\n```bash\npython scripts/train.py --config_path path/to/the/ocr_config.json\n```\n\n## Evaluating\n\nTo test the model:\n\n```bash\npython scripts/evaluate.py \\\n--config_path path/to/the/ocr_config.json \\\n--model_path path/to/the/model-weights.ckpt\n```\n\nIf you want to use a beam search decoder with LM, you can pass lm_path arg with path to .arpa kenLM file.\n--lm_path path/to/the/language-model.arpa\n\n## ONNX\n\nYou can convert Torch model to ONNX to speed up inference on cpu.\n\n```bash\npython scripts/torch2onnx.py \\\n--config_path path/to/the/ocr_config.json \\\n--model_path path/to/the/model-weights.ckpt\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-forever%2Focr-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fai-forever%2Focr-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-forever%2Focr-model/lists"}