JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
PyPostYOLOv8seg.PyPostYOLOv8seg Class Reference

Python DNN post-processor for YOLOv8-Seg. More...

Public Member Functions

 __init__ (self)
 Constructor.
 
 init (self)
 JeVois parameters initialization.
 
 freeze (self, doit)
 Freeze some parameters that should not be changed at runtime.
 
 loadClasses (self, filename)
 Parameter callback: Load class names when 'classes' parameter value is changed by model zoo.
 
 process (self, outs, preproc)
 Get network outputs outs is a list of numpy arrays for the network's outputs.
 
 getLabel (self, id, score)
 Helper to get class name and confidence as a clean string, and a color that varies with class name.
 
 report (self, outimg, helper, overlay, idle)
 Report the latest results obtained by process() by drawing them outimg is None or a RawImage to draw into when in Legacy mode (drawing to an image sent to USB) helper is None or a GUIhelper to do OpenGL drawings when in JeVois-Pro GUI mode overlay is True if user wishes to see overlay text idle is true if keyboard/mouse have been idle for a while, which typically would reduce what is displayed.
 
 postprocess (self, preds, preproc, blobsize, nm=32)
 
 process_mask (self, protos, masks_in, bboxes, im0_shape)
 

Static Public Member Functions

 masks2segments (masks)
 
 crop_mask (masks, boxes)
 
 scale_mask (masks, im0_shape, ratio_pad=None)
 

Public Attributes

 boxes
 
 segments
 
 masks
 
 classmap
 
 classes
 
 loadClasses
 
 conf
 
 iou
 
 smoothing
 
 fillmask
 
 drawboxes
 

Detailed Description

Python DNN post-processor for YOLOv8-Seg.

Adapted from https://github.com/ultralytics/ultralytics/blob/main/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py

This network produces two outputs:

  • 1x116x8400: standard YOLOv8 output (detected boxes and class confidences)
  • 1x32x160x160: segmentation masks

Here, we combine them to produce a final display.

Author
Laurent Itti
Email:
itti@usc.edu
Address:
University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
Main URL:
http://jevois.org
Support URL:
http://jevois.org/doc
Other URL:
http://iLab.usc.edu
License:
GPL v3
Distribution:
Unrestricted
Restrictions:
None

Definition at line 30 of file PyPostYOLOv8seg.py.

Constructor & Destructor Documentation

◆ __init__()

PyPostYOLOv8seg.PyPostYOLOv8seg.__init__ (   self)

Constructor.

Definition at line 33 of file PyPostYOLOv8seg.py.

Member Function Documentation

◆ crop_mask()

PyPostYOLOv8seg.PyPostYOLOv8seg.crop_mask (   masks,
  boxes 
)
static
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)

Args:
    masks (Numpy.ndarray): [n, h, w] tensor of masks.
    boxes (Numpy.ndarray): [n, 4] tensor of bbox coordinates in relative point form.

Returns:
    (Numpy.ndarray): The masks are being cropped to the bounding box.

Definition at line 216 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.process_mask().

◆ freeze()

◆ getLabel()

PyPostYOLOv8seg.PyPostYOLOv8seg.getLabel (   self,
  id,
  score 
)

◆ init()

PyPostYOLOv8seg.PyPostYOLOv8seg.init (   self)

JeVois parameters initialization.

These can be set by users in the GUI or JeVois model zoo file

Definition at line 44 of file PyPostYOLOv8seg.py.

◆ loadClasses()

PyPostYOLOv8seg.PyPostYOLOv8seg.loadClasses (   self,
  filename 
)

Parameter callback: Load class names when 'classes' parameter value is changed by model zoo.

Definition at line 80 of file PyPostYOLOv8seg.py.

References PyPostClassify.PyPostClassify.classmap, PyPostDAMOyolo.PyPostDAMOyolo.classmap, PyPostYolo.PyPostYolo.classmap, and PyPostYOLOv8seg.PyPostYOLOv8seg.classmap.

◆ masks2segments()

PyPostYOLOv8seg.PyPostYOLOv8seg.masks2segments (   masks)
static
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)

Args:
    masks (numpy.ndarray): the output of the model, which is a tensor of shape (batch_size, 160, 160).

Returns:
    segments (List): list of segment masks.

Definition at line 193 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess().

◆ postprocess()

◆ process()

PyPostYOLOv8seg.PyPostYOLOv8seg.process (   self,
  outs,
  preproc 
)

Get network outputs outs is a list of numpy arrays for the network's outputs.

preproc is a handle to the pre-processor that was used, useful to recover transforms from original image to cropped/resized network inputs.

