edgefirst-validator 4.2.1__py3-none-any.whl

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 (73) hide show
  1. deepview/modelpack/utils/argmax.py +16 -0
  2. edgefirst/validator/__init__.py +1 -0
  3. edgefirst/validator/__main__.py +375 -0
  4. edgefirst/validator/datasets/__init__.py +118 -0
  5. edgefirst/validator/datasets/cache.py +296 -0
  6. edgefirst/validator/datasets/core.py +250 -0
  7. edgefirst/validator/datasets/darknet.py +446 -0
  8. edgefirst/validator/datasets/database.py +1067 -0
  9. edgefirst/validator/datasets/instance/__init__.py +4 -0
  10. edgefirst/validator/datasets/instance/core.py +222 -0
  11. edgefirst/validator/datasets/instance/detection.py +145 -0
  12. edgefirst/validator/datasets/instance/multitask.py +80 -0
  13. edgefirst/validator/datasets/instance/segmentation.py +120 -0
  14. edgefirst/validator/datasets/utils/fetch.py +682 -0
  15. edgefirst/validator/datasets/utils/readers.py +425 -0
  16. edgefirst/validator/datasets/utils/transformations.py +1695 -0
  17. edgefirst/validator/evaluators/__init__.py +17 -0
  18. edgefirst/validator/evaluators/callbacks/__init__.py +3 -0
  19. edgefirst/validator/evaluators/callbacks/core.py +192 -0
  20. edgefirst/validator/evaluators/callbacks/plots.py +900 -0
  21. edgefirst/validator/evaluators/callbacks/studio.py +234 -0
  22. edgefirst/validator/evaluators/core.py +257 -0
  23. edgefirst/validator/evaluators/detection.py +749 -0
  24. edgefirst/validator/evaluators/multitask.py +270 -0
  25. edgefirst/validator/evaluators/parameters/__init__.py +53 -0
  26. edgefirst/validator/evaluators/parameters/core.py +554 -0
  27. edgefirst/validator/evaluators/parameters/dataset.py +239 -0
  28. edgefirst/validator/evaluators/parameters/model.py +338 -0
  29. edgefirst/validator/evaluators/parameters/validation.py +528 -0
  30. edgefirst/validator/evaluators/segmentation.py +729 -0
  31. edgefirst/validator/evaluators/utils/__init__.py +3 -0
  32. edgefirst/validator/evaluators/utils/classify.py +292 -0
  33. edgefirst/validator/evaluators/utils/match.py +262 -0
  34. edgefirst/validator/evaluators/utils/timer.py +132 -0
  35. edgefirst/validator/metrics/__init__.py +9 -0
  36. edgefirst/validator/metrics/data/__init__.py +7 -0
  37. edgefirst/validator/metrics/data/label.py +668 -0
  38. edgefirst/validator/metrics/data/metrics.py +759 -0
  39. edgefirst/validator/metrics/data/plots.py +476 -0
  40. edgefirst/validator/metrics/data/stats.py +507 -0
  41. edgefirst/validator/metrics/detection.py +595 -0
  42. edgefirst/validator/metrics/segmentation.py +173 -0
  43. edgefirst/validator/metrics/utils/math.py +717 -0
  44. edgefirst/validator/publishers/__init__.py +3 -0
  45. edgefirst/validator/publishers/console.py +147 -0
  46. edgefirst/validator/publishers/studio.py +128 -0
  47. edgefirst/validator/publishers/tensorboard.py +119 -0
  48. edgefirst/validator/publishers/utils/logger.py +111 -0
  49. edgefirst/validator/publishers/utils/table.py +403 -0
  50. edgefirst/validator/runners/__init__.py +8 -0
  51. edgefirst/validator/runners/core.py +727 -0
  52. edgefirst/validator/runners/deepviewrt.py +177 -0
  53. edgefirst/validator/runners/hailo.py +263 -0
  54. edgefirst/validator/runners/keras.py +150 -0
  55. edgefirst/validator/runners/kinara.py +265 -0
  56. edgefirst/validator/runners/offline.py +228 -0
  57. edgefirst/validator/runners/onnx.py +241 -0
  58. edgefirst/validator/runners/processing/decode.py +320 -0
  59. edgefirst/validator/runners/processing/dvapi.py +4192 -0
  60. edgefirst/validator/runners/processing/nms.py +637 -0
  61. edgefirst/validator/runners/processing/outputs.py +507 -0
  62. edgefirst/validator/runners/tensorrt.py +321 -0
  63. edgefirst/validator/runners/tflite.py +221 -0
  64. edgefirst/validator/validate.py +843 -0
  65. edgefirst/validator/visualize/__init__.py +3 -0
  66. edgefirst/validator/visualize/detection.py +623 -0
  67. edgefirst/validator/visualize/segmentation.py +281 -0
  68. edgefirst/validator/visualize/utils/plots.py +635 -0
  69. edgefirst_validator-4.2.1.dist-info/METADATA +111 -0
  70. edgefirst_validator-4.2.1.dist-info/RECORD +73 -0
  71. edgefirst_validator-4.2.1.dist-info/WHEEL +5 -0
  72. edgefirst_validator-4.2.1.dist-info/entry_points.txt +2 -0
  73. edgefirst_validator-4.2.1.dist-info/top_level.txt +2 -0
