pythia.utils.maskrcnn#
Simple python MASKRCNN output parser.
The function extract_maskrcnn_mask should be used.
The core function, resize_mask_vec, is based on its cpp counterpart resizeMask, from deepstream cpp sources. It was ported to python and vectorized via numpy to improve speed.
Author: <Pablo Woolvett pablowoolvett@gmail.com>
- class pythia.utils.maskrcnn.DsBBox(*args, **kwargs)[source]#
Bases:
dict
Deepstream-style Bounding box.
- height: float#
- left: float#
- top: float#
- width: float#
- pythia.utils.maskrcnn._gen_clips(width: ndarray, original_width: int, height: ndarray, original_height: int) Tuple[ndarray, ndarray, ndarray, ndarray] [source]#
- pythia.utils.maskrcnn._gen_idxs(original_width: int, left: ndarray, right: ndarray, top: ndarray, bottom: ndarray) Tuple[ndarray, ndarray, ndarray, ndarray] [source]#
- pythia.utils.maskrcnn._gen_ranges(original_height: int, original_width: int, target_height: int, target_width: int) Tuple[ndarray, ndarray] [source]#
- pythia.utils.maskrcnn._interpolate(width: ndarray, left: ndarray, height: ndarray, top: ndarray, left_top_val: ndarray, right_top_val: ndarray, left_bottom_val: ndarray, right_bottom_val: ndarray) ndarray [source]#
- pythia.utils.maskrcnn.extract_maskrcnn_mask(obj_meta: NvDsObjectMeta) ndarray [source]#
Extract maskrcnn mask from deepstream object.
- Parameters:
obj_meta – Deepstream object meta from detection.
- Returns:
A 2d binary mask of np.uint8 valued 0 and 255.
Example
>>> obj_meta = pyds.NvDsObjectMeta.cast(...) >>> mask = extract_maskrcnn_mask(obj_meta) >>> mask.shape, mask.dtype ((300,100), dtype('uint8'))
See also
resize_mask_vec for the internal implementation.
- pythia.utils.maskrcnn.polygon_to_bbox(polygons: List[List[int]], top: float, left: float) DsBBox [source]#
Generate bounding box from polygons.
The polygons are assumed to be relative to a mask.
- Parameters:
polygons – collection of polygons, where each polygon is a sequence of the form ‘y0,x0,y1,x1,…,yn,xn’.
top – top offset from the mask.
left – left offset from the mask.
- Returns:
Bounding box which circumscribes the mask.
- pythia.utils.maskrcnn.resize_mask_vec(src: ndarray, src_shape: Tuple[int, int], target_shape: Tuple[int, int], threshold: float) ndarray [source]#
Resize mask from original deepstream object into numpy array.
- Parameters:
src – Mask array from deepstream object.
src_shape – Shape of the original mask in (height,width) format.
target_shape – Shape of the target mask in (height,width) format.
threshold – Threshold for the mask.
- Returns:
A 2d binary mask of np.uint8 valued 0 and 255.
See also
- extract_maskrcnn_mask in this module for sample usage from
deepstream.
- resizeMask function at
sample_apps/deepstream-mrcnn-app/deepstream_mrcnn_test.cpp