Definition at line 91 of file PyPostYOLOv8seg.py.

References PyPostDAMOyolo.PyPostDAMOyolo.boxes, PyPostYolo.PyPostYolo.boxes, PyPostYOLOv8seg.PyPostYOLOv8seg.boxes, PyPostYOLOv8seg.PyPostYOLOv8seg.masks, DetectionDNN.postprocess(), PyDetectionDNN.PyDetectionDNN.postprocess(), PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess(), PyPostDAMOyolo.PyPostDAMOyolo.postprocess(), Line.segments, and PyPostYOLOv8seg.PyPostYOLOv8seg.segments.

◆ process_mask()

PyPostYOLOv8seg.PyPostYOLOv8seg.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)

Args:
    protos (numpy.ndarray): [mask_dim, mask_h, mask_w].
    masks_in (numpy.ndarray): [n, mask_dim], n is number of masks after nms.
    bboxes (numpy.ndarray): bboxes re-scaled to original image shape.
    im0_shape (tuple): the size of the input image (h,w,c).

Returns:
    (numpy.ndarray): The upsampled masks.

Definition at line 235 of file PyPostYOLOv8seg.py.

References PyPostYOLOv8seg.PyPostYOLOv8seg.crop_mask(), and PyPostYOLOv8seg.PyPostYOLOv8seg.scale_mask().

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess().

◆ report()

PyPostYOLOv8seg.PyPostYOLOv8seg.report (   self,
  outimg,
  helper,
  overlay,
  idle 
)

Report the latest results obtained by process() by drawing them outimg is None or a RawImage to draw into when in Legacy mode (drawing to an image sent to USB) helper is None or a GUIhelper to do OpenGL drawings when in JeVois-Pro GUI mode overlay is True if user wishes to see overlay text idle is true if keyboard/mouse have been idle for a while, which typically would reduce what is displayed.

Note that report() is called on every frame even though the network may run slower or take some time to load and initialize, thus you should be prepared for report() being called even before process() has ever been called (i.e., create some class member variables to hold the reported results, initialize them to some defaults in your constructor, report their current values here, and update their values in process()).

Definition at line 116 of file PyPostYOLOv8seg.py.

References PyPostDAMOyolo.PyPostDAMOyolo.boxes, PyPostYolo.PyPostYolo.boxes, PyPostYOLOv8seg.PyPostYOLOv8seg.boxes, PyPostYOLOv8seg.PyPostYOLOv8seg.drawboxes, PyPostYOLOv8seg.PyPostYOLOv8seg.fillmask, PyPostDAMOyolo.PyPostDAMOyolo.getLabel(), PyPostYolo.PyPostYolo.getLabel(), PyPostYOLOv8seg.PyPostYOLOv8seg.getLabel(), Line.segments, PyPostYOLOv8seg.PyPostYOLOv8seg.segments, and PyPostYOLOv8seg.PyPostYOLOv8seg.smoothing.

◆ scale_mask()

PyPostYOLOv8seg.PyPostYOLOv8seg.scale_mask (   masks,
  im0_shape,
  ratio_pad = None 
)
static
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)

Args:
    masks (np.ndarray): resized and padded masks/images, [h, w, num]/[h, w, 3].
    im0_shape (tuple): the original image shape.
    ratio_pad (tuple): the ratio of the padding to the original image.

Returns:
    masks (np.ndarray): The masks that are being returned.

Definition at line 261 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.process_mask().

Member Data Documentation

◆ boxes

◆ classes

◆ classmap

◆ conf

PyPostYOLOv8seg.PyPostYOLOv8seg.conf

Definition at line 52 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess().

◆ drawboxes

PyPostYOLOv8seg.PyPostYOLOv8seg.drawboxes

Definition at line 69 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.report().

◆ fillmask

PyPostYOLOv8seg.PyPostYOLOv8seg.fillmask

Definition at line 64 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.report().

◆ iou

PyPostYOLOv8seg.PyPostYOLOv8seg.iou

Definition at line 56 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess().

◆ loadClasses

PyPostYOLOv8seg.PyPostYOLOv8seg.loadClasses

Definition at line 50 of file PyPostYOLOv8seg.py.

◆ masks

PyPostYOLOv8seg.PyPostYOLOv8seg.masks

Definition at line 37 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.process().

◆ segments

PyPostYOLOv8seg.PyPostYOLOv8seg.segments

◆ smoothing

PyPostYOLOv8seg.PyPostYOLOv8seg.smoothing

Definition at line 60 of file PyPostYOLOv8seg.py.

Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.report().


The documentation for this class was generated from the following file: