pydfine 0.0.1__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.
- pydfine-0.0.1/LICENSE +201 -0
- pydfine-0.0.1/NOTICE +21 -0
- pydfine-0.0.1/PKG-INFO +239 -0
- pydfine-0.0.1/README.md +163 -0
- pydfine-0.0.1/dfine/__init__.py +48 -0
- pydfine-0.0.1/dfine/backends/__init__.py +6 -0
- pydfine-0.0.1/dfine/backends/native/__init__.py +29 -0
- pydfine-0.0.1/dfine/backends/native/box_ops.py +86 -0
- pydfine-0.0.1/dfine/backends/native/coco.py +103 -0
- pydfine-0.0.1/dfine/backends/native/common.py +75 -0
- pydfine-0.0.1/dfine/backends/native/criterion.py +514 -0
- pydfine-0.0.1/dfine/backends/native/denoising.py +115 -0
- pydfine-0.0.1/dfine/backends/native/dfine.py +94 -0
- pydfine-0.0.1/dfine/backends/native/dfine_decoder.py +956 -0
- pydfine-0.0.1/dfine/backends/native/dfine_utils.py +130 -0
- pydfine-0.0.1/dfine/backends/native/dist.py +29 -0
- pydfine-0.0.1/dfine/backends/native/hgnetv2.py +505 -0
- pydfine-0.0.1/dfine/backends/native/hybrid_encoder.py +505 -0
- pydfine-0.0.1/dfine/backends/native/loader.py +70 -0
- pydfine-0.0.1/dfine/backends/native/matcher.py +139 -0
- pydfine-0.0.1/dfine/backends/native/ops.py +120 -0
- pydfine-0.0.1/dfine/backends/native/postprocessor.py +119 -0
- pydfine-0.0.1/dfine/cli.py +193 -0
- pydfine-0.0.1/dfine/config.py +393 -0
- pydfine-0.0.1/dfine/convert.py +265 -0
- pydfine-0.0.1/dfine/downloads.py +52 -0
- pydfine-0.0.1/dfine/export/__init__.py +12 -0
- pydfine-0.0.1/dfine/export/onnx.py +154 -0
- pydfine-0.0.1/dfine/model.py +591 -0
- pydfine-0.0.1/dfine/registry.py +134 -0
- pydfine-0.0.1/dfine/results.py +192 -0
- pydfine-0.0.1/dfine/track/__init__.py +74 -0
- pydfine-0.0.1/dfine/track/byte_tracker.py +322 -0
- pydfine-0.0.1/dfine/track/kalman_filter.py +96 -0
- pydfine-0.0.1/dfine/train/__init__.py +43 -0
- pydfine-0.0.1/dfine/train/augment.py +127 -0
- pydfine-0.0.1/dfine/train/dataset.py +486 -0
- pydfine-0.0.1/dfine/train/distributed.py +194 -0
- pydfine-0.0.1/dfine/train/ema.py +67 -0
- pydfine-0.0.1/dfine/train/evaluator.py +114 -0
- pydfine-0.0.1/dfine/train/logger.py +143 -0
- pydfine-0.0.1/dfine/train/scheduler.py +100 -0
- pydfine-0.0.1/dfine/train/trainer.py +315 -0
- pydfine-0.0.1/dfine/train/visualizer.py +152 -0
- pydfine-0.0.1/pydfine.egg-info/PKG-INFO +239 -0
- pydfine-0.0.1/pydfine.egg-info/SOURCES.txt +71 -0
- pydfine-0.0.1/pydfine.egg-info/dependency_links.txt +1 -0
- pydfine-0.0.1/pydfine.egg-info/entry_points.txt +2 -0
- pydfine-0.0.1/pydfine.egg-info/requires.txt +51 -0
- pydfine-0.0.1/pydfine.egg-info/top_level.txt +1 -0
- pydfine-0.0.1/pyproject.toml +126 -0
- pydfine-0.0.1/setup.cfg +4 -0
- pydfine-0.0.1/tests/test_augment.py +166 -0
- pydfine-0.0.1/tests/test_backbone.py +74 -0
- pydfine-0.0.1/tests/test_cli.py +64 -0
- pydfine-0.0.1/tests/test_config.py +130 -0
- pydfine-0.0.1/tests/test_convert.py +200 -0
- pydfine-0.0.1/tests/test_criterion.py +140 -0
- pydfine-0.0.1/tests/test_dataset.py +264 -0
- pydfine-0.0.1/tests/test_decoder.py +87 -0
- pydfine-0.0.1/tests/test_distributed.py +149 -0
- pydfine-0.0.1/tests/test_encoder.py +65 -0
- pydfine-0.0.1/tests/test_evaluator.py +113 -0
- pydfine-0.0.1/tests/test_export.py +137 -0
- pydfine-0.0.1/tests/test_loader.py +148 -0
- pydfine-0.0.1/tests/test_model.py +177 -0
- pydfine-0.0.1/tests/test_parity.py +80 -0
- pydfine-0.0.1/tests/test_postprocessor.py +105 -0
- pydfine-0.0.1/tests/test_registry.py +89 -0
- pydfine-0.0.1/tests/test_results.py +99 -0
- pydfine-0.0.1/tests/test_tracker.py +134 -0
- pydfine-0.0.1/tests/test_trainer.py +202 -0
- pydfine-0.0.1/tests/test_video.py +67 -0
pydfine-0.0.1/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.
|
pydfine-0.0.1/NOTICE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
pydfine
|
|
2
|
+
Copyright 2026 pydfine contributors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
It is a derivative work of D-FINE and includes source code ported from it:
|
|
7
|
+
|
|
8
|
+
D-FINE — https://github.com/Peterande/D-FINE
|
|
9
|
+
Copyright 2024 The D-FINE Authors
|
|
10
|
+
Licensed under the Apache License, Version 2.0.
|
|
11
|
+
|
|
12
|
+
The ported modules under `dfine/backends/native/` preserve upstream layer and
|
|
13
|
+
parameter names (so released D-FINE `.pth` checkpoints load unchanged) and each
|
|
14
|
+
carries a per-file header naming its source file, license, and the changes made.
|
|
15
|
+
|
|
16
|
+
D-FINE itself builds on earlier work; those attributions are retained in the
|
|
17
|
+
relevant ported source files:
|
|
18
|
+
|
|
19
|
+
- RT-DETR — Copyright 2023 lyuwenyu — Apache-2.0
|
|
20
|
+
- DETR — Copyright 2020 Facebook, Inc. — Apache-2.0
|
|
21
|
+
- PaddleDetection / PP-HGNetV2 — Apache-2.0
|
pydfine-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pydfine
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Ultralytics-style, config-first Python library for the D-FINE real-time object detector.
|
|
5
|
+
Author: pydfine contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/HoshiBatista/pydfine
|
|
8
|
+
Project-URL: Documentation, https://hoshibatista.github.io/pydfine/
|
|
9
|
+
Project-URL: Repository, https://github.com/HoshiBatista/pydfine
|
|
10
|
+
Project-URL: Issues, https://github.com/HoshiBatista/pydfine/issues
|
|
11
|
+
Project-URL: Upstream, https://github.com/Peterande/D-FINE
|
|
12
|
+
Project-URL: Paper, https://arxiv.org/abs/2410.13842
|
|
13
|
+
Keywords: d-fine,object-detection,detr,computer-vision,pytorch,onnx
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.9
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
License-File: NOTICE
|
|
32
|
+
Requires-Dist: numpy>=1.21
|
|
33
|
+
Provides-Extra: torch
|
|
34
|
+
Requires-Dist: torch>=2.0.1; extra == "torch"
|
|
35
|
+
Requires-Dist: torchvision>=0.15.2; extra == "torch"
|
|
36
|
+
Requires-Dist: pillow>=9.0; extra == "torch"
|
|
37
|
+
Provides-Extra: train
|
|
38
|
+
Requires-Dist: pydfine[torch]; extra == "train"
|
|
39
|
+
Requires-Dist: scipy>=1.10; extra == "train"
|
|
40
|
+
Requires-Dist: faster-coco-eval>=1.6.6; extra == "train"
|
|
41
|
+
Requires-Dist: tensorboard>=2.13; extra == "train"
|
|
42
|
+
Requires-Dist: matplotlib>=3.6; extra == "train"
|
|
43
|
+
Requires-Dist: pyyaml>=6.0; extra == "train"
|
|
44
|
+
Provides-Extra: export
|
|
45
|
+
Requires-Dist: onnx>=1.14; extra == "export"
|
|
46
|
+
Requires-Dist: onnxruntime>=1.16; extra == "export"
|
|
47
|
+
Requires-Dist: onnxsim>=0.4; extra == "export"
|
|
48
|
+
Provides-Extra: video
|
|
49
|
+
Requires-Dist: pydfine[torch]; extra == "video"
|
|
50
|
+
Requires-Dist: opencv-python>=4.6; extra == "video"
|
|
51
|
+
Provides-Extra: interop
|
|
52
|
+
Requires-Dist: pandas>=1.3; extra == "interop"
|
|
53
|
+
Requires-Dist: supervision>=0.18; extra == "interop"
|
|
54
|
+
Provides-Extra: track
|
|
55
|
+
Requires-Dist: pydfine[video]; extra == "track"
|
|
56
|
+
Requires-Dist: scipy>=1.10; extra == "track"
|
|
57
|
+
Provides-Extra: docs
|
|
58
|
+
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
59
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
60
|
+
Requires-Dist: mkdocstrings[python]>=0.26; extra == "docs"
|
|
61
|
+
Provides-Extra: dev
|
|
62
|
+
Requires-Dist: pydfine[torch]; extra == "dev"
|
|
63
|
+
Requires-Dist: ruff==0.15.21; extra == "dev"
|
|
64
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
65
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
66
|
+
Requires-Dist: pre-commit>=3.5; extra == "dev"
|
|
67
|
+
Requires-Dist: opencv-python-headless>=4.6; extra == "dev"
|
|
68
|
+
Requires-Dist: scipy>=1.10; extra == "dev"
|
|
69
|
+
Requires-Dist: faster-coco-eval>=1.6.6; extra == "dev"
|
|
70
|
+
Requires-Dist: pyyaml>=6.0; extra == "dev"
|
|
71
|
+
Requires-Dist: onnx>=1.14; extra == "dev"
|
|
72
|
+
Requires-Dist: onnxruntime>=1.16; extra == "dev"
|
|
73
|
+
Requires-Dist: pandas>=1.3; extra == "dev"
|
|
74
|
+
Requires-Dist: supervision>=0.18; extra == "dev"
|
|
75
|
+
Dynamic: license-file
|
|
76
|
+
|
|
77
|
+
# dfine
|
|
78
|
+
|
|
79
|
+
A batteries-included Python library for the **D-FINE** real-time object detector
|
|
80
|
+
([Peterande/D-FINE](https://github.com/Peterande/D-FINE), ICLR 2025 Spotlight),
|
|
81
|
+
with an `ultralytics`-style developer experience.
|
|
82
|
+
|
|
83
|
+
[](https://pypi.org/project/pydfine/)
|
|
84
|
+
[](https://pypi.org/project/pydfine/)
|
|
85
|
+
[](LICENSE)
|
|
86
|
+
|
|
87
|
+
📖 **Documentation:** <https://hoshibatista.github.io/pydfine/>
|
|
88
|
+
|
|
89
|
+
Install: `pip install pydfine` (core, torch-free) — `import dfine` to use it.
|
|
90
|
+
|
|
91
|
+
**Design goal:** the entire model — backbone, encoder, decoder, losses, denoising,
|
|
92
|
+
training, augmentation — is configured through **typed Python parameters on one
|
|
93
|
+
class**. No YAML files, no config-registry indirection, no `torchrun` incantations.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from dfine import DFINE
|
|
97
|
+
|
|
98
|
+
# Presets fill sensible defaults; every single field is overridable inline.
|
|
99
|
+
model = DFINE(
|
|
100
|
+
size="l", # n | s | m | l | x -> sets backbone, dims, depths
|
|
101
|
+
num_classes=80,
|
|
102
|
+
num_queries=300,
|
|
103
|
+
hidden_dim=256,
|
|
104
|
+
reg_max=32, # Fine-grained Distribution Refinement bins
|
|
105
|
+
backbone="hgnetv2_b4",
|
|
106
|
+
backbone_pretrained=True,
|
|
107
|
+
device="cuda",
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
results = model.predict("street.jpg", conf=0.4)
|
|
111
|
+
results[0].save("out.jpg")
|
|
112
|
+
|
|
113
|
+
model.train(data="dataset/", epochs=72, imgsz=640, batch=32)
|
|
114
|
+
metrics = model.val()
|
|
115
|
+
model.export(format="onnx")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Fully custom architecture, no preset:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
model = DFINE(
|
|
122
|
+
num_classes=3,
|
|
123
|
+
backbone="hgnetv2_b0", use_lab=True, freeze_at=-1,
|
|
124
|
+
hidden_dim=256, encoder_dim_feedforward=1024, encoder_layers=1, nhead=8,
|
|
125
|
+
decoder_layers=4, eval_idx=-1, num_levels=3, num_points=[3, 6, 3],
|
|
126
|
+
reg_max=32, reg_scale=4.0, lqe_layers=2,
|
|
127
|
+
num_denoising=100, label_noise_ratio=0.5, box_noise_scale=1.0,
|
|
128
|
+
class_names=["cat", "dog", "bird"],
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Status
|
|
133
|
+
|
|
134
|
+
Inference is complete and bit-exact with upstream; the training stack (loop, data,
|
|
135
|
+
augmentation, COCO `val`, multi-GPU DDP, visualization) is in — only `export` remains.
|
|
136
|
+
Done so far:
|
|
137
|
+
|
|
138
|
+
- **Config-first core** — `DFINEConfig` (every model/training param as a typed field),
|
|
139
|
+
verified `n/s/m/l/x` presets, validation, checkpoint registry, `dfine models` CLI.
|
|
140
|
+
- **Native model port (Path A)** under `dfine/backends/native/` — the full
|
|
141
|
+
**backbone → encoder → decoder** stack ported from upstream `src/` with the
|
|
142
|
+
YAML/registry layer stripped: `HGNetv2`, `HybridEncoder`, and `DFINETransformer`
|
|
143
|
+
(FDR head, LQE, contrastive denoising). Layer/param names preserved so released
|
|
144
|
+
`.pth` load unchanged. Each module builds from the config via `from_config(cfg)`.
|
|
145
|
+
|
|
146
|
+
- **Working inference** — assembled `DFINE` model + `DFINEPostProcessor`, upstream
|
|
147
|
+
`.pth` loading (`registry`/`downloads`, `from_pretrained`), and the public
|
|
148
|
+
`DFINE(...).predict(...) -> Results` API (`.boxes.xyxy/.conf/.cls`, `.plot()/.save()`).
|
|
149
|
+
|
|
150
|
+
- **Video** — `DFINE.predict_video(source, output=...)` writes an annotated mp4, or
|
|
151
|
+
`stream=True` yields per-frame `Results` (needs `pip install pydfine[video]`).
|
|
152
|
+
|
|
153
|
+
- **Training loss** — `HungarianMatcher` + `DFINECriterion` (VFL + L1 + GIoU + FGL +
|
|
154
|
+
DDF) ported and wired from the config; consumes the decoder's training-mode output.
|
|
155
|
+
|
|
156
|
+
- **Training loop** — `DFINE.train(train_loader, epochs=...)` runs the ported D-FINE
|
|
157
|
+
loop (AdamW param groups, EMA, AMP, grad clip, warmup + flat-cosine LR) with the same
|
|
158
|
+
**progress visualization as upstream**: a live console readout (`MetricLogger`) plus
|
|
159
|
+
TensorBoard scalars and a `loss_curve.png` under `output_dir` (needs
|
|
160
|
+
`pip install pydfine[train]`; W&B optional).
|
|
161
|
+
|
|
162
|
+
- **COCO data + augmentation** — `dfine.train.dataset.build_coco_dataloader(img_folder,
|
|
163
|
+
ann_file, cfg=...)` gives a ready `(images, targets)` loader (contiguous-label remap,
|
|
164
|
+
multi-scale collate); pass `transforms=dfine.train.augment.train_transforms(imgsz,
|
|
165
|
+
stop_epoch=...)` for D-FINE's full augment pipeline (photometric distort, zoom-out,
|
|
166
|
+
IoU-crop, H-flip) with the two-phase no-aug tail. Feeds straight into `DFINE.train`.
|
|
167
|
+
|
|
168
|
+
- **Have a YOLO dataset?** Convert it once — `dfine convert path/to/yolo path/to/coco`
|
|
169
|
+
(or `dfine.yolo_to_coco(...)`) — then `DFINE.train(data="path/to/coco")`. It reads the
|
|
170
|
+
`images/<split>` + `labels/<split>` layout (and `data.yaml` names) and writes the COCO
|
|
171
|
+
layout with 0-indexed categories that line up with the model's labels.
|
|
172
|
+
|
|
173
|
+
Only `export` (Phase 3) remains. See [`docs/ROADMAP.md`](docs/ROADMAP.md) for the full
|
|
174
|
+
status.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from dfine import DFINEConfig
|
|
178
|
+
|
|
179
|
+
cfg = DFINEConfig.preset("l", num_classes=3) # verified upstream defaults
|
|
180
|
+
cfg = DFINEConfig.preset("n") # 2-level, hidden_dim=128
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The ported modules already run end-to-end (needs the `torch` extra installed):
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
import torch
|
|
187
|
+
from dfine import DFINEConfig
|
|
188
|
+
from dfine.backends.native import HGNetv2, HybridEncoder, DFINETransformer
|
|
189
|
+
|
|
190
|
+
cfg = DFINEConfig.preset("l", num_classes=80)
|
|
191
|
+
backbone = HGNetv2.from_config(cfg).eval()
|
|
192
|
+
encoder = HybridEncoder.from_config(cfg).eval()
|
|
193
|
+
decoder = DFINETransformer.from_config(cfg).eval()
|
|
194
|
+
|
|
195
|
+
out = decoder(encoder(backbone(torch.randn(1, 3, cfg.imgsz, cfg.imgsz))))
|
|
196
|
+
# out["pred_logits"]: (1, 300, 80) out["pred_boxes"]: (1, 300, 4) [cxcywh, 0..1]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
> The one-class `DFINE(...)` façade at the top of this README works today for
|
|
200
|
+
> **inference** (`predict`/`load`/`from_pretrained`), **training** — both
|
|
201
|
+
> `train(data="coco/", epochs=...)` (a standard COCO root; the loaders are built for
|
|
202
|
+
> you) and `train(train_loader, epochs=...)` (a hand-built loader) — and **COCO
|
|
203
|
+
> evaluation** (`val(data="coco/")` → the 12 named COCO metrics, also run each epoch
|
|
204
|
+
> during `train`), all with the `pydfine[train]` extra. **Multi-GPU** is a single kwarg:
|
|
205
|
+
> `train(data="coco/", devices=N)` spawns one DDP worker per GPU (or launch with
|
|
206
|
+
> `torchrun` and call `train(...)` as usual). `export` is phase-stubbed and raises a
|
|
207
|
+
> clear "arriving in Phase N" until implemented.
|
|
208
|
+
|
|
209
|
+
## Why this exists
|
|
210
|
+
|
|
211
|
+
Upstream D-FINE is an excellent research repo, but using it means editing YAML,
|
|
212
|
+
copying config include-trees, and launching scripts. This library turns all of that
|
|
213
|
+
into one importable, fully-typed class with presets — so a developer can go from
|
|
214
|
+
`pip install` to a trained custom detector without touching a config file.
|
|
215
|
+
|
|
216
|
+
## For contributors and AI agents
|
|
217
|
+
|
|
218
|
+
This project is built to be developed largely by coding agents (Claude Code / any
|
|
219
|
+
agent that reads `AGENTS.md`). Start here:
|
|
220
|
+
|
|
221
|
+
| File | Purpose |
|
|
222
|
+
|---|---|
|
|
223
|
+
| [`AGENTS.md`](AGENTS.md) | **Canonical agent guide** — architecture, conventions, workflow, commands, definition of done. Read first. |
|
|
224
|
+
| [`CLAUDE.md`](CLAUDE.md) | Claude Code–specific notes; defers to `AGENTS.md`. |
|
|
225
|
+
| [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) | How D-FINE works and how we re-shape it into Python. |
|
|
226
|
+
| [`docs/CONFIG_REFERENCE.md`](docs/CONFIG_REFERENCE.md) | Every model parameter, default, and per-size preset. The heart of the "one class, many params" design. |
|
|
227
|
+
| [`docs/ROADMAP.md`](docs/ROADMAP.md) | Phased, checkbox task plan. |
|
|
228
|
+
|
|
229
|
+
## License & attribution
|
|
230
|
+
|
|
231
|
+
pydfine is licensed under the [Apache License 2.0](LICENSE).
|
|
232
|
+
|
|
233
|
+
It is a **derivative work of D-FINE**
|
|
234
|
+
([Peterande/D-FINE](https://github.com/Peterande/D-FINE), Apache-2.0, © 2024 The
|
|
235
|
+
D-FINE Authors): the model is a native port of upstream `src/`, with layer and
|
|
236
|
+
parameter names preserved so released `.pth` checkpoints load unchanged. Every ported
|
|
237
|
+
module under `dfine/backends/native/` carries a per-file header crediting its source
|
|
238
|
+
and describing the changes. See [`NOTICE`](NOTICE) for the full attribution, including
|
|
239
|
+
D-FINE's own lineage (RT-DETR, DETR, PaddleDetection).
|
pydfine-0.0.1/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# dfine
|
|
2
|
+
|
|
3
|
+
A batteries-included Python library for the **D-FINE** real-time object detector
|
|
4
|
+
([Peterande/D-FINE](https://github.com/Peterande/D-FINE), ICLR 2025 Spotlight),
|
|
5
|
+
with an `ultralytics`-style developer experience.
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/pydfine/)
|
|
8
|
+
[](https://pypi.org/project/pydfine/)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
|
|
11
|
+
📖 **Documentation:** <https://hoshibatista.github.io/pydfine/>
|
|
12
|
+
|
|
13
|
+
Install: `pip install pydfine` (core, torch-free) — `import dfine` to use it.
|
|
14
|
+
|
|
15
|
+
**Design goal:** the entire model — backbone, encoder, decoder, losses, denoising,
|
|
16
|
+
training, augmentation — is configured through **typed Python parameters on one
|
|
17
|
+
class**. No YAML files, no config-registry indirection, no `torchrun` incantations.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from dfine import DFINE
|
|
21
|
+
|
|
22
|
+
# Presets fill sensible defaults; every single field is overridable inline.
|
|
23
|
+
model = DFINE(
|
|
24
|
+
size="l", # n | s | m | l | x -> sets backbone, dims, depths
|
|
25
|
+
num_classes=80,
|
|
26
|
+
num_queries=300,
|
|
27
|
+
hidden_dim=256,
|
|
28
|
+
reg_max=32, # Fine-grained Distribution Refinement bins
|
|
29
|
+
backbone="hgnetv2_b4",
|
|
30
|
+
backbone_pretrained=True,
|
|
31
|
+
device="cuda",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
results = model.predict("street.jpg", conf=0.4)
|
|
35
|
+
results[0].save("out.jpg")
|
|
36
|
+
|
|
37
|
+
model.train(data="dataset/", epochs=72, imgsz=640, batch=32)
|
|
38
|
+
metrics = model.val()
|
|
39
|
+
model.export(format="onnx")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Fully custom architecture, no preset:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
model = DFINE(
|
|
46
|
+
num_classes=3,
|
|
47
|
+
backbone="hgnetv2_b0", use_lab=True, freeze_at=-1,
|
|
48
|
+
hidden_dim=256, encoder_dim_feedforward=1024, encoder_layers=1, nhead=8,
|
|
49
|
+
decoder_layers=4, eval_idx=-1, num_levels=3, num_points=[3, 6, 3],
|
|
50
|
+
reg_max=32, reg_scale=4.0, lqe_layers=2,
|
|
51
|
+
num_denoising=100, label_noise_ratio=0.5, box_noise_scale=1.0,
|
|
52
|
+
class_names=["cat", "dog", "bird"],
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Status
|
|
57
|
+
|
|
58
|
+
Inference is complete and bit-exact with upstream; the training stack (loop, data,
|
|
59
|
+
augmentation, COCO `val`, multi-GPU DDP, visualization) is in — only `export` remains.
|
|
60
|
+
Done so far:
|
|
61
|
+
|
|
62
|
+
- **Config-first core** — `DFINEConfig` (every model/training param as a typed field),
|
|
63
|
+
verified `n/s/m/l/x` presets, validation, checkpoint registry, `dfine models` CLI.
|
|
64
|
+
- **Native model port (Path A)** under `dfine/backends/native/` — the full
|
|
65
|
+
**backbone → encoder → decoder** stack ported from upstream `src/` with the
|
|
66
|
+
YAML/registry layer stripped: `HGNetv2`, `HybridEncoder`, and `DFINETransformer`
|
|
67
|
+
(FDR head, LQE, contrastive denoising). Layer/param names preserved so released
|
|
68
|
+
`.pth` load unchanged. Each module builds from the config via `from_config(cfg)`.
|
|
69
|
+
|
|
70
|
+
- **Working inference** — assembled `DFINE` model + `DFINEPostProcessor`, upstream
|
|
71
|
+
`.pth` loading (`registry`/`downloads`, `from_pretrained`), and the public
|
|
72
|
+
`DFINE(...).predict(...) -> Results` API (`.boxes.xyxy/.conf/.cls`, `.plot()/.save()`).
|
|
73
|
+
|
|
74
|
+
- **Video** — `DFINE.predict_video(source, output=...)` writes an annotated mp4, or
|
|
75
|
+
`stream=True` yields per-frame `Results` (needs `pip install pydfine[video]`).
|
|
76
|
+
|
|
77
|
+
- **Training loss** — `HungarianMatcher` + `DFINECriterion` (VFL + L1 + GIoU + FGL +
|
|
78
|
+
DDF) ported and wired from the config; consumes the decoder's training-mode output.
|
|
79
|
+
|
|
80
|
+
- **Training loop** — `DFINE.train(train_loader, epochs=...)` runs the ported D-FINE
|
|
81
|
+
loop (AdamW param groups, EMA, AMP, grad clip, warmup + flat-cosine LR) with the same
|
|
82
|
+
**progress visualization as upstream**: a live console readout (`MetricLogger`) plus
|
|
83
|
+
TensorBoard scalars and a `loss_curve.png` under `output_dir` (needs
|
|
84
|
+
`pip install pydfine[train]`; W&B optional).
|
|
85
|
+
|
|
86
|
+
- **COCO data + augmentation** — `dfine.train.dataset.build_coco_dataloader(img_folder,
|
|
87
|
+
ann_file, cfg=...)` gives a ready `(images, targets)` loader (contiguous-label remap,
|
|
88
|
+
multi-scale collate); pass `transforms=dfine.train.augment.train_transforms(imgsz,
|
|
89
|
+
stop_epoch=...)` for D-FINE's full augment pipeline (photometric distort, zoom-out,
|
|
90
|
+
IoU-crop, H-flip) with the two-phase no-aug tail. Feeds straight into `DFINE.train`.
|
|
91
|
+
|
|
92
|
+
- **Have a YOLO dataset?** Convert it once — `dfine convert path/to/yolo path/to/coco`
|
|
93
|
+
(or `dfine.yolo_to_coco(...)`) — then `DFINE.train(data="path/to/coco")`. It reads the
|
|
94
|
+
`images/<split>` + `labels/<split>` layout (and `data.yaml` names) and writes the COCO
|
|
95
|
+
layout with 0-indexed categories that line up with the model's labels.
|
|
96
|
+
|
|
97
|
+
Only `export` (Phase 3) remains. See [`docs/ROADMAP.md`](docs/ROADMAP.md) for the full
|
|
98
|
+
status.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from dfine import DFINEConfig
|
|
102
|
+
|
|
103
|
+
cfg = DFINEConfig.preset("l", num_classes=3) # verified upstream defaults
|
|
104
|
+
cfg = DFINEConfig.preset("n") # 2-level, hidden_dim=128
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The ported modules already run end-to-end (needs the `torch` extra installed):
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
import torch
|
|
111
|
+
from dfine import DFINEConfig
|
|
112
|
+
from dfine.backends.native import HGNetv2, HybridEncoder, DFINETransformer
|
|
113
|
+
|
|
114
|
+
cfg = DFINEConfig.preset("l", num_classes=80)
|
|
115
|
+
backbone = HGNetv2.from_config(cfg).eval()
|
|
116
|
+
encoder = HybridEncoder.from_config(cfg).eval()
|
|
117
|
+
decoder = DFINETransformer.from_config(cfg).eval()
|
|
118
|
+
|
|
119
|
+
out = decoder(encoder(backbone(torch.randn(1, 3, cfg.imgsz, cfg.imgsz))))
|
|
120
|
+
# out["pred_logits"]: (1, 300, 80) out["pred_boxes"]: (1, 300, 4) [cxcywh, 0..1]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
> The one-class `DFINE(...)` façade at the top of this README works today for
|
|
124
|
+
> **inference** (`predict`/`load`/`from_pretrained`), **training** — both
|
|
125
|
+
> `train(data="coco/", epochs=...)` (a standard COCO root; the loaders are built for
|
|
126
|
+
> you) and `train(train_loader, epochs=...)` (a hand-built loader) — and **COCO
|
|
127
|
+
> evaluation** (`val(data="coco/")` → the 12 named COCO metrics, also run each epoch
|
|
128
|
+
> during `train`), all with the `pydfine[train]` extra. **Multi-GPU** is a single kwarg:
|
|
129
|
+
> `train(data="coco/", devices=N)` spawns one DDP worker per GPU (or launch with
|
|
130
|
+
> `torchrun` and call `train(...)` as usual). `export` is phase-stubbed and raises a
|
|
131
|
+
> clear "arriving in Phase N" until implemented.
|
|
132
|
+
|
|
133
|
+
## Why this exists
|
|
134
|
+
|
|
135
|
+
Upstream D-FINE is an excellent research repo, but using it means editing YAML,
|
|
136
|
+
copying config include-trees, and launching scripts. This library turns all of that
|
|
137
|
+
into one importable, fully-typed class with presets — so a developer can go from
|
|
138
|
+
`pip install` to a trained custom detector without touching a config file.
|
|
139
|
+
|
|
140
|
+
## For contributors and AI agents
|
|
141
|
+
|
|
142
|
+
This project is built to be developed largely by coding agents (Claude Code / any
|
|
143
|
+
agent that reads `AGENTS.md`). Start here:
|
|
144
|
+
|
|
145
|
+
| File | Purpose |
|
|
146
|
+
|---|---|
|
|
147
|
+
| [`AGENTS.md`](AGENTS.md) | **Canonical agent guide** — architecture, conventions, workflow, commands, definition of done. Read first. |
|
|
148
|
+
| [`CLAUDE.md`](CLAUDE.md) | Claude Code–specific notes; defers to `AGENTS.md`. |
|
|
149
|
+
| [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) | How D-FINE works and how we re-shape it into Python. |
|
|
150
|
+
| [`docs/CONFIG_REFERENCE.md`](docs/CONFIG_REFERENCE.md) | Every model parameter, default, and per-size preset. The heart of the "one class, many params" design. |
|
|
151
|
+
| [`docs/ROADMAP.md`](docs/ROADMAP.md) | Phased, checkbox task plan. |
|
|
152
|
+
|
|
153
|
+
## License & attribution
|
|
154
|
+
|
|
155
|
+
pydfine is licensed under the [Apache License 2.0](LICENSE).
|
|
156
|
+
|
|
157
|
+
It is a **derivative work of D-FINE**
|
|
158
|
+
([Peterande/D-FINE](https://github.com/Peterande/D-FINE), Apache-2.0, © 2024 The
|
|
159
|
+
D-FINE Authors): the model is a native port of upstream `src/`, with layer and
|
|
160
|
+
parameter names preserved so released `.pth` checkpoints load unchanged. Every ported
|
|
161
|
+
module under `dfine/backends/native/` carries a per-file header crediting its source
|
|
162
|
+
and describing the changes. See [`NOTICE`](NOTICE) for the full attribution, including
|
|
163
|
+
D-FINE's own lineage (RT-DETR, DETR, PaddleDetection).
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""dfine — a config-first, ultralytics-style wrapper around D-FINE.
|
|
2
|
+
|
|
3
|
+
The whole model is configured by typed params on one class. Phase 0/1 ships the
|
|
4
|
+
config surface (``DFINEConfig``, presets); ``DFINE`` and ``Results`` land with the
|
|
5
|
+
inference backend (Phase 2) and are exposed lazily so importing this package never
|
|
6
|
+
requires torch until you actually build a model.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from .config import SIZE_PRESETS, SIZES, DFINEConfig, list_presets
|
|
14
|
+
from .convert import yolo_to_coco
|
|
15
|
+
from .registry import list_checkpoints
|
|
16
|
+
|
|
17
|
+
__version__ = "0.0.1"
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"DFINEConfig",
|
|
21
|
+
"SIZE_PRESETS",
|
|
22
|
+
"SIZES",
|
|
23
|
+
"list_presets",
|
|
24
|
+
"list_checkpoints",
|
|
25
|
+
"yolo_to_coco",
|
|
26
|
+
"__version__",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
# Inference symbols live in modules that import torch; expose them lazily so a bare
|
|
30
|
+
# `import dfine` (config/CLI only) never requires the torch extra.
|
|
31
|
+
_LAZY = {
|
|
32
|
+
"DFINE": "model",
|
|
33
|
+
"Results": "results",
|
|
34
|
+
"Boxes": "results",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def __getattr__(name: str) -> Any:
|
|
39
|
+
if name in _LAZY:
|
|
40
|
+
try:
|
|
41
|
+
mod = __import__(f"dfine.{_LAZY[name]}", fromlist=[name])
|
|
42
|
+
except ImportError as exc: # torch/torchvision/pillow not installed
|
|
43
|
+
raise AttributeError(
|
|
44
|
+
f"dfine.{name} needs the inference deps — install with "
|
|
45
|
+
f"`pip install pydfine[torch]` (missing: {exc.name})."
|
|
46
|
+
) from exc
|
|
47
|
+
return getattr(mod, name)
|
|
48
|
+
raise AttributeError(f"module 'dfine' has no attribute {name!r}")
|