3lc-ultralytics 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.
Files changed (35) hide show
  1. 3lc_ultralytics-0.1.0/PKG-INFO +270 -0
  2. 3lc_ultralytics-0.1.0/README.md +258 -0
  3. 3lc_ultralytics-0.1.0/pyproject.toml +42 -0
  4. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/__init__.py +23 -0
  5. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/_static/dashboard.png +0 -0
  6. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/classify/__init__.py +4 -0
  7. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/classify/dataset.py +109 -0
  8. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/classify/trainer.py +86 -0
  9. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/classify/utils.py +115 -0
  10. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/classify/validator.py +123 -0
  11. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/constants.py +28 -0
  12. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/detect/__init__.py +4 -0
  13. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/detect/dataset.py +392 -0
  14. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/detect/loss.py +145 -0
  15. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/detect/trainer.py +109 -0
  16. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/detect/utils.py +260 -0
  17. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/detect/validator.py +170 -0
  18. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/engine/__init__.py +0 -0
  19. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/engine/dataset.py +129 -0
  20. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/engine/model.py +136 -0
  21. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/engine/trainer.py +201 -0
  22. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/engine/utils.py +33 -0
  23. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/engine/validator.py +464 -0
  24. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/overrides.py +42 -0
  25. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/segment/__init__.py +4 -0
  26. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/segment/trainer.py +57 -0
  27. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/segment/utils.py +96 -0
  28. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/segment/validator.py +108 -0
  29. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/settings.py +361 -0
  30. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/utils/__init__.py +16 -0
  31. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/utils/check_version.py +16 -0
  32. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/utils/dataset.py +206 -0
  33. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/utils/embeddings.py +30 -0
  34. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/utils/sampler.py +50 -0
  35. 3lc_ultralytics-0.1.0/src/tlc_ultralytics/utils/schemas.py +52 -0
