Ruff Docstring formatting (#15793)
Signed-off-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
d27664216b
commit
776ca86369
60 changed files with 241 additions and 309 deletions
|
|
@ -21,7 +21,6 @@ class YOLOv8Seg:
|
|||
Args:
|
||||
onnx_model (str): Path to the ONNX model.
|
||||
"""
|
||||
|
||||
# Build Ort session
|
||||
self.session = ort.InferenceSession(
|
||||
onnx_model,
|
||||
|
|
@ -57,7 +56,6 @@ class YOLOv8Seg:
|
|||
segments (List): list of segments.
|
||||
masks (np.ndarray): [N, H, W], output masks.
|
||||
"""
|
||||
|
||||
# Pre-process
|
||||
im, ratio, (pad_w, pad_h) = self.preprocess(im0)
|
||||
|
||||
|
|
@ -90,7 +88,6 @@ class YOLOv8Seg:
|
|||
pad_w (float): width padding in letterbox.
|
||||
pad_h (float): height padding in letterbox.
|
||||
"""
|
||||
|
||||
# Resize and pad input image using letterbox() (Borrowed from Ultralytics)
|
||||
shape = img.shape[:2] # original image shape
|
||||
new_shape = (self.model_height, self.model_width)
|
||||
|
|
@ -130,7 +127,7 @@ class YOLOv8Seg:
|
|||
"""
|
||||
x, protos = preds[0], preds[1] # Two outputs: predictions and protos
|
||||
|
||||
# Transpose the first output: (Batch_size, xywh_conf_cls_nm, Num_anchors) -> (Batch_size, Num_anchors, xywh_conf_cls_nm)
|
||||
# Transpose dim 1: (Batch_size, xywh_conf_cls_nm, Num_anchors) -> (Batch_size, Num_anchors, xywh_conf_cls_nm)
|
||||
x = np.einsum("bcn->bnc", x)
|
||||
|
||||
# Predictions filtering by conf-threshold
|
||||
|
|
@ -169,8 +166,8 @@ class YOLOv8Seg:
|
|||
@staticmethod
|
||||
def masks2segments(masks):
|
||||
"""
|
||||
It takes a list of masks(n,h,w) and returns a list of segments(n,xy) (Borrowed from
|
||||
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L750)
|
||||
Takes a list of masks(n,h,w) and returns a list of segments(n,xy), from
|
||||
https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/ops.py.
|
||||
|
||||
Args:
|
||||
masks (numpy.ndarray): the output of the model, which is a tensor of shape (batch_size, 160, 160).
|
||||
|
|
@ -191,8 +188,8 @@ class YOLOv8Seg:
|
|||
@staticmethod
|
||||
def crop_mask(masks, boxes):
|
||||
"""
|
||||
It takes a mask and a bounding box, and returns a mask that is cropped to the bounding box. (Borrowed from
|
||||
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L599)
|
||||
Takes a mask and a bounding box, and returns a mask that is cropped to the bounding box, from
|
||||
https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/ops.py.
|
||||
|
||||
Args:
|
||||
masks (Numpy.ndarray): [n, h, w] tensor of masks.
|
||||
|
|
@ -209,8 +206,8 @@ class YOLOv8Seg:
|
|||
|
||||
def process_mask(self, protos, masks_in, bboxes, im0_shape):
|
||||
"""
|
||||
Takes the output of the mask head, and applies the mask to the bounding boxes. This produces masks of higher quality
|
||||
but is slower. (Borrowed from https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L618)
|
||||
Takes the output of the mask head, and applies the mask to the bounding boxes. This produces masks of higher
|
||||
quality but is slower, from https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/ops.py.
|
||||
|
||||
Args:
|
||||
protos (numpy.ndarray): [mask_dim, mask_h, mask_w].
|
||||
|
|
@ -232,8 +229,8 @@ class YOLOv8Seg:
|
|||
@staticmethod
|
||||
def scale_mask(masks, im0_shape, ratio_pad=None):
|
||||
"""
|
||||
Takes a mask, and resizes it to the original image size. (Borrowed from
|
||||
https://github.com/ultralytics/ultralytics/blob/465df3024f44fa97d4fad9986530d5a13cdabdca/ultralytics/utils/ops.py#L305)
|
||||
Takes a mask, and resizes it to the original image size, from
|
||||
https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/ops.py.
|
||||
|
||||
Args:
|
||||
masks (np.ndarray): resized and padded masks/images, [h, w, num]/[h, w, 3].
|
||||
|
|
@ -277,7 +274,6 @@ class YOLOv8Seg:
|
|||
Returns:
|
||||
None
|
||||
"""
|
||||
|
||||
# Draw rectangles and polygons
|
||||
im_canvas = im.copy()
|
||||
for (*box, conf, cls_), segment in zip(bboxes, segments):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue