Initial release (seed 0 weights)
Browse files- .gitattributes +3 -0
- LICENSE +201 -0
- NOTICE +51 -0
- README.md +147 -0
- config.json +17 -0
- config.yml +96 -0
- examples/example_01.png +3 -0
- examples/example_01_pred.png +3 -0
- examples/example_02.png +3 -0
- inference/infer.py +186 -0
- inference/requirements.txt +11 -0
- model.safetensors +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ 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 |
+
examples/example_01.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
examples/example_01_pred.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
examples/example_02.png filter=lfs diff=lfs merge=lfs -text
|
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.
|
NOTICE
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
floorplan-dfine-obj — D-FINE floor-plan detector (part of the floorplan-dfine {obj,str,spa} model set)
|
| 2 |
+
Copyright 2026 Digitalpresso Inc.
|
| 3 |
+
(TODO: confirm the legal English company name before publishing)
|
| 4 |
+
|
| 5 |
+
Licensed under the Apache License, Version 2.0 (see LICENSE).
|
| 6 |
+
|
| 7 |
+
-------------------------------------------------------------------------------
|
| 8 |
+
Model architecture and initialization
|
| 9 |
+
-------------------------------------------------------------------------------
|
| 10 |
+
These models use the D-FINE detector (https://github.com/Peterande/D-FINE),
|
| 11 |
+
Copyright (c) the D-FINE authors, licensed under the Apache License 2.0.
|
| 12 |
+
|
| 13 |
+
Training started from the official D-FINE-M checkpoint pre-trained on COCO only
|
| 14 |
+
(dfine_m_coco.pth). No Objects365-derived checkpoint (*_obj365, *_obj2coco) was
|
| 15 |
+
used at any stage.
|
| 16 |
+
|
| 17 |
+
Modifications to D-FINE used for training (training-time only; inference uses
|
| 18 |
+
unmodified upstream D-FINE at commit 956d170):
|
| 19 |
+
* src/data/dataset/coco_dataset.py, src/zoo/dfine/dfine_criterion.py:
|
| 20 |
+
per-source class masking — classification loss is zeroed for classes that a
|
| 21 |
+
training source does not annotate, so unlabeled classes are not learned as
|
| 22 |
+
background when several datasets are mixed.
|
| 23 |
+
* src/solver/det_solver.py: write last.pth every epoch (resume robustness).
|
| 24 |
+
|
| 25 |
+
-------------------------------------------------------------------------------
|
| 26 |
+
Training data attribution
|
| 27 |
+
-------------------------------------------------------------------------------
|
| 28 |
+
This research used datasets from 'The Open AI Dataset Project (AI-Hub, S. Korea)'.
|
| 29 |
+
All data information can be accessed through 'AI-Hub (www.aihub.or.kr)'.
|
| 30 |
+
- Dataset: 건축 도면 데이터 (Architectural Drawing Data), AI-Hub dataset 71465 (NIA, Korea).
|
| 31 |
+
- The AI-Hub data itself is NOT redistributed with these models.
|
| 32 |
+
|
| 33 |
+
Swiss Dwellings — Standfest, M., Franzen, M., Schröder, Y., et al. (Archilyse AG),
|
| 34 |
+
Zenodo record 7788422 (DOI 10.5281/zenodo.7788422), v3.0.0,
|
| 35 |
+
licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/).
|
| 36 |
+
Floor plans were rasterized by us from the published vector geometry; door
|
| 37 |
+
swing arcs were added by rule because the source does not encode them.
|
| 38 |
+
|
| 39 |
+
SYNBUILD-3D — the SYNBUILD-3D authors (github.com/kdmayer/SYNBUILD-3D), Stanford Digital Repository
|
| 40 |
+
https://purl.stanford.edu/kz908vb7844 (arXiv:2508.21169),
|
| 41 |
+
licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/).
|
| 42 |
+
Used for the structure (STR) model only.
|
| 43 |
+
|
| 44 |
+
Floorplan Synthetic 2500 — dataset of 2,500 synthetic single-family floor plan images,
|
| 45 |
+
figshare https://figshare.com/articles/dataset/28282802,
|
| 46 |
+
licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/).
|
| 47 |
+
Object labels were derived by us from the colour-coded renders.
|
| 48 |
+
Used for the structure (STR) model only.
|
| 49 |
+
|
| 50 |
+
For the STR model, Swiss Dwellings walls were re-derived from the vector geometry as
|
| 51 |
+
straight segments between openings, to match the wall convention of the other sources.
|
README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: pytorch
|
| 4 |
+
pipeline_tag: object-detection
|
| 5 |
+
tags:
|
| 6 |
+
- object-detection
|
| 7 |
+
- floor-plan
|
| 8 |
+
- architecture
|
| 9 |
+
- d-fine
|
| 10 |
+
- document-analysis
|
| 11 |
+
- swiss-dwellings
|
| 12 |
+
# Training data (no HF dataset ids): AI-Hub 71465 (Korea, not redistributed),
|
| 13 |
+
# Swiss Dwellings v3.0.0 (Zenodo 10.5281/zenodo.7788422, CC BY 4.0).
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# floorplan-dfine-obj — floor-plan fixtures detector (D-FINE-M)
|
| 17 |
+
|
| 18 |
+
Object detector for architectural floor-plan drawings, **OBJ — fixtures layer**. It is one of three
|
| 19 |
+
sibling models that share one class taxonomy (`config.json -> id2label`), so their outputs can be merged
|
| 20 |
+
into a single page parse: [digitalpresso/floorplan-dfine-str](https://huggingface.co/digitalpresso/floorplan-dfine-str), [digitalpresso/floorplan-dfine-spa](https://huggingface.co/digitalpresso/floorplan-dfine-spa).
|
| 21 |
+
|
| 22 |
+
- Architecture: D-FINE-M (HGNetv2-B2), 19.9 M parameters, 128 queries, 80 MB (safetensors)
|
| 23 |
+
- Input: 1920 x 1920 tiles of full-resolution drawings (25 % overlap), see *How to use*
|
| 24 |
+
- Initialization: official **COCO-only** D-FINE-M checkpoint (no Objects365 lineage)
|
| 25 |
+
- Weights: training seed 0 (g1scan s0)
|
| 26 |
+
|
| 27 |
+
## Classes
|
| 28 |
+
|
| 29 |
+
| id | name |
|
| 30 |
+
|---|---|
|
| 31 |
+
| 23 | toilet |
|
| 32 |
+
| 24 | washbasin |
|
| 33 |
+
| 25 | bathtub |
|
| 34 |
+
| 26 | sink |
|
| 35 |
+
| 27 | stove |
|
| 36 |
+
|
| 37 |
+
Ids follow the shared taxonomy (id = taxonomy index + 1), which is why this model's ids do not start at 1.
|
| 38 |
+
|
| 39 |
+
## How to use
|
| 40 |
+
|
| 41 |
+
Drawings are large and symbols are small, so inference must reproduce the training protocol:
|
| 42 |
+
**1920 px tiles with 25 % overlap**, per-tile detection, then per-class NMS across tiles.
|
| 43 |
+
`inference/infer.py` does this. It needs the *unmodified* upstream D-FINE source (Apache-2.0) pinned to
|
| 44 |
+
commit `956d170`; the released weights load into it with `strict=True`.
|
| 45 |
+
|
| 46 |
+
```bash
|
| 47 |
+
git clone https://huggingface.co/digitalpresso/floorplan-dfine-obj && cd floorplan-dfine-obj
|
| 48 |
+
git clone https://github.com/Peterande/D-FINE && git -C D-FINE checkout 956d170
|
| 49 |
+
pip install -r inference/requirements.txt
|
| 50 |
+
python inference/infer.py --dfine-root D-FINE --image examples/example_01.png \
|
| 51 |
+
--out detections.json --viz detections_viz.png
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
Output: JSON list of `{"label", "category_id", "bbox": [x, y, w, h], "score"}` in page pixels.
|
| 55 |
+
Defaults (score > 0.3, NMS IoU 0.6) are in `config.json`. `--drop-truncated` additionally
|
| 56 |
+
removes cut-off fragments at interior tile edges; it is off by default because the metrics below were measured without it.
|
| 57 |
+
Add `--device cpu` (or `cuda:0`) to choose the device; a 2048 px page takes a few seconds on CPU.
|
| 58 |
+
|
| 59 |
+
## Evaluation
|
| 60 |
+
|
| 61 |
+
Single training run (seed 0) — the released weights. Seed-to-seed spread for this recipe will be added when the two additional training seeds finish.
|
| 62 |
+
|
| 63 |
+
| Benchmark | Metric | **This release (seed 0)** |
|
| 64 |
+
|---|---|---|
|
| 65 |
+
| Korean held-out test (1,010 drawings, AI-Hub 71465 derived) | mAP@0.5 | 0.976 |
|
| 66 |
+
| Swiss Dwellings val | mAP@0.5 | 0.976 |
|
| 67 |
+
| Swiss Dwellings val | mAP@0.5:0.95 | 0.969 |
|
| 68 |
+
|
| 69 |
+
- Korean held-out test: a frozen, de-duplicated test set built from AI-Hub dataset 71465, never used for training or
|
| 70 |
+
model selection. Classes that belong to another layer and appear only by accident in this task's ground truth are excluded
|
| 71 |
+
from the average (a single such box would otherwise move the macro average by more than 0.1).
|
| 72 |
+
- Swiss / SYNBUILD: validation splits of our rasterized versions, split by site (Swiss) or by building (SYNBUILD),
|
| 73 |
+
so no building appears in both train and validation.
|
| 74 |
+
|
| 75 |
+
Per-class AP@0.5, seed 0, Swiss Dwellings val:
|
| 76 |
+
|
| 77 |
+
| Class | AP@0.5 | GT boxes |
|
| 78 |
+
|---|---|---|
|
| 79 |
+
| toilet | 0.977 | 5,682 |
|
| 80 |
+
| washbasin | 0.976 | 5,977 |
|
| 81 |
+
| bathtub | 0.973 | 4,034 |
|
| 82 |
+
|
| 83 |
+
Per-class AP@0.5, seed 0, Korean held-out test:
|
| 84 |
+
|
| 85 |
+
| Class | AP@0.5 |
|
| 86 |
+
|---|---|
|
| 87 |
+
| toilet | 0.971 |
|
| 88 |
+
| washbasin | 0.981 |
|
| 89 |
+
| sink | 0.963 |
|
| 90 |
+
| stove | 0.986 |
|
| 91 |
+
| bathtub | 0.979 |
|
| 92 |
+
|
| 93 |
+
## Limitations
|
| 94 |
+
|
| 95 |
+
- Swiss render contains toilet / washbasin / bathtub only (no sink or stove); `sink` and `stove` are learned
|
| 96 |
+
from AI-Hub alone and are not evaluated on Swiss.
|
| 97 |
+
- Fixtures drawn as unusual symbols (e.g. wall-hung or corner units in different conventions) may be missed.
|
| 98 |
+
- **Drawing conventions.** Trained on Korean apartment plans (AI-Hub), Swiss apartments and synthetic
|
| 99 |
+
buildings. Plans with very different drafting conventions (hatching styles, CAD colour schemes,
|
| 100 |
+
hand-drawn sketches) are out of distribution.
|
| 101 |
+
- **Scale.** In the training data a door is roughly 60-70 px long. Rasters at a much lower resolution should
|
| 102 |
+
be upscaled to about that scale before inference.
|
| 103 |
+
- **Scan quality.** Trained with a scan / re-print degradation augmentation (applied to half of the training
|
| 104 |
+
tiles: resolution loss, blur, paper and ink level shifts, noise, JPEG artefacts). Strongly degraded scans,
|
| 105 |
+
especially downscaled ones, still increase missed and spurious boxes.
|
| 106 |
+
- Detection only: no room polygons, no text/OCR, no dimension reading.
|
| 107 |
+
|
| 108 |
+
## Training data
|
| 109 |
+
|
| 110 |
+
| Source | License | Training tiles |
|
| 111 |
+
|---|---|---|
|
| 112 |
+
| AI-Hub 건축 도면 데이터 (71465), NIA, Korea | AI-Hub terms (model release permitted with attribution; data not redistributed) | 134,053 |
|
| 113 |
+
| Swiss Dwellings v3.0.0 (Zenodo 10.5281/zenodo.7788422, Archilyse AG), rasterized by us | CC BY 4.0 | 18,070 |
|
| 114 |
+
|
| 115 |
+
Swiss has no sink/stove; the loss for those classes is masked on Swiss tiles.
|
| 116 |
+
|
| 117 |
+
Training: 6 epochs, AdamW, batch 12, strong augmentation for the first 2 epochs, scan / re-print degradation
|
| 118 |
+
augmentation on half of the tiles, 1920 px tiles.
|
| 119 |
+
|
| 120 |
+
This work used datasets from 'The Open AI Dataset Project (AI-Hub, S. Korea)'. All data information can be
|
| 121 |
+
accessed through 'AI-Hub (www.aihub.or.kr)'. **No AI-Hub image or derived data is included in this repository**;
|
| 122 |
+
only trained weights are released.
|
| 123 |
+
|
| 124 |
+
Swiss Dwellings v3.0.0 is used under CC BY 4.0 (full citations in `NOTICE`).
|
| 125 |
+
Training tiles are 1920 px crops (Swiss: 2048 px mosaics of floor plans).
|
| 126 |
+
|
| 127 |
+
## Examples
|
| 128 |
+
|
| 129 |
+
`examples/example_01.png`, `example_02.png`: 2048 px mosaics of validation floor plans from Swiss Dwellings
|
| 130 |
+
(CC BY 4.0, Archilyse AG), rasterized by us from the published vector geometry. `example_01_pred.png` is this model's output on example_01.
|
| 131 |
+
|
| 132 |
+
## License and attribution
|
| 133 |
+
|
| 134 |
+
Weights and code: **Apache License 2.0** (see `LICENSE`, `NOTICE`). Copyright 2026 Digitalpresso Inc.
|
| 135 |
+
Third-party attributions (D-FINE, AI-Hub, Swiss Dwellings, SYNBUILD-3D) are listed in `NOTICE`.
|
| 136 |
+
|
| 137 |
+
## Citation
|
| 138 |
+
|
| 139 |
+
```bibtex
|
| 140 |
+
@misc{floorplan_dfine_obj_2026,
|
| 141 |
+
title = {floorplan-dfine-obj: D-FINE floor-plan fixtures detector},
|
| 142 |
+
author = {Digitalpresso Inc.},
|
| 143 |
+
year = {2026},
|
| 144 |
+
howpublished = {Hugging Face model repository},
|
| 145 |
+
note = {TODO: confirm author string and URL before publishing}
|
| 146 |
+
}
|
| 147 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture": "D-FINE-M (HGNetv2-B2)",
|
| 3 |
+
"task": "obj",
|
| 4 |
+
"num_queries": 128,
|
| 5 |
+
"input_size": 1920,
|
| 6 |
+
"tile_size": 1920,
|
| 7 |
+
"tile_overlap": 0.25,
|
| 8 |
+
"score_threshold": 0.3,
|
| 9 |
+
"nms_iou": 0.6,
|
| 10 |
+
"id2label": {
|
| 11 |
+
"23": "toilet",
|
| 12 |
+
"24": "washbasin",
|
| 13 |
+
"25": "bathtub",
|
| 14 |
+
"26": "sink",
|
| 15 |
+
"27": "stove"
|
| 16 |
+
}
|
| 17 |
+
}
|
config.yml
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# D-FINE-M inference config for the OBJ model (floorplan-global). Upstream D-FINE @ 956d170.
|
| 2 |
+
task: detection
|
| 3 |
+
model: DFINE
|
| 4 |
+
criterion: DFINECriterion
|
| 5 |
+
postprocessor: DFINEPostProcessor
|
| 6 |
+
num_classes: 28
|
| 7 |
+
remap_mscoco_category: false
|
| 8 |
+
eval_spatial_size:
|
| 9 |
+
- 1920
|
| 10 |
+
- 1920
|
| 11 |
+
DFINE:
|
| 12 |
+
backbone: HGNetv2
|
| 13 |
+
encoder: HybridEncoder
|
| 14 |
+
decoder: DFINETransformer
|
| 15 |
+
HGNetv2:
|
| 16 |
+
pretrained: false
|
| 17 |
+
local_model_dir: weight/hgnetv2/
|
| 18 |
+
name: B2
|
| 19 |
+
return_idx:
|
| 20 |
+
- 1
|
| 21 |
+
- 2
|
| 22 |
+
- 3
|
| 23 |
+
freeze_at: -1
|
| 24 |
+
freeze_norm: false
|
| 25 |
+
use_lab: true
|
| 26 |
+
HybridEncoder:
|
| 27 |
+
in_channels:
|
| 28 |
+
- 384
|
| 29 |
+
- 768
|
| 30 |
+
- 1536
|
| 31 |
+
feat_strides:
|
| 32 |
+
- 8
|
| 33 |
+
- 16
|
| 34 |
+
- 32
|
| 35 |
+
hidden_dim: 256
|
| 36 |
+
use_encoder_idx:
|
| 37 |
+
- 2
|
| 38 |
+
num_encoder_layers: 1
|
| 39 |
+
nhead: 8
|
| 40 |
+
dim_feedforward: 1024
|
| 41 |
+
dropout: 0.0
|
| 42 |
+
enc_act: gelu
|
| 43 |
+
expansion: 1.0
|
| 44 |
+
depth_mult: 0.67
|
| 45 |
+
act: silu
|
| 46 |
+
DFINETransformer:
|
| 47 |
+
feat_channels:
|
| 48 |
+
- 256
|
| 49 |
+
- 256
|
| 50 |
+
- 256
|
| 51 |
+
feat_strides:
|
| 52 |
+
- 8
|
| 53 |
+
- 16
|
| 54 |
+
- 32
|
| 55 |
+
hidden_dim: 256
|
| 56 |
+
num_levels: 3
|
| 57 |
+
num_layers: 4
|
| 58 |
+
eval_idx: -1
|
| 59 |
+
num_queries: 128
|
| 60 |
+
num_denoising: 100
|
| 61 |
+
label_noise_ratio: 0.5
|
| 62 |
+
box_noise_scale: 1.0
|
| 63 |
+
reg_max: 32
|
| 64 |
+
reg_scale: 4
|
| 65 |
+
layer_scale: 1
|
| 66 |
+
num_points:
|
| 67 |
+
- 3
|
| 68 |
+
- 6
|
| 69 |
+
- 3
|
| 70 |
+
cross_attn_method: default
|
| 71 |
+
query_select_method: default
|
| 72 |
+
DFINEPostProcessor:
|
| 73 |
+
num_top_queries: 128
|
| 74 |
+
DFINECriterion:
|
| 75 |
+
weight_dict:
|
| 76 |
+
loss_vfl: 1
|
| 77 |
+
loss_bbox: 5
|
| 78 |
+
loss_giou: 2
|
| 79 |
+
loss_fgl: 0.15
|
| 80 |
+
loss_ddf: 1.5
|
| 81 |
+
losses:
|
| 82 |
+
- vfl
|
| 83 |
+
- boxes
|
| 84 |
+
- local
|
| 85 |
+
alpha: 0.75
|
| 86 |
+
gamma: 2.0
|
| 87 |
+
reg_max: 32
|
| 88 |
+
matcher:
|
| 89 |
+
type: HungarianMatcher
|
| 90 |
+
weight_dict:
|
| 91 |
+
cost_class: 2
|
| 92 |
+
cost_bbox: 5
|
| 93 |
+
cost_giou: 2
|
| 94 |
+
alpha: 0.25
|
| 95 |
+
gamma: 2.0
|
| 96 |
+
use_focal_loss: true
|
examples/example_01.png
ADDED
|
Git LFS Details
|
examples/example_01_pred.png
ADDED
|
Git LFS Details
|
examples/example_02.png
ADDED
|
Git LFS Details
|
inference/infer.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Tiled inference for the floorplan-global D-FINE detectors (STR / SPA / OBJ).
|
| 3 |
+
|
| 4 |
+
Floor-plan drawings are large and their symbols are small, so the models were trained on
|
| 5 |
+
1920x1920 tiles cut with 25% overlap. This script reproduces that protocol at inference time:
|
| 6 |
+
|
| 7 |
+
image -> 1920px tiles (25% overlap) -> D-FINE per tile -> shift boxes back to page
|
| 8 |
+
-> optional truncated-box filter -> per-class NMS across tiles
|
| 9 |
+
|
| 10 |
+
Requirements
|
| 11 |
+
* Upstream D-FINE source (Apache-2.0), pinned commit 956d170:
|
| 12 |
+
git clone https://github.com/Peterande/D-FINE && git -C D-FINE checkout 956d170
|
| 13 |
+
* torch, torchvision, pillow, pyyaml, safetensors (see requirements.txt)
|
| 14 |
+
|
| 15 |
+
Usage
|
| 16 |
+
python inference/infer.py --dfine-root ./D-FINE --image plan.png --out plan.json
|
| 17 |
+
python inference/infer.py --dfine-root ./D-FINE --image plan.png --viz plan_viz.png --device cuda:0
|
| 18 |
+
|
| 19 |
+
--model-dir defaults to the repository root (the folder that contains config.yml,
|
| 20 |
+
config.json and model.safetensors), i.e. the parent of this script's folder.
|
| 21 |
+
|
| 22 |
+
Output: JSON list of {"label", "category_id", "bbox": [x, y, w, h], "score"} in page pixels.
|
| 23 |
+
"""
|
| 24 |
+
import argparse
|
| 25 |
+
import json
|
| 26 |
+
import sys
|
| 27 |
+
from pathlib import Path
|
| 28 |
+
|
| 29 |
+
import torch
|
| 30 |
+
import torchvision.transforms as T
|
| 31 |
+
from PIL import Image
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def tile_starts(size: int, tile: int, stride: int):
|
| 35 |
+
if size <= tile:
|
| 36 |
+
return [0]
|
| 37 |
+
starts = list(range(0, size - tile + 1, stride))
|
| 38 |
+
if starts[-1] != size - tile:
|
| 39 |
+
starts.append(size - tile)
|
| 40 |
+
return starts
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def make_tiles(im: Image.Image, input_size: int, tile: int, stride: int):
|
| 44 |
+
w, h = im.size
|
| 45 |
+
meta = [(x0, y0, min(tile, w - x0), min(tile, h - y0))
|
| 46 |
+
for y0 in tile_starts(h, tile, stride) for x0 in tile_starts(w, tile, stride)]
|
| 47 |
+
tfm = T.Compose([T.Resize((input_size, input_size)), T.ToTensor()])
|
| 48 |
+
tiles = torch.stack([tfm(im.crop((x0, y0, x0 + tw, y0 + th))) for x0, y0, tw, th in meta])
|
| 49 |
+
return tiles, meta
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def load_model(dfine_root: Path, model_dir: Path, device: str):
|
| 53 |
+
sys.path.insert(0, str(dfine_root))
|
| 54 |
+
from src.core import YAMLConfig # upstream D-FINE
|
| 55 |
+
from safetensors.torch import load_file
|
| 56 |
+
|
| 57 |
+
cfg = YAMLConfig(str(model_dir / "config.yml"))
|
| 58 |
+
cfg.model.load_state_dict(load_file(str(model_dir / "model.safetensors")), strict=True)
|
| 59 |
+
|
| 60 |
+
class Detector(torch.nn.Module):
|
| 61 |
+
def __init__(self):
|
| 62 |
+
super().__init__()
|
| 63 |
+
self.model = cfg.model.deploy()
|
| 64 |
+
self.postprocessor = cfg.postprocessor.deploy()
|
| 65 |
+
|
| 66 |
+
def forward(self, images, orig_sizes):
|
| 67 |
+
return self.postprocessor(self.model(images), orig_sizes)
|
| 68 |
+
|
| 69 |
+
return Detector().to(device).eval()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
@torch.no_grad()
|
| 73 |
+
def detect(model, im, meta_cfg, device, batch_size=4, score_thr=None, nms_iou=None,
|
| 74 |
+
drop_truncated=False, trunc_edge=6.0):
|
| 75 |
+
from torchvision.ops import nms
|
| 76 |
+
|
| 77 |
+
tile = int(meta_cfg["tile_size"])
|
| 78 |
+
stride = round(tile * (1 - float(meta_cfg["tile_overlap"])))
|
| 79 |
+
score_thr = float(meta_cfg["score_threshold"] if score_thr is None else score_thr)
|
| 80 |
+
nms_iou = float(meta_cfg["nms_iou"] if nms_iou is None else nms_iou)
|
| 81 |
+
id2label = {int(k): v for k, v in meta_cfg["id2label"].items()}
|
| 82 |
+
|
| 83 |
+
tiles, meta = make_tiles(im, int(meta_cfg["input_size"]), tile, stride)
|
| 84 |
+
W = max(x0 + tw for x0, _, tw, _ in meta)
|
| 85 |
+
H = max(y0 + th for _, y0, _, th in meta)
|
| 86 |
+
e = float(trunc_edge)
|
| 87 |
+
tm = torch.tensor(meta, dtype=torch.float32, device=device)
|
| 88 |
+
cov = (tm[:, 0] + e, tm[:, 1] + e, tm[:, 0] + tm[:, 2] - e, tm[:, 1] + tm[:, 3] - e)
|
| 89 |
+
|
| 90 |
+
boxes_all, scores_all, labels_all = [], [], []
|
| 91 |
+
for i in range(0, len(meta), batch_size):
|
| 92 |
+
bm = meta[i:i + batch_size]
|
| 93 |
+
sizes = torch.tensor([[tw, th] for _, _, tw, th in bm], dtype=torch.float32, device=device)
|
| 94 |
+
labels, boxes, scores = model(tiles[i:i + batch_size].to(device), sizes)
|
| 95 |
+
for j, (x0, y0, tw, th) in enumerate(bm):
|
| 96 |
+
keep = scores[j] > score_thr
|
| 97 |
+
if drop_truncated and keep.any():
|
| 98 |
+
# A box glued to an *interior* tile edge is usually a cut-off fragment; drop it when
|
| 99 |
+
# another tile fully contains it (that tile sees the whole object).
|
| 100 |
+
b = boxes[j]
|
| 101 |
+
touch = torch.zeros_like(keep)
|
| 102 |
+
if x0 > 0:
|
| 103 |
+
touch |= b[:, 0] < e
|
| 104 |
+
if y0 > 0:
|
| 105 |
+
touch |= b[:, 1] < e
|
| 106 |
+
if x0 + tw < W:
|
| 107 |
+
touch |= b[:, 2] > tw - e
|
| 108 |
+
if y0 + th < H:
|
| 109 |
+
touch |= b[:, 3] > th - e
|
| 110 |
+
cand = keep & touch
|
| 111 |
+
if cand.any():
|
| 112 |
+
gx1, gy1, gx2, gy2 = (b[:, 0:1] + x0, b[:, 1:2] + y0, b[:, 2:3] + x0, b[:, 3:4] + y0)
|
| 113 |
+
covered = ((cov[0] <= gx1) & (cov[1] <= gy1) & (gx2 <= cov[2]) & (gy2 <= cov[3])).any(dim=1)
|
| 114 |
+
keep = keep & ~(cand & covered)
|
| 115 |
+
if not keep.any():
|
| 116 |
+
continue
|
| 117 |
+
b = boxes[j][keep].clone()
|
| 118 |
+
b[:, [0, 2]] += x0
|
| 119 |
+
b[:, [1, 3]] += y0
|
| 120 |
+
boxes_all.append(b)
|
| 121 |
+
scores_all.append(scores[j][keep])
|
| 122 |
+
labels_all.append(labels[j][keep])
|
| 123 |
+
|
| 124 |
+
if not boxes_all:
|
| 125 |
+
return []
|
| 126 |
+
boxes, scores, labels = torch.cat(boxes_all), torch.cat(scores_all), torch.cat(labels_all)
|
| 127 |
+
out = []
|
| 128 |
+
for cls in labels.unique().tolist():
|
| 129 |
+
if int(cls) not in id2label:
|
| 130 |
+
continue
|
| 131 |
+
m = labels == cls
|
| 132 |
+
k = nms(boxes[m], scores[m], iou_threshold=nms_iou)
|
| 133 |
+
for (x1, y1, x2, y2), s in zip(boxes[m][k].tolist(), scores[m][k].tolist()):
|
| 134 |
+
out.append({"label": id2label[int(cls)], "category_id": int(cls),
|
| 135 |
+
"bbox": [round(x1, 2), round(y1, 2), round(x2 - x1, 2), round(y2 - y1, 2)],
|
| 136 |
+
"score": round(s, 4)})
|
| 137 |
+
return sorted(out, key=lambda d: -d["score"])
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def draw_viz(im, dets, path):
|
| 141 |
+
from PIL import ImageDraw
|
| 142 |
+
palette = [(230, 25, 75), (60, 180, 75), (0, 130, 200), (245, 130, 48), (145, 30, 180), (70, 240, 240),
|
| 143 |
+
(240, 50, 230), (210, 245, 60), (0, 128, 128), (170, 110, 40), (128, 0, 0), (0, 0, 128)]
|
| 144 |
+
canvas = im.copy()
|
| 145 |
+
dr = ImageDraw.Draw(canvas)
|
| 146 |
+
for d in dets:
|
| 147 |
+
x, y, w, h = d["bbox"]
|
| 148 |
+
c = palette[d["category_id"] % len(palette)]
|
| 149 |
+
dr.rectangle([x, y, x + w, y + h], outline=c, width=3)
|
| 150 |
+
dr.text((x + 3, y + 2), f'{d["label"]} {d["score"]:.2f}', fill=c)
|
| 151 |
+
canvas.save(path)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def main():
|
| 155 |
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 156 |
+
ap.add_argument("--dfine-root", required=True, type=Path, help="upstream D-FINE checkout (commit 956d170)")
|
| 157 |
+
ap.add_argument("--model-dir", type=Path, default=Path(__file__).resolve().parent.parent,
|
| 158 |
+
help="folder with config.yml, config.json, model.safetensors (default: repository root)")
|
| 159 |
+
ap.add_argument("--image", required=True, type=Path)
|
| 160 |
+
ap.add_argument("--out", type=Path, default=None, help="output JSON (default: stdout)")
|
| 161 |
+
ap.add_argument("--viz", type=Path, default=None, help="also write an overlay PNG with the boxes")
|
| 162 |
+
ap.add_argument("--device", default="cuda:0" if torch.cuda.is_available() else "cpu")
|
| 163 |
+
ap.add_argument("--batch-size", type=int, default=4)
|
| 164 |
+
ap.add_argument("--score-thr", type=float, default=None, help="override config.json score_threshold")
|
| 165 |
+
ap.add_argument("--nms-iou", type=float, default=None, help="override config.json nms_iou")
|
| 166 |
+
ap.add_argument("--drop-truncated", action="store_true",
|
| 167 |
+
help="drop cut-off fragments at interior tile edges (off by default = protocol of the reported metrics)")
|
| 168 |
+
a = ap.parse_args()
|
| 169 |
+
|
| 170 |
+
meta_cfg = json.loads((a.model_dir / "config.json").read_text())
|
| 171 |
+
model = load_model(a.dfine_root, a.model_dir, a.device)
|
| 172 |
+
Image.MAX_IMAGE_PIXELS = None # drawings can be very large
|
| 173 |
+
im = Image.open(a.image).convert("RGB")
|
| 174 |
+
dets = detect(model, im, meta_cfg, a.device, a.batch_size, a.score_thr, a.nms_iou, a.drop_truncated)
|
| 175 |
+
if a.viz:
|
| 176 |
+
draw_viz(im, dets, a.viz)
|
| 177 |
+
text = json.dumps(dets, ensure_ascii=False)
|
| 178 |
+
if a.out:
|
| 179 |
+
a.out.write_text(text + "\n")
|
| 180 |
+
print(f"{len(dets)} detections -> {a.out}", file=sys.stderr)
|
| 181 |
+
else:
|
| 182 |
+
print(text)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
if __name__ == "__main__":
|
| 186 |
+
main()
|
inference/requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.1
|
| 2 |
+
torchvision>=0.16
|
| 3 |
+
pillow
|
| 4 |
+
pyyaml
|
| 5 |
+
safetensors
|
| 6 |
+
# The upstream D-FINE package (src/__init__.py) imports these at import time, even for inference:
|
| 7 |
+
scipy
|
| 8 |
+
tensorboard
|
| 9 |
+
faster-coco-eval
|
| 10 |
+
calflops
|
| 11 |
+
# plus upstream D-FINE @ 956d170 (git clone https://github.com/Peterande/D-FINE && git -C D-FINE checkout 956d170)
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d89e2fa8a2925f3a04cb5e7eba163e35161fd8371e7261ae4bd821dfa3fa7444
|
| 3 |
+
size 79655792
|