@@ -0,0 +1,270 @@
1
+ Metadata-Version: 2.3
2
+ Name: 3lc-ultralytics
3
+ Version: 0.1.0
4
+ Summary: 3LC integration with Ultralytics YOLO
5
+ Author: 3LC
6
+ Author-email: 3LC <support@3lc.ai>
7
+ Requires-Dist: 3lc>=2.13.1,<=2.16.1
8
+ Requires-Dist: pacmap>=0.8.0
9
+ Requires-Dist: ultralytics>=8.3.146,<8.3.154
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+
13
+ <p align="center">
14
+ <img src="https://3lc.ai/wp-content/uploads/2023/09/3LC-Logo_Footer.svg">
15
+ </p>
16
+
17
+ <h1 align="center">3LC YOLO Integration</h1>
18
+
19
+ <div align="center">
20
+
21
+ ![PyPI](https://img.shields.io/pypi/v/3lc-ultralytics?logo=pypi&logoColor=white) [![Discord](https://img.shields.io/badge/discord-3LC-5865F2?logo=discord&logoColor=white)](https://discord.gg/fwnwFtfafC)
22
+
23
+ </div>
24
+
25
+ <p align="center">
26
+ <a href="#quick-start">Quick Start</a> •
27
+ <a href="#working-with-datasets">Working with Datasets</a> •
28
+ <a href="#task-specific-configuration">Task-Specific Configuration</a> •
29
+ <a href="#metrics-collection-only">Metrics Collection</a> •
30
+ <a href="#3lc-settings">3LC Settings</a> •
31
+ <a href="#frequently-asked-questions">FAQ</a>
32
+ </p>
33
+
34
+ <p align="center">
35
+ Ultralytics YOLO classification, object detection and segmentation with 3LC integrated.
36
+ </p>
37
+
38
+ ## About 3LC
39
+
40
+ [3LC](https://3lc.ai) is a tool which enables data scientists to improve machine learning models in a data-centric fashion. It collects per-sample predictions and metrics, allows viewing and modifying the dataset in the context of those predictions in the 3LC Dashboard, and rerunning training with the revised dataset.
41
+
42
+ 3LC is free for non-commercial use.
43
+
44
+ ![3LC Dashboard Overview](https://github.com/3lc-ai/ultralytics/blob/tlc-integration/ultralytics/utils/tlc/_static/dashboard.png?raw=true)
45
+
46
+ ## Quick Start
47
+
48
+ ### Installation
49
+
50
+ Install the package and requirements into a virtual environment:
51
+
52
+ ```bash
53
+ pip install 3lc-ultralytics
54
+ ```
55
+
56
+ ### Basic Training
57
+
58
+ Import `YOLO` from `tlc_ultralytics` and start training with 3LC integration:
59
+
60
+ ```python
61
+ from tlc_ultralytics import YOLO
62
+
63
+ model = YOLO("yolo11n.pt")
64
+ model.train(data="coco128.yaml", epochs=1)
65
+ ```
66
+
67
+ In the background, 3LC creates `tlc.Table`s for each split and a `tlc.Run`, which can be opened in the 3LC Dashboard.
68
+
69
+ ### Examples
70
+
71
+ Check out the [examples directory](examples/) for complete training and metrics collection examples for each supported task:
72
+
73
+ - **Classification**: [examples/classify/train.py](examples/classify/train.py) and [examples/classify/collect.py](examples/classify/collect.py)
74
+ - **Object Detection**: [examples/detect/train.py](examples/detect/train.py) and [examples/detect/collect.py](examples/detect/collect.py)
75
+ - **Segmentation**: [examples/detect/train.py](examples/segment/train.py) and [examples/detect/collect.py](examples/segment/collect.py)
76
+
77
+ ## Working with Datasets
78
+
79
+ The integration supports three ways of providing the data use. These are listed below:
80
+
81
+ <details open>
82
+ <summary><strong>Using 3LC Tables Directly (Recommended)</strong></summary>
83
+
84
+ The recommended way of providing the data to use is to pass `tlc.Table`s or `tlc.Url`s to `tlc.Table`s directly.
85
+
86
+ To learn how to create `tlc.Table`s for your dataset, check out the [examples directory](/examples/).
87
+
88
+ ```python
89
+ from tlc_ultralytics import YOLO
90
+
91
+ model = YOLO("yolo11n.pt")
92
+
93
+ # Using table instances
94
+ tables = {
95
+ "train": my_train_table,
96
+ "val": my_val_table
97
+ }
98
+ model.train(tables=tables)
99
+
100
+ # Using table URLs
101
+ tables = {
102
+ "train": "/url/or/path/to/train/table",
103
+ "val": "/url/or/path/to/val/table"
104
+ }
105
+ model.train(tables=tables, ...)
106
+ ```
107
+
108
+ When `tables` is provided, any value of `data` is ignored. In training, the table for the key `"train"` is used for training, and `"val"` or `"test"` for validation (val takes precedence).
109
+
110
+ </details>
111
+
112
+ <details>
113
+ <summary>Using Existing YOLO Datasets</summary>
114
+
115
+ Another alternative is to pass the argument `data` like in vanilla Ultralytics, pointing to a YOLO dataset YAML file. See the [Ultralytics Documentation](https://docs.ultralytics.com/datasets/) to learn more.
116
+
117
+ 3LC parses these datasets and creates `tlc.Table`s for each split, which can be viewed in the Dashboard. Once you make new versions of your data in the 3LC Dashboard, you can use the same command with `data=<path to your dataset>`, and the latest version will be used automatically. The integration will use default values for `project_name` (the name of the provided dataset yaml file, e.g. `"my_dataset"` for `"data=/path/to/my_dataset.yaml"`), `dataset_name` (the split, e.g. `"train"`) and `table_name` (`"initial"`).
118
+
119
+ </details>
120
+
121
+ <details>
122
+ <summary>Using 3LC YAML Files</summary>
123
+
124
+ The third and final way of providing the data is through what we call a 3LC YOLO YAML file. This is available in order to be compatible with the corresponding [YOLOv5 Integration](https://github.com/3lc-ai/yolov5).
125
+
126
+ Create a dataset YAML file, and provide the `tlc.Url` to each split in the file:
127
+
128
+ ```yaml
129
+ # my_dataset.yaml
130
+ train: /path/to/train/table
131
+ val: /path/to/val/table
132
+
133
+ # With versioning
134
+ train: /path/to/train/table:latest
135
+ val: s3://path/to/val/table
136
+ ```
137
+
138
+ Then use it with the `3LC://` prefix to specify that it is a 3LC YOLO YAML file:
139
+
140
+ ```python
141
+ from tlc_ultralytics import YOLO
142
+
143
+ model = YOLO("yolo11n.pt")
144
+ model.train(data="3LC://my_dataset.yaml")
145
+ ```
146
+
147
+ Note: `names` and `nc` are not needed since the `tlc.Table`s themselves contain the category names and indices.
148
+
149
+ </details>
150
+
151
+ ## Task-Specific Configuration
152
+
153
+ ### Classification
154
+
155
+ For image classification, you can provide `image_column_name` and `label_column_name` when calling `model.train()`, `model.val()` and `model.collect()` if you are providing your own table which has different column names to those expected by 3LC.
156
+
157
+ ### Object Detection
158
+
159
+ In addition to tables created with `Table.from_yolo()` (which is called internally when you provide a YOLO dataset), it is also possible to use tables with the COCO format used in the 3LC Detectron2 integration. If you have created 3LC tables in the Detectron2 integration, you can also use this `tlc.Table` in this integration!
160
+
161
+ ### Segmentation
162
+
163
+ Working with instance segmentation in the 3LC integration is similar to object detection. If you are using `tlc.Table.from_yolo()` to create your tables, make sure to pass `task="segment"`, as the default is `"detect"`.
164
+
165
+ For instance segmentation, you can provide `image_column_name` and `label_column_name` when calling `model.train()`, `model.val()` and `model.collect()` if you are providing your own table which has different column names to those expected by 3LC. Note that the `label_column_name` should be the path to the segmentation label field within the table schema, with the default being `"segmentations.instance_properties.label"` which points to the category labels for each segmentation instance.
166
+
167
+ ### Unsupported Tasks
168
+
169
+ Some YOLO tasks can not yet be visualized in the 3LC Dashboard, but these are on the roadmap and will be made available in the future:
170
+
171
+ - **Pose Estimation**: Not yet supported. Let us know on Discord if you would like this to be supported!
172
+ - **OBB (Oriented Object Detection)**: Not yet supported. Let us know on Discord if you would like this to be supported!
173
+
174
+ ## Metrics Collection Only
175
+
176
+ It is possible to create runs where only metrics collection, and no training, is performed. This is useful when you already have a trained model and would like to collect metrics, or if you would like to collect metrics on a different dataset to the one you trained and validated on.
177
+
178
+ Use the method `model.collect()` to perform metrics collection only. Either pass `data` (a path to a yaml file) and `splits` (an iterable of split names to collect metrics for), or a dictionary `tables` like detailed in the previous section, to define which data to collect metrics on. This will create a run, collect the metrics on each split by calling `model.val()` and finally reduce any embeddings that were collected. Any additional arguments, such as `imgsz` and `batch`, are forwarded as `model.val(**kwargs)`.
179
+
180
+ ### Example: Metrics Collection
181
+
182
+ ```python
183
+ from tlc_ultralytics import Settings, YOLO
184
+
185
+ model = YOLO("yolo11m.pt")
186
+
187
+ settings = Settings(
188
+ image_embeddings_dim=2,
189
+ conf_thres=0.2,
190
+ )
191
+
192
+ model.collect(
193
+ data="coco128.yaml",
194
+ splits=("train", "val"),
195
+ settings=settings,
196
+ batch=32,
197
+ imgsz=320
198
+ )
199
+ ```
200
+
201
+ See [examples/detect/collect.py](examples/detect/collect.py) for a complete metrics collection example.
202
+
203
+ ## 3LC Settings
204
+
205
+ The integration offers a rich set of settings and features which can be set through an instance of `Settings`, which are in addition to the regular YOLO settings. They allow specifying which metrics to collect, how often to collect them, and whether to use sampling weights during training.
206
+
207
+ The available 3LC settings can be seen in the `Settings` class in [settings.py](src/tlc_ultralytics/settings.py).
208
+
209
+ Providing invalid values (or combinations of values) will either log an appropriate warning or raise an error, depending on the case.
210
+
211
+ ### Image Embeddings
212
+
213
+ Image embeddings can be collected by setting `image_embeddings_dim` to 2 or 3. Similar images, as seen by the model, tend to be close to each other in this space. In the 3LC Dashboard these embeddings can be visualized, allowing you to find similar images, duplicates and imbalances in your dataset, and take appropriate actions to mitigate these issues.
214
+
215
+ The way in which embeddings are collected is different for the different tasks:
216
+
217
+ - **Classification**: The integration scans your model for the first occurrence of a `torch.nn.Linear` layer. The inputs to this layer are used to extract image embeddings.
218
+ - **Object Detection and Instance Segmentation**: The output of the spatial pooling function is used to extract embeddings.
219
+
220
+ You can change which `3lc`-supported reducer to use by setting `image_embeddings_reducer`. `pacmap` is the default.
221
+
222
+ ### Run Properties
223
+
224
+ Use `project_name`, `run_name` and `run_description` to customize the `tlc.Run` that is created. Any tables created by the integration will be under the `project_name` provided here. If these settings are not set, appropriate defaults are used instead.
225
+
226
+ ### Sampling Weights
227
+
228
+ Use `sampling_weights=True` to enable the usage of sampling weights. This resamples the data presented to the model according to the weight column in the `Table`. If a sample has weight 2.0, it is twice as likely to appear as a particular sample with weight 1.0. Any given sample can occur multiple times in one epoch. This setting only applies to training.
229
+
230
+ ### Exclude Zero Weight Samples
231
+
232
+ Use `exclude_zero_weight_training=True` (only applies to training) and `exclude_zero_weight_collection=True` to eliminate rows with weight 0.0. If your table has samples with weight 0.0, this will effectively reduce the size of the dataset (i.e. reduce the number of iterations per epoch).
233
+
234
+ ### Metrics Collection Settings
235
+
236
+ - **`collection_val_only=True`**: Disable metrics collection on the training set. This only applies to training.
237
+ - **`collection_disable=True`**: Disable metrics collection entirely. This only applies to training. A run will still be created, and hyperparameters and aggregate metrics will be logged to 3LC.
238
+ - **`collection_epoch_start` and `collection_epoch_interval`**: Define when to collect metrics during training. The start epoch is 1-based, i.e. 1 means after the first epoch. As an example, `collection_epoch_start=1` with `collection_epoch_interval=2` means metrics collection will occur after the first epoch and then every other epoch after that.
239
+
240
+ ## Dashboard Output
241
+
242
+ When viewing all your YOLO runs in the 3LC Dashboard, charts will show up with per-epoch aggregate metrics produced by YOLO for each run. This allows you to follow your runs in real-time, and compare them with each other.
243
+
244
+ # Frequently Asked Questions
245
+
246
+ ## What is the difference between before and after training metrics?
247
+
248
+ By default, the 3LC integration collects metrics only after training with the `best.pt` weights written by YOLO. These are the after training metrics.
249
+
250
+ If a starting metrics collection epoch is provided (optionally with an interval), metrics are also collected during training, this time with the exponential moving average that YOLO uses for its validation passes.
251
+
252
+ ## What happens if I use early stopping? Does it interfere with 3LC?
253
+
254
+ Early stopping can be used just like before. Unless metrics collection is disabled, final validation passes are performed over the train and validation sets after training, regardless of whether that is due to early stopping or completing all the epochs.
255
+
256
+ ## Why is embeddings collection disabled by default?
257
+
258
+ Embeddings collection has an extra dependency for the library used for reduction, and a performance implication (fitting and applying the reducer) at the end of a run. It is therefore disabled by default.
259
+
260
+ ## How do I collect embeddings for each bounding box?
261
+
262
+ In order to collect embeddings (or other additional metrics) for each bounding box, refer to the [advanced 3LC examples](https://github.com/3lc-ai/3lc-examples/tree/main/tutorials/5-advanced-examples).
263
+
264
+ ## Can I use the Ultralytics YOLO CLI commands in the integration to train and collect metrics?
265
+
266
+ This is not supported yet, but will be added in a future commit!
267
+
268
+ ## Why is the 3LC integration pinned to just a few versions of `Ultralytics`?
269
+
270
+ Ultralytics makes changes to the internals of the `ultralytics` codebase, which occasionally breaks the 3LC integration. It is therefore pinned to versions which are known to work with the integration.
@@ -0,0 +1,258 @@
1
+ <p align="center">
2
+ <img src="https://3lc.ai/wp-content/uploads/2023/09/3LC-Logo_Footer.svg">
3
+ </p>
4
+
5
+ <h1 align="center">3LC YOLO Integration</h1>
6
+
7
+ <div align="center">
8
+
9
+ ![PyPI](https://img.shields.io/pypi/v/3lc-ultralytics?logo=pypi&logoColor=white) [![Discord](https://img.shields.io/badge/discord-3LC-5865F2?logo=discord&logoColor=white)](https://discord.gg/fwnwFtfafC)
10
+
11
+ </div>
12
+
13
+ <p align="center">
14
+ <a href="#quick-start">Quick Start</a> •
15
+ <a href="#working-with-datasets">Working with Datasets</a> •
16
+ <a href="#task-specific-configuration">Task-Specific Configuration</a> •
17
+ <a href="#metrics-collection-only">Metrics Collection</a> •
18
+ <a href="#3lc-settings">3LC Settings</a> •
19
+ <a href="#frequently-asked-questions">FAQ</a>
20
+ </p>
21
+
22
+ <p align="center">
23
+ Ultralytics YOLO classification, object detection and segmentation with 3LC integrated.
24
+ </p>
25
+
26
+ ## About 3LC
27
+
28
+ [3LC](https://3lc.ai) is a tool which enables data scientists to improve machine learning models in a data-centric fashion. It collects per-sample predictions and metrics, allows viewing and modifying the dataset in the context of those predictions in the 3LC Dashboard, and rerunning training with the revised dataset.
29
+
30
+ 3LC is free for non-commercial use.
31
+
32
+ ![3LC Dashboard Overview](https://github.com/3lc-ai/ultralytics/blob/tlc-integration/ultralytics/utils/tlc/_static/dashboard.png?raw=true)
33
+
34
+ ## Quick Start
35
+
36
+ ### Installation
37
+
38
+ Install the package and requirements into a virtual environment:
39
+
40
+ ```bash
41
+ pip install 3lc-ultralytics
42
+ ```
43
+
44
+ ### Basic Training
45
+
46
+ Import `YOLO` from `tlc_ultralytics` and start training with 3LC integration:
47
+
48
+ ```python
49
+ from tlc_ultralytics import YOLO
50
+
51
+ model = YOLO("yolo11n.pt")
52
+ model.train(data="coco128.yaml", epochs=1)
53
+ ```
54
+
55
+ In the background, 3LC creates `tlc.Table`s for each split and a `tlc.Run`, which can be opened in the 3LC Dashboard.
56
+
57
+ ### Examples
58
+
59
+ Check out the [examples directory](examples/) for complete training and metrics collection examples for each supported task:
60
+
61
+ - **Classification**: [examples/classify/train.py](examples/classify/train.py) and [examples/classify/collect.py](examples/classify/collect.py)
62
+ - **Object Detection**: [examples/detect/train.py](examples/detect/train.py) and [examples/detect/collect.py](examples/detect/collect.py)
63
+ - **Segmentation**: [examples/detect/train.py](examples/segment/train.py) and [examples/detect/collect.py](examples/segment/collect.py)
64
+
65
+ ## Working with Datasets
66
+
67
+ The integration supports three ways of providing the data use. These are listed below:
68
+
69
+ <details open>
70
+ <summary><strong>Using 3LC Tables Directly (Recommended)</strong></summary>
71
+
72
+ The recommended way of providing the data to use is to pass `tlc.Table`s or `tlc.Url`s to `tlc.Table`s directly.
73
+
74
+ To learn how to create `tlc.Table`s for your dataset, check out the [examples directory](/examples/).
75
+
76
+ ```python
77
+ from tlc_ultralytics import YOLO
78
+
79
+ model = YOLO("yolo11n.pt")
80
+
81
+ # Using table instances
82
+ tables = {
83
+ "train": my_train_table,
84
+ "val": my_val_table
85
+ }
86
+ model.train(tables=tables)
87
+
88
+ # Using table URLs
89
+ tables = {
90
+ "train": "/url/or/path/to/train/table",
91
+ "val": "/url/or/path/to/val/table"
92
+ }
93
+ model.train(tables=tables, ...)
94
+ ```
95
+
96
+ When `tables` is provided, any value of `data` is ignored. In training, the table for the key `"train"` is used for training, and `"val"` or `"test"` for validation (val takes precedence).
97
+
98
+ </details>
99
+
100
+ <details>
101
+ <summary>Using Existing YOLO Datasets</summary>
102
+
103
+ Another alternative is to pass the argument `data` like in vanilla Ultralytics, pointing to a YOLO dataset YAML file. See the [Ultralytics Documentation](https://docs.ultralytics.com/datasets/) to learn more.
104
+
105
+ 3LC parses these datasets and creates `tlc.Table`s for each split, which can be viewed in the Dashboard. Once you make new versions of your data in the 3LC Dashboard, you can use the same command with `data=<path to your dataset>`, and the latest version will be used automatically. The integration will use default values for `project_name` (the name of the provided dataset yaml file, e.g. `"my_dataset"` for `"data=/path/to/my_dataset.yaml"`), `dataset_name` (the split, e.g. `"train"`) and `table_name` (`"initial"`).
106
+
107
+ </details>
108
+
109
+ <details>
110
+ <summary>Using 3LC YAML Files</summary>
111
+
112
+ The third and final way of providing the data is through what we call a 3LC YOLO YAML file. This is available in order to be compatible with the corresponding [YOLOv5 Integration](https://github.com/3lc-ai/yolov5).
113
+
114
+ Create a dataset YAML file, and provide the `tlc.Url` to each split in the file:
115
+
116
+ ```yaml
117
+ # my_dataset.yaml
118
+ train: /path/to/train/table
119
+ val: /path/to/val/table
120
+
121
+ # With versioning
122
+ train: /path/to/train/table:latest
123
+ val: s3://path/to/val/table
124
+ ```
125
+
126
+ Then use it with the `3LC://` prefix to specify that it is a 3LC YOLO YAML file:
127
+
128
+ ```python
129
+ from tlc_ultralytics import YOLO
130
+
131
+ model = YOLO("yolo11n.pt")
132
+ model.train(data="3LC://my_dataset.yaml")
133
+ ```
134
+
135
+ Note: `names` and `nc` are not needed since the `tlc.Table`s themselves contain the category names and indices.
136
+
137
+ </details>
138
+
139
+ ## Task-Specific Configuration
140
+
141
+ ### Classification
142
+
143
+ For image classification, you can provide `image_column_name` and `label_column_name` when calling `model.train()`, `model.val()` and `model.collect()` if you are providing your own table which has different column names to those expected by 3LC.
144
+
145
+ ### Object Detection
146
+
147
+ In addition to tables created with `Table.from_yolo()` (which is called internally when you provide a YOLO dataset), it is also possible to use tables with the COCO format used in the 3LC Detectron2 integration. If you have created 3LC tables in the Detectron2 integration, you can also use this `tlc.Table` in this integration!
148
+
149
+ ### Segmentation
150
+
151
+ Working with instance segmentation in the 3LC integration is similar to object detection. If you are using `tlc.Table.from_yolo()` to create your tables, make sure to pass `task="segment"`, as the default is `"detect"`.
152
+
153
+ For instance segmentation, you can provide `image_column_name` and `label_column_name` when calling `model.train()`, `model.val()` and `model.collect()` if you are providing your own table which has different column names to those expected by 3LC. Note that the `label_column_name` should be the path to the segmentation label field within the table schema, with the default being `"segmentations.instance_properties.label"` which points to the category labels for each segmentation instance.
154
+
155
+ ### Unsupported Tasks
156
+
157
+ Some YOLO tasks can not yet be visualized in the 3LC Dashboard, but these are on the roadmap and will be made available in the future:
158
+
159
+ - **Pose Estimation**: Not yet supported. Let us know on Discord if you would like this to be supported!
160
+ - **OBB (Oriented Object Detection)**: Not yet supported. Let us know on Discord if you would like this to be supported!
161
+
162
+ ## Metrics Collection Only
163
+
164
+ It is possible to create runs where only metrics collection, and no training, is performed. This is useful when you already have a trained model and would like to collect metrics, or if you would like to collect metrics on a different dataset to the one you trained and validated on.
165
+
166
+ Use the method `model.collect()` to perform metrics collection only. Either pass `data` (a path to a yaml file) and `splits` (an iterable of split names to collect metrics for), or a dictionary `tables` like detailed in the previous section, to define which data to collect metrics on. This will create a run, collect the metrics on each split by calling `model.val()` and finally reduce any embeddings that were collected. Any additional arguments, such as `imgsz` and `batch`, are forwarded as `model.val(**kwargs)`.
167
+
168
+ ### Example: Metrics Collection
169
+
170
+ ```python
171
+ from tlc_ultralytics import Settings, YOLO
172
+
173
+ model = YOLO("yolo11m.pt")
174
+
175
+ settings = Settings(
176
+ image_embeddings_dim=2,
177
+ conf_thres=0.2,
178
+ )
179
+
180
+ model.collect(
181
+ data="coco128.yaml",
182
+ splits=("train", "val"),
183
+ settings=settings,
184
+ batch=32,
185
+ imgsz=320
186
+ )
187
+ ```
188
+
189
+ See [examples/detect/collect.py](examples/detect/collect.py) for a complete metrics collection example.
190
+
191
+ ## 3LC Settings
192
+
193
+ The integration offers a rich set of settings and features which can be set through an instance of `Settings`, which are in addition to the regular YOLO settings. They allow specifying which metrics to collect, how often to collect them, and whether to use sampling weights during training.
194
+
195
+ The available 3LC settings can be seen in the `Settings` class in [settings.py](src/tlc_ultralytics/settings.py).
196
+
197
+ Providing invalid values (or combinations of values) will either log an appropriate warning or raise an error, depending on the case.
198
+
199
+ ### Image Embeddings
200
+
201
+ Image embeddings can be collected by setting `image_embeddings_dim` to 2 or 3. Similar images, as seen by the model, tend to be close to each other in this space. In the 3LC Dashboard these embeddings can be visualized, allowing you to find similar images, duplicates and imbalances in your dataset, and take appropriate actions to mitigate these issues.
202
+
203
+ The way in which embeddings are collected is different for the different tasks:
204
+
205
+ - **Classification**: The integration scans your model for the first occurrence of a `torch.nn.Linear` layer. The inputs to this layer are used to extract image embeddings.
206
+ - **Object Detection and Instance Segmentation**: The output of the spatial pooling function is used to extract embeddings.
207
+
208
+ You can change which `3lc`-supported reducer to use by setting `image_embeddings_reducer`. `pacmap` is the default.
209
+
210
+ ### Run Properties
211
+
212
+ Use `project_name`, `run_name` and `run_description` to customize the `tlc.Run` that is created. Any tables created by the integration will be under the `project_name` provided here. If these settings are not set, appropriate defaults are used instead.
213
+
214
+ ### Sampling Weights
215
+
216
+ Use `sampling_weights=True` to enable the usage of sampling weights. This resamples the data presented to the model according to the weight column in the `Table`. If a sample has weight 2.0, it is twice as likely to appear as a particular sample with weight 1.0. Any given sample can occur multiple times in one epoch. This setting only applies to training.
217
+
218
+ ### Exclude Zero Weight Samples
219
+
220
+ Use `exclude_zero_weight_training=True` (only applies to training) and `exclude_zero_weight_collection=True` to eliminate rows with weight 0.0. If your table has samples with weight 0.0, this will effectively reduce the size of the dataset (i.e. reduce the number of iterations per epoch).
221
+
222
+ ### Metrics Collection Settings
223
+
224
+ - **`collection_val_only=True`**: Disable metrics collection on the training set. This only applies to training.
225
+ - **`collection_disable=True`**: Disable metrics collection entirely. This only applies to training. A run will still be created, and hyperparameters and aggregate metrics will be logged to 3LC.
226
+ - **`collection_epoch_start` and `collection_epoch_interval`**: Define when to collect metrics during training. The start epoch is 1-based, i.e. 1 means after the first epoch. As an example, `collection_epoch_start=1` with `collection_epoch_interval=2` means metrics collection will occur after the first epoch and then every other epoch after that.
227
+
228
+ ## Dashboard Output
229
+
230
+ When viewing all your YOLO runs in the 3LC Dashboard, charts will show up with per-epoch aggregate metrics produced by YOLO for each run. This allows you to follow your runs in real-time, and compare them with each other.
231
+
232
+ # Frequently Asked Questions
233
+
234
+ ## What is the difference between before and after training metrics?
235
+
236
+ By default, the 3LC integration collects metrics only after training with the `best.pt` weights written by YOLO. These are the after training metrics.
237
+
238
+ If a starting metrics collection epoch is provided (optionally with an interval), metrics are also collected during training, this time with the exponential moving average that YOLO uses for its validation passes.
239
+
240
+ ## What happens if I use early stopping? Does it interfere with 3LC?
241
+
242
+ Early stopping can be used just like before. Unless metrics collection is disabled, final validation passes are performed over the train and validation sets after training, regardless of whether that is due to early stopping or completing all the epochs.
243
+
244
+ ## Why is embeddings collection disabled by default?
245
+
246
+ Embeddings collection has an extra dependency for the library used for reduction, and a performance implication (fitting and applying the reducer) at the end of a run. It is therefore disabled by default.
247
+
248
+ ## How do I collect embeddings for each bounding box?
249
+
250
+ In order to collect embeddings (or other additional metrics) for each bounding box, refer to the [advanced 3LC examples](https://github.com/3lc-ai/3lc-examples/tree/main/tutorials/5-advanced-examples).
251
+
252
+ ## Can I use the Ultralytics YOLO CLI commands in the integration to train and collect metrics?
253
+
254
+ This is not supported yet, but will be added in a future commit!
255
+
256
+ ## Why is the 3LC integration pinned to just a few versions of `Ultralytics`?
257
+
258
+ Ultralytics makes changes to the internals of the `ultralytics` codebase, which occasionally breaks the 3LC integration. It is therefore pinned to versions which are known to work with the integration.
@@ -0,0 +1,42 @@
1
+ [project]
2
+ name = "3lc-ultralytics"
3
+ version = "0.1.0"
4
+ description = "3LC integration with Ultralytics YOLO"
5
+ readme = "README.md"
6
+ authors = [
7
+ {name = "3LC", email = "support@3lc.ai"},
8
+ ]
9
+ requires-python = ">=3.9"
10
+ dependencies = [
11
+ "3lc>=2.13.1,<=2.16.1",
12
+ "pacmap>=0.8.0",
13
+ "ultralytics>=8.3.146,<8.3.154",
14
+ ]
15
+
16
+ [build]
17
+ includes = [
18
+ "src/tlc_ultralytics",
19
+ ]
20
+
21
+ [build-system]
22
+ requires = ["uv_build>=0.7.19,<0.8.0"]
23
+ build-backend = "uv_build"
24
+
25
+ [tool.uv.build-backend]
26
+ module-name = "tlc_ultralytics"
27
+
28
+ [dependency-groups]
29
+ dev = [
30
+ "pytest>=8.3.5",
31
+ "pytest-xdist>=3.8.0",
32
+ "ruff>=0.11.11",
33
+ ]
34
+
35
+ [tool.uv]
36
+ default-groups = ["dev"]
37
+ required-version = ">=0.7.19"
38
+
39
+ [tool.uv.sources]
40
+ "3lc" = [
41
+ { path = "../tlc-monorepo", editable=true },
42
+ ]
@@ -0,0 +1,23 @@
1
+ # ruff: noqa: E402
2
+
3
+ import random
4
+
5
+ import sentry_sdk
6
+
7
+ sentry_sdk.profiler.transaction_profiler.random = random.Random()
8
+
9
+ from importlib.metadata import PackageNotFoundError, version
10
+
11
+ from tlc_ultralytics.engine.model import TLCYOLO, YOLO
12
+ from tlc_ultralytics.settings import Settings
13
+
14
+ try:
15
+ __version__ = version("3lc-ultralytics")
16
+ except PackageNotFoundError:
17
+ __version__ = "unknown"
18
+
19
+ __all__ = [
20
+ "TLCYOLO",
21
+ "YOLO",
22
+ "Settings",
23
+ ]
@@ -0,0 +1,4 @@
1
+ from .trainer import TLCClassificationTrainer
2
+ from .validator import TLCClassificationValidator
3
+
4
+ __all__ = ["TLCClassificationTrainer", "TLCClassificationValidator"]