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,507 @@
1
+ from typing import List, Union
2
+
3
+ import numpy as np
4
+
5
+ from edgefirst.validator.metrics.data import (DetectionLabelData,
6
+ SegmentationLabelData)
7
+
8
+
9
+ class YOLOStats:
10
+ """
11
+ Storing the pre-calculations of the Ultralytics metrics. The statistics
12
+ are formatted in the same manner as Ultralytics which contains the
13
+ correction matrix, the prediction class, the prediction confidence, and
14
+ the ground truth class all of which are used to calculate the metrics.
15
+ """
16
+
17
+ def __init__(self):
18
+ self.__stats = {
19
+ "tp": [],
20
+ "conf": [],
21
+ "pred_cls": [],
22
+ "target_cls": [],
23
+ "target_img": [],
24
+ "tp_m": []
25
+ }
26
+ self.__ious = np.array([
27
+ 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95])
28
+
29
+ @property
30
+ def stats(self) -> dict:
31
+ """
32
+ Attribute to access the stats required for
33
+ computing Ultralytics metrics.
34
+
35
+ Returns
36
+ -------
37
+ dict
38
+ This list contains the keys (['tp', 'conf', 'pred_cls',
39
+ 'target_cls', 'target_img', 'tp_m']) with the
40
+ following items [tp (n, 10), conf (n, 1), pred_cls (n, 1),
41
+ target_cls (n, 1), target_img (nc, ), tp_m (n, 10)].
42
+
43
+ The tp/tp_m matrix contains True or False values for each IoU
44
+ step of all n predictions. The conf contains the confidence
45
+ scores of each prediction. The pred_cls contains the labels
46
+ of each prediction. The target_cls contains the labels
47
+ of each ground truth.
48
+ """
49
+ return self.__stats
50
+
51
+ @stats.setter
52
+ def stats(self, stat: dict):
53
+ """
54
+ Sets the stats to a new value.
55
+
56
+ Parameters
57
+ ----------
58
+ stat: dict
59
+ These are the stats to set.
60
+ """
61
+ self.__stats = stat
62
+
63
+ @property
64
+ def ious(self) -> np.ndarray:
65
+ """
66
+ Attribute to access the ious which contains the IoU steps for validation.
67
+ By default set from 0.50 to 0.95 in 0.05 steps.
68
+
69
+ Returns
70
+ -------
71
+ np.ndarray
72
+ The list of IoUs to evaluate the model.
73
+ """
74
+ return self.__ious
75
+
76
+ @ious.setter
77
+ def ious(self, iou: np.ndarray):
78
+ """
79
+ Sets the IoU steps to a new value.
80
+
81
+ Parameters
82
+ ----------
83
+ iou: np.ndarray
84
+ These are the various IoU levels to evaluate the model.
85
+ """
86
+ self.__ious = iou
87
+
88
+ def reset(self):
89
+ """
90
+ Resets the stats to an empty container.
91
+ """
92
+ self.stats = {
93
+ "tp": [],
94
+ "conf": [],
95
+ "pred_cls": [],
96
+ "target_cls": [],
97
+ "target_img": [],
98
+ "tp_m": []
99
+ }
100
+
101
+
102
+ class DetectionStats(YOLOStats):
103
+ """
104
+ Storing the pre-calculations of the EdgeFirst metrics. The statistics
105
+ contains DetectionLabelData containers for each label found during validation.
106
+ A label container will store the number of ground truths, true positives,
107
+ false positives, false negatives of the specific label. This will be used
108
+ to calculate the metrics.
109
+ """
110
+
111
+ def __init__(self):
112
+ super(DetectionStats, self).__init__()
113
+
114
+ self.__tp = list() # Model correct matrix (n, 10).
115
+ self.__conf = list() # Prediction confidence scores.
116
+ self.__pred_cls = list() # Prediction labels.
117
+ self.__target_cls = list() # Ground truths labels.
118
+
119
+ # A list containing the strings or integers of unique labels.
120
+ self.__labels = list()
121
+ # A list containing the DetectionLabelData objects for each label.
122
+ self.__stats = list()
123
+
124
+ @property
125
+ def labels(self) -> list:
126
+ """
127
+ Attribute to access the list of unique labels found.
128
+
129
+ Returns
130
+ -------
131
+ list
132
+ This contains unique labels found during validation.
133
+ """
134
+ return self.__labels
135
+
136
+ @labels.setter
137
+ def labels(self, new_labels: list):
138
+ """
139
+ Sets the list of unique labels found during validation.
140
+
141
+ Parameters
142
+ ----------
143
+ new_labels: list
144
+ This is the list of unique labels found during validation.
145
+ """
146
+ self.__labels = new_labels
147
+
148
+ @property
149
+ def stats(self) -> List[DetectionLabelData]:
150
+ """
151
+ Attribute to access the stats which contains DetectionLabelData
152
+ objects needed to compute EdgeFirst metrics.
153
+
154
+ Returns
155
+ -------
156
+ List[DetectionLabelData]
157
+ This list contains DetectionLabelData objects where each
158
+ object tracks the metrics of a specific label.
159
+ """
160
+ return self.__stats
161
+
162
+ @stats.setter
163
+ def stats(self, stat: List[DetectionLabelData]):
164
+ """
165
+ Sets the stats to a new value.
166
+
167
+ Parameters
168
+ ----------
169
+ stat: List[DetectionLabelData]
170
+ These are the stats to set.
171
+ """
172
+ self.__stats = stat
173
+
174
+ def get_label_data(
175
+ self,
176
+ label: Union[str, int, np.integer]
177
+ ) -> Union[DetectionLabelData, None]:
178
+ """
179
+ Grabs the DetectionLabelData object by the label.
180
+
181
+ Parameters
182
+ ----------
183
+ label: Union[str, int, np.integer]
184
+ A unique string label or integer index to
185
+ fetch the LabelData container.
186
+
187
+ Returns
188
+ -------
189
+ Union[DetectionLabelData, None]
190
+ The data container of the label specified if
191
+ it exists. None if the label does not exist.
192
+ """
193
+ for label_data in self.stats:
194
+ if label_data.label == label:
195
+ return label_data
196
+ return None
197
+
198
+ def add_label_data(self, label: Union[str, int, np.integer]):
199
+ """
200
+ Adds a DetectionLabelData object for the label.
201
+
202
+ Parameters
203
+ ----------
204
+ label: Union[str, int, np.integer]
205
+ The string label or the integer index
206
+ to place as a data container.
207
+ """
208
+ self.stats.append(DetectionLabelData(label))
209
+
210
+ def capture_class(self, labels: Union[list, np.ndarray]):
211
+ """
212
+ Records the unique labels encountered from the prediction and
213
+ ground truth and creates a DetectionLabelData container
214
+ for each unique label found. Ignores 'background' or empty string
215
+ labels.
216
+
217
+ Parameters
218
+ ----------
219
+ labels: Union[list, np.ndarray]
220
+ This list contains labels for one image from either the
221
+ ground truth or the predictions.
222
+ """
223
+ for label in labels:
224
+ if isinstance(label, str):
225
+ if label.lower() in ["background", " ", ""]:
226
+ continue
227
+ if label not in self.labels:
228
+ self.add_label_data(label)
229
+ self.labels.append(label)
230
+
231
+ @property
232
+ def tp(self) -> list:
233
+ """
234
+ Attribute to access the correct matrix.
235
+
236
+ Returns
237
+ -------
238
+ list
239
+ This is a (n, 10) correct matrix similar to Ultralytics parameters
240
+ which arranges all the classes in rows and 10 IoU thresholds in
241
+ columns and contains boolean values of True or False depending
242
+ on the class and the IoU threshold.
243
+ """
244
+ return self.__tp
245
+
246
+ @tp.setter
247
+ def tp(self, this_tp: list):
248
+ """
249
+ Sets the correct matrix to a new value.
250
+
251
+ Parameters
252
+ ----------
253
+ this_tp: list
254
+ The correct matrix to set.
255
+ """
256
+ self.__tp = this_tp
257
+
258
+ @property
259
+ def conf(self) -> list:
260
+ """
261
+ Attribute to access the model prediction confidence scores.
262
+
263
+ Returns
264
+ -------
265
+ list
266
+ An array of model prediction scores for each label
267
+ in the row of the correct matrix.
268
+ """
269
+ return self.__conf
270
+
271
+ @conf.setter
272
+ def conf(self, this_conf: list):
273
+ """
274
+ Sets the confidence scores to a new value.
275
+
276
+ Parameters
277
+ ----------
278
+ this_conf: list
279
+ The model prediction scores of each row in the correct matrix.
280
+ """
281
+ self.__conf = this_conf
282
+
283
+ @property
284
+ def pred_cls(self) -> list:
285
+ """
286
+ Attribute to access the model class labels.
287
+
288
+ Returns
289
+ -------
290
+ list
291
+ An array of model labels for each row in the correct matrix.
292
+ """
293
+ return self.__pred_cls
294
+
295
+ @pred_cls.setter
296
+ def pred_cls(self, this_pred_cls: list):
297
+ """
298
+ Sets the model prediction labels to a new value.
299
+
300
+ Parameters
301
+ ----------
302
+ this_pred_cls: list
303
+ The model prediction labels of each row in the correct matrix.
304
+ """
305
+ self.__pred_cls = this_pred_cls
306
+
307
+ @property
308
+ def target_cls(self) -> list:
309
+ """
310
+ Attribute to access the ground truth class labels.
311
+
312
+ Returns
313
+ -------
314
+ list
315
+ An array of ground truth labels for each row in the correct matrix.
316
+ """
317
+ return self.__target_cls
318
+
319
+ @target_cls.setter
320
+ def target_cls(self, this_target_cls: list):
321
+ """
322
+ Set the ground truth labels to a new value.
323
+
324
+ Parameters
325
+ ----------
326
+ this_target_cls: list
327
+ The ground truth labels of each row in the correct matrix.
328
+ """
329
+ self.__target_cls = this_target_cls
330
+
331
+ def reset(self):
332
+ """
333
+ Resets the container back to an empty list.
334
+ """
335
+ self.stats = list()
336
+ self.labels = list()
337
+
338
+ self.tp = list()
339
+ self.conf = list()
340
+ self.pred_cls = list() # classes of detections
341
+ self.target_cls = list() # classes of ground truths
342
+
343
+
344
+ class SegmentationStats:
345
+ """
346
+ Acts as a container of SegmentationLabelData objects for each label
347
+ and provides methods to capture the total number of true predictions
348
+ and false predictions pixels.
349
+ """
350
+
351
+ def __init__(self):
352
+
353
+ # A list containing the strings or integers of unique labels.
354
+ self.__labels = list()
355
+ # A list containing the SegmentationLabelData objects for each label.
356
+ self.__stats = list()
357
+ # A list containing the IoU values between the ground truth
358
+ # and the prediction masks throughout the datasety.
359
+ self.__ious = list()
360
+
361
+ @property
362
+ def labels(self) -> list:
363
+ """
364
+ Attribute to access the list of unique labels found.
365
+
366
+ Returns
367
+ -------
368
+ list
369
+ This contains unique labels found during validation.
370
+ """
371
+ return self.__labels
372
+
373
+ @labels.setter
374
+ def labels(self, new_labels: list):
375
+ """
376
+ Sets the list of unique labels found during validation.
377
+
378
+ Parameters
379
+ ----------
380
+ new_labels: list
381
+ This is the list of unique labels found during validation.
382
+ """
383
+ self.__labels = new_labels
384
+
385
+ @property
386
+ def stats(self) -> List[SegmentationLabelData]:
387
+ """
388
+ Attribute to access the stats which contains SegmentationLabelData
389
+ objects needed to compute EdgeFirst metrics.
390
+
391
+ Returns
392
+ -------
393
+ List[SegmentationLabelData]
394
+ This list contains SegmentationLabelData objects where each
395
+ object tracks the metrics of a specific label.
396
+ """
397
+ return self.__stats
398
+
399
+ @stats.setter
400
+ def stats(self, stat: List[SegmentationLabelData]):
401
+ """
402
+ Sets the stats to a new value.
403
+
404
+ Parameters
405
+ ----------
406
+ stat: List[SegmentationLabelData]
407
+ These are the stats to set.
408
+ """
409
+ self.__stats = stat
410
+
411
+ @property
412
+ def ious(self) -> list:
413
+ """
414
+ Attribute to access the list of IoUs between the
415
+ ground truth and the prediction masks.
416
+
417
+ Returns
418
+ -------
419
+ list
420
+ This contains the mask IoU values during validation.
421
+ """
422
+ return self.__ious
423
+
424
+ @ious.setter
425
+ def ious(self, this_ious: list):
426
+ """
427
+ Sets the list of mask IoU values during validation.
428
+
429
+ Parameters
430
+ ----------
431
+ this_ious: list
432
+ This is the list of IoU values during validation.
433
+ """
434
+ self.__ious = this_ious
435
+
436
+ def get_label_data(
437
+ self,
438
+ label: Union[str, int, np.integer]
439
+ ) -> Union[SegmentationLabelData, None]:
440
+ """
441
+ Grabs the SegmentationLabelData object by the label.
442
+
443
+ Parameters
444
+ ----------
445
+ label: Union[str, int, np.integer]
446
+ A unique string label or integer index to
447
+ fetch the LabelData container.
448
+
449
+ Returns
450
+ -------
451
+ Union[SegmentationLabelData, None]
452
+ The data container of the label specified if
453
+ it exists. None if the label does not exist.
454
+ """
455
+ for label_data in self.stats:
456
+ if label_data.label == label:
457
+ return label_data
458
+ return None
459
+
460
+ def add_label_data(self, label: Union[str, int, np.integer]):
461
+ """
462
+ Adds a SegmentationLabelData object for the label.
463
+
464
+ Parameters
465
+ ----------
466
+ label: Union[str, int, np.integer]
467
+ The string label or the integer index
468
+ to place as a data container.
469
+ """
470
+ self.stats.append(SegmentationLabelData(label))
471
+
472
+ def capture_class(
473
+ self,
474
+ class_labels: Union[list, np.ndarray],
475
+ labels: List[str] = None
476
+ ):
477
+ """
478
+ Records the unique labels encountered in the prediction and
479
+ ground truth and creates a container (SegmentationLabelData)
480
+ for the label found in the model predictions and ground truth.
481
+
482
+ Parameters
483
+ ----------
484
+ class_labels: list of int.
485
+ All unique indices for the classes found from the ground
486
+ truth and the model prediction masks.
487
+ labels: list
488
+ This list contains unique string labels for the classes found.
489
+ This is optional to convert the integer labels into string
490
+ labels.
491
+ """
492
+ for label in class_labels:
493
+ if labels is not None:
494
+ label: str = labels[label]
495
+ if label.lower() in [" ", ""]:
496
+ continue
497
+ if label not in self.labels:
498
+ self.add_label_data(label)
499
+ self.labels.append(label)
500
+
501
+ def reset(self):
502
+ """
503
+ Resets the containers to an empty list
504
+ and resets the labels captured to an empty list.
505
+ """
506
+ self.stats, self.labels = list(), list()
507
+ self.ious = list()