Spaces:
Runtime error
Runtime error
pawandev
commited on
Commit
·
bfea304
1
Parent(s):
defc287
first push
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- Dockerfile +23 -0
- local_test.py +21 -0
- main.py +100 -0
- requirements.txt +7 -0
- torch/.DS_Store +0 -0
- torch/hub/.DS_Store +0 -0
- torch/hub/baudm_parseq_main/.DS_Store +0 -0
- torch/hub/baudm_parseq_main/.git-blame-ignore-revs +2 -0
- torch/hub/baudm_parseq_main/.github/contexts-example.png +0 -0
- torch/hub/baudm_parseq_main/.github/gh-teaser.png +0 -0
- torch/hub/baudm_parseq_main/.github/system.png +0 -0
- torch/hub/baudm_parseq_main/.gitignore +148 -0
- torch/hub/baudm_parseq_main/.pre-commit-config.yaml +18 -0
- torch/hub/baudm_parseq_main/Datasets.md +92 -0
- torch/hub/baudm_parseq_main/LICENSE +202 -0
- torch/hub/baudm_parseq_main/Makefile +30 -0
- torch/hub/baudm_parseq_main/NOTICE +18 -0
- torch/hub/baudm_parseq_main/README.md +280 -0
- torch/hub/baudm_parseq_main/bench.py +54 -0
- torch/hub/baudm_parseq_main/configs/.DS_Store +0 -0
- torch/hub/baudm_parseq_main/configs/bench.yaml +10 -0
- torch/hub/baudm_parseq_main/configs/charset/36_lowercase.yaml +3 -0
- torch/hub/baudm_parseq_main/configs/charset/62_mixed-case.yaml +3 -0
- torch/hub/baudm_parseq_main/configs/charset/94_full.yaml +3 -0
- torch/hub/baudm_parseq_main/configs/dataset/real.yaml +3 -0
- torch/hub/baudm_parseq_main/configs/dataset/synth.yaml +7 -0
- torch/hub/baudm_parseq_main/configs/experiment/abinet-sv.yaml +8 -0
- torch/hub/baudm_parseq_main/configs/experiment/abinet.yaml +3 -0
- torch/hub/baudm_parseq_main/configs/experiment/crnn.yaml +6 -0
- torch/hub/baudm_parseq_main/configs/experiment/parseq-patch16-224.yaml +7 -0
- torch/hub/baudm_parseq_main/configs/experiment/parseq-tiny.yaml +9 -0
- torch/hub/baudm_parseq_main/configs/experiment/parseq.yaml +3 -0
- torch/hub/baudm_parseq_main/configs/experiment/trba.yaml +6 -0
- torch/hub/baudm_parseq_main/configs/experiment/trbc.yaml +11 -0
- torch/hub/baudm_parseq_main/configs/experiment/tune_abinet-lm.yaml +17 -0
- torch/hub/baudm_parseq_main/configs/experiment/vitstr.yaml +7 -0
- torch/hub/baudm_parseq_main/configs/main.yaml +52 -0
- torch/hub/baudm_parseq_main/configs/model/abinet.yaml +26 -0
- torch/hub/baudm_parseq_main/configs/model/crnn.yaml +9 -0
- torch/hub/baudm_parseq_main/configs/model/parseq.yaml +25 -0
- torch/hub/baudm_parseq_main/configs/model/trba.yaml +10 -0
- torch/hub/baudm_parseq_main/configs/model/vitstr.yaml +13 -0
- torch/hub/baudm_parseq_main/configs/tune.yaml +18 -0
- torch/hub/baudm_parseq_main/demo_images/art-01107.jpg +0 -0
- torch/hub/baudm_parseq_main/demo_images/coco-1166773.jpg +0 -0
- torch/hub/baudm_parseq_main/demo_images/cute-184.jpg +0 -0
- torch/hub/baudm_parseq_main/demo_images/ic13_word_256.png +0 -0
- torch/hub/baudm_parseq_main/demo_images/ic15_word_26.png +0 -0
- torch/hub/baudm_parseq_main/demo_images/uber-27491.jpg +0 -0
- torch/hub/baudm_parseq_main/hubconf.py +66 -0
Dockerfile
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM public.ecr.aws/lambda/python:3.12
|
2 |
+
|
3 |
+
# Copy requirements.txt
|
4 |
+
COPY requirements.txt ${LAMBDA_TASK_ROOT}
|
5 |
+
|
6 |
+
# Install the specified packages
|
7 |
+
RUN pip install -r requirements.txt
|
8 |
+
|
9 |
+
# Install OpenCV dependencies
|
10 |
+
# RUN yum install -y libSM libXrender libXext
|
11 |
+
|
12 |
+
# Copy function code
|
13 |
+
COPY main.py ${LAMBDA_TASK_ROOT}/
|
14 |
+
COPY torch ${LAMBDA_TASK_ROOT}/torch/
|
15 |
+
COPY local_test.py ${LAMBDA_TASK_ROOT}/
|
16 |
+
|
17 |
+
# Ensure the model files have correct permissions
|
18 |
+
RUN chmod -R 755 ${LAMBDA_TASK_ROOT}/torch/
|
19 |
+
RUN chmod -R 755 ${LAMBDA_TASK_ROOT}
|
20 |
+
RUN chmod -R 755 ${LAMBDA_TASK_ROOT}/
|
21 |
+
|
22 |
+
# Set the CMD to run the test script
|
23 |
+
CMD [ "main.lambda_handler" ]
|
local_test.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from main import lambda_handler
|
3 |
+
|
4 |
+
event = {
|
5 |
+
"headers": {
|
6 |
+
"Content-Type": "application/json"
|
7 |
+
},
|
8 |
+
"body": json.dumps({
|
9 |
+
"imgUrl": "https://iduploadbucket.s3.ap-south-1.amazonaws.com/DFaqQf.png",
|
10 |
+
"brightness":1,
|
11 |
+
"contrast":4,
|
12 |
+
"saturation":4
|
13 |
+
}),
|
14 |
+
"httpMethod": "POST",
|
15 |
+
"isBase64Encoded": False,
|
16 |
+
"path": "/captchaSolver"
|
17 |
+
}
|
18 |
+
|
19 |
+
response = lambda_handler(event, None)
|
20 |
+
print(json.dumps(response, indent=4))
|
21 |
+
|
main.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import json
|
3 |
+
import requests
|
4 |
+
from io import BytesIO
|
5 |
+
from time import time
|
6 |
+
import base64
|
7 |
+
|
8 |
+
from torchOcr import OCRModel
|
9 |
+
|
10 |
+
def validate_image_url(img_url):
|
11 |
+
response = requests.get(img_url)
|
12 |
+
if response.status_code != 200:
|
13 |
+
raise ValueError("Failed to retrieve image from URL")
|
14 |
+
if response.headers['Content-Type'] not in ['image/jpeg', 'image/jpg', 'image/png']:
|
15 |
+
raise ValueError("Invalid file type")
|
16 |
+
return response.content
|
17 |
+
|
18 |
+
def lambda_handler(event, context):
|
19 |
+
http_method = event['httpMethod']
|
20 |
+
path = event['path']
|
21 |
+
start_time = time()
|
22 |
+
|
23 |
+
ocr_model = OCRModel()
|
24 |
+
|
25 |
+
try:
|
26 |
+
if http_method == 'GET' and path == '/':
|
27 |
+
return {
|
28 |
+
"statusCode": 200,
|
29 |
+
"body": json.dumps({"message": "Hello from CaptchaSolver v1.0!"})
|
30 |
+
}
|
31 |
+
|
32 |
+
if http_method != 'POST':
|
33 |
+
return {
|
34 |
+
"statusCode": 405,
|
35 |
+
"body": json.dumps({"error": "Method not allowed"})
|
36 |
+
}
|
37 |
+
|
38 |
+
content_type = event['headers'].get('Content-Type', '')
|
39 |
+
|
40 |
+
if 'multipart/form-data' in content_type:
|
41 |
+
# Handle file upload via Postman
|
42 |
+
file_content = event['body']
|
43 |
+
img_buffer = BytesIO(base64.b64decode(file_content))
|
44 |
+
img_url = None # No URL provided in this case
|
45 |
+
brightness = body.get('brightness', 1.0)
|
46 |
+
contrast = body.get('contrast', 1.0)
|
47 |
+
sharpness = body.get('sharpness', 1.0)
|
48 |
+
else:
|
49 |
+
# Handle JSON input
|
50 |
+
body = json.loads(event.get('body', '{}'))
|
51 |
+
img_url = body.get('imgUrl')
|
52 |
+
img_buffer = None
|
53 |
+
brightness = body.get('brightness', 1.0)
|
54 |
+
contrast = body.get('contrast', 1.0)
|
55 |
+
sharpness = body.get('sharpness', 1.0)
|
56 |
+
|
57 |
+
if not img_url and not img_buffer:
|
58 |
+
return {
|
59 |
+
"statusCode": 400,
|
60 |
+
"body": json.dumps({"error": "Either imgUrl or image buffer must be provided"})
|
61 |
+
}
|
62 |
+
|
63 |
+
if img_url:
|
64 |
+
img_content = validate_image_url(img_url)
|
65 |
+
image_buffer = io.BytesIO(img_content)
|
66 |
+
else:
|
67 |
+
image_buffer = img_buffer
|
68 |
+
|
69 |
+
if path == '/captchaSolver':
|
70 |
+
detected_text = ocr_model.predict(image_buffer, brightness, contrast, sharpness)
|
71 |
+
result_message = "OCR Completed Successfully."
|
72 |
+
else:
|
73 |
+
return {
|
74 |
+
"statusCode": 404,
|
75 |
+
"body": json.dumps({"error": "Path not found"})
|
76 |
+
}
|
77 |
+
|
78 |
+
end_time = time()
|
79 |
+
execution_time = end_time - start_time
|
80 |
+
|
81 |
+
return {
|
82 |
+
"statusCode": 200,
|
83 |
+
"body": json.dumps({
|
84 |
+
"detected_text": detected_text,
|
85 |
+
"result": result_message,
|
86 |
+
"execution_time": f"{round(execution_time, 2)} sec",
|
87 |
+
})
|
88 |
+
}
|
89 |
+
|
90 |
+
except ValueError as ve:
|
91 |
+
return {
|
92 |
+
"statusCode": 400,
|
93 |
+
"body": json.dumps({"error": str(ve)})
|
94 |
+
}
|
95 |
+
except Exception as e:
|
96 |
+
print(f"Error: {str(e)}")
|
97 |
+
return {
|
98 |
+
"statusCode": 500,
|
99 |
+
"body": json.dumps({"error": "Internal server error", "details": str(e)})
|
100 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pillow
|
2 |
+
torchvision
|
3 |
+
pyyaml
|
4 |
+
pytorch_lightning
|
5 |
+
timm
|
6 |
+
nltk
|
7 |
+
requests
|
torch/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
torch/hub/.DS_Store
ADDED
Binary file (8.2 kB). View file
|
|
torch/hub/baudm_parseq_main/.DS_Store
ADDED
Binary file (10.2 kB). View file
|
|
torch/hub/baudm_parseq_main/.git-blame-ignore-revs
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# Migrate code style to pyink
|
2 |
+
91f56d71736b77242f31dfb408f71d49fc0e3fcc
|
torch/hub/baudm_parseq_main/.github/contexts-example.png
ADDED
![]() |
torch/hub/baudm_parseq_main/.github/gh-teaser.png
ADDED
![]() |
torch/hub/baudm_parseq_main/.github/system.png
ADDED
![]() |
torch/hub/baudm_parseq_main/.gitignore
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Output directories
|
2 |
+
outputs/
|
3 |
+
multirun/
|
4 |
+
ray_results/
|
5 |
+
|
6 |
+
# Byte-compiled / optimized / DLL files
|
7 |
+
__pycache__/
|
8 |
+
*.py[cod]
|
9 |
+
*$py.class
|
10 |
+
|
11 |
+
# C extensions
|
12 |
+
*.so
|
13 |
+
|
14 |
+
# Distribution / packaging
|
15 |
+
requirements/core.*.txt
|
16 |
+
.Python
|
17 |
+
build/
|
18 |
+
develop-eggs/
|
19 |
+
dist/
|
20 |
+
downloads/
|
21 |
+
eggs/
|
22 |
+
.eggs/
|
23 |
+
lib/
|
24 |
+
lib64/
|
25 |
+
parts/
|
26 |
+
sdist/
|
27 |
+
var/
|
28 |
+
wheels/
|
29 |
+
share/python-wheels/
|
30 |
+
*.egg-info/
|
31 |
+
.installed.cfg
|
32 |
+
*.egg
|
33 |
+
MANIFEST
|
34 |
+
|
35 |
+
# PyInstaller
|
36 |
+
# Usually these files are written by a python script from a template
|
37 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
38 |
+
*.manifest
|
39 |
+
*.spec
|
40 |
+
|
41 |
+
# Installer logs
|
42 |
+
pip-log.txt
|
43 |
+
pip-delete-this-directory.txt
|
44 |
+
|
45 |
+
# Unit test / coverage reports
|
46 |
+
htmlcov/
|
47 |
+
.tox/
|
48 |
+
.nox/
|
49 |
+
.coverage
|
50 |
+
.coverage.*
|
51 |
+
.cache
|
52 |
+
nosetests.xml
|
53 |
+
coverage.xml
|
54 |
+
*.cover
|
55 |
+
*.py,cover
|
56 |
+
.hypothesis/
|
57 |
+
.pytest_cache/
|
58 |
+
cover/
|
59 |
+
|
60 |
+
# Translations
|
61 |
+
*.mo
|
62 |
+
*.pot
|
63 |
+
|
64 |
+
# Django stuff:
|
65 |
+
*.log
|
66 |
+
local_settings.py
|
67 |
+
db.sqlite3
|
68 |
+
db.sqlite3-journal
|
69 |
+
|
70 |
+
# Flask stuff:
|
71 |
+
instance/
|
72 |
+
.webassets-cache
|
73 |
+
|
74 |
+
# Scrapy stuff:
|
75 |
+
.scrapy
|
76 |
+
|
77 |
+
# Sphinx documentation
|
78 |
+
docs/_build/
|
79 |
+
|
80 |
+
# PyBuilder
|
81 |
+
.pybuilder/
|
82 |
+
target/
|
83 |
+
|
84 |
+
# Jupyter Notebook
|
85 |
+
.ipynb_checkpoints
|
86 |
+
|
87 |
+
# IPython
|
88 |
+
profile_default/
|
89 |
+
ipython_config.py
|
90 |
+
|
91 |
+
# pyenv
|
92 |
+
# For a library or package, you might want to ignore these files since the code is
|
93 |
+
# intended to run in multiple environments; otherwise, check them in:
|
94 |
+
# .python-version
|
95 |
+
|
96 |
+
# pipenv
|
97 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
98 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
99 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
100 |
+
# install all needed dependencies.
|
101 |
+
#Pipfile.lock
|
102 |
+
|
103 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
104 |
+
__pypackages__/
|
105 |
+
|
106 |
+
# Celery stuff
|
107 |
+
celerybeat-schedule
|
108 |
+
celerybeat.pid
|
109 |
+
|
110 |
+
# SageMath parsed files
|
111 |
+
*.sage.py
|
112 |
+
|
113 |
+
# Environments
|
114 |
+
.env
|
115 |
+
.venv
|
116 |
+
env/
|
117 |
+
venv/
|
118 |
+
ENV/
|
119 |
+
env.bak/
|
120 |
+
venv.bak/
|
121 |
+
.python-version
|
122 |
+
|
123 |
+
# Spyder project settings
|
124 |
+
.spyderproject
|
125 |
+
.spyproject
|
126 |
+
|
127 |
+
# Rope project settings
|
128 |
+
.ropeproject
|
129 |
+
|
130 |
+
# mkdocs documentation
|
131 |
+
/site
|
132 |
+
|
133 |
+
# mypy
|
134 |
+
.mypy_cache/
|
135 |
+
.dmypy.json
|
136 |
+
dmypy.json
|
137 |
+
|
138 |
+
# Pyre type checker
|
139 |
+
.pyre/
|
140 |
+
|
141 |
+
# pytype static type analyzer
|
142 |
+
.pytype/
|
143 |
+
|
144 |
+
# Cython debug symbols
|
145 |
+
cython_debug/
|
146 |
+
|
147 |
+
# IDE
|
148 |
+
.idea/
|
torch/hub/baudm_parseq_main/.pre-commit-config.yaml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
exclude: '(abinet|crnn|trba|vitstr)/(?!system.py)'
|
2 |
+
|
3 |
+
repos:
|
4 |
+
- repo: https://github.com/baudm/isort
|
5 |
+
rev: 5.13.2
|
6 |
+
hooks:
|
7 |
+
- id: isort
|
8 |
+
|
9 |
+
- repo: https://github.com/google/pyink
|
10 |
+
rev: 23.10.0
|
11 |
+
hooks:
|
12 |
+
- id: pyink
|
13 |
+
|
14 |
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
15 |
+
rev: v0.2.2
|
16 |
+
hooks:
|
17 |
+
- id: ruff
|
18 |
+
args: [--exit-non-zero-on-fix]
|
torch/hub/baudm_parseq_main/Datasets.md
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
We use various synthetic and real datasets. More info is in Appendix F of the supplementary material. Some preprocessing scripts are included in [`tools/`](tools).
|
2 |
+
|
3 |
+
| Dataset | Type | Remarks |
|
4 |
+
|:-------:|:-----:|:--------|
|
5 |
+
| [MJSynth](https://www.robots.ox.ac.uk/~vgg/data/text/) | synthetic | Case-sensitive annotations were extracted from the image filenames |
|
6 |
+
| [SynthText](https://www.robots.ox.ac.uk/~vgg/data/scenetext/) | synthetic | Processed with [`crop_by_word_bb_syn90k.py`](https://github.com/FangShancheng/ABINet/blob/main/tools/crop_by_word_bb_syn90k.py) |
|
7 |
+
| [IC13](https://rrc.cvc.uab.es/?ch=2) | real | Three archives: 857, 1015, 1095 (full) |
|
8 |
+
| [IC15](https://rrc.cvc.uab.es/?ch=4) | real | Two archives: 1811, 2077 (full) |
|
9 |
+
| [CUTE80](http://cs-chan.com/downloads_cute80_dataset.html) | real | \[1\] |
|
10 |
+
| [IIIT5k](https://cvit.iiit.ac.in/research/projects/cvit-projects/the-iiit-5k-word-dataset) | real | \[1\] |
|
11 |
+
| [SVT](http://vision.ucsd.edu/~kai/svt/) | real | \[1\] |
|
12 |
+
| [SVTP](https://openaccess.thecvf.com/content_iccv_2013/html/Phan_Recognizing_Text_with_2013_ICCV_paper.html) | real | \[1\] |
|
13 |
+
| [ArT](https://rrc.cvc.uab.es/?ch=14) | real | \[2\] |
|
14 |
+
| [LSVT](https://rrc.cvc.uab.es/?ch=16) | real | \[2\] |
|
15 |
+
| [MLT19](https://rrc.cvc.uab.es/?ch=15) | real | \[2\] |
|
16 |
+
| [RCTW17](https://rctw.vlrlab.net/dataset.html) | real | \[2\] |
|
17 |
+
| [ReCTS](https://rrc.cvc.uab.es/?ch=12) | real | \[2\] |
|
18 |
+
| [Uber-Text](https://s3-us-west-2.amazonaws.com/uber-common-public/ubertext/index.html) | real | \[2\] |
|
19 |
+
| [COCO-Text v1.4](https://rrc.cvc.uab.es/?ch=5) | real | Processed with [`coco_text_converter.py`](tools/coco_text_converter.py) |
|
20 |
+
| [COCO-Text v2.0](https://bgshih.github.io/cocotext/) | real | Processed with [`coco_2_converter.py`](tools/coco_2_converter.py) |
|
21 |
+
| [OpenVINO](https://proceedings.mlr.press/v157/krylov21a.html) | real | [Annotations](https://storage.openvinotoolkit.org/repositories/openvino_training_extensions/datasets/open_images_v5_text/) for a subset of [Open Images](https://github.com/cvdfoundation/open-images-dataset). Processed with [`openvino_converter.py`](tools/openvino_converter.py). |
|
22 |
+
| [TextOCR](https://textvqa.org/textocr/) | real | Annotations for a subset of Open Images. Processed with [`textocr_converter.py`](tools/textocr_converter.py). A _horizontal_ version can be generated by passing `--rectify_pose`. |
|
23 |
+
|
24 |
+
\[1\] Case-sensitive annotations from [Long and Yao](https://github.com/Jyouhou/Case-Sensitive-Scene-Text-Recognition-Datasets) + [our corrections](https://github.com/baudm/Case-Sensitive-Scene-Text-Recognition-Datasets). Processed with [case_sensitive_str_datasets_converter.py](tools/case_sensitive_str_datasets_converter.py)<br/>
|
25 |
+
\[2\] Archives used as-is from [Baek et al.](https://github.com/ku21fan/STR-Fewer-Labels/blob/main/data.md) They are included in the dataset release for convenience. Please refer to their work for more info about the datasets.
|
26 |
+
|
27 |
+
The preprocessed archives are available here: [val + test + most of train](https://drive.google.com/drive/folders/1NYuoi7dfJVgo-zUJogh8UQZgIMpLviOE), [TextOCR + OpenVINO](https://drive.google.com/drive/folders/1D9z_YJVa6f-O0juni-yG5jcwnhvYw-qC)
|
28 |
+
|
29 |
+
The expected filesystem structure is as follows:
|
30 |
+
```
|
31 |
+
data
|
32 |
+
├── test
|
33 |
+
│ ├── ArT
|
34 |
+
│ ├── COCOv1.4
|
35 |
+
│ ├── CUTE80
|
36 |
+
│ ├── IC13_1015
|
37 |
+
│ ├── IC13_1095 # Full IC13 test set. Typically not used for benchmarking but provided here for convenience.
|
38 |
+
│ ├── IC13_857
|
39 |
+
│ ├── IC15_1811
|
40 |
+
│ ├── IC15_2077
|
41 |
+
│ ├── IIIT5k
|
42 |
+
│ ├── SVT
|
43 |
+
│ ├── SVTP
|
44 |
+
│ └── Uber
|
45 |
+
├── train
|
46 |
+
│ ├── real
|
47 |
+
│ │ ├── ArT
|
48 |
+
│ │ │ ├── train
|
49 |
+
│ │ │ └── val
|
50 |
+
│ │ ├── COCOv2.0
|
51 |
+
│ │ │ ├── train
|
52 |
+
│ │ │ └── val
|
53 |
+
│ │ ├── LSVT
|
54 |
+
│ │ │ ├── test
|
55 |
+
│ │ │ ├── train
|
56 |
+
│ │ │ └── val
|
57 |
+
│ │ ├── MLT19
|
58 |
+
│ │ │ ├── test
|
59 |
+
│ │ │ ├── train
|
60 |
+
│ │ │ └── val
|
61 |
+
│ │ ├── OpenVINO
|
62 |
+
│ │ │ ├── train_1
|
63 |
+
│ │ │ ├── train_2
|
64 |
+
│ │ │ ├── train_5
|
65 |
+
│ │ │ ├── train_f
|
66 |
+
│ │ │ └── validation
|
67 |
+
│ │ ├── RCTW17
|
68 |
+
│ │ │ ├── test
|
69 |
+
│ │ │ ├── train
|
70 |
+
│ │ │ └── val
|
71 |
+
│ │ ├── ReCTS
|
72 |
+
│ │ │ ├── test
|
73 |
+
│ │ │ ├── train
|
74 |
+
│ │ │ └── val
|
75 |
+
│ │ ├── TextOCR
|
76 |
+
│ │ │ ├── train
|
77 |
+
│ │ │ └── val
|
78 |
+
│ │ └── Uber
|
79 |
+
│ │ ├── train
|
80 |
+
│ │ └── val
|
81 |
+
│ └── synth
|
82 |
+
│ ├── MJ
|
83 |
+
│ │ ├── test
|
84 |
+
│ │ ├── train
|
85 |
+
│ │ └── val
|
86 |
+
│ └── ST
|
87 |
+
└── val
|
88 |
+
├── IC13
|
89 |
+
├── IC15
|
90 |
+
├── IIIT5k
|
91 |
+
└── SVT
|
92 |
+
```
|
torch/hub/baudm_parseq_main/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
Apache License
|
3 |
+
Version 2.0, January 2004
|
4 |
+
http://www.apache.org/licenses/
|
5 |
+
|
6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7 |
+
|
8 |
+
1. Definitions.
|
9 |
+
|
10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
12 |
+
|
13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14 |
+
the copyright owner that is granting the License.
|
15 |
+
|
16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
17 |
+
other entities that control, are controlled by, or are under common
|
18 |
+
control with that entity. For the purposes of this definition,
|
19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
20 |
+
direction or management of such entity, whether by contract or
|
21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23 |
+
|
24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25 |
+
exercising permissions granted by this License.
|
26 |
+
|
27 |
+
"Source" form shall mean the preferred form for making modifications,
|
28 |
+
including but not limited to software source code, documentation
|
29 |
+
source, and configuration files.
|
30 |
+
|
31 |
+
"Object" form shall mean any form resulting from mechanical
|
32 |
+
transformation or translation of a Source form, including but
|
33 |
+
not limited to compiled object code, generated documentation,
|
34 |
+
and conversions to other media types.
|
35 |
+
|
36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
37 |
+
Object form, made available under the License, as indicated by a
|
38 |
+
copyright notice that is included in or attached to the work
|
39 |
+
(an example is provided in the Appendix below).
|
40 |
+
|
41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42 |
+
form, that is based on (or derived from) the Work and for which the
|
43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
45 |
+
of this License, Derivative Works shall not include works that remain
|
46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47 |
+
the Work and Derivative Works thereof.
|
48 |
+
|
49 |
+
"Contribution" shall mean any work of authorship, including
|
50 |
+
the original version of the Work and any modifications or additions
|
51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
55 |
+
means any form of electronic, verbal, or written communication sent
|
56 |
+
to the Licensor or its representatives, including but not limited to
|
57 |
+
communication on electronic mailing lists, source code control systems,
|
58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
60 |
+
excluding communication that is conspicuously marked or otherwise
|
61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
62 |
+
|
63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
65 |
+
subsequently incorporated within the Work.
|
66 |
+
|
67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
72 |
+
Work and such Derivative Works in Source or Object form.
|
73 |
+
|
74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77 |
+
(except as stated in this section) patent license to make, have made,
|
78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79 |
+
where such license applies only to those patent claims licensable
|
80 |
+
by such Contributor that are necessarily infringed by their
|
81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
83 |
+
institute patent litigation against any entity (including a
|
84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85 |
+
or a Contribution incorporated within the Work constitutes direct
|
86 |
+
or contributory patent infringement, then any patent licenses
|
87 |
+
granted to You under this License for that Work shall terminate
|
88 |
+
as of the date such litigation is filed.
|
89 |
+
|
90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
91 |
+
Work or Derivative Works thereof in any medium, with or without
|
92 |
+
modifications, and in Source or Object form, provided that You
|
93 |
+
meet the following conditions:
|
94 |
+
|
95 |
+
(a) You must give any other recipients of the Work or
|
96 |
+
Derivative Works a copy of this License; and
|
97 |
+
|
98 |
+
(b) You must cause any modified files to carry prominent notices
|
99 |
+
stating that You changed the files; and
|
100 |
+
|
101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
102 |
+
that You distribute, all copyright, patent, trademark, and
|
103 |
+
attribution notices from the Source form of the Work,
|
104 |
+
excluding those notices that do not pertain to any part of
|
105 |
+
the Derivative Works; and
|
106 |
+
|
107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108 |
+
distribution, then any Derivative Works that You distribute must
|
109 |
+
include a readable copy of the attribution notices contained
|
110 |
+
within such NOTICE file, excluding those notices that do not
|
111 |
+
pertain to any part of the Derivative Works, in at least one
|
112 |
+
of the following places: within a NOTICE text file distributed
|
113 |
+
as part of the Derivative Works; within the Source form or
|
114 |
+
documentation, if provided along with the Derivative Works; or,
|
115 |
+
within a display generated by the Derivative Works, if and
|
116 |
+
wherever such third-party notices normally appear. The contents
|
117 |
+
of the NOTICE file are for informational purposes only and
|
118 |
+
do not modify the License. You may add Your own attribution
|
119 |
+
notices within Derivative Works that You distribute, alongside
|
120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
121 |
+
that such additional attribution notices cannot be construed
|
122 |
+
as modifying the License.
|
123 |
+
|
124 |
+
You may add Your own copyright statement to Your modifications and
|
125 |
+
may provide additional or different license terms and conditions
|
126 |
+
for use, reproduction, or distribution of Your modifications, or
|
127 |
+
for any such Derivative Works as a whole, provided Your use,
|
128 |
+
reproduction, and distribution of the Work otherwise complies with
|
129 |
+
the conditions stated in this License.
|
130 |
+
|
131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
133 |
+
by You to the Licensor shall be under the terms and conditions of
|
134 |
+
this License, without any additional terms or conditions.
|
135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136 |
+
the terms of any separate license agreement you may have executed
|
137 |
+
with Licensor regarding such Contributions.
|
138 |
+
|
139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
141 |
+
except as required for reasonable and customary use in describing the
|
142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
143 |
+
|
144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145 |
+
agreed to in writing, Licensor provides the Work (and each
|
146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148 |
+
implied, including, without limitation, any warranties or conditions
|
149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151 |
+
appropriateness of using or redistributing the Work and assume any
|
152 |
+
risks associated with Your exercise of permissions under this License.
|
153 |
+
|
154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
155 |
+
whether in tort (including negligence), contract, or otherwise,
|
156 |
+
unless required by applicable law (such as deliberate and grossly
|
157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158 |
+
liable to You for damages, including any direct, indirect, special,
|
159 |
+
incidental, or consequential damages of any character arising as a
|
160 |
+
result of this License or out of the use or inability to use the
|
161 |
+
Work (including but not limited to damages for loss of goodwill,
|
162 |
+
work stoppage, computer failure or malfunction, or any and all
|
163 |
+
other commercial damages or losses), even if such Contributor
|
164 |
+
has been advised of the possibility of such damages.
|
165 |
+
|
166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169 |
+
or other liability obligations and/or rights consistent with this
|
170 |
+
License. However, in accepting such obligations, You may act only
|
171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172 |
+
of any other Contributor, and only if You agree to indemnify,
|
173 |
+
defend, and hold each Contributor harmless for any liability
|
174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
175 |
+
of your accepting any such warranty or additional liability.
|
176 |
+
|
177 |
+
END OF TERMS AND CONDITIONS
|
178 |
+
|
179 |
+
APPENDIX: How to apply the Apache License to your work.
|
180 |
+
|
181 |
+
To apply the Apache License to your work, attach the following
|
182 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183 |
+
replaced with your own identifying information. (Don't include
|
184 |
+
the brackets!) The text should be enclosed in the appropriate
|
185 |
+
comment syntax for the file format. We also recommend that a
|
186 |
+
file or class name and description of purpose be included on the
|
187 |
+
same "printed page" as the copyright notice for easier
|
188 |
+
identification within third-party archives.
|
189 |
+
|
190 |
+
Copyright [yyyy] [name of copyright owner]
|
191 |
+
|
192 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193 |
+
you may not use this file except in compliance with the License.
|
194 |
+
You may obtain a copy of the License at
|
195 |
+
|
196 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
197 |
+
|
198 |
+
Unless required by applicable law or agreed to in writing, software
|
199 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201 |
+
See the License for the specific language governing permissions and
|
202 |
+
limitations under the License.
|
torch/hub/baudm_parseq_main/Makefile
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Reference: https://dida.do/blog/managing-layered-requirements-with-pip-tools
|
2 |
+
|
3 |
+
REQUIREMENTS_TXT := $(addsuffix .txt, $(basename $(wildcard requirements/*.in)))
|
4 |
+
PIP_COMPILE := pip-compile --quiet --no-header --allow-unsafe --resolver=backtracking --strip-extras
|
5 |
+
|
6 |
+
.DEFAULT_GOAL := help
|
7 |
+
.PHONY: reqs clean-reqs help
|
8 |
+
|
9 |
+
requirements/constraints.txt: requirements/*.in
|
10 |
+
CONSTRAINTS=/dev/null $(PIP_COMPILE) --output-file $@ $^ --extra-index-url https://download.pytorch.org/whl/cpu
|
11 |
+
|
12 |
+
requirements/%.txt: requirements/%.in requirements/constraints.txt
|
13 |
+
CONSTRAINTS=constraints.txt $(PIP_COMPILE) --no-annotate --output-file $@ $<
|
14 |
+
@# Remove --extra-index-url, blank lines, and torch dependency from non-core groups
|
15 |
+
@[ $* = core ] || sed '/^--/d; /^$$/d; /^torch==/d' -i $@
|
16 |
+
|
17 |
+
reqs: $(REQUIREMENTS_TXT) ## Generate the requirements files
|
18 |
+
|
19 |
+
torch-%: requirements/core.txt ## Set PyTorch platform to use, e.g. cpu, cu117, rocm5.2
|
20 |
+
@echo Generating requirements/core.$*.txt
|
21 |
+
@sed 's|cpu|$*|' $< >requirements/core.$*.txt
|
22 |
+
|
23 |
+
clean-reqs: ## Delete the requirements files
|
24 |
+
rm -f requirements/constraints.txt requirements/core.*.txt $(REQUIREMENTS_TXT)
|
25 |
+
|
26 |
+
git-config: ## Common Git configuration
|
27 |
+
git config blame.ignoreRevsFile .git-blame-ignore-revs
|
28 |
+
|
29 |
+
help: ## Display this help
|
30 |
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
torch/hub/baudm_parseq_main/NOTICE
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Scene Text Recognition Model Hub
|
2 |
+
Copyright 2022 Darwin Bautista
|
3 |
+
|
4 |
+
The Initial Developer of strhub/models/abinet (sans system.py) is
|
5 |
+
Fang et al. (https://github.com/FangShancheng/ABINet).
|
6 |
+
Copyright 2021-2022 USTC
|
7 |
+
|
8 |
+
The Initial Developer of strhub/models/crnn (sans system.py) is
|
9 |
+
Jieru Mei (https://github.com/meijieru/crnn.pytorch).
|
10 |
+
Copyright 2017-2022 Jieru Mei
|
11 |
+
|
12 |
+
The Initial Developer of strhub/models/trba (sans system.py) is
|
13 |
+
Jeonghun Baek (https://github.com/clovaai/deep-text-recognition-benchmark).
|
14 |
+
Copyright 2019-2022 NAVER Corp.
|
15 |
+
|
16 |
+
The Initial Developer of strhub/models/vitstr (sans system.py) is
|
17 |
+
Rowel Atienza (https://github.com/roatienza/deep-text-recognition-benchmark).
|
18 |
+
Copyright 2021-2022 Rowel Atienza
|
torch/hub/baudm_parseq_main/README.md
ADDED
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## News
|
2 |
+
- **2024-02-22**: Updated for PyTorch 2.0 and Lightning 2.0
|
3 |
+
- **2024-01-16**: Featured in the [NVIDIA Developer Blog](https://developer.nvidia.com/blog/robust-scene-text-detection-and-recognition-introduction/)
|
4 |
+
- **2023-11-18**: [Interview with Deci AI at ECCV 2022](https://deeplearningdaily.substack.com/p/exclusive-interview-with-a-researcher) published
|
5 |
+
- **2023-09-07**: [Added](https://github.com/PaddlePaddle/PaddleOCR/blob/main/doc/doc_en/algorithm_rec_parseq_en.md) to [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR), one of the most popular multilingual OCR toolkits
|
6 |
+
- **2023-06-15**: [Added](https://mindee.github.io/doctr/modules/models.html#doctr.models.recognition.parseq) to [docTR](https://github.com/mindee/doctr), a deep learning-based library for OCR
|
7 |
+
- **2022-07-14**: Initial public release (ranked #1 overall for STR on [Papers With Code](https://paperswithcode.com/paper/scene-text-recognition-with-permuted) at the time of release)
|
8 |
+
- **2022-07-04**: Accepted at ECCV 2022
|
9 |
+
|
10 |
+
<div align="center">
|
11 |
+
|
12 |
+
# Scene Text Recognition with<br/>Permuted Autoregressive Sequence Models
|
13 |
+
[](https://github.com/baudm/parseq/blob/main/LICENSE)
|
14 |
+
[](https://arxiv.org/abs/2207.06966)
|
15 |
+
[](https://www.ecva.net/papers/eccv_2022/papers_ECCV/html/556_ECCV_2022_paper.php)
|
16 |
+
[](https://huggingface.co/spaces/baudm/PARSeq-OCR)
|
17 |
+
|
18 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-coco-text?p=scene-text-recognition-with-permuted)
|
19 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-ic19-art?p=scene-text-recognition-with-permuted)
|
20 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-icdar2013?p=scene-text-recognition-with-permuted)
|
21 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-iiit5k?p=scene-text-recognition-with-permuted)
|
22 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-cute80?p=scene-text-recognition-with-permuted)
|
23 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-icdar2015?p=scene-text-recognition-with-permuted)
|
24 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-svt?p=scene-text-recognition-with-permuted)
|
25 |
+
[](https://paperswithcode.com/sota/scene-text-recognition-on-svtp?p=scene-text-recognition-with-permuted)
|
26 |
+
|
27 |
+
[**Darwin Bautista**](https://github.com/baudm) and [**Rowel Atienza**](https://github.com/roatienza)
|
28 |
+
|
29 |
+
Electrical and Electronics Engineering Institute<br/>
|
30 |
+
University of the Philippines, Diliman
|
31 |
+
|
32 |
+
[Method](#method-tldr) | [Sample Results](#sample-results) | [Getting Started](#getting-started) | [FAQ](#frequently-asked-questions) | [Training](#training) | [Evaluation](#evaluation) | [Citation](#citation)
|
33 |
+
|
34 |
+
</div>
|
35 |
+
|
36 |
+
Scene Text Recognition (STR) models use language context to be more robust against noisy or corrupted images. Recent approaches like ABINet use a standalone or external Language Model (LM) for prediction refinement. In this work, we show that the external LM—which requires upfront allocation of dedicated compute capacity—is inefficient for STR due to its poor performance vs cost characteristics. We propose a more efficient approach using **p**ermuted **a**uto**r**egressive **seq**uence (PARSeq) models. View our ECCV [poster](https://drive.google.com/file/d/19luOT_RMqmafLMhKQQHBnHNXV7fOCRfw/view) and [presentation](https://drive.google.com/file/d/11VoZW4QC5tbMwVIjKB44447uTiuCJAAD/view) for a brief overview.
|
37 |
+
|
38 |
+

|
39 |
+
|
40 |
+
**NOTE:** _P-S and P-Ti are shorthands for PARSeq-S and PARSeq-Ti, respectively._
|
41 |
+
|
42 |
+
### Method tl;dr
|
43 |
+
|
44 |
+
Our main insight is that with an ensemble of autoregressive (AR) models, we could unify the current STR decoding methods (context-aware AR and context-free non-AR) and the bidirectional (cloze) refinement model:
|
45 |
+
<div align="center"><img src=".github/contexts-example.png" alt="Unified STR model" width="75%"/></div>
|
46 |
+
|
47 |
+
A single Transformer can realize different models by merely varying its attention mask. With the correct decoder parameterization, it can be trained with Permutation Language Modeling to enable inference for arbitrary output positions given arbitrary subsets of the input context. This *arbitrary decoding* characteristic results in a _unified_ STR model—PARSeq—capable of context-free and context-aware inference, as well as iterative prediction refinement using bidirectional context **without** requiring a standalone language model. PARSeq can be considered an ensemble of AR models with shared architecture and weights:
|
48 |
+
|
49 |
+

|
50 |
+
**NOTE:** _LayerNorm and Dropout layers are omitted. `[B]`, `[E]`, and `[P]` stand for beginning-of-sequence (BOS), end-of-sequence (EOS), and padding tokens, respectively. `T` = 25 results in 26 distinct position tokens. The position tokens both serve as query vectors and position embeddings for the input context. For `[B]`, no position embedding is added. Attention
|
51 |
+
masks are generated from the given permutations and are used only for the context-position attention. L<sub>ce</sub> pertains to the cross-entropy loss._
|
52 |
+
|
53 |
+
### Sample Results
|
54 |
+
<div align="center">
|
55 |
+
|
56 |
+
| Input Image | PARSeq-S<sub>A</sub> | ABINet | TRBA | ViTSTR-S | CRNN |
|
57 |
+
|:--------------------------------------------------------------------------:|:--------------------:|:-----------------:|:-----------------:|:-----------------:|:-----------------:|
|
58 |
+
| <img src="demo_images/art-01107.jpg" alt="CHEWBACCA" width="128"/> | CHEWBACCA | CHEWBA**GG**A | CHEWBACCA | CHEWBACCA | CHEW**U**ACCA |
|
59 |
+
| <img src="demo_images/coco-1166773.jpg" alt="Chevron" width="128"/> | Chevro**l** | Chevro\_ | Chevro\_ | Chevr\_\_ | Chevr\_\_ |
|
60 |
+
| <img src="demo_images/cute-184.jpg" alt="SALMON" height="128"/> | SALMON | SALMON | SALMON | SALMON | SA\_MON |
|
61 |
+
| <img src="demo_images/ic13_word_256.png" alt="Verbandstoffe" width="128"/> | Verbandst**e**ffe | Verbandst**e**ffe | Verbandst**ell**e | Verbandst**e**ffe | Verbands**le**ffe |
|
62 |
+
| <img src="demo_images/ic15_word_26.png" alt="Kappa" width="128"/> | Kappa | Kappa | Ka**s**pa | Kappa | Ka**ad**a |
|
63 |
+
| <img src="demo_images/uber-27491.jpg" alt="3rdAve" height="128"/> | 3rdAve | 3=-Ave | 3rdAve | 3rdAve | **Coke** |
|
64 |
+
|
65 |
+
**NOTE:** _Bold letters and underscores indicate wrong and missing character predictions, respectively._
|
66 |
+
</div>
|
67 |
+
|
68 |
+
## Getting Started
|
69 |
+
This repository contains the reference implementation for PARSeq and reproduced models (collectively referred to as _Scene Text Recognition Model Hub_). See `NOTICE` for copyright information.
|
70 |
+
Majority of the code is licensed under the Apache License v2.0 (see `LICENSE`) while ABINet and CRNN sources are
|
71 |
+
released under the BSD and MIT licenses, respectively (see corresponding `LICENSE` files for details).
|
72 |
+
|
73 |
+
### Demo
|
74 |
+
An [interactive Gradio demo](https://huggingface.co/spaces/baudm/PARSeq-OCR) hosted at Hugging Face is available. The pretrained weights released here are used for the demo.
|
75 |
+
|
76 |
+
### Installation
|
77 |
+
Requires Python >= 3.9 and PyTorch >= 2.0. The default requirements files will install the latest versions of the dependencies (as of February 22, 2024).
|
78 |
+
```bash
|
79 |
+
# Use specific platform build. Other PyTorch 2.0 options: cu118, cu121, rocm5.7
|
80 |
+
platform=cpu
|
81 |
+
# Generate requirements files for specified PyTorch platform
|
82 |
+
make torch-${platform}
|
83 |
+
# Install the project and core + train + test dependencies. Subsets: [dev,train,test,bench,tune]
|
84 |
+
pip install -r requirements/core.${platform}.txt -e .[train,test]
|
85 |
+
```
|
86 |
+
#### Updating dependency version pins
|
87 |
+
```bash
|
88 |
+
pip install pip-tools
|
89 |
+
make clean-reqs reqs # Regenerate all the requirements files
|
90 |
+
```
|
91 |
+
### Datasets
|
92 |
+
Download the [datasets](Datasets.md) from the following links:
|
93 |
+
1. [LMDB archives](https://drive.google.com/drive/folders/1NYuoi7dfJVgo-zUJogh8UQZgIMpLviOE) for MJSynth, SynthText, IIIT5k, SVT, SVTP, IC13, IC15, CUTE80, ArT, RCTW17, ReCTS, LSVT, MLT19, COCO-Text, and Uber-Text.
|
94 |
+
2. [LMDB archives](https://drive.google.com/drive/folders/1D9z_YJVa6f-O0juni-yG5jcwnhvYw-qC) for TextOCR and OpenVINO.
|
95 |
+
|
96 |
+
### Pretrained Models via Torch Hub
|
97 |
+
Available models are: `abinet`, `crnn`, `trba`, `vitstr`, `parseq_tiny`, `parseq_patch16_224`, and `parseq`.
|
98 |
+
```python
|
99 |
+
import torch
|
100 |
+
from PIL import Image
|
101 |
+
from strhub.data.module import SceneTextDataModule
|
102 |
+
|
103 |
+
# Load model and image transforms
|
104 |
+
parseq = torch.hub.load('baudm/parseq', 'parseq', pretrained=True).eval()
|
105 |
+
img_transform = SceneTextDataModule.get_transform(parseq.hparams.img_size)
|
106 |
+
|
107 |
+
img = Image.open('/path/to/image.png').convert('RGB')
|
108 |
+
# Preprocess. Model expects a batch of images with shape: (B, C, H, W)
|
109 |
+
img = img_transform(img).unsqueeze(0)
|
110 |
+
|
111 |
+
logits = parseq(img)
|
112 |
+
logits.shape # torch.Size([1, 26, 95]), 94 characters + [EOS] symbol
|
113 |
+
|
114 |
+
# Greedy decoding
|
115 |
+
pred = logits.softmax(-1)
|
116 |
+
label, confidence = parseq.tokenizer.decode(pred)
|
117 |
+
print('Decoded label = {}'.format(label[0]))
|
118 |
+
```
|
119 |
+
|
120 |
+
## Frequently Asked Questions
|
121 |
+
- How do I train on a new language? See Issues [#5](https://github.com/baudm/parseq/issues/5) and [#9](https://github.com/baudm/parseq/issues/9).
|
122 |
+
- Can you export to TorchScript or ONNX? Yes, see Issue [#12](https://github.com/baudm/parseq/issues/12#issuecomment-1267842315).
|
123 |
+
- How do I test on my own dataset? See Issue [#27](https://github.com/baudm/parseq/issues/27).
|
124 |
+
- How do I finetune and/or create a custom dataset? See Issue [#7](https://github.com/baudm/parseq/issues/7).
|
125 |
+
- What is `val_NED`? See Issue [#10](https://github.com/baudm/parseq/issues/10).
|
126 |
+
|
127 |
+
## Training
|
128 |
+
The training script can train any supported model. You can override any configuration using the command line. Please refer to [Hydra](https://hydra.cc) docs for more info about the syntax. Use `./train.py --help` to see the default configuration.
|
129 |
+
|
130 |
+
<details><summary>Sample commands for different training configurations</summary><p>
|
131 |
+
|
132 |
+
### Finetune using pretrained weights
|
133 |
+
```bash
|
134 |
+
./train.py +experiment=parseq-tiny pretrained=parseq-tiny # Not all experiments have pretrained weights
|
135 |
+
```
|
136 |
+
|
137 |
+
### Train a model variant/preconfigured experiment
|
138 |
+
The base model configurations are in `configs/model/`, while variations are stored in `configs/experiment/`.
|
139 |
+
```bash
|
140 |
+
./train.py +experiment=parseq-tiny # Some examples: abinet-sv, trbc
|
141 |
+
```
|
142 |
+
|
143 |
+
### Specify the character set for training
|
144 |
+
```bash
|
145 |
+
./train.py charset=94_full # Other options: 36_lowercase or 62_mixed-case. See configs/charset/
|
146 |
+
```
|
147 |
+
|
148 |
+
### Specify the training dataset
|
149 |
+
```bash
|
150 |
+
./train.py dataset=real # Other option: synth. See configs/dataset/
|
151 |
+
```
|
152 |
+
|
153 |
+
### Change general model training parameters
|
154 |
+
```bash
|
155 |
+
./train.py model.img_size=[32, 128] model.max_label_length=25 model.batch_size=384
|
156 |
+
```
|
157 |
+
|
158 |
+
### Change data-related training parameters
|
159 |
+
```bash
|
160 |
+
./train.py data.root_dir=data data.num_workers=2 data.augment=true
|
161 |
+
```
|
162 |
+
|
163 |
+
### Change `pytorch_lightning.Trainer` parameters
|
164 |
+
```bash
|
165 |
+
./train.py trainer.max_epochs=20 trainer.accelerator=gpu trainer.devices=2
|
166 |
+
```
|
167 |
+
Note that you can pass any [Trainer parameter](https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html),
|
168 |
+
you just need to prefix it with `+` if it is not originally specified in `configs/main.yaml`.
|
169 |
+
|
170 |
+
### Resume training from checkpoint (experimental)
|
171 |
+
```bash
|
172 |
+
./train.py +experiment=<model_exp> ckpt_path=outputs/<model>/<timestamp>/checkpoints/<checkpoint>.ckpt
|
173 |
+
```
|
174 |
+
|
175 |
+
</p></details>
|
176 |
+
|
177 |
+
## Evaluation
|
178 |
+
The test script, ```test.py```, can be used to evaluate any model trained with this project. For more info, see ```./test.py --help```.
|
179 |
+
|
180 |
+
PARSeq runtime parameters can be passed using the format `param:type=value`. For example, PARSeq NAR decoding can be invoked via `./test.py parseq.ckpt refine_iters:int=2 decode_ar:bool=false`.
|
181 |
+
|
182 |
+
<details><summary>Sample commands for reproducing results</summary><p>
|
183 |
+
|
184 |
+
### Lowercase alphanumeric comparison on benchmark datasets (Table 6)
|
185 |
+
```bash
|
186 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt # or use the released weights: ./test.py pretrained=parseq
|
187 |
+
```
|
188 |
+
**Sample output:**
|
189 |
+
| Dataset | # samples | Accuracy | 1 - NED | Confidence | Label Length |
|
190 |
+
|:---------:|----------:|---------:|--------:|-----------:|-------------:|
|
191 |
+
| IIIT5k | 3000 | 99.00 | 99.79 | 97.09 | 5.09 |
|
192 |
+
| SVT | 647 | 97.84 | 99.54 | 95.87 | 5.86 |
|
193 |
+
| IC13_1015 | 1015 | 98.13 | 99.43 | 97.19 | 5.31 |
|
194 |
+
| IC15_2077 | 2077 | 89.22 | 96.43 | 91.91 | 5.33 |
|
195 |
+
| SVTP | 645 | 96.90 | 99.36 | 94.37 | 5.86 |
|
196 |
+
| CUTE80 | 288 | 98.61 | 99.80 | 96.43 | 5.53 |
|
197 |
+
| **Combined** | **7672** | **95.95** | **98.78** | **95.34** | **5.33** |
|
198 |
+
--------------------------------------------------------------------------
|
199 |
+
|
200 |
+
### Benchmark using different evaluation character sets (Table 4)
|
201 |
+
```bash
|
202 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt # lowercase alphanumeric (36-character set)
|
203 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --cased # mixed-case alphanumeric (62-character set)
|
204 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --cased --punctuation # mixed-case alphanumeric + punctuation (94-character set)
|
205 |
+
```
|
206 |
+
|
207 |
+
### Lowercase alphanumeric comparison on more challenging datasets (Table 5)
|
208 |
+
```bash
|
209 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --new
|
210 |
+
```
|
211 |
+
|
212 |
+
### Benchmark Model Compute Requirements (Figure 5)
|
213 |
+
```bash
|
214 |
+
./bench.py model=parseq model.decode_ar=false model.refine_iters=3
|
215 |
+
<torch.utils.benchmark.utils.common.Measurement object at 0x7f8fcae67ee0>
|
216 |
+
model(x)
|
217 |
+
Median: 14.87 ms
|
218 |
+
IQR: 0.33 ms (14.78 to 15.12)
|
219 |
+
7 measurements, 10 runs per measurement, 1 thread
|
220 |
+
| module | #parameters | #flops | #activations |
|
221 |
+
|:----------------------|:--------------|:---------|:---------------|
|
222 |
+
| model | 23.833M | 3.255G | 8.214M |
|
223 |
+
| encoder | 21.381M | 2.88G | 7.127M |
|
224 |
+
| decoder | 2.368M | 0.371G | 1.078M |
|
225 |
+
| head | 36.575K | 3.794M | 9.88K |
|
226 |
+
| text_embed.embedding | 37.248K | 0 | 0 |
|
227 |
+
```
|
228 |
+
|
229 |
+
### Latency Measurements vs Output Label Length (Appendix I)
|
230 |
+
```bash
|
231 |
+
./bench.py model=parseq model.decode_ar=false model.refine_iters=3 +range=true
|
232 |
+
```
|
233 |
+
|
234 |
+
### Orientation robustness benchmark (Appendix J)
|
235 |
+
```bash
|
236 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --cased --punctuation # no rotation
|
237 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --cased --punctuation --rotation 90
|
238 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --cased --punctuation --rotation 180
|
239 |
+
./test.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --cased --punctuation --rotation 270
|
240 |
+
```
|
241 |
+
|
242 |
+
### Using trained models to read text from images (Appendix L)
|
243 |
+
```bash
|
244 |
+
./read.py outputs/<model>/<timestamp>/checkpoints/last.ckpt --images demo_images/* # Or use ./read.py pretrained=parseq
|
245 |
+
Additional keyword arguments: {}
|
246 |
+
demo_images/art-01107.jpg: CHEWBACCA
|
247 |
+
demo_images/coco-1166773.jpg: Chevrol
|
248 |
+
demo_images/cute-184.jpg: SALMON
|
249 |
+
demo_images/ic13_word_256.png: Verbandsteffe
|
250 |
+
demo_images/ic15_word_26.png: Kaopa
|
251 |
+
demo_images/uber-27491.jpg: 3rdAve
|
252 |
+
|
253 |
+
# use NAR decoding + 2 refinement iterations for PARSeq
|
254 |
+
./read.py pretrained=parseq refine_iters:int=2 decode_ar:bool=false --images demo_images/*
|
255 |
+
```
|
256 |
+
</p></details>
|
257 |
+
|
258 |
+
## Tuning
|
259 |
+
|
260 |
+
We use [Ray Tune](https://www.ray.io/ray-tune) for automated parameter tuning of the learning rate. See `./tune.py --help`. Extend `tune.py` to support tuning of other hyperparameters.
|
261 |
+
```bash
|
262 |
+
./tune.py tune.num_samples=20 # find optimum LR for PARSeq's default config using 20 trials
|
263 |
+
./tune.py +experiment=tune_abinet-lm # find the optimum learning rate for ABINet's language model
|
264 |
+
```
|
265 |
+
|
266 |
+
## Citation
|
267 |
+
```bibtex
|
268 |
+
@InProceedings{bautista2022parseq,
|
269 |
+
title={Scene Text Recognition with Permuted Autoregressive Sequence Models},
|
270 |
+
author={Bautista, Darwin and Atienza, Rowel},
|
271 |
+
booktitle={European Conference on Computer Vision},
|
272 |
+
pages={178--196},
|
273 |
+
month={10},
|
274 |
+
year={2022},
|
275 |
+
publisher={Springer Nature Switzerland},
|
276 |
+
address={Cham},
|
277 |
+
doi={10.1007/978-3-031-19815-1_11},
|
278 |
+
url={https://doi.org/10.1007/978-3-031-19815-1_11}
|
279 |
+
}
|
280 |
+
```
|
torch/hub/baudm_parseq_main/bench.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# Scene Text Recognition Model Hub
|
3 |
+
# Copyright 2022 Darwin Bautista
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing, software
|
12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions and
|
15 |
+
# limitations under the License.
|
16 |
+
|
17 |
+
import os
|
18 |
+
|
19 |
+
import hydra
|
20 |
+
from fvcore.nn import ActivationCountAnalysis, FlopCountAnalysis, flop_count_table
|
21 |
+
from omegaconf import DictConfig
|
22 |
+
|
23 |
+
import torch
|
24 |
+
from torch.utils import benchmark
|
25 |
+
|
26 |
+
|
27 |
+
@torch.inference_mode()
|
28 |
+
@hydra.main(config_path='configs', config_name='bench', version_base='1.2')
|
29 |
+
def main(config: DictConfig):
|
30 |
+
# For consistent behavior
|
31 |
+
os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8'
|
32 |
+
torch.backends.cudnn.benchmark = False
|
33 |
+
torch.use_deterministic_algorithms(True)
|
34 |
+
|
35 |
+
device = config.get('device', 'cuda')
|
36 |
+
|
37 |
+
h, w = config.data.img_size
|
38 |
+
x = torch.rand(1, 3, h, w, device=device)
|
39 |
+
model = hydra.utils.instantiate(config.model).eval().to(device)
|
40 |
+
|
41 |
+
if config.get('range', False):
|
42 |
+
for i in range(1, 26, 4):
|
43 |
+
timer = benchmark.Timer(stmt='model(x, len)', globals={'model': model, 'x': x, 'len': i})
|
44 |
+
print(timer.blocked_autorange(min_run_time=1))
|
45 |
+
else:
|
46 |
+
timer = benchmark.Timer(stmt='model(x)', globals={'model': model, 'x': x})
|
47 |
+
flops = FlopCountAnalysis(model, x)
|
48 |
+
acts = ActivationCountAnalysis(model, x)
|
49 |
+
print(timer.blocked_autorange(min_run_time=1))
|
50 |
+
print(flop_count_table(flops, 1, acts, False))
|
51 |
+
|
52 |
+
|
53 |
+
if __name__ == '__main__':
|
54 |
+
main()
|
torch/hub/baudm_parseq_main/configs/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
torch/hub/baudm_parseq_main/configs/bench.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Disable any logging or output
|
2 |
+
defaults:
|
3 |
+
- main
|
4 |
+
- _self_
|
5 |
+
- override hydra/job_logging: disabled
|
6 |
+
|
7 |
+
hydra:
|
8 |
+
output_subdir: null
|
9 |
+
run:
|
10 |
+
dir: .
|
torch/hub/baudm_parseq_main/configs/charset/36_lowercase.yaml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
model:
|
3 |
+
charset_train: "0123456789abcdefghijklmnopqrstuvwxyz"
|
torch/hub/baudm_parseq_main/configs/charset/62_mixed-case.yaml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
model:
|
3 |
+
charset_train: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
torch/hub/baudm_parseq_main/configs/charset/94_full.yaml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
model:
|
3 |
+
charset_train: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
torch/hub/baudm_parseq_main/configs/dataset/real.yaml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
data:
|
3 |
+
train_dir: real
|
torch/hub/baudm_parseq_main/configs/dataset/synth.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
data:
|
3 |
+
train_dir: synth
|
4 |
+
num_workers: 3
|
5 |
+
|
6 |
+
trainer:
|
7 |
+
limit_train_batches: 0.20496 # to match the steps per epoch of `real`
|
torch/hub/baudm_parseq_main/configs/experiment/abinet-sv.yaml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: abinet
|
4 |
+
|
5 |
+
model:
|
6 |
+
name: abinet-sv
|
7 |
+
v_num_layers: 2
|
8 |
+
v_attention: attention
|
torch/hub/baudm_parseq_main/configs/experiment/abinet.yaml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: abinet
|
torch/hub/baudm_parseq_main/configs/experiment/crnn.yaml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: crnn
|
4 |
+
|
5 |
+
data:
|
6 |
+
num_workers: 5
|
torch/hub/baudm_parseq_main/configs/experiment/parseq-patch16-224.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: parseq
|
4 |
+
|
5 |
+
model:
|
6 |
+
img_size: [ 224, 224 ] # [ height, width ]
|
7 |
+
patch_size: [ 16, 16 ] # [ height, width ]
|
torch/hub/baudm_parseq_main/configs/experiment/parseq-tiny.yaml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: parseq
|
4 |
+
|
5 |
+
model:
|
6 |
+
name: parseq-tiny
|
7 |
+
embed_dim: 192
|
8 |
+
enc_num_heads: 3
|
9 |
+
dec_num_heads: 6
|
torch/hub/baudm_parseq_main/configs/experiment/parseq.yaml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: parseq
|
torch/hub/baudm_parseq_main/configs/experiment/trba.yaml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: trba
|
4 |
+
|
5 |
+
data:
|
6 |
+
num_workers: 3
|
torch/hub/baudm_parseq_main/configs/experiment/trbc.yaml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: trba
|
4 |
+
|
5 |
+
model:
|
6 |
+
name: trbc
|
7 |
+
_target_: strhub.models.trba.system.TRBC
|
8 |
+
lr: 1e-4
|
9 |
+
|
10 |
+
data:
|
11 |
+
num_workers: 3
|
torch/hub/baudm_parseq_main/configs/experiment/tune_abinet-lm.yaml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: abinet
|
4 |
+
|
5 |
+
model:
|
6 |
+
name: abinet-lm
|
7 |
+
lm_only: true
|
8 |
+
|
9 |
+
data:
|
10 |
+
augment: false
|
11 |
+
num_workers: 3
|
12 |
+
|
13 |
+
tune:
|
14 |
+
gpus_per_trial: 0.5
|
15 |
+
lr:
|
16 |
+
min: 1e-5
|
17 |
+
max: 1e-3
|
torch/hub/baudm_parseq_main/configs/experiment/vitstr.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @package _global_
|
2 |
+
defaults:
|
3 |
+
- override /model: vitstr
|
4 |
+
|
5 |
+
model:
|
6 |
+
img_size: [ 32, 128 ] # [ height, width ]
|
7 |
+
patch_size: [ 4, 8 ] # [ height, width ]
|
torch/hub/baudm_parseq_main/configs/main.yaml
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
defaults:
|
2 |
+
- _self_
|
3 |
+
- model: parseq
|
4 |
+
- charset: 94_full
|
5 |
+
- dataset: real
|
6 |
+
|
7 |
+
model:
|
8 |
+
_convert_: all
|
9 |
+
img_size: [ 32, 128 ] # [ height, width ]
|
10 |
+
max_label_length: 25
|
11 |
+
# The ordering in charset_train matters. It determines the token IDs assigned to each character.
|
12 |
+
charset_train: ???
|
13 |
+
# For charset_test, ordering doesn't matter.
|
14 |
+
charset_test: "0123456789abcdefghijklmnopqrstuvwxyz"
|
15 |
+
batch_size: 384
|
16 |
+
weight_decay: 0.0
|
17 |
+
warmup_pct: 0.075 # equivalent to 1.5 epochs of warm up
|
18 |
+
|
19 |
+
data:
|
20 |
+
_target_: strhub.data.module.SceneTextDataModule
|
21 |
+
root_dir: data
|
22 |
+
train_dir: ???
|
23 |
+
batch_size: ${model.batch_size}
|
24 |
+
img_size: ${model.img_size}
|
25 |
+
charset_train: ${model.charset_train}
|
26 |
+
charset_test: ${model.charset_test}
|
27 |
+
max_label_length: ${model.max_label_length}
|
28 |
+
remove_whitespace: true
|
29 |
+
normalize_unicode: true
|
30 |
+
augment: true
|
31 |
+
num_workers: 2
|
32 |
+
|
33 |
+
trainer:
|
34 |
+
_target_: pytorch_lightning.Trainer
|
35 |
+
_convert_: all
|
36 |
+
val_check_interval: 1000
|
37 |
+
#max_steps: 169680 # 20 epochs x 8484 steps (for batch size = 384, real data)
|
38 |
+
max_epochs: 20
|
39 |
+
gradient_clip_val: 20
|
40 |
+
accelerator: gpu
|
41 |
+
devices: 2
|
42 |
+
|
43 |
+
ckpt_path: null
|
44 |
+
pretrained: null
|
45 |
+
|
46 |
+
hydra:
|
47 |
+
output_subdir: config
|
48 |
+
run:
|
49 |
+
dir: outputs/${model.name}/${now:%Y-%m-%d}_${now:%H-%M-%S}
|
50 |
+
sweep:
|
51 |
+
dir: multirun/${model.name}/${now:%Y-%m-%d}_${now:%H-%M-%S}
|
52 |
+
subdir: ${hydra.job.override_dirname}
|
torch/hub/baudm_parseq_main/configs/model/abinet.yaml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: abinet
|
2 |
+
_target_: strhub.models.abinet.system.ABINet
|
3 |
+
|
4 |
+
# Shared Transformer configuration
|
5 |
+
d_model: 512
|
6 |
+
nhead: 8
|
7 |
+
d_inner: 2048
|
8 |
+
activation: relu
|
9 |
+
dropout: 0.1
|
10 |
+
|
11 |
+
# Architecture
|
12 |
+
v_backbone: transformer
|
13 |
+
v_num_layers: 3
|
14 |
+
v_attention: position
|
15 |
+
v_attention_mode: nearest
|
16 |
+
l_num_layers: 4
|
17 |
+
l_use_self_attn: false
|
18 |
+
|
19 |
+
# Training
|
20 |
+
lr: 3.4e-4
|
21 |
+
l_lr: 3e-4
|
22 |
+
iter_size: 3
|
23 |
+
a_loss_weight: 1.
|
24 |
+
v_loss_weight: 1.
|
25 |
+
l_loss_weight: 1.
|
26 |
+
l_detach: true
|
torch/hub/baudm_parseq_main/configs/model/crnn.yaml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: crnn
|
2 |
+
_target_: strhub.models.crnn.system.CRNN
|
3 |
+
|
4 |
+
# Architecture
|
5 |
+
hidden_size: 256
|
6 |
+
leaky_relu: false
|
7 |
+
|
8 |
+
# Training
|
9 |
+
lr: 5.1e-4
|
torch/hub/baudm_parseq_main/configs/model/parseq.yaml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: parseq
|
2 |
+
_target_: strhub.models.parseq.system.PARSeq
|
3 |
+
|
4 |
+
# Data
|
5 |
+
patch_size: [ 4, 8 ] # [ height, width ]
|
6 |
+
|
7 |
+
# Architecture
|
8 |
+
embed_dim: 384
|
9 |
+
enc_num_heads: 6
|
10 |
+
enc_mlp_ratio: 4
|
11 |
+
enc_depth: 12
|
12 |
+
dec_num_heads: 12
|
13 |
+
dec_mlp_ratio: 4
|
14 |
+
dec_depth: 1
|
15 |
+
|
16 |
+
# Training
|
17 |
+
lr: 7e-4
|
18 |
+
perm_num: 6
|
19 |
+
perm_forward: true
|
20 |
+
perm_mirrored: true
|
21 |
+
dropout: 0.1
|
22 |
+
|
23 |
+
# Decoding mode (test)
|
24 |
+
decode_ar: true
|
25 |
+
refine_iters: 1
|
torch/hub/baudm_parseq_main/configs/model/trba.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: trba
|
2 |
+
_target_: strhub.models.trba.system.TRBA
|
3 |
+
|
4 |
+
# Architecture
|
5 |
+
num_fiducial: 20
|
6 |
+
output_channel: 512
|
7 |
+
hidden_size: 256
|
8 |
+
|
9 |
+
# Training
|
10 |
+
lr: 6.9e-4
|
torch/hub/baudm_parseq_main/configs/model/vitstr.yaml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: vitstr
|
2 |
+
_target_: strhub.models.vitstr.system.ViTSTR
|
3 |
+
|
4 |
+
# Data
|
5 |
+
img_size: [ 224, 224 ] # [ height, width ]
|
6 |
+
patch_size: [ 16, 16 ] # [ height, width ]
|
7 |
+
|
8 |
+
# Architecture
|
9 |
+
embed_dim: 384
|
10 |
+
num_heads: 6
|
11 |
+
|
12 |
+
# Training
|
13 |
+
lr: 8.9e-4
|
torch/hub/baudm_parseq_main/configs/tune.yaml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
defaults:
|
2 |
+
- main
|
3 |
+
- _self_
|
4 |
+
|
5 |
+
trainer:
|
6 |
+
devices: 1 # tuning with DDP is not yet supported.
|
7 |
+
|
8 |
+
tune:
|
9 |
+
num_samples: 10
|
10 |
+
gpus_per_trial: 1
|
11 |
+
lr:
|
12 |
+
min: 1e-4
|
13 |
+
max: 2e-3
|
14 |
+
resume_dir: null
|
15 |
+
|
16 |
+
hydra:
|
17 |
+
run:
|
18 |
+
dir: ray_results/${model.name}/${now:%Y-%m-%d}_${now:%H-%M-%S}
|
torch/hub/baudm_parseq_main/demo_images/art-01107.jpg
ADDED
![]() |
torch/hub/baudm_parseq_main/demo_images/coco-1166773.jpg
ADDED
![]() |
torch/hub/baudm_parseq_main/demo_images/cute-184.jpg
ADDED
![]() |
torch/hub/baudm_parseq_main/demo_images/ic13_word_256.png
ADDED
![]() |
torch/hub/baudm_parseq_main/demo_images/ic15_word_26.png
ADDED
![]() |
torch/hub/baudm_parseq_main/demo_images/uber-27491.jpg
ADDED
![]() |
torch/hub/baudm_parseq_main/hubconf.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from strhub.models.utils import create_model
|
2 |
+
|
3 |
+
dependencies = ['torch', 'pytorch_lightning', 'timm']
|
4 |
+
|
5 |
+
|
6 |
+
def parseq_tiny(pretrained: bool = False, decode_ar: bool = True, refine_iters: int = 1, **kwargs):
|
7 |
+
"""
|
8 |
+
PARSeq tiny model (img_size=128x32, patch_size=8x4, d_model=192)
|
9 |
+
@param pretrained: (bool) Use pretrained weights
|
10 |
+
@param decode_ar: (bool) use AR decoding
|
11 |
+
@param refine_iters: (int) number of refinement iterations to use
|
12 |
+
"""
|
13 |
+
return create_model('parseq-tiny', pretrained, decode_ar=decode_ar, refine_iters=refine_iters, **kwargs)
|
14 |
+
|
15 |
+
|
16 |
+
def parseq(pretrained: bool = False, decode_ar: bool = True, refine_iters: int = 1, **kwargs):
|
17 |
+
"""
|
18 |
+
PARSeq base model (img_size=128x32, patch_size=8x4, d_model=384)
|
19 |
+
@param pretrained: (bool) Use pretrained weights
|
20 |
+
@param decode_ar: (bool) use AR decoding
|
21 |
+
@param refine_iters: (int) number of refinement iterations to use
|
22 |
+
"""
|
23 |
+
return create_model('parseq', pretrained, decode_ar=decode_ar, refine_iters=refine_iters, **kwargs)
|
24 |
+
|
25 |
+
|
26 |
+
def parseq_patch16_224(pretrained: bool = False, decode_ar: bool = True, refine_iters: int = 1, **kwargs):
|
27 |
+
"""
|
28 |
+
PARSeq base model (img_size=224x224, patch_size=16x16, d_model=384)
|
29 |
+
@param pretrained: (bool) Use pretrained weights
|
30 |
+
@param decode_ar: (bool) use AR decoding
|
31 |
+
@param refine_iters: (int) number of refinement iterations to use
|
32 |
+
"""
|
33 |
+
return create_model('parseq-patch16-224', pretrained, decode_ar=decode_ar, refine_iters=refine_iters, **kwargs)
|
34 |
+
|
35 |
+
|
36 |
+
def abinet(pretrained: bool = False, iter_size: int = 3, **kwargs):
|
37 |
+
"""
|
38 |
+
ABINet model (img_size=128x32)
|
39 |
+
@param pretrained: (bool) Use pretrained weights
|
40 |
+
@param iter_size: (int) number of refinement iterations to use
|
41 |
+
"""
|
42 |
+
return create_model('abinet', pretrained, iter_size=iter_size, **kwargs)
|
43 |
+
|
44 |
+
|
45 |
+
def trba(pretrained: bool = False, **kwargs):
|
46 |
+
"""
|
47 |
+
TRBA model (img_size=128x32)
|
48 |
+
@param pretrained: (bool) Use pretrained weights
|
49 |
+
"""
|
50 |
+
return create_model('trba', pretrained, **kwargs)
|
51 |
+
|
52 |
+
|
53 |
+
def vitstr(pretrained: bool = False, **kwargs):
|
54 |
+
"""
|
55 |
+
ViTSTR small model (img_size=128x32, patch_size=8x4, d_model=384)
|
56 |
+
@param pretrained: (bool) Use pretrained weights
|
57 |
+
"""
|
58 |
+
return create_model('vitstr', pretrained, **kwargs)
|
59 |
+
|
60 |
+
|
61 |
+
def crnn(pretrained: bool = False, **kwargs):
|
62 |
+
"""
|
63 |
+
CRNN model (img_size=128x32)
|
64 |
+
@param pretrained: (bool) Use pretrained weights
|
65 |
+
"""
|
66 |
+
return create_model('crnn', pretrained, **kwargs)
|