Model Module
ImageBoundingBoxes
Class that represents the detected objects bounding boxes from an object detection model on an image.
Source code in devices\raspberry_pi_5\src\model\__init__.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
__init__(xywhn=None, xyxy=None, xywh=None, xyxyn=None, cls=None, conf=None, n=None)
Initialize the ImageBoundingBoxes instance with bounding box coordinates, classes, and confidences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xywh
|
Optional[List]
|
Bounding box coordinates in the format (x_center, y_center, width, height). |
None
|
xyxy
|
Optional[List]
|
Bounding box coordinates in the format (x1, y1, x2, y2). |
None
|
xywhn
|
Optional[List]
|
Normalized bounding box coordinates in the format (x_center, y_center, width, height). |
None
|
xyxyn
|
Optional[List]
|
Normalized bounding box coordinates in the format (x1, y1, x2, y2). |
None
|
cls
|
Optional[List]
|
Class indices for each detected object. |
None
|
conf
|
Optional[List]
|
Confidence scores for each detected object. |
None
|
n
|
Optional[int]
|
Number of detected objects. |
None
|
Source code in devices\raspberry_pi_5\src\model\__init__.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
__str__()
String representation of the objects detected in the image.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A formatted string containing the bounding boxes, classes, and confidences. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
from_hailo(input_data, threshold=0.5)
staticmethod
Extract detections from the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data
|
List
|
Raw detections from the model. |
required |
threshold
|
float
|
Score threshold for filtering detections. Defaults to 0.5. |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
ImageBoundingBoxes |
ImageBoundingBoxes
|
An instance containing the bounding boxes, classes, and confidences. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
from_pt_cpu(input_data)
staticmethod
Extract detections from the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data
|
List
|
Raw detections from the model. |
required |
Returns:
Name | Type | Description |
---|---|---|
ImageBoundingBoxes |
ImageBoundingBoxes
|
An instance containing the bounding boxes, classes, and confidences. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
80 81 82 83 84 85 86 87 88 89 90 91 |
|
from_pt_cpu_boxes(boxes)
staticmethod
Initialize a new ImageBoundingBoxes instances from a PyTorch CPU tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boxes
|
Tensor
|
The bounding boxes' tensor. |
required |
Returns:
Name | Type | Description |
---|---|---|
ImageBoundingBoxes |
ImageBoundingBoxes
|
An instance containing the bounding boxes, classes, and confidences. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
get_boxes()
Get the bounding box coordinates and class of the detected objects.
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple
|
A tuple containing the class, confidence, and bounding box coordinates in xyxy format. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
192 193 194 195 196 197 198 199 |
|
get_classes()
Get the classes of the detected objects.
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
A list of class indices for each detected object. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
174 175 176 177 178 179 180 181 |
|
get_confidences()
Get the confidence of the detected objects.
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
A list of confidence scores for each detected object. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
183 184 185 186 187 188 189 190 |
|
get_number_of_objects()
Get the number of detected objects.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of detected objects. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
129 130 131 132 133 134 135 136 |
|
get_xywh()
Get the bounding box coordinates in the format (x_center, y_center, width, height).
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
A list of bounding box coordinates in the format (x_center, y_center, width, height). |
Source code in devices\raspberry_pi_5\src\model\__init__.py
147 148 149 150 151 152 153 154 |
|
get_xywhn()
Get the bounding box coordinates in the format (x_center, y_center, width, height) normalized.
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
A list of bounding box coordinates in the format (x_center, y_center, width, height) normalized. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
156 157 158 159 160 161 162 163 |
|
get_xyxy()
Get the bounding box coordinates in the format (x1, y1, x2, y2).
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
A list of bounding box coordinates in the format (x1, y1, x2, y2). |
Source code in devices\raspberry_pi_5\src\model\__init__.py
138 139 140 141 142 143 144 145 |
|
get_xyxyn()
Get the bounding box coordinates in the format (x1, y1, x2, y2) normalized.
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
A list of bounding box coordinates in the format (x1, y1, x2, y2) normalized. |
Source code in devices\raspberry_pi_5\src\model\__init__.py
165 166 167 168 169 170 171 172 |
|