@@ -0,0 +1,528 @@
1
+ import os
2
+
3
+ from edgefirst.validator.datasets.utils.transformations import clamp
4
+ from edgefirst.validator.publishers.utils.logger import set_silent_condition
5
+
6
+
7
+ class ValidationParameters:
8
+ """
9
+ Container for validation parameters used for
10
+ specifying additional settings for validation.
11
+
12
+ Parameters
13
+ ----------
14
+ method: str
15
+ Reproducing validation results reported by Ultralytics by default. Specify
16
+ validation method seen in other sources such as YOLOv7. Options could
17
+ be "ultralytics" for the official validator from Ultralytics which
18
+ supports YOLOv5, YOLOv8, and YOLOv11. However, there are variations
19
+ such as "yolov7" for YOLOv7 and "edgefirst" for internal Au-Zone implementations.
20
+ iou_threshold: float
21
+ This is the threshold for the validation IoU which distinguish
22
+ matched detections as either true positives or localization
23
+ false positives. Localization false positives have an IoU below this
24
+ threshold. Default is set to 0.50.
25
+ score_threshold: float
26
+ This is the threshold for validation score which provides
27
+ extra score filtering of the predictions.
28
+ metric: str
29
+ The type of metric to use in the matching algorithm. Options could
30
+ be one of the following: "iou" or "centerpoint". Using either the
31
+ intersection over union with highest overlap as being the best matches
32
+ or centerpoint distance with the closest distance being the best matches.
33
+ Default is set to "iou".
34
+ matching_leniency: int
35
+ Distance metric to be considered a valid match when using the "centerpoint"
36
+ metric. Default is 2 where the distance is no more than twice the
37
+ size of the bounding box.
38
+ clamp_boxes: int
39
+ Clamp bounding boxes for the minimum size as this value set. By default
40
+ this setting is not specified.
41
+ ignore_boxes: int
42
+ Ignore bounding boxes with sizes less than this value set. By default
43
+ this setting is not specified.
44
+ display: int
45
+ Specify the limit of the number of visualization results to display.
46
+ By default it is set to -1 which means all samples in the dataset.
47
+ plots: bool
48
+ Specify whether to save the validation plots. This is only effective
49
+ when setting the visualization or the tensorboard parameters to a path.
50
+ By default it is set to True which means to save the plots.
51
+ silent: bool
52
+ Specify whether to suppress validation updates on the terminal. This is
53
+ useful when using the validator as an API to prevent any output messages.
54
+ visualize: str
55
+ Specify the path to store the validation results in disk.
56
+ tensorboard: str
57
+ Specify the path to output the tensorboard file for visualization
58
+ using tensorboar.d
59
+ json_out: str
60
+ Specify the path to output the JSON files storing the validation results.
61
+ csv_out: str
62
+ Specify the path to output a CSV file containing the metrics. If the
63
+ path already exists, then a new row is added to the contents of
64
+ the CSV file.
65
+ include_background: bool
66
+ For segmentation validation, specifying to True includes the background
67
+ class in the metrics which will ultimately increase the metric outcomes
68
+ since most of the pixels in the image are from the background class.
69
+ **kwargs: dict
70
+ Define extra arguments as part of the validation parameters.
71
+ """
72
+
73
+ def __init__(
74
+ self,
75
+ method: str = "ultralytics",
76
+ iou_threshold: float = 0.50,
77
+ score_threshold: float = 0.00,
78
+ metric: str = "iou",
79
+ matching_leniency: int = 2,
80
+ clamp_boxes: int = None,
81
+ ignore_boxes: int = None,
82
+ display: int = -1,
83
+ plots: bool = True,
84
+ silent: bool = False,
85
+ visualize: str = None,
86
+ tensorboard: str = None,
87
+ json_out: str = None,
88
+ csv_out: str = None,
89
+ include_background: bool = False,
90
+ **kwargs: dict
91
+ ):
92
+ self.__method = method.lower()
93
+ self.__iou_threshold = iou_threshold
94
+ self.__score_threshold = score_threshold
95
+ self.__metric = metric.lower()
96
+ self.__matching_leniency = matching_leniency
97
+ self.__clamp_boxes = clamp_boxes
98
+ self.__ignore_boxes = ignore_boxes
99
+ self.__display = display
100
+ self.__plots = plots
101
+ self.__silent = silent
102
+ self.__visualize = visualize
103
+ self.__tensorboard = tensorboard
104
+ self.__json_out = json_out
105
+ self.__csv_out = csv_out
106
+ self.__include_background = include_background
107
+
108
+ if visualize:
109
+ os.makedirs(visualize, exist_ok=True)
110
+
111
+ if tensorboard:
112
+ os.makedirs(tensorboard, exist_ok=True)
113
+
114
+ if json_out:
115
+ os.makedirs(json_out, exist_ok=True)
116
+
117
+ if csv_out:
118
+ dir_path = os.path.dirname(csv_out)
119
+ if dir_path:
120
+ os.makedirs(dir_path, exist_ok=True)
121
+
122
+ @property
123
+ def method(self) -> str:
124
+ """
125
+ Attribute to access validation methods.
126
+ Specifies the validation method to
127
+ reproduce in EdgeFirst Validator. By default the "ultralytics" methods
128
+ seen in YOLOv5, YOLOv8, and YOLOv11 are used. However, other variations
129
+ such as "yolov7" from YOLOv7 and "edgefirst" for internal Au-Zone
130
+ implementations are also possible.
131
+ """
132
+ return self.__method
133
+
134
+ @method.setter
135
+ def method(self, methods: str):
136
+ """
137
+ Sets the validation method.
138
+
139
+ Parameters
140
+ ----------
141
+ methods: str
142
+ The validation method to reproduce.
143
+ Options include "ultralytics", "yolov7", or "edgefirst".
144
+ """
145
+ self.__method = methods.lower() if methods is not None else methods
146
+
147
+ @property
148
+ def iou_threshold(self) -> float:
149
+ """
150
+ Attribute to access the validation IoU threshold.
151
+ This metric is used to classify matched detections as either
152
+ true positives or false positives. Detections with IoUs below this
153
+ threshold will be classified as localization false positives.
154
+
155
+ Returns
156
+ -------
157
+ float:
158
+ The validation IoU threshold.
159
+ """
160
+ return self.__iou_threshold
161
+
162
+ @iou_threshold.setter
163
+ def iou_threshold(self, iou: float):
164
+ """
165
+ Sets the validation IoU threshold.
166
+
167
+ Parameters
168
+ ----------
169
+ iou: float
170
+ The validation IoU threshold to set.
171
+ """
172
+ self.__iou_threshold = clamp(iou)
173
+
174
+ @property
175
+ def score_threshold(self) -> float:
176
+ """
177
+ Attribute to access the validation score threshold.
178
+ This metric is used as an extra filter of the score threshold
179
+ by keeping predictions with scores greater than or equal to this
180
+ set threshold.
181
+
182
+ Returns
183
+ -------
184
+ float:
185
+ The validation score threshold.
186
+ """
187
+ return self.__score_threshold
188
+
189
+ @score_threshold.setter
190
+ def score_threshold(self, score: float):
191
+ """
192
+ Sets the validation score threshold.
193
+
194
+ Parameters
195
+ ----------
196
+ iou: float
197
+ The validation score threshold to set.
198
+ """
199
+ self.__score_threshold = clamp(score)
200
+
201
+ @property
202
+ def metric(self) -> str:
203
+ """
204
+ Attribute to access the metric type.
205
+ This parameter is used to define which metric ("iou", "centerpoint")
206
+ to use to match the predictions to ground truth.
207
+
208
+ Returns
209
+ -------
210
+ str
211
+ The metric type.
212
+ """
213
+ return self.__metric
214
+
215
+ @metric.setter
216
+ def metric(self, this_metric: str):
217
+ """
218
+ Sets the metric type.
219
+
220
+ Parameters
221
+ ----------
222
+ this_metric: str
223
+ The metric to set.
224
+ """
225
+ self.__metric = (this_metric.lower() if
226
+ this_metric is not None else this_metric)
227
+
228
+ @property
229
+ def matching_leniency(self) -> int:
230
+ """
231
+ Attribute to access the leniency factor
232
+ for center distance calculations.
233
+
234
+ Returns
235
+ -------
236
+ int
237
+ The leniency factor. This is a criteria to consider
238
+ center distances if the number of times the diagonal
239
+ (center to corner) of the smallest bounding box fits within the
240
+ box to box center distance does not exceed the leniency factor.
241
+
242
+ """
243
+ return self.__matching_leniency
244
+
245
+ @matching_leniency.setter
246
+ def matching_leniency(self, leniency_factor: int):
247
+ """
248
+ Sets the leniency factor. This is a criteria to consider
249
+ center distances if the number of times the diagonal
250
+ (center to corner) of the smallest bounding box fits within the
251
+ box to box center distance does not exceed the leniency factor.
252
+
253
+ Parameters
254
+ ----------
255
+ leniency_factor: int
256
+ The leniency_factor to set.
257
+ """
258
+ self.__matching_leniency = leniency_factor
259
+
260
+ @property
261
+ def clamp_boxes(self) -> int:
262
+ """
263
+ Attribute to access clamp boxes.
264
+ This is used to specify the lowest limit for the
265
+ box dimensions in pixels. Any box dimensions (height or width)
266
+ lower than this setting will be resized to this setting.
267
+
268
+ Returns
269
+ -------
270
+ int
271
+ The pixel dimension to clamp.
272
+ """
273
+ return self.__clamp_boxes
274
+
275
+ @clamp_boxes.setter
276
+ def clamp_boxes(self, this_clamp_boxes: int):
277
+ """
278
+ Sets the clamp boxes.
279
+
280
+ Parameters
281
+ ----------
282
+ this_clamp_boxes: int
283
+ The clamp_boxes to set.
284
+ """
285
+ self.__clamp_boxes = this_clamp_boxes
286
+
287
+ @property
288
+ def ignore_boxes(self) -> int:
289
+ """
290
+ Attribute to access ignore boxes.
291
+ Any box dimension (width or height) lower than this limit
292
+ will be ignored from validation.
293
+
294
+ Returns
295
+ -------
296
+ int
297
+ The pixel dimension to ignore.
298
+ """
299
+ return self.__ignore_boxes
300
+
301
+ @ignore_boxes.setter
302
+ def ignore_boxes(self, this_ignore_boxes: int):
303
+ """
304
+ Sets the ignore boxes.
305
+
306
+ Parameters
307
+ ----------
308
+ this_ignore_boxes: int
309
+ The ignore_boxes to set.
310
+ """
311
+ self.__ignore_boxes = this_ignore_boxes
312
+
313
+ @property
314
+ def display(self) -> int:
315
+ """
316
+ Attribute to access display.
317
+ Set the number of images to display showing results for validation.
318
+
319
+ Returns
320
+ -------
321
+ int
322
+ The number of images to display.
323
+ """
324
+ return self.__display
325
+
326
+ @display.setter
327
+ def display(self, this_display: int):
328
+ """
329
+ Sets the number of images to display.
330
+
331
+ Parameters
332
+ ----------
333
+ this_display: int
334
+ The display to set.
335
+ """
336
+ self.__display = this_display
337
+
338
+ @property
339
+ def plots(self) -> bool:
340
+ """
341
+ Attribute to access plots.
342
+ Specify whether to draw validation plots or not.
343
+ Validation plots include: Confusion Matrix, PR-curve, and
344
+ classification histogram.
345
+
346
+ Returns
347
+ -------
348
+ bool
349
+ Condition to include plots.
350
+ """
351
+ return self.__plots
352
+
353
+ @plots.setter
354
+ def plots(self, this_plots: bool):
355
+ """
356
+ Specify to include validation plots.
357
+
358
+ Parameters
359
+ ----------
360
+ this_plots: bool
361
+ The plots to set.
362
+ """
363
+ self.__plots = this_plots
364
+
365
+ @property
366
+ def silent(self) -> bool:
367
+ """
368
+ Attribute to access the display flag.
369
+ This is a flag to determine whether messages
370
+ are printed to console. Does not print when silent is True.
371
+
372
+ Returns
373
+ -------
374
+ bool
375
+ Condition to disable validation logging.
376
+ """
377
+ return self.__silent
378
+
379
+ @silent.setter
380
+ def silent(self, silent: bool):
381
+ """
382
+ Sets a flag to determine whether messages are printed to console.
383
+ Does not print when silent is True.
384
+
385
+ Parameters
386
+ ----------
387
+ silent: bool
388
+ This is the condition to disable validation logging.
389
+ """
390
+ self.__silent = silent
391
+ set_silent_condition(silent)
392
+
393
+ @property
394
+ def visualize(self) -> str:
395
+ """
396
+ Attribute to access the visualize.
397
+ This is the path to store the validation results which
398
+ includes images.
399
+
400
+ Returns
401
+ -------
402
+ str
403
+ The path to save validation results.
404
+ """
405
+ return self.__visualize
406
+
407
+ @visualize.setter
408
+ def visualize(self, this_visualize: str):
409
+ """
410
+ Sets the path to save the validation results in disk.
411
+
412
+ Parameters
413
+ ----------
414
+ this_visualize: str
415
+ The visualize to set.
416
+ """
417
+ os.makedirs(this_visualize, exist_ok=True)
418
+ self.__visualize = this_visualize
419
+
420
+ @property
421
+ def tensorboard(self) -> str:
422
+ """
423
+ Attribute to access the tensorboard.
424
+ This is the path to store the validation results which includes
425
+ tfevent files to be loaded using tensorboard.
426
+
427
+ Returns
428
+ -------
429
+ str
430
+ The path to save validation results.
431
+ """
432
+ return self.__tensorboard
433
+
434
+ @tensorboard.setter
435
+ def tensorboard(self, this_tensorboard: str):
436
+ """
437
+ Sets the path to save the validation results in a tfevents file.
438
+
439
+ Parameters
440
+ ----------
441
+ this_tensorboard: str
442
+ The tensorboard to set.
443
+ """
444
+ os.makedirs(this_tensorboard, exist_ok=True)
445
+ self.__tensorboard = this_tensorboard
446
+
447
+ @property
448
+ def json_out(self) -> str:
449
+ """
450
+ Attribute to access the json_out.
451
+ This is the path to save the JSON files containing
452
+ validation metrics and raw data to draw the plots.
453
+
454
+ Returns
455
+ -------
456
+ str
457
+ The path to save JSON files.
458
+ """
459
+ return self.__json_out
460
+
461
+ @json_out.setter
462
+ def json_out(self, this_json_out: str):
463
+ """
464
+ Sets the path to save the JSON files in disk.
465
+
466
+ Parameters
467
+ ----------
468
+ this_json_out: str
469
+ The path to the JSON files to set.
470
+ """
471
+ os.makedirs(this_json_out, exist_ok=True)
472
+ self.__json_out = this_json_out
473
+
474
+ @property
475
+ def csv_out(self) -> str:
476
+ """
477
+ Attribute to access the csv_out.
478
+ This is the path to save the metrics as a CSV.
479
+
480
+ Returns
481
+ -------
482
+ str
483
+ The path to save the CSV file containing the metrics.
484
+ """
485
+ return self.__csv_out
486
+
487
+ @csv_out.setter
488
+ def csv_out(self, csv: str):
489
+ """
490
+ Sets the path to save the CSV file in disk
491
+
492
+ Parameters
493
+ ----------
494
+ csv: str
495
+ The path to the CSV file containing the metrics.
496
+ If the file exists, then a new row is added to
497
+ the existing contents. Otherwise a new file is created.
498
+ """
499
+ dir_path = os.path.dirname(csv)
500
+ if dir_path:
501
+ os.makedirs(dir_path, exist_ok=True)
502
+ self.__csv_out = csv
503
+
504
+ @property
505
+ def include_background(self) -> bool:
506
+ """
507
+ Attribute to access include_background.
508
+ Specify whether to include background as
509
+ part of segmentation validation.
510
+
511
+ Returns
512
+ -------
513
+ bool
514
+ Condition to include background for segmentation validation.
515
+ """
516
+ return self.__include_background
517
+
518
+ @include_background.setter
519
+ def include_background(self, this_include_background: bool):
520
+ """
521
+ Specify to include background class for segmentation validation.
522
+
523
+ Parameters
524
+ ----------
525
+ this_include_background: bool
526
+ The include_background to set.
527
+ """
528
+ self.__include_background = this_include_background