JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
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 | |
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:
Here, we combine them to produce a final display.
Definition at line 30 of file PyPostYOLOv8seg.py.
PyPostYOLOv8seg.PyPostYOLOv8seg.__init__ | ( | self | ) |
Constructor.
Definition at line 33 of file PyPostYOLOv8seg.py.
|
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().
PyPostYOLOv8seg.PyPostYOLOv8seg.freeze | ( | self, | |
doit | |||
) |
Freeze some parameters that should not be changed at runtime.
Definition at line 75 of file PyPostYOLOv8seg.py.
References Darknet.classes, Yolo.classes, PyPostClassify.PyPostClassify.classes, PyPostDAMOyolo.PyPostDAMOyolo.classes, PyPostYolo.PyPostYolo.classes, PyPostYOLOv8seg.PyPostYOLOv8seg.classes, PyClassificationDNN.PyClassificationDNN.classes, PyDetectionDNN.PyDetectionDNN.classes, PyEmotion.PyEmotion.classes, and PyPostYOLOv8seg.PyPostYOLOv8seg.freeze().
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.freeze().
PyPostYOLOv8seg.PyPostYOLOv8seg.getLabel | ( | self, | |
id, | |||
score | |||
) |
Helper to get class name and confidence as a clean string, and a color that varies with class name.
Definition at line 97 of file PyPostYOLOv8seg.py.
References PyPostClassify.PyPostClassify.classmap, PyPostDAMOyolo.PyPostDAMOyolo.classmap, PyPostYolo.PyPostYolo.classmap, and PyPostYOLOv8seg.PyPostYOLOv8seg.classmap.
Referenced by PyPostDAMOyolo.PyPostDAMOyolo.report(), PyPostYolo.PyPostYolo.report(), and PyPostYOLOv8seg.PyPostYOLOv8seg.report().
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.
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.
|
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().
PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess | ( | self, | |
preds, | |||
preproc, | |||
blobsize, | |||
nm = 32 |
|||
) |
Definition at line 142 of file PyPostYOLOv8seg.py.
References PyPostYOLOv8seg.PyPostYOLOv8seg.conf, PyPostYOLOv8seg.PyPostYOLOv8seg.iou, PyPostYOLOv8seg.PyPostYOLOv8seg.masks2segments(), and PyPostYOLOv8seg.PyPostYOLOv8seg.process_mask().
Referenced by PyDetectionDNN.PyDetectionDNN.process(), PyPostDAMOyolo.PyPostDAMOyolo.process(), and PyPostYOLOv8seg.PyPostYOLOv8seg.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.
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().
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.
|
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().
PyPostYOLOv8seg.PyPostYOLOv8seg.boxes |
PyPostYOLOv8seg.PyPostYOLOv8seg.classes |
Definition at line 47 of file PyPostYOLOv8seg.py.
Referenced by PyPostClassify.PyPostClassify.freeze(), PyPostDAMOyolo.PyPostDAMOyolo.freeze(), PyPostYolo.PyPostYolo.freeze(), PyPostYOLOv8seg.PyPostYOLOv8seg.freeze(), PyDetectionDNN.PyDetectionDNN.postprocess(), and PyClassificationDNN.PyClassificationDNN.process().
PyPostYOLOv8seg.PyPostYOLOv8seg.classmap |
Definition at line 40 of file PyPostYOLOv8seg.py.
Referenced by PyPostDAMOyolo.PyPostDAMOyolo.getLabel(), PyPostYolo.PyPostYolo.getLabel(), PyPostYOLOv8seg.PyPostYOLOv8seg.getLabel(), PyPostClassify.PyPostClassify.loadClasses(), PyPostDAMOyolo.PyPostDAMOyolo.loadClasses(), PyPostYolo.PyPostYolo.loadClasses(), PyPostYOLOv8seg.PyPostYOLOv8seg.loadClasses(), and PyPostClassify.PyPostClassify.process().
PyPostYOLOv8seg.PyPostYOLOv8seg.conf |
Definition at line 52 of file PyPostYOLOv8seg.py.
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess().
PyPostYOLOv8seg.PyPostYOLOv8seg.drawboxes |
Definition at line 69 of file PyPostYOLOv8seg.py.
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.report().
PyPostYOLOv8seg.PyPostYOLOv8seg.fillmask |
Definition at line 64 of file PyPostYOLOv8seg.py.
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.report().
PyPostYOLOv8seg.PyPostYOLOv8seg.iou |
Definition at line 56 of file PyPostYOLOv8seg.py.
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.postprocess().
PyPostYOLOv8seg.PyPostYOLOv8seg.loadClasses |
Definition at line 50 of file PyPostYOLOv8seg.py.
PyPostYOLOv8seg.PyPostYOLOv8seg.masks |
Definition at line 37 of file PyPostYOLOv8seg.py.
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.process().
PyPostYOLOv8seg.PyPostYOLOv8seg.segments |
Definition at line 36 of file PyPostYOLOv8seg.py.
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.process(), and PyPostYOLOv8seg.PyPostYOLOv8seg.report().
PyPostYOLOv8seg.PyPostYOLOv8seg.smoothing |
Definition at line 60 of file PyPostYOLOv8seg.py.
Referenced by PyPostYOLOv8seg.PyPostYOLOv8seg.report().