Initial model release
Browse files- .gitattributes +15 -0
- .gitignore +4 -0
- LICENSE +201 -0
- README.md +171 -0
- TechnicalReport.pdf +3 -0
- ckpts/rf-detrs/checkpoint_best_total.safetensors +3 -0
- ckpts/rt-detrv4s-cradiov4-so400m/best_stg2.safetensors +3 -0
- ckpts/rt-detrv4s-dinov3b/best_stg2.safetensors +3 -0
- figures/CrowdHuman_Dataset.png +3 -0
- figures/qualitative_five_model_panels/head_high/05_273275,c0ae0000aec25c12.png +3 -0
- figures/qualitative_five_model_panels/head_low/02_283647,120b7000e2e46855.png +3 -0
- figures/qualitative_five_model_panels/head_low/03_283554,3a7ad00020c75baa.png +3 -0
- figures/qualitative_five_model_panels/head_low/10_273278,76802000732a3dff.png +3 -0
- figures/qualitative_five_model_panels/head_medium/02_273278,14081f000db0bb9ab.png +3 -0
- figures/qualitative_five_model_panels/head_medium/10_273278,3ffee00000e633e6.png +3 -0
- figures/qualitative_five_model_panels/person_high/01_283647,2944000f069ba24.png +3 -0
- figures/qualitative_five_model_panels/person_high/04_273275,12f36e000ed03b48f.png +3 -0
- figures/qualitative_five_model_panels/person_low/01_282555,bc73f000c20d1945.png +3 -0
- figures/qualitative_five_model_panels/person_low/10_283647,b71200031068c38.png +3 -0
- figures/qualitative_five_model_panels/person_medium/01_282555,a8d86000f6480c8d.png +3 -0
- figures/qualitative_five_model_panels/person_medium/02_283554,1079d00027611494.png +3 -0
- figures/qualitative_five_model_panels/person_medium/07_273278,16c7a0000490fb17.png +3 -0
- figures/qualitative_five_model_panels/qualitative_selection_manifest.json +0 -0
- scripts/convert_release_checkpoint.py +71 -0
- scripts/inference.py +286 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,18 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
TechnicalReport.pdf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
figures/CrowdHuman_Dataset.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
figures/qualitative_five_model_panels/head_high/05_273275,c0ae0000aec25c12.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
figures/qualitative_five_model_panels/head_low/02_283647,120b7000e2e46855.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
figures/qualitative_five_model_panels/head_low/03_283554,3a7ad00020c75baa.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
figures/qualitative_five_model_panels/head_low/10_273278,76802000732a3dff.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
figures/qualitative_five_model_panels/head_medium/02_273278,14081f000db0bb9ab.png filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
figures/qualitative_five_model_panels/head_medium/10_273278,3ffee00000e633e6.png filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
figures/qualitative_five_model_panels/person_high/01_283647,2944000f069ba24.png filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
figures/qualitative_five_model_panels/person_high/04_273275,12f36e000ed03b48f.png filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
figures/qualitative_five_model_panels/person_low/01_282555,bc73f000c20d1945.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
figures/qualitative_five_model_panels/person_low/10_283647,b71200031068c38.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
figures/qualitative_five_model_panels/person_medium/01_282555,a8d86000f6480c8d.png filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
figures/qualitative_five_model_panels/person_medium/02_283554,1079d00027611494.png filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
figures/qualitative_five_model_panels/person_medium/07_273278,16c7a0000490fb17.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
outputs/
|
| 4 |
+
converted/
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
library_name: pytorch
|
| 6 |
+
pipeline_tag: object-detection
|
| 7 |
+
datasets:
|
| 8 |
+
- sshao0516/CrowdHuman
|
| 9 |
+
tags:
|
| 10 |
+
- crowdhuman
|
| 11 |
+
- object-detection
|
| 12 |
+
- person-detection
|
| 13 |
+
- head-detection
|
| 14 |
+
- rtdetrv4
|
| 15 |
+
- rf-detr
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Improving RT-DETRv4 Person and Head Detection on CrowdHuman with C-RADIOv4 Distillation
|
| 19 |
+
|
| 20 |
+
## Abstract
|
| 21 |
+
|
| 22 |
+
Real-time person and head detection in dense crowds remains fundamentally difficult, as detectors must localize partially visible bodies under severe inter-person occlusion while preserving the fine-grained semantics needed to separate tiny heads in heavily cluttered scenes. Recent real-time detection transformers such as RT-DETRv4 address feature degradation in lightweight detectors by distilling knowledge from vision foundation models (VFMs), yet the impact of teacher choice on detection performance is underexplored. In this paper, we benchmark RT-DETRv4-S against YOLO26-S, YOLOv8-S, and RF-DETR-S on CrowdHuman visible-person and head detection, and investigate whether replacing the default DINOv3-Base teacher with C-RADIOv4-SO400M can further improve detection quality. Rather than scaling the DINOv3 teacher from the default Base model to a much larger DINOv3-7B variant, we study an alternative design in which the student is supervised by C-RADIOv4, an agglomerative vision backbone that already distills knowledge from DINOv3-7B together with complementary teachers such as SAM3 and SigLIP2. RT-DETRv4-S already surpasses all three baselines under both teachers. With C-RADIOv4, it achieves the best mAP on both visible-person (0.8410) and head detection (0.7881), improving over DINOv3 by +0.91 pp and +1.71 pp, respectively, and outperforming the Ultralytics YOLO26-S baseline by +2.47 pp and +2.91 pp.
|
| 23 |
+
|
| 24 |
+
For detailed methodology, training protocol,evaluation protocol, please refer to [Technical Report](TechnicalReport.pdf).
|
| 25 |
+
|
| 26 |
+
## Evaluation and Results
|
| 27 |
+
|
| 28 |
+
This release focuses on compact visible-person and head detection on CrowdHuman. The study uses CrowdHuman visible-body and head annotations, trains on the training split, and evaluates on the validation split. RT-DETRv4-S is compared against YOLO26-S, YOLOv8-S, and RF-DETR-S, and the teacher study isolates the effect of replacing the default DINOv3-Base teacher with C-RADIOv4-SO400M while keeping the RT-DETRv4-S detector fixed.
|
| 29 |
+
|
| 30 |
+
Across the evaluated compact models, RT-DETRv4-S with C-RADIOv4-SO400M is the strongest configuration on both visible-person and head detection. The teacher swap improves visible-person mAP from `0.8319` to `0.8410` and head mAP from `0.7710` to `0.7881`. Because RT-DETRv4 uses distillation only during training, the DINOv3-Base and C-RADIOv4 variants share the same inference architecture and deployment cost.
|
| 31 |
+
|
| 32 |
+
**Table 1.** Visible-person detection results on CrowdHuman validation. Best result in **bold**, second-best <u>underlined</u>.
|
| 33 |
+
|
| 34 |
+
| Model | mAP |
|
| 35 |
+
|---|---:|
|
| 36 |
+
| RT-DETRv4-S (C-RADIOv4-SO400M) | **0.8410** |
|
| 37 |
+
| RT-DETRv4-S (DINOv3 Base) | <u>0.8319</u> |
|
| 38 |
+
| YOLOv8-S | 0.8263 |
|
| 39 |
+
| YOLO26-S | 0.8163 |
|
| 40 |
+
| RF-DETR-S | 0.8006 |
|
| 41 |
+
|
| 42 |
+
**Table 2.** Head detection results on CrowdHuman validation (ignore-region mode 1). Best in **bold**, second-best <u>underlined</u>.
|
| 43 |
+
|
| 44 |
+
| Model | mAP |
|
| 45 |
+
|---|---:|
|
| 46 |
+
| RT-DETRv4-S (C-RADIOv4-SO400M) | **0.7881** |
|
| 47 |
+
| RT-DETRv4-S (DINOv3 Base) | <u>0.7710</u> |
|
| 48 |
+
| YOLO26-S | 0.7590 |
|
| 49 |
+
| YOLOv8-S | 0.7336 |
|
| 50 |
+
| RF-DETR-S | 0.6990 |
|
| 51 |
+
|
| 52 |
+
**Table 3.** Visible-person mAP of default COCO-pretrained checkpoints evaluated on CrowdHuman validation. Best in **bold**, second-best <u>underlined</u>.
|
| 53 |
+
|
| 54 |
+
| Model | mAP |
|
| 55 |
+
|---|---:|
|
| 56 |
+
| RF-DETR-S | **0.6956** |
|
| 57 |
+
| YOLOv8-S | <u>0.6935</u> |
|
| 58 |
+
| RT-DETRv4-S | 0.6846 |
|
| 59 |
+
| YOLO26-S | 0.6715 |
|
| 60 |
+
|
| 61 |
+
**Table 4.** TensorRT latency on NVIDIA T4 together with reported model complexity.
|
| 62 |
+
|
| 63 |
+
| Model | Resolution | TensorRT Latency on T4 (ms) | Params (M) | GFLOPs |
|
| 64 |
+
|---|---:|---:|---:|---:|
|
| 65 |
+
| RT-DETRv4-S [12] | 640 | 3.66 | 10 | 25 |
|
| 66 |
+
| YOLO26-S [16] | 640 | **2.5** | **9.5** | **20.7** |
|
| 67 |
+
| YOLOv8-S [8, 15] | 640 | 6.97 | 11 | 29 |
|
| 68 |
+
| RF-DETR-S [13, 14] | 512 | 3.50 | 32.1 | 59.8 |
|
| 69 |
+
|
| 70 |
+
## Qualitative Analysis
|
| 71 |
+
|
| 72 |
+
Qualitative comparisons use `2 x 3` panels with the original image first and the five detectors ordered by descending mAP for the corresponding task. Visualizations use confidence threshold `0.40`, and true-positive versus false-positive assignments are determined by greedy one-to-one matching at IoU `0.50`. Dashed blue boxes denote ground truth, green boxes denote true positives, and red boxes denote false positives.
|
| 73 |
+
|
| 74 |
+
[](figures/qualitative_five_model_panels/person_low/01_282555,bc73f000c20d1945.png)
|
| 75 |
+
|
| 76 |
+
[](figures/qualitative_five_model_panels/person_medium/07_273278,16c7a0000490fb17.png)
|
| 77 |
+
|
| 78 |
+
[](figures/qualitative_five_model_panels/person_high/01_283647,2944000f069ba24.png)
|
| 79 |
+
|
| 80 |
+
[](figures/qualitative_five_model_panels/head_low/03_283554,3a7ad00020c75baa.png)
|
| 81 |
+
|
| 82 |
+
[](figures/qualitative_five_model_panels/head_medium/10_273278,3ffee00000e633e6.png)
|
| 83 |
+
|
| 84 |
+
[](figures/qualitative_five_model_panels/head_high/05_273275,c0ae0000aec25c12.png)
|
| 85 |
+
|
| 86 |
+
## Model Inference
|
| 87 |
+
|
| 88 |
+
All model weights are available in this repository:
|
| 89 |
+
|
| 90 |
+
- `ckpts/rt-detrv4s-cradiov4-so400m/best_stg2.safetensors`
|
| 91 |
+
- `ckpts/rt-detrv4s-dinov3b/best_stg2.safetensors`
|
| 92 |
+
- `ckpts/rf-detrs/checkpoint_best_total.safetensors`
|
| 93 |
+
|
| 94 |
+
Use the official repositories for inference:
|
| 95 |
+
|
| 96 |
+
1. [RT-DETRv4](https://github.com/RT-DETRs/RT-DETRv4) for the two RT-DETRv4-S checkpoints.
|
| 97 |
+
2. [RF-DETR](https://github.com/roboflow/rf-detr) for the RF-DETR-S checkpoint.
|
| 98 |
+
|
| 99 |
+
### Dependencies
|
| 100 |
+
|
| 101 |
+
The inference wrapper requires the following Python packages:
|
| 102 |
+
|
| 103 |
+
```bash
|
| 104 |
+
pip install torch safetensors pillow numpy supervision
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
For RT-DETRv4, also install the dependencies from the [RT-DETRv4 repository](https://github.com/RT-DETRs/RT-DETRv4).
|
| 108 |
+
For RF-DETR, also install the dependencies from the [RF-DETR repository](https://github.com/roboflow/rf-detr) (or `pip install rfdetr`).
|
| 109 |
+
|
| 110 |
+
### Usage
|
| 111 |
+
|
| 112 |
+
Use `scripts/inference.py` to run inference. It handles checkpoint conversion automatically and runs inference through the official repository code. For RT-DETRv4 it also generates a minimal 2-class inference config automatically, so users do not need to hand-write one. The C-RADIOv4 teacher is not needed at inference time; only the trained student weights are used.
|
| 113 |
+
|
| 114 |
+
The RT-DETRv4 wrapper saves the converted checkpoint, the generated inference YAML, and the official `torch_results.jpg` / `torch_results.mp4` output. The RF-DETR wrapper saves the converted checkpoint, an annotated image, and a JSON file with predictions.
|
| 115 |
+
|
| 116 |
+
Example RT-DETRv4 inference (C-RADIOv4 teacher):
|
| 117 |
+
|
| 118 |
+
```bash
|
| 119 |
+
python scripts/inference.py rtdetrv4 \
|
| 120 |
+
--repo /path/to/RT-DETRv4 \
|
| 121 |
+
--checkpoint ckpts/rt-detrv4s-cradiov4-so400m/best_stg2.safetensors \
|
| 122 |
+
--input /path/to/image.jpg \
|
| 123 |
+
--device cuda \
|
| 124 |
+
--output-dir outputs/rtdetrv4_cradio
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
Example RT-DETRv4 inference (DINOv3-Base teacher):
|
| 128 |
+
|
| 129 |
+
```bash
|
| 130 |
+
python scripts/inference.py rtdetrv4 \
|
| 131 |
+
--repo /path/to/RT-DETRv4 \
|
| 132 |
+
--checkpoint ckpts/rt-detrv4s-dinov3b/best_stg2.safetensors \
|
| 133 |
+
--input /path/to/image.jpg \
|
| 134 |
+
--device cuda \
|
| 135 |
+
--output-dir outputs/rtdetrv4_dinov3b
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
Example RF-DETR inference:
|
| 139 |
+
|
| 140 |
+
```bash
|
| 141 |
+
python scripts/inference.py rfdetr \
|
| 142 |
+
--repo /path/to/rf-detr \
|
| 143 |
+
--checkpoint ckpts/rf-detrs/checkpoint_best_total.safetensors \
|
| 144 |
+
--input /path/to/image.jpg \
|
| 145 |
+
--device cuda \
|
| 146 |
+
--output-dir outputs/rfdetr
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
### Standalone Checkpoint Conversion
|
| 150 |
+
|
| 151 |
+
This release also includes `scripts/convert_release_checkpoint.py` for users who only want checkpoint conversion without running inference.
|
| 152 |
+
|
| 153 |
+
```bash
|
| 154 |
+
# Convert RT-DETRv4 checkpoint
|
| 155 |
+
python scripts/convert_release_checkpoint.py \
|
| 156 |
+
--framework rtdetrv4 \
|
| 157 |
+
--input ckpts/rt-detrv4s-cradiov4-so400m/best_stg2.safetensors \
|
| 158 |
+
--output converted/best_stg2.pth
|
| 159 |
+
|
| 160 |
+
# Convert RF-DETR checkpoint
|
| 161 |
+
python scripts/convert_release_checkpoint.py \
|
| 162 |
+
--framework rfdetr \
|
| 163 |
+
--input ckpts/rf-detrs/checkpoint_best_total.safetensors \
|
| 164 |
+
--output converted/checkpoint_best_total.pth
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
## Summary
|
| 168 |
+
|
| 169 |
+
This release packages the main checkpoints from the accompanying CrowdHuman study and highlights teacher selection as a key design choice for VFM-distilled detectors. With the RT-DETRv4-S student fixed, replacing DINOv3-Base with C-RADIOv4 improves visible-person mAP by `+0.91` points and head mAP by `+1.71` points, indicating that the gains come from a stronger transferred representation rather than from increased student capacity.
|
| 170 |
+
|
| 171 |
+
Among the compact models evaluated, the C-RADIOv4-distilled RT-DETRv4-S checkpoint is the strongest overall, reaching `0.8410` visible-person mAP and `0.7881` head mAP on CrowdHuman validation. Because the teacher is used only during training, these gains do not add inference-time cost, making the C-RADIOv4-based RT-DETRv4-S checkpoint the most practical release in this comparison.
|
TechnicalReport.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:409448d09566f8c839dbd1d8f051fce590ead2de9e71bb64573ab9fea39e35a3
|
| 3 |
+
size 22841660
|
ckpts/rf-detrs/checkpoint_best_total.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:16092352a61d4bd0fe77be94db28db5fc19e9201540d6f39f3513f037fb03db1
|
| 3 |
+
size 127238024
|
ckpts/rt-detrv4s-cradiov4-so400m/best_stg2.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8a0cc9acdf6adccf39511ac626335c1deb0003278e74b12295d70cdb6a44c869
|
| 3 |
+
size 42417812
|
ckpts/rt-detrv4s-dinov3b/best_stg2.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c553edb5546f0f21201c2d3272b081b92e1cf3fbee062246fbfc3a3db6497ffb
|
| 3 |
+
size 42023052
|
figures/CrowdHuman_Dataset.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/head_high/05_273275,c0ae0000aec25c12.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/head_low/02_283647,120b7000e2e46855.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/head_low/03_283554,3a7ad00020c75baa.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/head_low/10_273278,76802000732a3dff.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/head_medium/02_273278,14081f000db0bb9ab.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/head_medium/10_273278,3ffee00000e633e6.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/person_high/01_283647,2944000f069ba24.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/person_high/04_273275,12f36e000ed03b48f.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/person_low/01_282555,bc73f000c20d1945.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/person_low/10_283647,b71200031068c38.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/person_medium/01_282555,a8d86000f6480c8d.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/person_medium/02_283554,1079d00027611494.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/person_medium/07_273278,16c7a0000490fb17.png
ADDED
|
Git LFS Details
|
figures/qualitative_five_model_panels/qualitative_selection_manifest.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/convert_release_checkpoint.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Convert HF release safetensors checkpoints into official repo checkpoint layouts."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
from argparse import Namespace
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import torch
|
| 11 |
+
from safetensors.torch import load_file
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def parse_args() -> argparse.Namespace:
|
| 15 |
+
parser = argparse.ArgumentParser(
|
| 16 |
+
description=(
|
| 17 |
+
"Convert a safetensors release checkpoint into the PyTorch checkpoint "
|
| 18 |
+
"layout expected by the official RT-DETRv4 or RF-DETR repositories."
|
| 19 |
+
)
|
| 20 |
+
)
|
| 21 |
+
parser.add_argument(
|
| 22 |
+
"--framework",
|
| 23 |
+
choices=("rtdetrv4", "rfdetr"),
|
| 24 |
+
required=True,
|
| 25 |
+
help="Target official repository format.",
|
| 26 |
+
)
|
| 27 |
+
parser.add_argument(
|
| 28 |
+
"--input",
|
| 29 |
+
type=Path,
|
| 30 |
+
required=True,
|
| 31 |
+
help="Input .safetensors checkpoint path.",
|
| 32 |
+
)
|
| 33 |
+
parser.add_argument(
|
| 34 |
+
"--output",
|
| 35 |
+
type=Path,
|
| 36 |
+
required=True,
|
| 37 |
+
help="Output .pth checkpoint path.",
|
| 38 |
+
)
|
| 39 |
+
parser.add_argument(
|
| 40 |
+
"--class-names",
|
| 41 |
+
nargs="+",
|
| 42 |
+
default=["person", "head"],
|
| 43 |
+
help="Class names to store in RF-DETR checkpoint metadata.",
|
| 44 |
+
)
|
| 45 |
+
return parser.parse_args()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def main() -> None:
|
| 49 |
+
args = parse_args()
|
| 50 |
+
state_dict = load_file(str(args.input))
|
| 51 |
+
args.output.parent.mkdir(parents=True, exist_ok=True)
|
| 52 |
+
|
| 53 |
+
if args.framework == "rtdetrv4":
|
| 54 |
+
payload = {"model": state_dict}
|
| 55 |
+
else:
|
| 56 |
+
payload = {
|
| 57 |
+
"model": state_dict,
|
| 58 |
+
"args": Namespace(class_names=args.class_names),
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
torch.save(payload, args.output)
|
| 62 |
+
|
| 63 |
+
print(f"Converted {args.input} -> {args.output}")
|
| 64 |
+
print(f"Framework: {args.framework}")
|
| 65 |
+
print(f"Tensors: {len(state_dict)}")
|
| 66 |
+
if args.framework == "rfdetr":
|
| 67 |
+
print(f"Class names: {args.class_names}")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
main()
|
scripts/inference.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Run release checkpoints through the official RT-DETRv4 or RF-DETR repositories."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
import subprocess
|
| 9 |
+
import sys
|
| 10 |
+
from argparse import Namespace
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
from safetensors.torch import load_file
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
IMAGE_SUFFIXES = {".jpg", ".jpeg", ".png", ".bmp", ".webp"}
|
| 18 |
+
VIDEO_SUFFIXES = {".mp4", ".avi", ".mov", ".mkv"}
|
| 19 |
+
DEFAULT_CLASS_NAMES = ["person", "head"]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def convert_checkpoint(
|
| 23 |
+
framework: str,
|
| 24 |
+
checkpoint_path: Path,
|
| 25 |
+
output_dir: Path,
|
| 26 |
+
class_names: list[str] | None = None,
|
| 27 |
+
) -> Path:
|
| 28 |
+
checkpoint_path = checkpoint_path.resolve()
|
| 29 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 30 |
+
|
| 31 |
+
if checkpoint_path.suffix == ".pth":
|
| 32 |
+
return checkpoint_path
|
| 33 |
+
|
| 34 |
+
if checkpoint_path.suffix != ".safetensors":
|
| 35 |
+
raise ValueError(f"Unsupported checkpoint format: {checkpoint_path}")
|
| 36 |
+
|
| 37 |
+
state_dict = load_file(str(checkpoint_path))
|
| 38 |
+
output_path = output_dir / f"{checkpoint_path.stem}.pth"
|
| 39 |
+
|
| 40 |
+
if framework == "rtdetrv4":
|
| 41 |
+
payload = {"model": state_dict}
|
| 42 |
+
else:
|
| 43 |
+
payload = {
|
| 44 |
+
"model": state_dict,
|
| 45 |
+
"args": Namespace(class_names=class_names or DEFAULT_CLASS_NAMES),
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
torch.save(payload, output_path)
|
| 49 |
+
return output_path
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def infer_teacher_dim(checkpoint_path: Path, explicit: int | None) -> int:
|
| 53 |
+
if explicit is not None:
|
| 54 |
+
return explicit
|
| 55 |
+
|
| 56 |
+
checkpoint_path = checkpoint_path.resolve()
|
| 57 |
+
state_dict = None
|
| 58 |
+
if checkpoint_path.suffix == ".safetensors":
|
| 59 |
+
state_dict = load_file(str(checkpoint_path))
|
| 60 |
+
elif checkpoint_path.suffix == ".pth":
|
| 61 |
+
payload = torch.load(checkpoint_path, map_location="cpu", weights_only=False)
|
| 62 |
+
state_dict = payload["model"] if isinstance(payload, dict) and "model" in payload else payload
|
| 63 |
+
|
| 64 |
+
if isinstance(state_dict, dict) and "encoder.feature_projector.0.weight" in state_dict:
|
| 65 |
+
return int(state_dict["encoder.feature_projector.0.weight"].shape[0])
|
| 66 |
+
|
| 67 |
+
name = checkpoint_path.as_posix().lower()
|
| 68 |
+
if "cradio" in name or "cradiov4" in name or "c-radio" in name:
|
| 69 |
+
return 1152
|
| 70 |
+
return 768
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def write_rtdetrv4_config(repo_path: Path, output_dir: Path, teacher_dim: int) -> Path:
|
| 74 |
+
config_path = output_dir / "rtdetrv4_person_head_inference.yml"
|
| 75 |
+
base_config = (repo_path / "configs" / "rtv4" / "rtv4_hgnetv2_s_coco.yml").resolve()
|
| 76 |
+
config_text = (
|
| 77 |
+
"__include__: [\n"
|
| 78 |
+
f" '{base_config}'\n"
|
| 79 |
+
"]\n\n"
|
| 80 |
+
"num_classes: 2\n"
|
| 81 |
+
"remap_mscoco_category: False\n\n"
|
| 82 |
+
"HGNetv2:\n"
|
| 83 |
+
" pretrained: False\n\n"
|
| 84 |
+
"HybridEncoder:\n"
|
| 85 |
+
f" distill_teacher_dim: {teacher_dim}\n"
|
| 86 |
+
)
|
| 87 |
+
config_path.write_text(config_text)
|
| 88 |
+
return config_path
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def run_rtdetrv4(args: argparse.Namespace) -> None:
|
| 92 |
+
repo_path = args.repo.resolve()
|
| 93 |
+
input_path = args.input.resolve()
|
| 94 |
+
output_dir = args.output_dir.resolve()
|
| 95 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 96 |
+
|
| 97 |
+
converted_ckpt = convert_checkpoint("rtdetrv4", args.checkpoint, output_dir / "artifacts")
|
| 98 |
+
teacher_dim = infer_teacher_dim(args.checkpoint, args.teacher_dim)
|
| 99 |
+
config_path = write_rtdetrv4_config(repo_path, output_dir, teacher_dim)
|
| 100 |
+
|
| 101 |
+
command = [
|
| 102 |
+
sys.executable,
|
| 103 |
+
str((repo_path / "tools" / "inference" / "torch_inf.py").resolve()),
|
| 104 |
+
"-c",
|
| 105 |
+
str(config_path),
|
| 106 |
+
"-r",
|
| 107 |
+
str(converted_ckpt),
|
| 108 |
+
"-i",
|
| 109 |
+
str(input_path),
|
| 110 |
+
"-d",
|
| 111 |
+
args.device,
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
subprocess.run(command, cwd=output_dir, check=True)
|
| 115 |
+
|
| 116 |
+
result_name = "torch_results.jpg"
|
| 117 |
+
if input_path.suffix.lower() in VIDEO_SUFFIXES:
|
| 118 |
+
result_name = "torch_results.mp4"
|
| 119 |
+
|
| 120 |
+
print(
|
| 121 |
+
json.dumps(
|
| 122 |
+
{
|
| 123 |
+
"framework": "rtdetrv4",
|
| 124 |
+
"converted_checkpoint": str(converted_ckpt),
|
| 125 |
+
"generated_config": str(config_path),
|
| 126 |
+
"result": str(output_dir / result_name),
|
| 127 |
+
"teacher_dim": teacher_dim,
|
| 128 |
+
},
|
| 129 |
+
indent=2,
|
| 130 |
+
)
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def build_label_lookup(class_names) -> dict[int, str]:
|
| 135 |
+
"""Build an int -> str lookup from whatever format class_names is in."""
|
| 136 |
+
if isinstance(class_names, dict):
|
| 137 |
+
return {int(k): v for k, v in class_names.items()}
|
| 138 |
+
if isinstance(class_names, (list, tuple)):
|
| 139 |
+
return {i: name for i, name in enumerate(class_names)}
|
| 140 |
+
return {}
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def resolve_class_name(label_lookup: dict[int, str], raw_class_id: int) -> str:
|
| 144 |
+
if raw_class_id in label_lookup:
|
| 145 |
+
return label_lookup[raw_class_id]
|
| 146 |
+
if raw_class_id + 1 in label_lookup:
|
| 147 |
+
return label_lookup[raw_class_id + 1]
|
| 148 |
+
return str(raw_class_id)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def run_rfdetr(args: argparse.Namespace) -> None:
|
| 152 |
+
import numpy as np
|
| 153 |
+
import supervision as sv
|
| 154 |
+
from PIL import Image
|
| 155 |
+
|
| 156 |
+
repo_path = args.repo.resolve()
|
| 157 |
+
output_dir = args.output_dir.resolve()
|
| 158 |
+
input_path = args.input.resolve()
|
| 159 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 160 |
+
|
| 161 |
+
if input_path.suffix.lower() not in IMAGE_SUFFIXES:
|
| 162 |
+
raise ValueError("RF-DETR wrapper currently supports image inference only.")
|
| 163 |
+
|
| 164 |
+
sys.path.insert(0, str(repo_path))
|
| 165 |
+
sys.path.insert(0, str(repo_path / "src"))
|
| 166 |
+
|
| 167 |
+
from rfdetr import RFDETRSmall
|
| 168 |
+
|
| 169 |
+
converted_ckpt = convert_checkpoint(
|
| 170 |
+
"rfdetr",
|
| 171 |
+
args.checkpoint,
|
| 172 |
+
output_dir / "artifacts",
|
| 173 |
+
class_names=args.class_names,
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
model = RFDETRSmall(
|
| 177 |
+
pretrain_weights=str(converted_ckpt),
|
| 178 |
+
device=args.device,
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
image = Image.open(input_path).convert("RGB")
|
| 182 |
+
detections = model.predict(image, threshold=args.threshold)
|
| 183 |
+
|
| 184 |
+
label_lookup = build_label_lookup(getattr(model, "class_names", args.class_names))
|
| 185 |
+
labels = []
|
| 186 |
+
for class_id, confidence in zip(detections.class_id.tolist(), detections.confidence.tolist()):
|
| 187 |
+
class_name = resolve_class_name(label_lookup, int(class_id))
|
| 188 |
+
labels.append(f"{class_name} {confidence:.2f}")
|
| 189 |
+
|
| 190 |
+
image_np = np.array(image)
|
| 191 |
+
annotated = sv.BoxAnnotator().annotate(scene=image_np, detections=detections)
|
| 192 |
+
annotated = sv.LabelAnnotator().annotate(scene=annotated, detections=detections, labels=labels)
|
| 193 |
+
|
| 194 |
+
output_image = output_dir / f"{input_path.stem}_rfdetr.jpg"
|
| 195 |
+
output_json = output_dir / f"{input_path.stem}_rfdetr.json"
|
| 196 |
+
|
| 197 |
+
Image.fromarray(annotated).save(output_image)
|
| 198 |
+
|
| 199 |
+
predictions = []
|
| 200 |
+
for box, confidence, class_id in zip(
|
| 201 |
+
detections.xyxy.tolist(),
|
| 202 |
+
detections.confidence.tolist(),
|
| 203 |
+
detections.class_id.tolist(),
|
| 204 |
+
):
|
| 205 |
+
raw_id = int(class_id)
|
| 206 |
+
predictions.append(
|
| 207 |
+
{
|
| 208 |
+
"bbox_xyxy": [round(float(v), 4) for v in box],
|
| 209 |
+
"confidence": round(float(confidence), 6),
|
| 210 |
+
"class_id": raw_id,
|
| 211 |
+
"class_name": resolve_class_name(label_lookup, raw_id),
|
| 212 |
+
}
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
output_json.write_text(json.dumps(predictions, indent=2))
|
| 216 |
+
|
| 217 |
+
print(
|
| 218 |
+
json.dumps(
|
| 219 |
+
{
|
| 220 |
+
"framework": "rfdetr",
|
| 221 |
+
"converted_checkpoint": str(converted_ckpt),
|
| 222 |
+
"result_image": str(output_image),
|
| 223 |
+
"result_json": str(output_json),
|
| 224 |
+
},
|
| 225 |
+
indent=2,
|
| 226 |
+
)
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def build_parser() -> argparse.ArgumentParser:
|
| 231 |
+
parser = argparse.ArgumentParser(
|
| 232 |
+
description="Run this release through the official RT-DETRv4 or RF-DETR repositories."
|
| 233 |
+
)
|
| 234 |
+
subparsers = parser.add_subparsers(dest="framework", required=True)
|
| 235 |
+
|
| 236 |
+
rtdetr_parser = subparsers.add_parser("rtdetrv4", help="Run official RT-DETRv4 inference.")
|
| 237 |
+
rtdetr_parser.add_argument("--repo", type=Path, required=True, help="Path to the official RT-DETRv4 repository.")
|
| 238 |
+
rtdetr_parser.add_argument("--checkpoint", type=Path, required=True, help="Release checkpoint (.safetensors or .pth).")
|
| 239 |
+
rtdetr_parser.add_argument("--input", type=Path, required=True, help="Input image or video path.")
|
| 240 |
+
rtdetr_parser.add_argument("--device", default="cpu", help="Inference device passed to official script.")
|
| 241 |
+
rtdetr_parser.add_argument(
|
| 242 |
+
"--output-dir",
|
| 243 |
+
type=Path,
|
| 244 |
+
default=Path("outputs/rtdetrv4"),
|
| 245 |
+
help="Directory where converted weights, temp config, and outputs are written.",
|
| 246 |
+
)
|
| 247 |
+
rtdetr_parser.add_argument(
|
| 248 |
+
"--teacher-dim",
|
| 249 |
+
type=int,
|
| 250 |
+
choices=(768, 1152),
|
| 251 |
+
default=None,
|
| 252 |
+
help="Override the RT-DETRv4 distillation projection dimension if auto-detection is wrong.",
|
| 253 |
+
)
|
| 254 |
+
rtdetr_parser.set_defaults(func=run_rtdetrv4)
|
| 255 |
+
|
| 256 |
+
rfdetr_parser = subparsers.add_parser("rfdetr", help="Run official RF-DETR inference.")
|
| 257 |
+
rfdetr_parser.add_argument("--repo", type=Path, required=True, help="Path to the official RF-DETR repository.")
|
| 258 |
+
rfdetr_parser.add_argument("--checkpoint", type=Path, required=True, help="Release checkpoint (.safetensors or .pth).")
|
| 259 |
+
rfdetr_parser.add_argument("--input", type=Path, required=True, help="Input image path.")
|
| 260 |
+
rfdetr_parser.add_argument("--device", default="cpu", help="Device passed to RF-DETR.")
|
| 261 |
+
rfdetr_parser.add_argument(
|
| 262 |
+
"--output-dir",
|
| 263 |
+
type=Path,
|
| 264 |
+
default=Path("outputs/rfdetr"),
|
| 265 |
+
help="Directory where converted weights and outputs are written.",
|
| 266 |
+
)
|
| 267 |
+
rfdetr_parser.add_argument("--threshold", type=float, default=0.4, help="Detection threshold.")
|
| 268 |
+
rfdetr_parser.add_argument(
|
| 269 |
+
"--class-names",
|
| 270 |
+
nargs="+",
|
| 271 |
+
default=DEFAULT_CLASS_NAMES,
|
| 272 |
+
help="Class names stored in converted RF-DETR checkpoints.",
|
| 273 |
+
)
|
| 274 |
+
rfdetr_parser.set_defaults(func=run_rfdetr)
|
| 275 |
+
|
| 276 |
+
return parser
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def main() -> None:
|
| 280 |
+
parser = build_parser()
|
| 281 |
+
args = parser.parse_args()
|
| 282 |
+
args.func(args)
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
if __name__ == "__main__":
|
| 286 |
+
main()
|