combustion.vision¶
combustion.vision
Conversions¶
-
combustion.vision.
to_8bit
(img, per_channel=True, same_on_batch=False)[source]¶ Converts an image Tensor or numpy array with an arbitrary range of values to a uint8 (byte) Tensor / numpy array. This is particularly useful when attempting to visualize images that have been standardized to zero mean unit variance or have higher than 8 bits of resolution.
- Parameters
- Return type
- Shape:
Image: \((C, H, W)\) or \((N, C, H, W)\) where \(N\) is an optional batch dimension.
Ops¶
-
combustion.vision.
nms
(boxes, scores, iou_threshold)[source]¶ Performs non-maximal suppression on anchor boxes as per torchvision.ops.nms. Supports batched or non-batched inputs, and returns a tuple of index tensors that can be used to index the input boxes / scores tensors.
- Parameters
boxes (tensor) – The anchor boxes to perform non-maximal suppression on.
scores (tensor) – The confidence scores associated with each tensor.
iou_threshold (float) – Value on the interval \([0, 1]\) giving the intersection over union threshold over which non-maximal boxes will be suppressed.
- Return type
Tuple[torch.Tensor, Tuple]
- Shape:
Boxes: \((N, 4)\) or \((B, N, 4)\) where \(B\) is an optional batch dimension and N is the number of anchor boxes.
Scores: \((N)\) or \((B, N)\) where \(B\) is an optional batch dimension and N is the number of anchor boxes.
Output: Tensor tuple giving the maximal indices, each of shape \((K)\).
Example:
>>> boxes = torch.tensor([[ >>> [0., 0., 10., 10.], >>> [1., 1., 11., 11.], >>> [10., 10., 20., 20.] >>> ]]) >>> scores = torch.tensor([[0.1, 0.5, 0.05]]) >>> nms_indices = nms(boxes, scores, threshold=0.5) >>> nms_boxes, nms_scores = boxes[nms_indices], scores[nms_indices]
-
combustion.vision.
visualize_bbox
(img, bbox=None, label=None, scores=None, class_names=None, box_color=255, 0, 0, text_color=255, 255, 255, label_alpha=0.4, thickness=2)[source]¶ Adds bounding box visualization to an input array
- Parameters
img (Tensor or numpy.ndarray) – The image to draw anchor boxes on.
bbox (Tensor or numpy.ndarray, optional) – The anchor boxes to draw
label (Tensor or numpy.ndarray, optional) – Class labels associated with each anchor box
scores (Tensor or numpy.ndarray, optional) – Class scores associated with each anchor box
class_names (dict, optional) – Dictionary mapping integer class labels to string names. If
label
is supplied butclass_names
is not, integer class labels will be used.box_color (tuple of ints, optional) – A 3-tuple giving the RGB color value to use for anchor boxes.
text_color (tuple of ints, optional) – A 3-tuple giving the RGB color value to use for labels.
label_alpha (float, optional) – Alpha to apply to the colored background for class labels.
thickness (int, optional) – Specifies the thickness of anchor boxes.
- Returns
torch.Tensor
ornumpy.ndarray
(depending on what was given for img) with the output image.- Return type
Union[torch.Tensor, numpy.ndarray]
-
class
combustion.vision.
AnchorsToPoints
(num_classes, downsample, iou_threshold=0.7, radius_div=3)[source]¶ Transform that converts bounding boxes to CenterNet style labels as described in the paper Objects as Points.
- Transformed outputs are as follows
probabilities of a pixel being a box center of class i with gaussian smoothing
x and y coordinates of the bounding box center in a downsampled grid
height and width of the anchor box
- Parameters
num_classes (int) – The number of possible classes for classification.
downsample (int) – An integer factor by which the image size will be downsampled to produce the label heatmap.
iou_threshold (float, optional) – The IoU threshold required for a possible anchor box to be considered in the calculation of the Gaussian smoothing sigma. Default 0.7.
radius_div (float, optional) – The factor by which the radius of all possible anchor boxes with IoU > threshold will be divided to determine the Gaussian smoothing sigma. Default 3.
- Shape:
Bounding boxes: \((*, N, 4)\) where \(*\) means an optional batch dimension and \(N\) is the number of bounding boxes
Classes: \((*, N, 1)\)
Output: \((*, C + 4, H, W)\) where \(C\) is the number of classes, and \(H, W\) are the height and width of the downsampled heatmap.
-
class
combustion.vision.
PointsToAnchors
(upsample, max_roi, threshold=0.0)[source]¶ Transform that converts CenterNet style labels to anchor boxes and class labels (i.e. reverses the transform performed by AnchorsToPoints) as described in the paper Objects as Points. Anchor boxes are identified in the input as points that are greater than their 8 neighbors. The maximum number of boxes returned is parameterized, and selection is performed based on classification score. A threshold is can also be set such that scores below this threshold will not contribute to the output.
- Parameters
upsample (int) – An integer factor by which the points will be upsampled to produce box coordinates.
max_roi (int) – The maximum number of boxes to include in the final output. Only the top max_roi scoring points will be converted into anchor boxes.
threshold (float, optional) – If given, discard boxes with classification scores less than or equal to threshold. Default 0.0
- Shape:
Points: \((*, C + 4, H, W)\) where \(C\) is the number of classes, and \(H, W\) are the height and width of the heatmap.
Output: \((*, N, 6)\) where \(*\) means an optional batch dimension and \(N\) is the number of output anchor boxes. Indices 0-3 of the output give the box coordinates \((x1, y1, x2, y2)\), index 4 gives classification score, and index 5 gives the class label.