falcon-perception 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- falcon_perception-1.0.0/LICENSE +202 -0
- falcon_perception-1.0.0/NOTICE +21 -0
- falcon_perception-1.0.0/PKG-INFO +411 -0
- falcon_perception-1.0.0/README.md +348 -0
- falcon_perception-1.0.0/falcon_perception/__init__.py +409 -0
- falcon_perception-1.0.0/falcon_perception/__main__.py +37 -0
- falcon_perception-1.0.0/falcon_perception/anyup.py +539 -0
- falcon_perception-1.0.0/falcon_perception/attention.py +131 -0
- falcon_perception-1.0.0/falcon_perception/aux_output.py +272 -0
- falcon_perception-1.0.0/falcon_perception/batch_inference.py +322 -0
- falcon_perception-1.0.0/falcon_perception/data.py +570 -0
- falcon_perception-1.0.0/falcon_perception/kv_cache.py +31 -0
- falcon_perception-1.0.0/falcon_perception/mlx/__init__.py +3 -0
- falcon_perception-1.0.0/falcon_perception/mlx/anyup.py +407 -0
- falcon_perception-1.0.0/falcon_perception/mlx/attention.py +103 -0
- falcon_perception-1.0.0/falcon_perception/mlx/batch_inference.py +449 -0
- falcon_perception-1.0.0/falcon_perception/mlx/convert.py +87 -0
- falcon_perception-1.0.0/falcon_perception/mlx/kv_cache.py +71 -0
- falcon_perception-1.0.0/falcon_perception/mlx/model.py +528 -0
- falcon_perception-1.0.0/falcon_perception/mlx/rope.py +111 -0
- falcon_perception-1.0.0/falcon_perception/mlx/sampling.py +51 -0
- falcon_perception-1.0.0/falcon_perception/model.py +818 -0
- falcon_perception-1.0.0/falcon_perception/paged_attention.py +394 -0
- falcon_perception-1.0.0/falcon_perception/paged_inference.py +1429 -0
- falcon_perception-1.0.0/falcon_perception/paged_ocr_inference.py +645 -0
- falcon_perception-1.0.0/falcon_perception/rope.py +104 -0
- falcon_perception-1.0.0/falcon_perception/sampling.py +51 -0
- falcon_perception-1.0.0/falcon_perception/server/__init__.py +1 -0
- falcon_perception-1.0.0/falcon_perception/server/__main__.py +72 -0
- falcon_perception-1.0.0/falcon_perception/server/app.py +549 -0
- falcon_perception-1.0.0/falcon_perception/server/config.py +63 -0
- falcon_perception-1.0.0/falcon_perception/server/engine_worker.py +858 -0
- falcon_perception-1.0.0/falcon_perception/server/mask_combiner.py +303 -0
- falcon_perception-1.0.0/falcon_perception/server/mask_smoother.py +134 -0
- falcon_perception-1.0.0/falcon_perception/server/schemas.py +113 -0
- falcon_perception-1.0.0/falcon_perception/visualization_utils.py +1226 -0
- falcon_perception-1.0.0/falcon_perception.egg-info/PKG-INFO +411 -0
- falcon_perception-1.0.0/falcon_perception.egg-info/SOURCES.txt +41 -0
- falcon_perception-1.0.0/falcon_perception.egg-info/dependency_links.txt +1 -0
- falcon_perception-1.0.0/falcon_perception.egg-info/requires.txt +47 -0
- falcon_perception-1.0.0/falcon_perception.egg-info/top_level.txt +1 -0
- falcon_perception-1.0.0/pyproject.toml +107 -0
- falcon_perception-1.0.0/setup.cfg +4 -0
|
@@ -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 2026 Technology Innovation Institute (TII), UAE
|
|
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.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Falcon Perception
|
|
2
|
+
Copyright 2026 Technology Innovation Institute (TII), UAE
|
|
3
|
+
https://github.com/tiiuae/falcon-perception
|
|
4
|
+
|
|
5
|
+
This product includes software developed at the Technology Innovation
|
|
6
|
+
Institute (TII), Abu Dhabi, UAE.
|
|
7
|
+
|
|
8
|
+
If you use Falcon Perception — including its model weights, inference engine,
|
|
9
|
+
or derivative works (e.g. fine-tuned models, adapted architectures) — in any
|
|
10
|
+
public-facing work, publication, or product, please acknowledge the project by:
|
|
11
|
+
|
|
12
|
+
1. Retaining this NOTICE file in any redistribution.
|
|
13
|
+
2. Citing the project in academic or technical publications:
|
|
14
|
+
|
|
15
|
+
@preprint{falcon-perception2026,
|
|
16
|
+
title = {Falcon Perception: Natively Multimodal Dense Autoregressive
|
|
17
|
+
Vision-Language Transformer},
|
|
18
|
+
author = {TII Falcon Perception Team},
|
|
19
|
+
year = {2025},
|
|
20
|
+
url = {https://github.com/tiiuae/falcon-perception}
|
|
21
|
+
}
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: falcon-perception
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Falcon Perception is a dense vision-language model that performs object detection, instance segmentation, and OCR from natural language queries.
|
|
5
|
+
Author: Technology Innovation Institute
|
|
6
|
+
Maintainer-email: "Phuc H. Le Khac" <phuc.lekhac@tii.ae>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://github.com/tiiuae/Falcon-Perception
|
|
9
|
+
Project-URL: Repository, https://github.com/tiiuae/Falcon-Perception
|
|
10
|
+
Project-URL: Issues, https://github.com/tiiuae/Falcon-Perception/issues
|
|
11
|
+
Project-URL: Hugging Face, https://huggingface.co/tiiuae/Falcon-Perception
|
|
12
|
+
Keywords: vision-language-model,object-detection,instance-segmentation,ocr,falcon,deep-learning,computer-vision
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
License-File: NOTICE
|
|
27
|
+
Requires-Dist: einops>=0.8.1
|
|
28
|
+
Requires-Dist: numpy>=1.24
|
|
29
|
+
Requires-Dist: pillow>=12.0.0
|
|
30
|
+
Requires-Dist: tokenizers>=0.21.0
|
|
31
|
+
Requires-Dist: datasets>=4.5.0
|
|
32
|
+
Requires-Dist: pycocotools>=2.0.11
|
|
33
|
+
Requires-Dist: opencv-python>=4.12.0.88
|
|
34
|
+
Requires-Dist: scipy>=1.15.3
|
|
35
|
+
Requires-Dist: tyro>=1.0.3
|
|
36
|
+
Requires-Dist: hf-transfer>=0.1.9
|
|
37
|
+
Requires-Dist: requests>=2.31.0
|
|
38
|
+
Requires-Dist: hf-xet>=1.3.1
|
|
39
|
+
Requires-Dist: mlx>=0.30.0; sys_platform == "darwin" and platform_machine == "arm64"
|
|
40
|
+
Requires-Dist: torch>=2.11.0; sys_platform != "darwin"
|
|
41
|
+
Requires-Dist: torchvision>=0.26.0; sys_platform != "darwin"
|
|
42
|
+
Requires-Dist: safetensors>=0.7.0
|
|
43
|
+
Provides-Extra: torch
|
|
44
|
+
Requires-Dist: torch>=2.11.0; extra == "torch"
|
|
45
|
+
Requires-Dist: torchvision>=0.26.0; extra == "torch"
|
|
46
|
+
Provides-Extra: mlx
|
|
47
|
+
Requires-Dist: mlx>=0.30.0; (sys_platform == "darwin" and platform_machine == "arm64") and extra == "mlx"
|
|
48
|
+
Provides-Extra: ocr
|
|
49
|
+
Requires-Dist: falcon-perception[torch]; extra == "ocr"
|
|
50
|
+
Requires-Dist: transformers>=4.57.3; extra == "ocr"
|
|
51
|
+
Provides-Extra: dev
|
|
52
|
+
Requires-Dist: tensorboard>=2.20.0; extra == "dev"
|
|
53
|
+
Requires-Dist: ipykernel>=7.2.0; extra == "dev"
|
|
54
|
+
Requires-Dist: matplotlib>=3.10.8; extra == "dev"
|
|
55
|
+
Provides-Extra: server
|
|
56
|
+
Requires-Dist: fastapi>=0.129.0; extra == "server"
|
|
57
|
+
Requires-Dist: uvicorn[standard]>=0.40.0; extra == "server"
|
|
58
|
+
Requires-Dist: python-multipart>=0.0.22; extra == "server"
|
|
59
|
+
Provides-Extra: demo
|
|
60
|
+
Requires-Dist: streamlit>=1.52.2; extra == "demo"
|
|
61
|
+
Requires-Dist: requests>=2.31.0; extra == "demo"
|
|
62
|
+
Dynamic: license-file
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
<p align="center">
|
|
66
|
+
<img src="assets/logo.png" width="70%" alt="Falcon Perception and Falcon OCR" />
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
<p align="center">
|
|
70
|
+
<a href="http://arxiv.org/abs/2603.27365"><img src="https://img.shields.io/badge/arXiv-Tech%20Report-b31b1b?logo=arxiv&logoColor=white" alt="Tech Report" /></a>
|
|
71
|
+
<a href="https://huggingface.co/blog/tiiuae/falcon-perception"><img src="https://img.shields.io/badge/Blogpost-2196F3?logo=googledocs&logoColor=white" alt="Blogpost" /></a>
|
|
72
|
+
<a href="https://vision.falcon.aidrc.tii.ae"><img src="https://img.shields.io/badge/%F0%9F%9A%80-Playground-blue" alt="Playground" /></a>
|
|
73
|
+
</p>
|
|
74
|
+
<p align="center">
|
|
75
|
+
<a href="https://huggingface.co/datasets/tiiuae/PBench"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-PBench-orange" alt="PBench" /></a>
|
|
76
|
+
<a href="https://huggingface.co/tiiuae/Falcon-OCR"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-OCR%20Model-orange" alt="OCR Model" /></a>
|
|
77
|
+
<a href="https://huggingface.co/tiiuae/Falcon-Perception"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Perception%20Model-orange" alt="Perception Model" /></a>
|
|
78
|
+
</p>
|
|
79
|
+
|
|
80
|
+
# Falcon Perception
|
|
81
|
+
A minimal, readable yet performant PyTorch inference engine implementation of **Falcon Perception** — a natively multimodal, dense, autoregressive Transformer model that performs **object detection**, **instance segmentation**, or **OCR** from natural language queries.
|
|
82
|
+
|
|
83
|
+

|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
> *"Segment these expressions in the image: the cat on the left"* → bounding boxes + pixel-level masks
|
|
87
|
+
|
|
88
|
+
> *"Extract the text content from this image."* → text / latex formulas / html table ...
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Contents
|
|
92
|
+
- [Quick Start](#quick-start)
|
|
93
|
+
- [Installation](#installation)
|
|
94
|
+
- [Run Perception (detection / segmentation)](#run-perception-detection--segmentation)
|
|
95
|
+
- [Run OCR (text extraction)](#run-ocr-text-extraction)
|
|
96
|
+
- [Run Multiple Samples with Paged Inference Engine](#run-multiple-samples-with-paged-inference-engine)
|
|
97
|
+
- [Interactive Notebooks](#interactive-notebooks)
|
|
98
|
+
- [Inference Engines](#inference-engines)
|
|
99
|
+
- [PyTorch Inference Engines](#pytorch-inference-engines)
|
|
100
|
+
- [Paged Inference Engine](#paged-inference-engine)
|
|
101
|
+
- [Paged OCR Inference Engine](#paged-ocr-inference-engine)
|
|
102
|
+
- [Batch Inference Engine](#batch-inference-engine)
|
|
103
|
+
- [MLX Batch Inference Engine (Apple Silicon)](#mlx-batch-inference-engine-apple-silicon)
|
|
104
|
+
- [Inference Server](#inference-server)
|
|
105
|
+
- [Launch Server](#launch-server)
|
|
106
|
+
- [Launch Streamlit Demo App](#launch-streamlit-demo-app)
|
|
107
|
+
- [vLLM Docker Server (FalconOCR Only)](#vllm-docker-server-falconocr-only)
|
|
108
|
+
- [Serving Throughput](#serving-throughput)
|
|
109
|
+
- [Quick Start](#quick-start-1)
|
|
110
|
+
- [Citation](#citation)
|
|
111
|
+
- [Acknowledgments](#acknowledgments)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## Quick Start
|
|
115
|
+
|
|
116
|
+
### Installation
|
|
117
|
+
|
|
118
|
+
The package supports two backends: **PyTorch** (CUDA GPUs) and **MLX** (Apple Silicon Macs).
|
|
119
|
+
A bare `pip install` auto-detects your platform, or you can pick an explicit extra.
|
|
120
|
+
|
|
121
|
+
| Install command | Backend | When to use |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| `pip install -e .` | Auto-detect | Mac -> MLX, Linux -> Torch |
|
|
124
|
+
| `pip install -e ".[torch]"` | PyTorch + CUDA | GPU server or explicit Torch on Mac |
|
|
125
|
+
| `pip install -e ".[mlx]"` | MLX | Apple Silicon Mac |
|
|
126
|
+
| `pip install -e ".[ocr]"` | Torch + transformers | Layout-aware OCR (needs a layout detection model) |
|
|
127
|
+
| `pip install -e ".[dev]"` | -- | Adds tensorboard, matplotlib, ipykernel |
|
|
128
|
+
| `pip install -e ".[server]"` | -- | Adds FastAPI / Uvicorn for the paged inference server |
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Example: from source with uv (recommended)
|
|
132
|
+
uv sync # installs torch with CUDA 12.8 wheels by default
|
|
133
|
+
source .venv/bin/activate
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### CUDA version
|
|
137
|
+
|
|
138
|
+
`uv sync` defaults to **CUDA 12.8** wheels for PyTorch (works with NVIDIA driver >= 570.x).
|
|
139
|
+
If you need a different CUDA version, edit the `[[tool.uv.index]]` URL in `pyproject.toml`:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# CUDA 12.6 (driver >= 560.x)
|
|
143
|
+
url = "https://download.pytorch.org/whl/cu126"
|
|
144
|
+
# CUDA 13.0 (driver >= 575.x) — or remove [tool.uv.sources] entirely
|
|
145
|
+
url = "https://download.pytorch.org/whl/cu130"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Then re-run `uv lock && uv sync`.
|
|
149
|
+
|
|
150
|
+
If installing with **pip** instead of uv, install PyTorch first with the correct CUDA version:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
|
|
154
|
+
pip install -e .
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
> **Note:** The MLX backend does not require PyTorch or transformers at all.
|
|
158
|
+
> The core data pipeline and tokenizer run on numpy/PIL and the lightweight
|
|
159
|
+
> [tokenizers](https://github.com/huggingface/tokenizers) library.
|
|
160
|
+
|
|
161
|
+
### Run Perception (detection / segmentation)
|
|
162
|
+
|
|
163
|
+
**PyTorch (GPU)**
|
|
164
|
+
```bash
|
|
165
|
+
# Auto-downloads model + streaming sample image from Huggingface
|
|
166
|
+
python demo/perception_single.py
|
|
167
|
+
|
|
168
|
+
# Custom image and query, can be path or url
|
|
169
|
+
python demo/perception_single.py --image photo.jpg --query "cat"
|
|
170
|
+
|
|
171
|
+
# Detection only (no masks)
|
|
172
|
+
python demo/perception_single.py --image photo.jpg --query "cat" --task detection
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**MLX (Apple Silicon)**
|
|
176
|
+
```bash
|
|
177
|
+
python demo/perception_single_mlx.py --image photo.jpg --query "cat"
|
|
178
|
+
|
|
179
|
+
# Detection only
|
|
180
|
+
python demo/perception_single_mlx.py --image photo.jpg --query "cat" --task detection
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Run OCR (text extraction)
|
|
184
|
+
|
|
185
|
+
**PyTorch (GPU)**
|
|
186
|
+
```bash
|
|
187
|
+
# Auto-downloads model + stream sample image from HuggingFace
|
|
188
|
+
python demo/ocr_single.py
|
|
189
|
+
|
|
190
|
+
# Custom document image
|
|
191
|
+
python demo/ocr_single.py --image document.png
|
|
192
|
+
|
|
193
|
+
# Layout-aware OCR (detects regions first, then extracts text per region)
|
|
194
|
+
# Requires the [ocr] extra: pip install -e ".[ocr]"
|
|
195
|
+
# This will lazily download and run a 3rd party layout detection model
|
|
196
|
+
# PaddlePaddle/PP-DocLayoutV3_safetensors from Huggingface
|
|
197
|
+
python demo/ocr_single.py --image document.png --task ocr_layout
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**MLX (Apple Silicon)**
|
|
201
|
+
```bash
|
|
202
|
+
python demo/ocr_single_mlx.py --image document.png
|
|
203
|
+
python demo/ocr_single_mlx.py # loads a demo sample from OCRBench-v2
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**OCR modes**
|
|
207
|
+
|
|
208
|
+
| Mode | Best for | How |
|
|
209
|
+
|------|----------|-----|
|
|
210
|
+
| **Plain OCR** | Simple documents, real-world photos, slides, receipts, invoices | `--task ocr_plain` |
|
|
211
|
+
| **Layout + OCR** | Complex multi-column documents, academic papers, reports, dense pages | `--task ocr_layout` |
|
|
212
|
+
|
|
213
|
+
### Run Multiple Samples with Paged Inference Engine
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Perception — PBench dataset
|
|
217
|
+
python demo/perception_benchmark.py # stream 50 samples from HF
|
|
218
|
+
python demo/perception_benchmark.py --limit -1 # stream entire benchmark
|
|
219
|
+
|
|
220
|
+
# OCR — OCRBench-v2 dataset
|
|
221
|
+
python demo/ocr_benchmark.py
|
|
222
|
+
python demo/ocr_benchmark.py --limit 200
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Interactive Notebooks
|
|
226
|
+
|
|
227
|
+
Step-by-step walkthroughs with inline visualizations:
|
|
228
|
+
|
|
229
|
+
| Notebook | Description | Colab |
|
|
230
|
+
|---|---|---|
|
|
231
|
+
| [`demo/perception.ipynb`](demo/perception.ipynb) | **Falcon Perception** — engine setup, detection vs segmentation, HR cache, dense tuning, PBench level showcase, and benchmark with IoU metrics | [](https://colab.research.google.com/drive/1Jy6lRYuGMKJEt9--KBLm6kjbC-vQ0Uwe) |
|
|
232
|
+
| [`demo/ocr.ipynb`](demo/ocr.ipynb) | **Falcon OCR** — full-page and layout-based OCR across handwriting, formulas, tables, scanned documents, and scientific papers | [](https://colab.research.google.com/drive/1HYOcYWqmeUT9j2h6_dNM2lX1mlI34Bfa) |
|
|
233
|
+
| [`demo/perception_agent.ipynb`](demo/perception_agent.ipynb) | **Perception Agent** — grounded visual reasoning agent using Falcon Perception as a tool with an orchestrator VLM for multi-step scene understanding | [](https://colab.research.google.com/drive/1wg4EbNDKllAxoK1v5gbdRzkrKjdjIwbj) |
|
|
234
|
+
| [`demo/perception_ov_mot.ipynb`](demo/perception_ov_mot.ipynb) | **Open-Vocab Multi-Object Tracking** — video object tracking pipeline using Falcon Perception in detection and segmentation modes | [](https://colab.research.google.com/drive/13Hiei8As2JbiZuYllXQTNX_ZelysZSpH) |
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
## Inference Engines
|
|
238
|
+
|
|
239
|
+
### PyTorch Inference Engines
|
|
240
|
+
|
|
241
|
+
**We use FlexAttention for both inference engines and training.**
|
|
242
|
+
The hybrid attention mask (bidirectional image + causal text) is expressed as composable mask functions.
|
|
243
|
+
The FlexAttention's `maskmod` also make it easy to implement continuous batching with paged attention via simple Python.
|
|
244
|
+
PyTorch's `flex_attention` compiles them into fused Triton kernel — no custom attention code needed.
|
|
245
|
+
|
|
246
|
+
#### Paged Inference Engine
|
|
247
|
+
|
|
248
|
+
Performant engine with CUDAGraph and continuous batching via a paged KV cache:
|
|
249
|
+
|
|
250
|
+
- **Paged KV cache** with virtual page tables (no wasted memory from padding)
|
|
251
|
+
- **Continuous batching**: new sequences enter mid-generation, finished ones release pages immediately
|
|
252
|
+
- **Torch compile**: piece-wise region outside the flex attention kernel.
|
|
253
|
+
- **CUDA graph capture** for the decode loop (eliminates kernel launch overhead, important for small models)
|
|
254
|
+
- **Background tokenization**: CPU thread pool overlapped with GPU compute
|
|
255
|
+
- **Preemption**: if memory is tight, running sequences can be paused and re-prefilled later
|
|
256
|
+
- **High-Resolution image feature cache** (for segmentation): LRU cache with pre-allocated pinned memory buffers for async GPU↔CPU transfer of high-resolution image features. Help reduce prefill time for subsequent query of the same image.
|
|
257
|
+
|
|
258
|
+
Please check `demo/perception_single.py` and `demo/perception_benchmark.py` on how to directly instantiate and use the engine.
|
|
259
|
+
|
|
260
|
+
> **NOTE**: First run will takes longer ~10-30s for torch compile and CUDAGraph capture. Subsequent run will be faster, around ~100ms for prefill, ~200ms for upsampling (0ms if cached), and ~50ms for decode a couple of instances (~10 tokens). (measured on H100)
|
|
261
|
+
|
|
262
|
+
#### Paged OCR Inference Engine
|
|
263
|
+
|
|
264
|
+
Extends the Perception's paged engine for document understanding:
|
|
265
|
+
|
|
266
|
+
- **Layout detection**: runs a lightweight detector to find text regions, tables, figures, headers
|
|
267
|
+
- **Per-region OCR**: crops each region and runs OCR inference with a category-specific prompt
|
|
268
|
+
- **Continuous batching and gather**: all crops of the image are sent to the engine for continuous batched extraction. Once all crops are completed, the output are gathered and assembed into a structured output.
|
|
269
|
+
|
|
270
|
+
Please check `demo/ocr_single.py` and `demo/ocr_benchmark.py` on how to directly instantiate and use the engine.
|
|
271
|
+
|
|
272
|
+
> **NOTE**: First `layout_ocr` run will lazily download and run the document layout detection model.
|
|
273
|
+
|
|
274
|
+
#### Batch Inference Engine
|
|
275
|
+
|
|
276
|
+
The simplest and closest to training code path, make it easier to understand the model's forward pass without all the optimization.
|
|
277
|
+
All sequences are left-padded to the same length (with correct rope indices and attention mask), runs a single prefill, then decodes token-by-token with a dense KV cache until all sequences are completed.
|
|
278
|
+
|
|
279
|
+
Please check the `demo/perception_single.py --engine-type batch` path for usage.
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
### MLX Batch Inference Engine (Apple Silicon)
|
|
283
|
+
|
|
284
|
+
The MLX backend provides batch inference on Apple Silicon Macs using the
|
|
285
|
+
[MLX](https://github.com/ml-explore/mlx) framework. It shares the same
|
|
286
|
+
model architecture and weights (auto-converted from safetensors on first load)
|
|
287
|
+
and produces equivalent results.
|
|
288
|
+
|
|
289
|
+
- Dense KV cache, left-padded batch inference
|
|
290
|
+
- `mx.fast.scaled_dot_product_attention` with native sink support
|
|
291
|
+
- Tiled windowed cross-attention in the AnyUp upsampler for memory efficiency
|
|
292
|
+
- No PyTorch or transformers dependency
|
|
293
|
+
|
|
294
|
+
See `demo/perception_single_mlx.py` for usage.
|
|
295
|
+
|
|
296
|
+
## Inference Server
|
|
297
|
+
|
|
298
|
+
The server provides a REST API to the continuous batching Paged Inference Engine across multiple GPUs.
|
|
299
|
+
|
|
300
|
+
### Launch server
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Install server and streamlit demo dependencies
|
|
304
|
+
uv sync --extra server --extra demo
|
|
305
|
+
|
|
306
|
+
# Auto-detects all available GPUs, compiles model, captures CUDA graphs
|
|
307
|
+
python -m falcon_perception.server
|
|
308
|
+
|
|
309
|
+
# Explicit config
|
|
310
|
+
python -m falcon_perception.server --config.num-gpus 2 --config.port 7680
|
|
311
|
+
|
|
312
|
+
# Or with the OCR model
|
|
313
|
+
python -m falcon_perception.server --config.hf-model-id tiiuae/Falcon-OCR --config.port 7681
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The server starts one engine worker per GPU in a separate process (i.e. Data Parallel). Each worker builds its own model, runs `torch.compile`, and captures CUDA graphs for the decode loop. Workers communicate with the main FastAPI process via `multiprocessing.Queue` and the server will assign new request to the worker with lowest number of queuing requests.
|
|
317
|
+
|
|
318
|
+
Please check the [`server/README.md`](falcon_perception/server/README.md) for detailed usage.
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
### Launch Streamlit Demo App
|
|
322
|
+
|
|
323
|
+
A browser-based demo UI that connects to the inference server.
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
# With a server already launched in a separate terminal, launch the Streamlit app
|
|
327
|
+
streamlit run demo/streamlit_app.py
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
The app provides:
|
|
331
|
+
- Image upload and URL input
|
|
332
|
+
- Automatic model detection — the task selector shows only tasks supported by the loaded model (segmentation/detection for Falcon-Perception, OCR plain/layout for Falcon-OCR)
|
|
333
|
+
- Interactive mask and bounding box overlay visualization
|
|
334
|
+
- Adjustable image resolution settings
|
|
335
|
+
- Per-request timing breakdown
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
## vLLM Docker Server (FalconOCR Only)
|
|
339
|
+
For FalconOCR without the extra perception heads, we also provide a vLLM docker server for fast deployment.
|
|
340
|
+
|
|
341
|
+
### Serving Throughput
|
|
342
|
+
|
|
343
|
+
Measured on a single A100-80GB GPU with vLLM, processing document images from olmOCR-Bench at very high concurrency for optimal utilisation of vllm.
|
|
344
|
+
|
|
345
|
+
- **Layout + OCR** — The full end-to-end pipeline: layout detection finds regions on each page, crops them, and the VLLM runs on every crop. This is the real-world serving number that includes both layout and OCR time.
|
|
346
|
+
|
|
347
|
+
| Mode | tok/s | img/s | Description |
|
|
348
|
+
|------|------:|------:|-------------|
|
|
349
|
+
| **Layout + OCR** | 5,825 | 2.9 | Full pipeline: layout detection → crop → per-region OCR |
|
|
350
|
+
|
|
351
|
+
At 0.3B parameters, Falcon OCR is roughly 3x smaller than 0.9B-class OCR VLMs (e.g. PaddleOCR VL), which translates directly into higher serving throughput at competitive accuracy.
|
|
352
|
+
|
|
353
|
+
### Quick Start
|
|
354
|
+
For production OCR serving, we also provide a Docker image (~6,000 tok/s on a single A100) that bundles vLLM with an end-to-end parsing pipeline. It exposes two services: **vLLM** (port 8000, OpenAI-compatible API) and a **Pipeline** (port 5002, layout → crop → OCR → markdown).
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
# Two GPUs (best throughput): vLLM on one, layout model on the other
|
|
358
|
+
docker run -d --name falcon-ocr \
|
|
359
|
+
--gpus '"device=0,1"' \
|
|
360
|
+
-e EXPOSED_GPU_IDS=0,1 -e VLLM_GPU=0 -e PIPELINE_GPU=1 \
|
|
361
|
+
-e VLLM_GPU_MEM_UTIL=0.90 \
|
|
362
|
+
-p 8000:8000 -p 5002:5002 \
|
|
363
|
+
ghcr.io/tiiuae/falcon-ocr:latest
|
|
364
|
+
|
|
365
|
+
# Single GPU (share memory — lower VLLM_GPU_MEM_UTIL to leave room for layout model)
|
|
366
|
+
docker run -d --name falcon-ocr \
|
|
367
|
+
--gpus '"device=0"' \
|
|
368
|
+
-e EXPOSED_GPU_IDS=0 -e VLLM_GPU=0 -e PIPELINE_GPU=0 \
|
|
369
|
+
-e VLLM_GPU_MEM_UTIL=0.55 -e MAX_NUM_SEQS=512 \
|
|
370
|
+
-p 8000:8000 -p 5002:5002 \
|
|
371
|
+
ghcr.io/tiiuae/falcon-ocr:latest
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# Upload (images or PDFs)
|
|
376
|
+
curl -X POST http://localhost:5002/falconocr/upload \
|
|
377
|
+
-F "files=@document.pdf;type=application/pdf"
|
|
378
|
+
|
|
379
|
+
# Parse with layout detection
|
|
380
|
+
curl -X POST http://localhost:5002/falconocr/parse \
|
|
381
|
+
-H "Content-Type: application/json" \
|
|
382
|
+
-d '{"images": ["data:image/jpeg;base64,<...>"], "skip_layout": false}'
|
|
383
|
+
|
|
384
|
+
# Parse without layout (full image → VLM directly)
|
|
385
|
+
curl -X POST http://localhost:5002/falconocr/parse \
|
|
386
|
+
-H "Content-Type: application/json" \
|
|
387
|
+
-d '{"images": ["data:image/jpeg;base64,<...>"], "skip_layout": true}'
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
See the [Falcon-OCR model card](https://huggingface.co/tiiuae/Falcon-OCR) for the full API reference, configuration variables, and deployment options.
|
|
391
|
+
|
|
392
|
+
## Citation
|
|
393
|
+
If you use Falcon-Perception, please cite
|
|
394
|
+
```
|
|
395
|
+
@article{bevli2026falcon,
|
|
396
|
+
title = {Falcon Perception},
|
|
397
|
+
author = {Bevli, Aviraj and Chaybouti, Sofian and Dahou, Yasser and Hacid, Hakim and Huynh, Ngoc Dung and Le Khac, Phuc H. and Narayan, Sanath and Para, Wamiq Reyaz and Singh, Ankit},
|
|
398
|
+
journal = {arXiv preprint arXiv:2603.27365},
|
|
399
|
+
year = {2026},
|
|
400
|
+
url = {https://arxiv.org/abs/2603.27365}
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
## Acknowledgments
|
|
404
|
+
We based on, built upon and are inspired by the following excellent work:
|
|
405
|
+
- https://github.com/pytorch/torchtitan
|
|
406
|
+
- https://github.com/karpathy/nanochat
|
|
407
|
+
- https://github.com/meta-pytorch/attention-gym
|
|
408
|
+
- https://github.com/changjonathanc/flex-nano-vllm
|
|
409
|
+
- https://github.com/vikhyat/moondream
|
|
410
|
+
- https://github.com/wimmerth/anyup
|
|
411
|
+
- https://github.com/roboflow/trackers
|