attr-eomt 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- attr_eomt-0.1.0/.github/workflows/publish.yml +41 -0
- attr_eomt-0.1.0/.github/workflows/tests.yml +32 -0
- attr_eomt-0.1.0/.gitignore +31 -0
- attr_eomt-0.1.0/LICENSE +201 -0
- attr_eomt-0.1.0/PKG-INFO +307 -0
- attr_eomt-0.1.0/README.md +271 -0
- attr_eomt-0.1.0/configs/coco.yaml +10 -0
- attr_eomt-0.1.0/docs/examples/example_1.png +0 -0
- attr_eomt-0.1.0/eomt/__init__.py +55 -0
- attr_eomt-0.1.0/eomt/api.py +253 -0
- attr_eomt-0.1.0/eomt/aux_cls.py +225 -0
- attr_eomt-0.1.0/eomt/box_loss.py +196 -0
- attr_eomt-0.1.0/eomt/config.py +230 -0
- attr_eomt-0.1.0/eomt/ema.py +67 -0
- attr_eomt-0.1.0/eomt/engine/__init__.py +7 -0
- attr_eomt-0.1.0/eomt/engine/predict.py +117 -0
- attr_eomt-0.1.0/eomt/engine/train.py +847 -0
- attr_eomt-0.1.0/eomt/engine/validate.py +391 -0
- attr_eomt-0.1.0/eomt/loss.py +279 -0
- attr_eomt-0.1.0/eomt/model.py +786 -0
- attr_eomt-0.1.0/eomt/plotting.py +157 -0
- attr_eomt-0.1.0/eomt/postprocess.py +253 -0
- attr_eomt-0.1.0/eomt/preprocess.py +55 -0
- attr_eomt-0.1.0/eomt/serialization.py +308 -0
- attr_eomt-0.1.0/eomt/visualize.py +98 -0
- attr_eomt-0.1.0/pyproject.toml +48 -0
- attr_eomt-0.1.0/sample_data/README.md +45 -0
- attr_eomt-0.1.0/sample_data/annotations/instances_train.json +44 -0
- attr_eomt-0.1.0/sample_data/annotations/instances_val.json +37 -0
- attr_eomt-0.1.0/sample_data/data.yaml +34 -0
- attr_eomt-0.1.0/sample_data/images/train/.gitkeep +0 -0
- attr_eomt-0.1.0/sample_data/images/val/.gitkeep +0 -0
- attr_eomt-0.1.0/scripts/predict.py +33 -0
- attr_eomt-0.1.0/scripts/train.py +57 -0
- attr_eomt-0.1.0/scripts/val.py +30 -0
- attr_eomt-0.1.0/tests/test_api.py +49 -0
- attr_eomt-0.1.0/tests/test_parity.py +107 -0
- attr_eomt-0.1.0/tests/test_smoke.py +453 -0
- attr_eomt-0.1.0/tests/test_sweep.py +102 -0
- attr_eomt-0.1.0/uv.lock +3104 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
# Builds the package and publishes to PyPI when a GitHub Release is published.
|
|
4
|
+
# Uses PyPI Trusted Publishing (OIDC) — no API token stored as a secret.
|
|
5
|
+
# One-time setup on PyPI: project Settings -> Publishing -> add a trusted publisher
|
|
6
|
+
# owner: imagra93 repo: attr-eomt workflow: publish.yml environment: pypi
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
11
|
+
workflow_dispatch: # allow manual runs (e.g. re-publishing an existing release)
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v5
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v6
|
|
20
|
+
- name: Build sdist + wheel
|
|
21
|
+
run: uv build
|
|
22
|
+
- name: Check metadata
|
|
23
|
+
run: uvx twine check dist/*
|
|
24
|
+
- uses: actions/upload-artifact@v4
|
|
25
|
+
with:
|
|
26
|
+
name: dist
|
|
27
|
+
path: dist/
|
|
28
|
+
|
|
29
|
+
publish:
|
|
30
|
+
needs: build
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
environment: pypi
|
|
33
|
+
permissions:
|
|
34
|
+
id-token: write # required for Trusted Publishing
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/download-artifact@v4
|
|
37
|
+
with:
|
|
38
|
+
name: dist
|
|
39
|
+
path: dist/
|
|
40
|
+
- name: Publish to PyPI
|
|
41
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v5
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v6
|
|
20
|
+
with:
|
|
21
|
+
enable-cache: true
|
|
22
|
+
|
|
23
|
+
- name: Create venv on Python ${{ matrix.python-version }}
|
|
24
|
+
run: uv venv --python ${{ matrix.python-version }}
|
|
25
|
+
|
|
26
|
+
- name: Install project (CPU torch)
|
|
27
|
+
env:
|
|
28
|
+
UV_TORCH_BACKEND: cpu
|
|
29
|
+
run: uv pip install -e ".[dev]"
|
|
30
|
+
|
|
31
|
+
- name: Run tests
|
|
32
|
+
run: uv run --no-sync pytest -q
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.ipynb_checkpoints/
|
|
10
|
+
|
|
11
|
+
# Virtual envs
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
env/
|
|
15
|
+
|
|
16
|
+
# Training artifacts
|
|
17
|
+
runs/
|
|
18
|
+
weights/
|
|
19
|
+
data/
|
|
20
|
+
*.pt
|
|
21
|
+
*.pth
|
|
22
|
+
|
|
23
|
+
# Datasets (auto-downloaded)
|
|
24
|
+
datasets/
|
|
25
|
+
data/coco/
|
|
26
|
+
scripts/sample_images/
|
|
27
|
+
|
|
28
|
+
# Editor / OS
|
|
29
|
+
.idea/
|
|
30
|
+
.vscode/
|
|
31
|
+
.DS_Store
|
attr_eomt-0.1.0/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 Derivative
|
|
95
|
+
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 do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
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.
|
attr_eomt-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: attr-eomt
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Standalone EoMT (Encoder-only Mask Transformer) for instance segmentation, with DINOv2 init, COCO training/validation and inference.
|
|
5
|
+
Project-URL: Homepage, https://github.com/imagra93/attr-eomt
|
|
6
|
+
Project-URL: Repository, https://github.com/imagra93/attr-eomt
|
|
7
|
+
Project-URL: Issues, https://github.com/imagra93/attr-eomt/issues
|
|
8
|
+
Author: attr-eomt contributors
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: coco,dinov2,eomt,instance-segmentation,transformers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: huggingface-hub>=0.23.0
|
|
17
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
18
|
+
Requires-Dist: numpy>=1.19.0
|
|
19
|
+
Requires-Dist: pillow>=9.1.0
|
|
20
|
+
Requires-Dist: pycocotools>=2.0.0
|
|
21
|
+
Requires-Dist: pyyaml>=6.0
|
|
22
|
+
Requires-Dist: requests>=2.25.0
|
|
23
|
+
Requires-Dist: scipy>=1.7.0
|
|
24
|
+
Requires-Dist: torch>=2.4.0
|
|
25
|
+
Requires-Dist: torchvision>=0.19.0
|
|
26
|
+
Requires-Dist: tqdm>=4.65.0
|
|
27
|
+
Requires-Dist: transformers>=5.1.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
32
|
+
Provides-Extra: logging
|
|
33
|
+
Requires-Dist: tensorboard>=2.10; extra == 'logging'
|
|
34
|
+
Requires-Dist: wandb>=0.15; extra == 'logging'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# attr-eomt
|
|
38
|
+
|
|
39
|
+
Standalone **EoMT** (Encoder-only Mask Transformer) for **instance segmentation**,
|
|
40
|
+
with one feature that sets it apart: **secondary per-instance classification heads**
|
|
41
|
+
("auxiliary classes"). Alongside the usual mask + class output, the model predicts
|
|
42
|
+
**one or several independent attributes for every detected instance** — and they
|
|
43
|
+
train and infer for free on top of segmentation, without inflating the primary
|
|
44
|
+
class space.
|
|
45
|
+
|
|
46
|
+
The name reflects exactly that: **attr-eomt** is EoMT extended with per-instance
|
|
47
|
+
**attr**ibute heads.
|
|
48
|
+
|
|
49
|
+
EoMT itself is a DINOv2-with-registers ViT whose last few transformer blocks are
|
|
50
|
+
augmented with learnable queries producing mask-classification output
|
|
51
|
+
(Mask2Former-style). This package builds it in three sizes, initializes the encoder
|
|
52
|
+
from DINOv2, and provides training, per-epoch COCO-mAP validation, and
|
|
53
|
+
inference/rendering — all behind a small `EoMT` class. It is a clean-room,
|
|
54
|
+
Apache-2.0-compatible reimplementation; weights you train are yours to release.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from eomt import EoMT
|
|
58
|
+
|
|
59
|
+
model = EoMT("l") # fresh large model (DINOv2 backbone)
|
|
60
|
+
model.train(data="coco", epochs=50) # COCO 2017 auto-downloads if missing
|
|
61
|
+
|
|
62
|
+
model = EoMT("runs/train/eomt-l") # reload a run — size/classes/heads auto-detected
|
|
63
|
+
model.predict("images/", plot=True) # render masks + per-instance attributes
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## ⭐ Auxiliary classes (secondary per-instance classification)
|
|
69
|
+
|
|
70
|
+
The primary task (instance segmentation over `nc` classes) is **unchanged**. On top
|
|
71
|
+
of it you can attach **one or several independent secondary classifiers** — a
|
|
72
|
+
per-instance *attribute* predicted for each detected mask, read straight from that
|
|
73
|
+
query's embedding. You can have as many heads as your data defines.
|
|
74
|
+
|
|
75
|
+
This answers the "classes **and** subclasses per instance" need by encoding a
|
|
76
|
+
*subclass per instance* rather than flattening to a `class × subclass` product space
|
|
77
|
+
(which would wreck Hungarian matching and thin out per-class statistics). Because
|
|
78
|
+
EoMT is **NMS-free**, two overlapping same-class instances stay two distinct queries;
|
|
79
|
+
the attribute head separates them from their embeddings.
|
|
80
|
+
|
|
81
|
+
### Example: a bowl of fruit
|
|
82
|
+
|
|
83
|
+
One model segments each fruit (primary classes `apple` / `banana` / `orange` /
|
|
84
|
+
`pear`) and, for **every** detection, reads off two **independent** attribute heads —
|
|
85
|
+
`ripeness` (`unripe` / `turning` / `ripe`) and a quality `grade` (`A` / `B`). The
|
|
86
|
+
renderer prints the primary class + score on the first row and each attribute + its
|
|
87
|
+
confidence on the row beneath it.
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+
`ripeness` and `grade` are *orthogonal* — they vary independently — which is exactly
|
|
92
|
+
the case that's awkward to fold into the primary class space. And because EoMT is
|
|
93
|
+
NMS-free, two apples (one ripe, one unripe) and two oranges stay four distinct
|
|
94
|
+
queries, each with its own `ripeness` and `grade`.
|
|
95
|
+
|
|
96
|
+
> The image above is a **simulation**: a stock photo with hand-placed detections fed
|
|
97
|
+
> through the package's own renderer ([`eomt.visualize.draw_instances`](eomt/visualize.py))
|
|
98
|
+
> to show the output format — not a trained model's predictions. The same pattern
|
|
99
|
+
> fits any "class **plus** per-instance sub-labels" task: **retail shelves → product +
|
|
100
|
+
> facing**, **cells / leaves → type + health**, **apparel → garment + pattern**.
|
|
101
|
+
|
|
102
|
+
### How it works
|
|
103
|
+
|
|
104
|
+
- **Embedding source.** Each head reads the per-query embedding — the input to EoMT's
|
|
105
|
+
`class_predictor`, captured with a forward hook (`[B, Q, hidden]`).
|
|
106
|
+
- **Matching.** Supervision reuses EoMT's *own* Hungarian matcher
|
|
107
|
+
(`model.eomt.criterion.matcher`), so every attribute is trained on the **same**
|
|
108
|
+
query→GT assignment the detection loss used. The attribute is read *after* matching.
|
|
109
|
+
- **Loss.** Cross-entropy per head over matched queries, summed across heads and
|
|
110
|
+
scaled by `aux_w` (default `1.0`), added to the segmentation loss. Empty-match
|
|
111
|
+
batches contribute a graph-preserving zero.
|
|
112
|
+
- **Checkpoint selection stays `segm/mAP`.** The attribute "rides along": its per-head
|
|
113
|
+
matched-query train accuracy is shown live and written to `metrics.csv`, but never
|
|
114
|
+
drives `best.pt`.
|
|
115
|
+
- **Inference.** Each result attaches `aux = {head: {"ids", "probs"}}` for the kept
|
|
116
|
+
detections, and `predict(plot=True)` renders each attribute next to the class label
|
|
117
|
+
using names stored in the checkpoint.
|
|
118
|
+
|
|
119
|
+
### Data format (auto-discovered from the COCO JSON)
|
|
120
|
+
|
|
121
|
+
Attributes live **inside the COCO annotations** — each annotation is already a
|
|
122
|
+
per-instance object, so alignment is automatic and `pycocotools` still parses it. Two
|
|
123
|
+
additions to a standard COCO file:
|
|
124
|
+
|
|
125
|
+
```jsonc
|
|
126
|
+
{
|
|
127
|
+
"categories": [ {"id": 1, "name": "apple"}, {"id": 2, "name": "banana"} ],
|
|
128
|
+
|
|
129
|
+
"attributes": [ // NEW, top-level: per-head vocab(s)
|
|
130
|
+
{"name": "ripeness", "categories": [{"id": 0, "name": "unripe"},
|
|
131
|
+
{"id": 1, "name": "turning"},
|
|
132
|
+
{"id": 2, "name": "ripe"}]},
|
|
133
|
+
{"name": "grade", "categories": [{"id": 10, "name": "A"},
|
|
134
|
+
{"id": 20, "name": "B"}]}
|
|
135
|
+
],
|
|
136
|
+
|
|
137
|
+
"annotations": [
|
|
138
|
+
{ "id": 1, "image_id": 42, "category_id": 1,
|
|
139
|
+
"segmentation": [...], "bbox": [...], "area": 1234, "iscrowd": 0,
|
|
140
|
+
"attributes": {"ripeness": 1, "grade": 20} } // NEW, per instance: {head: raw_id}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- The top-level `attributes` list defines each head's vocabulary; raw ids are remapped
|
|
146
|
+
to a contiguous `0..n-1` per head (so the non-contiguous `grade` ids `10`/`20` become
|
|
147
|
+
`0`/`1`). `categories` may be omitted, in which case the id set is inferred.
|
|
148
|
+
- Per-annotation `attributes` is a `{head: raw_id}` map; a missing value defaults to `0`.
|
|
149
|
+
- A JSON with **no** `attributes` ⇒ detection-only, behaving exactly as before.
|
|
150
|
+
|
|
151
|
+
No YAML changes are needed — heads (count, classes, names) are discovered straight from
|
|
152
|
+
the JSON, the same as `nc`. A tiny, self-contained example (two heads, including a
|
|
153
|
+
non-contiguous id set) lives in [sample_data/](sample_data/).
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Sizes
|
|
158
|
+
|
|
159
|
+
| size | backbone | hidden | layers | heads | queries |
|
|
160
|
+
|------|-----------------|--------|--------|-------|---------|
|
|
161
|
+
| `s` | DINOv2-small | 384 | 12 | 6 | 100 |
|
|
162
|
+
| `b` | DINOv2-base | 768 | 12 | 12 | 200 |
|
|
163
|
+
| `l` | DINOv2-large | 1024 | 24 | 16 | 200 |
|
|
164
|
+
|
|
165
|
+
Default input is a patch-14-aligned square (`644 = 14 × 46`) so DINOv2 weights load 1:1.
|
|
166
|
+
|
|
167
|
+
## Install
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
pip install attr-eomt # from PyPI
|
|
171
|
+
pip install "attr-eomt[logging]" # + tensorboard/wandb
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Or from source (editable, for development):
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pip install -e ".[dev]" # [dev] adds pytest/build/twine
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Pretrained weights
|
|
181
|
+
|
|
182
|
+
Checkpoints are hosted on the **Hugging Face Hub**, not bundled in the wheel.
|
|
183
|
+
Load one in a single line — it downloads once and is cached for later runs:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from eomt import EoMT
|
|
187
|
+
|
|
188
|
+
model = EoMT.from_pretrained("imagra93/eomt-l-coco") # downloads + caches
|
|
189
|
+
results = model.predict("images/", plot=True)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Equivalently, an `hf://` reference works anywhere a checkpoint path is accepted:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
EoMT("hf://imagra93/eomt-l-coco/model.pt").val(data="coco")
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`from_pretrained` accepts `filename=` (which checkpoint in the repo, default
|
|
199
|
+
`model.pt`), `revision=` (branch/tag/commit) and `device=`.
|
|
200
|
+
|
|
201
|
+
To publish your own trained weights to the Hub (creates the repo if needed; needs
|
|
202
|
+
`huggingface-cli login` or `HF_TOKEN`):
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
EoMT("runs/train/eomt-l").push_to_hub("your-username/eomt-l-coco") # private by default
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Quickstart
|
|
209
|
+
|
|
210
|
+
Everything goes through one class. Initialize it from a **size** (a fresh model with a
|
|
211
|
+
pretrained DINOv2 backbone) or from a **checkpoint / run folder** (size, classes, image
|
|
212
|
+
size and any auxiliary heads are auto-detected):
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from eomt import EoMT
|
|
216
|
+
|
|
217
|
+
# Train on COCO 2017 (auto-downloaded on first run). batch 4 with the default
|
|
218
|
+
# nominal_batch 16 accumulates to an effective batch of 16.
|
|
219
|
+
EoMT("l").train(data="coco", epochs=50, batch=4)
|
|
220
|
+
|
|
221
|
+
# ...or any COCO-format dataset (point at its data.yaml):
|
|
222
|
+
EoMT("s").train(data="sample_data/data.yaml", epochs=1, batch=1)
|
|
223
|
+
|
|
224
|
+
# Validate a checkpoint (COCO segm + bbox mAP):
|
|
225
|
+
metrics = EoMT("runs/train/eomt-l").val(data="coco")
|
|
226
|
+
|
|
227
|
+
# Predict + render on an image or a folder; results carry boxes/scores/classes/masks
|
|
228
|
+
# (+ `aux` for models with auxiliary heads). plot=True writes annotated images:
|
|
229
|
+
results = EoMT("runs/train/eomt-l").predict("images/", plot=True)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Ready-to-run wrappers live in [scripts/](scripts/):
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
python scripts/train.py --size l --epochs 50 --batch 4 # COCO by default
|
|
236
|
+
python scripts/val.py runs/train/eomt-l
|
|
237
|
+
python scripts/predict.py runs/train/eomt-l # uses scripts/sample_images
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
To resume or fine-tune, initialize from the checkpoint:
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
EoMT("runs/train/eomt-l").train(data="coco", resume=True) # continue the run
|
|
244
|
+
EoMT("runs/train/eomt-l").train(data="my.yaml", epochs=20) # warm-start (fine-tune)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Useful `train()` options
|
|
248
|
+
|
|
249
|
+
Passed as keyword arguments to `model.train(...)`:
|
|
250
|
+
|
|
251
|
+
| arg | default | effect |
|
|
252
|
+
|------|---------|--------|
|
|
253
|
+
| `nominal_batch` / `accum` | `16` / `0` | gradient accumulation to an **effective batch** of `nominal_batch` (EoMT recipe is 16); `accum=N` sets the step count explicitly |
|
|
254
|
+
| `ema` / `ema_decay` / `ema_tau` | `True` / `0.9999` / `2000` | validate & export `best.pt` from an **EMA** of the weights; decay + its warmup ramp |
|
|
255
|
+
| `llrd` | `0.85` | **layer-wise LR decay** on the DINOv2 backbone (`1.0` = flat `backbone_lr_mult`) |
|
|
256
|
+
| `min_scale` / `max_scale` | `0.1` / `2.0` | **Large-Scale Jitter** range (legacy stretch-style: `0.5` / `1.0`) |
|
|
257
|
+
| `letterbox` | `True` | aspect-preserving **letterbox** eval (vs legacy square stretch); recorded in the checkpoint |
|
|
258
|
+
| `flip_prob` | `0.5` | horizontal-flip probability. **Set `0`** for datasets with a left/right attribute — hflip mirrors pixels without swapping the laterality label |
|
|
259
|
+
| `mask_anneal` / `mask_anneal_start` / `mask_anneal_end` | `True` / `0.0` / `0.9` | anneal masked attention `1→0` over this fraction of training (EoMT recipe) |
|
|
260
|
+
| `aux_w` | `1.0` | weight on the summed secondary-head loss |
|
|
261
|
+
|
|
262
|
+
## Training recipe
|
|
263
|
+
|
|
264
|
+
Defaults follow the EoMT/Mask2Former fine-tuning recipe; each piece is a keyword
|
|
265
|
+
argument, so the legacy behaviour is one override away.
|
|
266
|
+
|
|
267
|
+
- **Effective batch via gradient accumulation.** LR / weight-decay / clip are tuned for
|
|
268
|
+
an effective batch of 16, so training accumulates `round(nominal_batch / batch)`
|
|
269
|
+
micro-batches per optimizer step. EoMT is a ViT (LayerNorm, no BatchNorm), so this is
|
|
270
|
+
~equivalent to a true large batch at a fraction of the memory.
|
|
271
|
+
- **EMA weights.** A moving average is validated and saved as `best.pt`; `last.pt` holds
|
|
272
|
+
the live weights plus optimizer and EMA state for exact resume.
|
|
273
|
+
- **Large-Scale Jitter (LSJ).** Training resizes aspect-preserving over
|
|
274
|
+
`[min_scale, max_scale]` then crops/pads to the square input — a strong scale aug.
|
|
275
|
+
- **Letterbox eval.** Validation/inference resize the long side and pad to a square; the
|
|
276
|
+
padding is cropped back out in postprocessing. The mode is stored per-checkpoint so
|
|
277
|
+
`val`/`predict` match training automatically.
|
|
278
|
+
- **Optimizer.** AdamW with no weight decay on norms/biases/embeddings and layer-wise LR
|
|
279
|
+
decay on the backbone (`llrd`, deeper layers get a higher LR).
|
|
280
|
+
- **Tunable objective.** The matcher/loss weights (`class_weight`, `mask_weight`,
|
|
281
|
+
`dice_weight`, `no_object_weight`), PointRend sampling (`train_num_points`) and
|
|
282
|
+
mask-head depth (`num_upscale_blocks`) are arguments, persisted in the checkpoint so a
|
|
283
|
+
tuned objective rebuilds on reload.
|
|
284
|
+
- **Masked-attention annealing.** The masked-attention probability is annealed `1 → 0`
|
|
285
|
+
over `[mask_anneal_start, mask_anneal_end]` of training, so the final stretch trains
|
|
286
|
+
**mask-free** and matches efficient (mask-less) inference. Validation and
|
|
287
|
+
checkpointing run mask-free (deterministic).
|
|
288
|
+
|
|
289
|
+
## What's included
|
|
290
|
+
|
|
291
|
+
- Architecture (`s`/`b`/`l`) + DINOv2 init — `eomt.model`, `eomt.config`
|
|
292
|
+
- **Secondary per-instance attribute heads** — `eomt.aux_cls`, `eomt.config.AuxHeadSpec`
|
|
293
|
+
- COCO-format datasets (incl. per-instance attributes), Large-Scale Jitter + letterbox
|
|
294
|
+
augmentations (torchvision v2), autodownload — `eomt.data`
|
|
295
|
+
- Training loop (AdamW + layer-wise LR decay + no-WD groups, cosine warmup, gradient
|
|
296
|
+
accumulation, AMP, EMA weights, masked-attention annealing, aux-head loss, resume,
|
|
297
|
+
per-epoch `metrics.csv`) — `eomt.engine.train`, `eomt.ema`
|
|
298
|
+
- COCO-mAP validation (`pycocotools`) with letterbox-aware mask remapping — `eomt.engine.validate`
|
|
299
|
+
- Mask2Former-style scoring (class confidence × mask objectness) — `eomt.postprocess`
|
|
300
|
+
- Inference + rendering (with attribute labels) — `eomt.engine.predict`, `eomt.visualize`
|
|
301
|
+
|
|
302
|
+
## Not included
|
|
303
|
+
|
|
304
|
+
Deployment-format export (ONNX / TensorRT / etc.) is intentionally out of scope. A
|
|
305
|
+
detect (true box head) family and a semantic-segmentation family are planned; the code
|
|
306
|
+
carries a `family` parameter so they can be added without API churn, but only
|
|
307
|
+
`instance` is implemented today.
|