BaseTensor
Bases: SimpleClass
Base tensor class with additional methods for easy manipulation and device handling.
Source code in ultralytics/yolo/engine/results.py
shape
property
Return the shape of the data tensor.
__getitem__(idx)
__init__(data, orig_shape)
Initialize BaseTensor with data and original shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
torch.Tensor | np.ndarray
|
Predictions, such as bboxes, masks and keypoints. |
required |
orig_shape |
tuple
|
Original shape of image. |
required |
Source code in ultralytics/yolo/engine/results.py
__len__()
cpu()
cuda()
numpy()
to(*args, **kwargs)
Return a copy of the tensor with the specified device and dtype.
Results
Bases: SimpleClass
A class for storing and manipulating inference results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orig_img |
numpy.ndarray
|
The original image as a numpy array. |
required |
path |
str
|
The path to the image file. |
required |
names |
dict
|
A dictionary of class names. |
required |
boxes |
torch.tensor
|
A 2D tensor of bounding box coordinates for each detection. |
None
|
masks |
torch.tensor
|
A 3D tensor of detection masks, where each mask is a binary image. |
None
|
probs |
torch.tensor
|
A 1D tensor of probabilities of each class for classification task. |
None
|
keypoints |
List[List[float]]
|
A list of detected keypoints for each object. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
orig_img |
numpy.ndarray
|
The original image as a numpy array. |
orig_shape |
tuple
|
The original image shape in (height, width) format. |
boxes |
Boxes
|
A Boxes object containing the detection bounding boxes. |
masks |
Masks
|
A Masks object containing the detection masks. |
probs |
Probs
|
A Probs object containing probabilities of each class for classification task. |
names |
dict
|
A dictionary of class names. |
path |
str
|
The path to the image file. |
keypoints |
Keypoints
|
A Keypoints object containing detected keypoints for each object. |
speed |
dict
|
A dictionary of preprocess, inference and postprocess speeds in milliseconds per image. |
_keys |
tuple
|
A tuple of attribute names for non-empty attributes. |
Source code in ultralytics/yolo/engine/results.py
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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
keys
property
Return a list of non-empty attribute names.
__getitem__(idx)
__init__(orig_img, path, names, boxes=None, masks=None, probs=None, keypoints=None)
Initialize the Results class.
Source code in ultralytics/yolo/engine/results.py
__len__()
cpu()
Return a copy of the Results object with all tensors on CPU memory.
cuda()
Return a copy of the Results object with all tensors on GPU memory.
new()
numpy()
Return a copy of the Results object with all tensors as numpy arrays.
pandas()
plot(conf=True, line_width=None, font_size=None, font='Arial.ttf', pil=False, img=None, img_gpu=None, kpt_line=True, labels=True, boxes=True, masks=True, probs=True, **kwargs)
Plots the detection results on an input RGB image. Accepts a numpy array (cv2) or a PIL Image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
bool
|
Whether to plot the detection confidence score. |
True
|
line_width |
float
|
The line width of the bounding boxes. If None, it is scaled to the image size. |
None
|
font_size |
float
|
The font size of the text. If None, it is scaled to the image size. |
None
|
font |
str
|
The font to use for the text. |
'Arial.ttf'
|
pil |
bool
|
Whether to return the image as a PIL Image. |
False
|
img |
numpy.ndarray
|
Plot to another image. if not, plot to original image. |
None
|
img_gpu |
torch.Tensor
|
Normalized image in gpu with shape (1, 3, 640, 640), for faster mask plotting. |
None
|
kpt_line |
bool
|
Whether to draw lines connecting keypoints. |
True
|
labels |
bool
|
Whether to plot the label of bounding boxes. |
True
|
boxes |
bool
|
Whether to plot the bounding boxes. |
True
|
masks |
bool
|
Whether to plot the masks. |
True
|
probs |
bool
|
Whether to plot classification probability |
True
|
Returns:
Type | Description |
---|---|
numpy.ndarray
|
A numpy array of the annotated image. |
Source code in ultralytics/yolo/engine/results.py
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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
save_crop(save_dir, file_name=Path('im.jpg'))
Save cropped predictions to save_dir/cls/file_name.jpg
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_dir |
str | pathlib.Path
|
Save path. |
required |
file_name |
str | pathlib.Path
|
File name. |
Path('im.jpg')
|
Source code in ultralytics/yolo/engine/results.py
save_txt(txt_file, save_conf=False)
Save predictions into txt file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
txt_file |
str
|
txt file path. |
required |
save_conf |
bool
|
save confidence score or not. |
False
|
Source code in ultralytics/yolo/engine/results.py
to(*args, **kwargs)
Return a copy of the Results object with tensors on the specified device and dtype.
tojson(normalize=False)
Convert the object to JSON format.
Source code in ultralytics/yolo/engine/results.py
update(boxes=None, masks=None, probs=None)
Update the boxes, masks, and probs attributes of the Results object.
Source code in ultralytics/yolo/engine/results.py
verbose()
Return log string for each task.
Source code in ultralytics/yolo/engine/results.py
Boxes
Bases: BaseTensor
A class for storing and manipulating detection boxes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boxes |
torch.Tensor) or (numpy.ndarray
|
A tensor or numpy array containing the detection boxes, with shape (num_boxes, 6). The last two columns should contain confidence and class values. |
required |
orig_shape |
tuple
|
Original image size, in the format (height, width). |
required |
Attributes:
Name | Type | Description |
---|---|---|
boxes |
torch.Tensor) or (numpy.ndarray
|
The detection boxes with shape (num_boxes, 6). |
orig_shape |
torch.Tensor) or (numpy.ndarray
|
Original image size, in the format (height, width). |
is_track |
bool
|
True if the boxes also include track IDs, False otherwise. |
Properties
xyxy (torch.Tensor) or (numpy.ndarray): The boxes in xyxy format. conf (torch.Tensor) or (numpy.ndarray): The confidence values of the boxes. cls (torch.Tensor) or (numpy.ndarray): The class values of the boxes. id (torch.Tensor) or (numpy.ndarray): The track IDs of the boxes (if available). xywh (torch.Tensor) or (numpy.ndarray): The boxes in xywh format. xyxyn (torch.Tensor) or (numpy.ndarray): The boxes in xyxy format normalized by original image size. xywhn (torch.Tensor) or (numpy.ndarray): The boxes in xywh format normalized by original image size. data (torch.Tensor): The raw bboxes tensor
Methods
cpu(): Move the object to CPU memory. numpy(): Convert the object to a numpy array. cuda(): Move the object to CUDA memory. to(args, *kwargs): Move the object to the specified device. pandas(): Convert the object to a pandas DataFrame (not yet implemented).
Source code in ultralytics/yolo/engine/results.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
|
boxes
property
Return the raw bboxes tensor (deprecated).
cls
property
Return the class values of the boxes.
conf
property
Return the confidence values of the boxes.
id
property
Return the track IDs of the boxes (if available).
xywh
cached
property
Return the boxes in xywh format.
xywhn
cached
property
Return the boxes in xywh format normalized by original image size.
xyxy
property
Return the boxes in xyxy format.
xyxyn
cached
property
Return the boxes in xyxy format normalized by original image size.
__init__(boxes, orig_shape)
Initialize the Boxes class.
Source code in ultralytics/yolo/engine/results.py
Masks
Bases: BaseTensor
A class for storing and manipulating detection masks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
masks |
torch.Tensor | np.ndarray
|
A tensor containing the detection masks, with shape (num_masks, height, width). |
required |
orig_shape |
tuple
|
Original image size, in the format (height, width). |
required |
Attributes:
Name | Type | Description |
---|---|---|
masks |
torch.Tensor | np.ndarray
|
A tensor containing the detection masks, with shape (num_masks, height, width). |
orig_shape |
tuple
|
Original image size, in the format (height, width). |
Properties
xy (list): A list of segments (pixels) which includes x, y segments of each detection. xyn (list): A list of segments (normalized) which includes x, y segments of each detection.
Methods
cpu(): Returns a copy of the masks tensor on CPU memory. numpy(): Returns a copy of the masks tensor as a numpy array. cuda(): Returns a copy of the masks tensor on GPU memory. to(): Returns a copy of the masks tensor with the specified device and dtype.
Source code in ultralytics/yolo/engine/results.py
masks
property
Return the raw masks tensor (deprecated).
segments
cached
property
Return segments (deprecated; normalized).
xy
cached
property
Return segments (pixels).
xyn
cached
property
Return segments (normalized).
__init__(masks, orig_shape)
Created 2023-04-16, Updated 2023-05-17
Authors: Glenn Jocher (3)