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,173 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Tuple
4
+
5
+ import numpy as np
6
+
7
+ from edgefirst.validator.publishers.utils.logger import logger
8
+ from edgefirst.validator.metrics import Metrics, Plots
9
+
10
+ if TYPE_CHECKING:
11
+ from edgefirst.validator.evaluators import ValidationParameters
12
+ from edgefirst.validator.metrics import (SegmentationStats,
13
+ SegmentationLabelData)
14
+
15
+
16
+ class SegmentationMetrics:
17
+ """
18
+ Runs the metric computations for segmentation. The resulting metrics
19
+ will be populated in the `Metrics` object that is created once initialized.
20
+
21
+ This provides methods to calculate::
22
+
23
+ 1. precision = true predictions / all predictions.
24
+ 2. recall = true predictions / all ground truths.
25
+ 3. accuracy = true predictions / all ground truths and all predictions.
26
+
27
+ Parameters
28
+ ----------
29
+ parameters: ValidationParameters
30
+ This contains validation parameters set from the command line.
31
+ segmentation_stats: SegmentationStats
32
+ This is container of the pre-metrics computations per class.
33
+ model_name: str
34
+ The base name of the model being validated.
35
+ dataset_name: str
36
+ The base name of the validation dataset.
37
+ save_path: str
38
+ The path to save the metrics on disk.
39
+ """
40
+
41
+ def __init__(
42
+ self,
43
+ parameters: ValidationParameters,
44
+ segmentation_stats: SegmentationStats,
45
+ model_name: str = "Model",
46
+ dataset_name: str = "Dataset",
47
+ save_path: str = None
48
+ ):
49
+ self.parameters = parameters
50
+ self.plots = Plots()
51
+ self.segmentation_stats = segmentation_stats
52
+ self.metrics = Metrics(model=model_name, dataset=dataset_name)
53
+ self.metrics.save_path = save_path
54
+
55
+ def run_metrics(self):
56
+ """
57
+ Method process for gathering all metrics used
58
+ for the segmentation validation. Currently only supports
59
+ EdgeFirst methods for computing the metrics. Future work will
60
+ include reproduction of Ultralytics metrics for segmentation.
61
+ """
62
+ if self.parameters.method in ["ultralytics", "yolov7"]:
63
+ logger("EdgeFirst metrics is currently supported for segmentation",
64
+ code="WARNING")
65
+
66
+ nc = len(self.segmentation_stats.stats)
67
+ ap, ar, aacc = 0., 0., 0.
68
+
69
+ if nc > 0:
70
+ for label_data in self.segmentation_stats.stats:
71
+ precision, recall, accuracy = self.compute_class_metrics(
72
+ label_data)
73
+ ap += precision
74
+ ar += recall
75
+ aacc += accuracy
76
+
77
+ data = {
78
+ 'precision': precision,
79
+ 'recall': recall,
80
+ 'accuracy': accuracy,
81
+ 'true_predictions': label_data.true_predictions,
82
+ 'false_predictions': label_data.false_predictions,
83
+ 'gt': label_data.ground_truths
84
+ }
85
+
86
+ self.plots.append_class_histogram_data(label_data.label, data)
87
+
88
+ self.metrics.precision["mean"] = ap / nc
89
+ self.metrics.recall["mean"] = ar / nc
90
+ self.metrics.accuracy["mean"] = aacc / nc
91
+ self.metrics.iou["mean"] = float(np.average(self.segmentation_stats.ious)
92
+ if len(self.segmentation_stats.ious)
93
+ else 0.0)
94
+
95
+ accuracy, f1 = self.compute_overall_metrics()
96
+ self.metrics.accuracy["overall"] = accuracy
97
+ self.metrics.f1["overall"] = f1
98
+
99
+ else:
100
+ data = {
101
+ 'precision': np.nan,
102
+ 'recall': np.nan,
103
+ 'accuracy': np.nan,
104
+ 'true_predictions': 0,
105
+ 'false_predictions': 0,
106
+ 'gt': 0
107
+ }
108
+ self.plots.append_class_histogram_data("No label", data)
109
+
110
+ def compute_class_metrics(
111
+ self,
112
+ label_data: SegmentationLabelData
113
+ ) -> Tuple[float, float, float]:
114
+ """
115
+ This is an EdgeFirst validation method.
116
+
117
+ Returns the precision, recall, and accuracy metrics of a specific class.
118
+
119
+ Parameters
120
+ ----------
121
+ label_data: SegmentationLabelData
122
+ This object contains the true predictions and false predictions
123
+ of a specific class.
124
+
125
+ Returns
126
+ -------
127
+ precision: float
128
+ This is the true predictions / all predictions for this class.
129
+ recall: float
130
+ This is the true predictions / all ground truths for this class.
131
+ accuracy: float
132
+ This is the true predictions / all ground truths and predictions
133
+ for this class.
134
+ """
135
+ precision, recall, accuracy = 0., 0., 0.
136
+ if label_data.true_predictions > 0:
137
+ precision = label_data.true_predictions / label_data.predictions
138
+ recall = label_data.true_predictions / label_data.ground_truths
139
+ accuracy = label_data.true_predictions / label_data.union
140
+ return precision, recall, accuracy
141
+
142
+ def compute_overall_metrics(self) -> Tuple[float, float]:
143
+ """
144
+ This is an EdgeFirst validation method.
145
+
146
+ Computes the overall segmentation accuracy.
147
+ Overall segmentation accuracy = true predictions pixels / union pixels.
148
+
149
+ Returns
150
+ -------
151
+ accuracy: float
152
+ This is the true prediction pixels / union pixels. The union
153
+ pixels is the number of ground truths | predictions.
154
+ f1: float
155
+ The F1 score based on
156
+ 2 * precision * recall / (precision + recall).
157
+ """
158
+ precision, recall, accuracy, f1 = 0., 0., 0., 0.
159
+ precision = self.metrics.true_predictions / self.metrics.predictions
160
+ recall = self.metrics.true_predictions / self.metrics.ground_truths
161
+ accuracy = self.metrics.true_predictions / self.metrics.union
162
+
163
+ if precision + recall > 0:
164
+ f1 = 2 * precision * recall / (precision + recall)
165
+ return accuracy, f1
166
+
167
+ def reset(self):
168
+ """
169
+ Reset the metric containers.
170
+ """
171
+ self.plots.reset()
172
+ self.segmentation_stats.reset()
173
+ self.metrics.reset()