perceptra-train 0.2.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.
- perceptra_train-0.2.0/LICENSE +201 -0
- perceptra_train-0.2.0/MANIFEST.in +17 -0
- perceptra_train-0.2.0/PKG-INFO +216 -0
- perceptra_train-0.2.0/README.md +166 -0
- perceptra_train-0.2.0/examples/__init__.py +0 -0
- perceptra_train-0.2.0/examples/basic_usage.py +46 -0
- perceptra_train-0.2.0/examples/batch_processing.py +101 -0
- perceptra_train-0.2.0/examples/coco_to_coco.py +47 -0
- perceptra_train-0.2.0/examples/yolo_to_yolo.py +59 -0
- perceptra_train-0.2.0/perceptra_train/__init__.py +46 -0
- perceptra_train-0.2.0/perceptra_train/__version__.py +8 -0
- perceptra_train-0.2.0/perceptra_train/cli.py +186 -0
- perceptra_train-0.2.0/perceptra_train/converters/__init__.py +6 -0
- perceptra_train-0.2.0/perceptra_train/converters/coco.py +60 -0
- perceptra_train-0.2.0/perceptra_train/converters/yolo.py +53 -0
- perceptra_train-0.2.0/perceptra_train/core/__init__.py +6 -0
- perceptra_train-0.2.0/perceptra_train/core/geometry.py +264 -0
- perceptra_train-0.2.0/perceptra_train/core/registry.py +78 -0
- perceptra_train-0.2.0/perceptra_train/core/types.py +238 -0
- perceptra_train-0.2.0/perceptra_train/filters/__init__.py +28 -0
- perceptra_train-0.2.0/perceptra_train/filters/base.py +45 -0
- perceptra_train-0.2.0/perceptra_train/filters/merge.py +41 -0
- perceptra_train-0.2.0/perceptra_train/filters/model_filter.py +251 -0
- perceptra_train-0.2.0/perceptra_train/filters/rules.py +153 -0
- perceptra_train-0.2.0/perceptra_train/generator.py +121 -0
- perceptra_train-0.2.0/perceptra_train/models/__init__.py +5 -0
- perceptra_train-0.2.0/perceptra_train/models/annotations.py +50 -0
- perceptra_train-0.2.0/perceptra_train/models/base.py +92 -0
- perceptra_train-0.2.0/perceptra_train/models/sam.py +191 -0
- perceptra_train-0.2.0/perceptra_train/models/ultralytics.py +181 -0
- perceptra_train-0.2.0/perceptra_train/pipeline/__init__.py +7 -0
- perceptra_train-0.2.0/perceptra_train/pipeline/builder.py +129 -0
- perceptra_train-0.2.0/perceptra_train/pipeline/config.py +216 -0
- perceptra_train-0.2.0/perceptra_train/pipeline/manifest.py +100 -0
- perceptra_train-0.2.0/perceptra_train/pipeline/runner.py +426 -0
- perceptra_train-0.2.0/perceptra_train/sources/__init__.py +5 -0
- perceptra_train-0.2.0/perceptra_train/sources/base.py +19 -0
- perceptra_train-0.2.0/perceptra_train/sources/coco.py +64 -0
- perceptra_train-0.2.0/perceptra_train/sources/folder.py +61 -0
- perceptra_train-0.2.0/perceptra_train/sources/yolo.py +88 -0
- perceptra_train-0.2.0/perceptra_train/utils/__init__.py +5 -0
- perceptra_train-0.2.0/perceptra_train/utils/validation.py +135 -0
- perceptra_train-0.2.0/perceptra_train/utils/visualization.py +42 -0
- perceptra_train-0.2.0/perceptra_train/writers/__init__.py +8 -0
- perceptra_train-0.2.0/perceptra_train/writers/base.py +50 -0
- perceptra_train-0.2.0/perceptra_train/writers/coco.py +128 -0
- perceptra_train-0.2.0/perceptra_train/writers/masks.py +51 -0
- perceptra_train-0.2.0/perceptra_train/writers/visualization.py +75 -0
- perceptra_train-0.2.0/perceptra_train/writers/yolo.py +63 -0
- perceptra_train-0.2.0/perceptra_train.egg-info/PKG-INFO +216 -0
- perceptra_train-0.2.0/perceptra_train.egg-info/SOURCES.txt +56 -0
- perceptra_train-0.2.0/perceptra_train.egg-info/dependency_links.txt +1 -0
- perceptra_train-0.2.0/perceptra_train.egg-info/entry_points.txt +2 -0
- perceptra_train-0.2.0/perceptra_train.egg-info/requires.txt +30 -0
- perceptra_train-0.2.0/perceptra_train.egg-info/top_level.txt +1 -0
- perceptra_train-0.2.0/pyproject.toml +101 -0
- perceptra_train-0.2.0/setup.cfg +4 -0
- perceptra_train-0.2.0/setup.py +7 -0
|
@@ -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.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
# Include important files in distribution
|
|
3
|
+
include README.md
|
|
4
|
+
include LICENSE
|
|
5
|
+
include pyproject.toml
|
|
6
|
+
include setup.py
|
|
7
|
+
|
|
8
|
+
# Include package data
|
|
9
|
+
recursive-include PerceptraTrain *.py
|
|
10
|
+
recursive-include examples *.py
|
|
11
|
+
|
|
12
|
+
# Exclude unnecessary files
|
|
13
|
+
recursive-exclude * __pycache__
|
|
14
|
+
recursive-exclude * *.py[co]
|
|
15
|
+
recursive-exclude tests *
|
|
16
|
+
recursive-exclude .github *
|
|
17
|
+
exclude .gitignore
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: perceptra-train
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Generate training data (YOLO / COCO, detection / segmentation) from combinations of models
|
|
5
|
+
Author-email: Tannous Geagea <tannousgeagea@hotmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/tannousgeagea/perceptra-train
|
|
8
|
+
Project-URL: Documentation, https://perceptra-train.readthedocs.io
|
|
9
|
+
Project-URL: Repository, https://github.com/tannousgeagea/perceptra-train
|
|
10
|
+
Project-URL: Issues, https://github.com/tannousgeagea/perceptra-train/issues
|
|
11
|
+
Keywords: segmentation,detection,pseudo-labeling,auto-labeling,annotation,yolo,coco,sam,computer-vision,dataset,deep-learning
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=1.24.0
|
|
26
|
+
Requires-Dist: pillow>=10.0.0
|
|
27
|
+
Requires-Dist: opencv-python>=4.8.0
|
|
28
|
+
Requires-Dist: tqdm>=4.65.0
|
|
29
|
+
Requires-Dist: pyyaml>=6.0
|
|
30
|
+
Requires-Dist: pydantic>=2.0
|
|
31
|
+
Provides-Extra: ultralytics
|
|
32
|
+
Requires-Dist: ultralytics>=8.3.0; extra == "ultralytics"
|
|
33
|
+
Provides-Extra: sam
|
|
34
|
+
Requires-Dist: perceptra-seg[torch]>=0.1.1; extra == "sam"
|
|
35
|
+
Provides-Extra: coco
|
|
36
|
+
Requires-Dist: pycocotools>=2.0.7; extra == "coco"
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: black>=23.11.0; extra == "dev"
|
|
41
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
42
|
+
Requires-Dist: ruff>=0.1.5; extra == "dev"
|
|
43
|
+
Requires-Dist: mypy>=1.7.0; extra == "dev"
|
|
44
|
+
Provides-Extra: docs
|
|
45
|
+
Requires-Dist: mkdocs>=1.5.0; extra == "docs"
|
|
46
|
+
Requires-Dist: mkdocs-material>=9.4.0; extra == "docs"
|
|
47
|
+
Provides-Extra: all
|
|
48
|
+
Requires-Dist: perceptra-train[coco,dev,docs,sam,ultralytics]; extra == "all"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
# šÆ PerceptraTrain
|
|
52
|
+
|
|
53
|
+
**Training data from combinations of models**
|
|
54
|
+
|
|
55
|
+
PerceptraTrain builds detection and segmentation datasets in YOLO, COCO or PNG-mask format from a stack of models.
|
|
56
|
+
|
|
57
|
+
- **Producers** propose instances: a segmentation or detection model, or existing labels.
|
|
58
|
+
- **Filter models** remove what must not be in the data, for example a crane grab or a truck door that the segmenter also "finds".
|
|
59
|
+
- **Rule filters** clean up the rest.
|
|
60
|
+
- **Writers** emit the dataset.
|
|
61
|
+
|
|
62
|
+
[](https://www.python.org/downloads/)
|
|
63
|
+
[](LICENSE)
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
images āāŗ decode (threads) āāŗ image-level filters (drop_image) āāŗ producers āāŗ merge (NMS)
|
|
67
|
+
āāŗ refiner (SAM: box ā mask) āāŗ filters (model / rules, in order) āāŗ task adapt āāŗ writers
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## ⨠Features
|
|
71
|
+
|
|
72
|
+
- **Model combinations.** Stack any number of producers and filter models. Each filter chooses an action:
|
|
73
|
+
- `drop_instance`: remove instances whose overlap (`ioa`/`iou`) with the filter's regions exceeds a threshold.
|
|
74
|
+
- `carve`: subtract the filter regions from the masks.
|
|
75
|
+
- `drop_image`: discard the whole frame.
|
|
76
|
+
- **Precise filtering.** Filter boxes can be turned into masks with SAM (`refine:`). A crane box contains real waste between the grab tines; the grab's own mask does not.
|
|
77
|
+
- **Tasks and formats.** `task: detect | segment`. Formats are `yolo`, `coco` (polygon or RLE) and `masks` (instance and semantic PNG). Detection boxes are re-derived from carved masks.
|
|
78
|
+
- **Efficient.** Images are decoded once by a thread pool, and inference is batched. Masks are stored as tight per-instance crops, never `NĆHĆW`. Polygons are extracted and files written on a separate thread pool. COCO is streamed to JSONL parts and merged at the end, so memory stays flat.
|
|
79
|
+
- **Robust.**
|
|
80
|
+
- A corrupt image or model failure is isolated to that image and recorded.
|
|
81
|
+
- Writes are atomic, and an interrupted run resumes where it stopped.
|
|
82
|
+
- `--shard i/N` enables multi-GPU and multi-node runs.
|
|
83
|
+
- Splits are deterministic and hash-based.
|
|
84
|
+
- A config fingerprint prevents mixing datasets in one directory.
|
|
85
|
+
- **Auditable.** Visualisations show kept instances in class colours, removed ones in red with the reason, and filter detections in yellow. `stats.json` reports removals per filter. `run_meta.json` stores the config, the model sha256s and package versions.
|
|
86
|
+
- **Pluggable.** Register your own source, producer, refiner, filter or writer with `@register(kind, name)` and reference it from YAML.
|
|
87
|
+
|
|
88
|
+
## š¦ Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install "perceptra-train[ultralytics]" # YOLO producers/filters + SAM refiner via Ultralytics (AGPL-3.0)
|
|
92
|
+
pip install "perceptra-train[sam]" # perceptra-seg SAM backend (legacy box ā mask path)
|
|
93
|
+
pip install "perceptra-train[coco]" # pycocotools for compressed RLE
|
|
94
|
+
pip install "perceptra-train[all]"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
> **Breaking change (0.2):** `perceptra-seg` is no longer a core dependency. Install the `[sam]` extra for `DataGenerator`.
|
|
98
|
+
|
|
99
|
+
## ā” Quick start
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
# pipeline.yaml
|
|
103
|
+
source: {type: folder, path: data/bunker_images}
|
|
104
|
+
|
|
105
|
+
producers:
|
|
106
|
+
- {name: waste, type: ultralytics, weights: models/base.segment.pt, conf: 0.25, imgsz: 1024}
|
|
107
|
+
|
|
108
|
+
filters:
|
|
109
|
+
- name: crane
|
|
110
|
+
type: model
|
|
111
|
+
model: {type: ultralytics, weights: models/CraneDetectionBunker_V11.pt, conf: 0.3}
|
|
112
|
+
classes: [crane]
|
|
113
|
+
refine: {type: ultralytics_sam, weights: mobile_sam.pt} # grab box -> grab mask
|
|
114
|
+
max_region_frac: 0.5 # ignore implausible giant detections
|
|
115
|
+
action: drop_instance # drop_instance | carve | drop_image
|
|
116
|
+
metric: ioa # share of the instance inside the crane region
|
|
117
|
+
threshold: 0.5
|
|
118
|
+
dilate_px: 10
|
|
119
|
+
- {type: area, min: 400}
|
|
120
|
+
|
|
121
|
+
output:
|
|
122
|
+
dir: runs/waste_seg
|
|
123
|
+
task: segment # detect | segment
|
|
124
|
+
formats: [yolo, {type: coco, mask_format: polygon}]
|
|
125
|
+
split: {train: 0.8, val: 0.2}
|
|
126
|
+
visualize: 50
|
|
127
|
+
|
|
128
|
+
runtime: {device: auto, batch_size: 8, workers: 4}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
perceptra-train inspect models/*.pt # task + class names of each model
|
|
133
|
+
perceptra-train validate pipeline.yaml --load-models # checks classes, task feasibility
|
|
134
|
+
perceptra-train run pipeline.yaml # resumable
|
|
135
|
+
perceptra-train run pipeline.yaml --set output.task=detect --output runs/waste_det
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Python:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from perceptra_train import run_pipeline
|
|
142
|
+
stats = run_pipeline("pipeline.yaml", **{"runtime.limit": 100})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
A complete example is in [`examples/pipelines/bunker_waste_seg.yaml`](examples/pipelines/bunker_waste_seg.yaml).
|
|
146
|
+
|
|
147
|
+
## š§© Building blocks
|
|
148
|
+
|
|
149
|
+
| Kind | `type` | Notes |
|
|
150
|
+
|---|---|---|
|
|
151
|
+
| source | `folder` | recursive; `list_file` restricts it to a subset |
|
|
152
|
+
| source | `coco`, `yolo` | existing detection labels, used by the `annotations` producer |
|
|
153
|
+
| producer | `ultralytics` | YOLO detect / segment / OBB. `classes:` selects (`[a, b]`) or renames (`{a: x, b: null}`) classes |
|
|
154
|
+
| producer | `annotations` | ground-truth boxes from a `coco`/`yolo` source |
|
|
155
|
+
| refiner | `ultralytics_sam` | SAM / MobileSAM / SAM2. Each image is encoded once and all boxes are decoded together |
|
|
156
|
+
| refiner | `perceptra_seg` | perceptra-seg `Segmentor` |
|
|
157
|
+
| filter | `model` | `action`, `metric`, `threshold`, `classes`, `dilate_px`, `max_region_frac`, `min_score`, `refine`, `min_remaining_area/frac` |
|
|
158
|
+
| filter | `score`, `area`, `classes`, `border`, `roi`, `aspect_ratio` | rule filters |
|
|
159
|
+
| writer | `yolo`, `coco`, `masks` | `include_empty` keeps negative images (default on) |
|
|
160
|
+
|
|
161
|
+
Further notes:
|
|
162
|
+
- When there are several producers, add `merge: {iou: 0.6, class_agnostic: false}` for mask-aware NMS across them.
|
|
163
|
+
- `task: segment` with a box-only producer requires a top-level `refiner:`. This is checked at build time.
|
|
164
|
+
|
|
165
|
+
**Choosing a filter metric.** IoA is the fraction of the *instance* that lies inside the filter region. It is asymmetric on purpose: a grab touching the corner of a large object must not remove the object, but a "waste" mask that is mostly grab must go. Use `carve` when instances partly overlap the unwanted object and the rest is worth keeping.
|
|
166
|
+
|
|
167
|
+
### Custom components
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from perceptra_train import register, Instances
|
|
171
|
+
|
|
172
|
+
@register("producer", "my_onnx")
|
|
173
|
+
class MyModel:
|
|
174
|
+
task = "segment"
|
|
175
|
+
names = {0: "waste"}
|
|
176
|
+
def __init__(self, weights, device="auto"): ...
|
|
177
|
+
def predict(self, frames) -> list[Instances]: ... # frames[i].image is BGR uint8
|
|
178
|
+
def close(self): ...
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## š Output
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
runs/waste_seg/
|
|
185
|
+
āāā images/{train,val}/ # symlinks (link_images: symlink|hardlink|copy|none)
|
|
186
|
+
āāā labels/{train,val}/*.txt # yolo
|
|
187
|
+
āāā annotations/{train,val}.json # coco (+ _parts/ streaming shards)
|
|
188
|
+
āāā masks/ semantic/ # masks writer
|
|
189
|
+
āāā data.yaml # ready for `yolo train data=...`
|
|
190
|
+
āāā visualizations/ # audit images
|
|
191
|
+
āāā manifest*.jsonl # per-image status (resume / shards)
|
|
192
|
+
āāā stats.json # counts per producer / filter / class / split
|
|
193
|
+
āāā run_meta.json # config, fingerprint, model sha256, versions
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## š Scaling out
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# 4 GPUs, one shard each
|
|
200
|
+
for i in 0 1 2 3; do CUDA_VISIBLE_DEVICES=$i perceptra-train run p.yaml --shard $i/4 & done; wait
|
|
201
|
+
perceptra-train finalize runs/waste_seg # merges COCO parts + stats
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## š Legacy box ā mask API
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from perceptra_train import DataGenerator
|
|
208
|
+
with DataGenerator({"model": "sam_v1", "device": "cuda"}, min_score_threshold=0.5, min_area=100) as gen:
|
|
209
|
+
stats = gen.process_dataset("images/", "annotations.json", "out/", input_format="coco", output_format="yolo")
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`perceptra-train --images ... --annotations ... --output ...` still works and is routed to `perceptra-train convert`. Both now run on the pipeline: annotations producer ā SAM refiner ā score and area filters. The output uses the layout above.
|
|
213
|
+
|
|
214
|
+
## š License
|
|
215
|
+
|
|
216
|
+
Apache 2.0. See [LICENSE](LICENSE). The optional Ultralytics backend is AGPL-3.0.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# šÆ PerceptraTrain
|
|
2
|
+
|
|
3
|
+
**Training data from combinations of models**
|
|
4
|
+
|
|
5
|
+
PerceptraTrain builds detection and segmentation datasets in YOLO, COCO or PNG-mask format from a stack of models.
|
|
6
|
+
|
|
7
|
+
- **Producers** propose instances: a segmentation or detection model, or existing labels.
|
|
8
|
+
- **Filter models** remove what must not be in the data, for example a crane grab or a truck door that the segmenter also "finds".
|
|
9
|
+
- **Rule filters** clean up the rest.
|
|
10
|
+
- **Writers** emit the dataset.
|
|
11
|
+
|
|
12
|
+
[](https://www.python.org/downloads/)
|
|
13
|
+
[](LICENSE)
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
images āāŗ decode (threads) āāŗ image-level filters (drop_image) āāŗ producers āāŗ merge (NMS)
|
|
17
|
+
āāŗ refiner (SAM: box ā mask) āāŗ filters (model / rules, in order) āāŗ task adapt āāŗ writers
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## ⨠Features
|
|
21
|
+
|
|
22
|
+
- **Model combinations.** Stack any number of producers and filter models. Each filter chooses an action:
|
|
23
|
+
- `drop_instance`: remove instances whose overlap (`ioa`/`iou`) with the filter's regions exceeds a threshold.
|
|
24
|
+
- `carve`: subtract the filter regions from the masks.
|
|
25
|
+
- `drop_image`: discard the whole frame.
|
|
26
|
+
- **Precise filtering.** Filter boxes can be turned into masks with SAM (`refine:`). A crane box contains real waste between the grab tines; the grab's own mask does not.
|
|
27
|
+
- **Tasks and formats.** `task: detect | segment`. Formats are `yolo`, `coco` (polygon or RLE) and `masks` (instance and semantic PNG). Detection boxes are re-derived from carved masks.
|
|
28
|
+
- **Efficient.** Images are decoded once by a thread pool, and inference is batched. Masks are stored as tight per-instance crops, never `NĆHĆW`. Polygons are extracted and files written on a separate thread pool. COCO is streamed to JSONL parts and merged at the end, so memory stays flat.
|
|
29
|
+
- **Robust.**
|
|
30
|
+
- A corrupt image or model failure is isolated to that image and recorded.
|
|
31
|
+
- Writes are atomic, and an interrupted run resumes where it stopped.
|
|
32
|
+
- `--shard i/N` enables multi-GPU and multi-node runs.
|
|
33
|
+
- Splits are deterministic and hash-based.
|
|
34
|
+
- A config fingerprint prevents mixing datasets in one directory.
|
|
35
|
+
- **Auditable.** Visualisations show kept instances in class colours, removed ones in red with the reason, and filter detections in yellow. `stats.json` reports removals per filter. `run_meta.json` stores the config, the model sha256s and package versions.
|
|
36
|
+
- **Pluggable.** Register your own source, producer, refiner, filter or writer with `@register(kind, name)` and reference it from YAML.
|
|
37
|
+
|
|
38
|
+
## š¦ Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install "perceptra-train[ultralytics]" # YOLO producers/filters + SAM refiner via Ultralytics (AGPL-3.0)
|
|
42
|
+
pip install "perceptra-train[sam]" # perceptra-seg SAM backend (legacy box ā mask path)
|
|
43
|
+
pip install "perceptra-train[coco]" # pycocotools for compressed RLE
|
|
44
|
+
pip install "perceptra-train[all]"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> **Breaking change (0.2):** `perceptra-seg` is no longer a core dependency. Install the `[sam]` extra for `DataGenerator`.
|
|
48
|
+
|
|
49
|
+
## ā” Quick start
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
# pipeline.yaml
|
|
53
|
+
source: {type: folder, path: data/bunker_images}
|
|
54
|
+
|
|
55
|
+
producers:
|
|
56
|
+
- {name: waste, type: ultralytics, weights: models/base.segment.pt, conf: 0.25, imgsz: 1024}
|
|
57
|
+
|
|
58
|
+
filters:
|
|
59
|
+
- name: crane
|
|
60
|
+
type: model
|
|
61
|
+
model: {type: ultralytics, weights: models/CraneDetectionBunker_V11.pt, conf: 0.3}
|
|
62
|
+
classes: [crane]
|
|
63
|
+
refine: {type: ultralytics_sam, weights: mobile_sam.pt} # grab box -> grab mask
|
|
64
|
+
max_region_frac: 0.5 # ignore implausible giant detections
|
|
65
|
+
action: drop_instance # drop_instance | carve | drop_image
|
|
66
|
+
metric: ioa # share of the instance inside the crane region
|
|
67
|
+
threshold: 0.5
|
|
68
|
+
dilate_px: 10
|
|
69
|
+
- {type: area, min: 400}
|
|
70
|
+
|
|
71
|
+
output:
|
|
72
|
+
dir: runs/waste_seg
|
|
73
|
+
task: segment # detect | segment
|
|
74
|
+
formats: [yolo, {type: coco, mask_format: polygon}]
|
|
75
|
+
split: {train: 0.8, val: 0.2}
|
|
76
|
+
visualize: 50
|
|
77
|
+
|
|
78
|
+
runtime: {device: auto, batch_size: 8, workers: 4}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
perceptra-train inspect models/*.pt # task + class names of each model
|
|
83
|
+
perceptra-train validate pipeline.yaml --load-models # checks classes, task feasibility
|
|
84
|
+
perceptra-train run pipeline.yaml # resumable
|
|
85
|
+
perceptra-train run pipeline.yaml --set output.task=detect --output runs/waste_det
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Python:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from perceptra_train import run_pipeline
|
|
92
|
+
stats = run_pipeline("pipeline.yaml", **{"runtime.limit": 100})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
A complete example is in [`examples/pipelines/bunker_waste_seg.yaml`](examples/pipelines/bunker_waste_seg.yaml).
|
|
96
|
+
|
|
97
|
+
## š§© Building blocks
|
|
98
|
+
|
|
99
|
+
| Kind | `type` | Notes |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| source | `folder` | recursive; `list_file` restricts it to a subset |
|
|
102
|
+
| source | `coco`, `yolo` | existing detection labels, used by the `annotations` producer |
|
|
103
|
+
| producer | `ultralytics` | YOLO detect / segment / OBB. `classes:` selects (`[a, b]`) or renames (`{a: x, b: null}`) classes |
|
|
104
|
+
| producer | `annotations` | ground-truth boxes from a `coco`/`yolo` source |
|
|
105
|
+
| refiner | `ultralytics_sam` | SAM / MobileSAM / SAM2. Each image is encoded once and all boxes are decoded together |
|
|
106
|
+
| refiner | `perceptra_seg` | perceptra-seg `Segmentor` |
|
|
107
|
+
| filter | `model` | `action`, `metric`, `threshold`, `classes`, `dilate_px`, `max_region_frac`, `min_score`, `refine`, `min_remaining_area/frac` |
|
|
108
|
+
| filter | `score`, `area`, `classes`, `border`, `roi`, `aspect_ratio` | rule filters |
|
|
109
|
+
| writer | `yolo`, `coco`, `masks` | `include_empty` keeps negative images (default on) |
|
|
110
|
+
|
|
111
|
+
Further notes:
|
|
112
|
+
- When there are several producers, add `merge: {iou: 0.6, class_agnostic: false}` for mask-aware NMS across them.
|
|
113
|
+
- `task: segment` with a box-only producer requires a top-level `refiner:`. This is checked at build time.
|
|
114
|
+
|
|
115
|
+
**Choosing a filter metric.** IoA is the fraction of the *instance* that lies inside the filter region. It is asymmetric on purpose: a grab touching the corner of a large object must not remove the object, but a "waste" mask that is mostly grab must go. Use `carve` when instances partly overlap the unwanted object and the rest is worth keeping.
|
|
116
|
+
|
|
117
|
+
### Custom components
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from perceptra_train import register, Instances
|
|
121
|
+
|
|
122
|
+
@register("producer", "my_onnx")
|
|
123
|
+
class MyModel:
|
|
124
|
+
task = "segment"
|
|
125
|
+
names = {0: "waste"}
|
|
126
|
+
def __init__(self, weights, device="auto"): ...
|
|
127
|
+
def predict(self, frames) -> list[Instances]: ... # frames[i].image is BGR uint8
|
|
128
|
+
def close(self): ...
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## š Output
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
runs/waste_seg/
|
|
135
|
+
āāā images/{train,val}/ # symlinks (link_images: symlink|hardlink|copy|none)
|
|
136
|
+
āāā labels/{train,val}/*.txt # yolo
|
|
137
|
+
āāā annotations/{train,val}.json # coco (+ _parts/ streaming shards)
|
|
138
|
+
āāā masks/ semantic/ # masks writer
|
|
139
|
+
āāā data.yaml # ready for `yolo train data=...`
|
|
140
|
+
āāā visualizations/ # audit images
|
|
141
|
+
āāā manifest*.jsonl # per-image status (resume / shards)
|
|
142
|
+
āāā stats.json # counts per producer / filter / class / split
|
|
143
|
+
āāā run_meta.json # config, fingerprint, model sha256, versions
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## š Scaling out
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# 4 GPUs, one shard each
|
|
150
|
+
for i in 0 1 2 3; do CUDA_VISIBLE_DEVICES=$i perceptra-train run p.yaml --shard $i/4 & done; wait
|
|
151
|
+
perceptra-train finalize runs/waste_seg # merges COCO parts + stats
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## š Legacy box ā mask API
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from perceptra_train import DataGenerator
|
|
158
|
+
with DataGenerator({"model": "sam_v1", "device": "cuda"}, min_score_threshold=0.5, min_area=100) as gen:
|
|
159
|
+
stats = gen.process_dataset("images/", "annotations.json", "out/", input_format="coco", output_format="yolo")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`perceptra-train --images ... --annotations ... --output ...` still works and is routed to `perceptra-train convert`. Both now run on the pipeline: annotations producer ā SAM refiner ā score and area filters. The output uses the layout above.
|
|
163
|
+
|
|
164
|
+
## š License
|
|
165
|
+
|
|
166
|
+
Apache 2.0. See [LICENSE](LICENSE). The optional Ultralytics backend is AGPL-3.0.
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Basic usage example for PerceptraTrain."""
|
|
2
|
+
|
|
3
|
+
from perceptra_train import DataGenerator
|
|
4
|
+
|
|
5
|
+
def main():
|
|
6
|
+
"""Basic example."""
|
|
7
|
+
|
|
8
|
+
print("PerceptraTrain - Basic Usage Example")
|
|
9
|
+
print("=" * 60)
|
|
10
|
+
|
|
11
|
+
# Initialize generator
|
|
12
|
+
print("\n1. Initializing generator...")
|
|
13
|
+
generator = DataGenerator(
|
|
14
|
+
segmentor_config={
|
|
15
|
+
"model": "sam_v1",
|
|
16
|
+
"device": "cuda",
|
|
17
|
+
"precision": "fp16",
|
|
18
|
+
},
|
|
19
|
+
min_score_threshold=0.7,
|
|
20
|
+
min_area=200,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# Process dataset
|
|
24
|
+
print("\n2. Processing dataset...")
|
|
25
|
+
stats = generator.process_dataset(
|
|
26
|
+
images_dir="data/images",
|
|
27
|
+
annotations_path="data/annotations.json",
|
|
28
|
+
output_dir="output/segmentation",
|
|
29
|
+
input_format="coco",
|
|
30
|
+
output_format="coco",
|
|
31
|
+
save_visualizations=True,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Print results
|
|
35
|
+
print("\n3. Results:")
|
|
36
|
+
print(f" Total images: {stats['total_images']}")
|
|
37
|
+
print(f" Successful masks: {stats['successful_masks']}")
|
|
38
|
+
print(f" Success rate: {stats['successful_masks']/stats['total_boxes']*100:.1f}%")
|
|
39
|
+
|
|
40
|
+
# Cleanup
|
|
41
|
+
generator.close()
|
|
42
|
+
print("\nā Done!")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
main()
|