tvm.relay.vision

Vision network related operators.

Multibox operations.

tvm.relay.op.vision.multibox.multibox_prior(data, sizes=(1.0, ), ratios=(1.0, ), steps=(-1.0, -1.0), offsets=(0.5, 0.5), clip=False)

Generate prior(anchor) boxes from data, sizes and ratios.

Parameters:
  • data (relay.Expr) – The input data tensor.
  • sizes (tuple of float, optional) – Tuple of sizes for anchor boxes.
  • ratios (tuple of float, optional) – Tuple of ratios for anchor boxes.
  • steps (Tuple of float, optional) – Priorbox step across y and x, -1 for auto calculation.
  • offsets (tuple of int, optional) – Priorbox center offsets, y and x respectively.
  • clip (boolean, optional) – Whether to clip out-of-boundary boxes.
Returns:

out – 3-D tensor with shape [1, h_in * w_in * (num_sizes + num_ratios - 1), 4]

Return type:

relay.Expr

tvm.relay.op.vision.multibox.multibox_transform_loc(cls_prob, loc_pred, anchor, clip=True, threshold=0.01, variances=(0.1, 0.1, 0.2, 0.2))

Location transformation for multibox detection

Parameters:
  • cls_prob (tvm.relay.Expr) – Class probabilities.
  • loc_pred (tvm.relay.Expr) – Location regression predictions.
  • anchor (tvm.relay.Expr) – Prior anchor boxes.
  • clip (boolean, optional) – Whether to clip out-of-boundary boxes.
  • threshold (double, optional) – Threshold to be a positive prediction.
  • variances (Tuple of float, optional) – variances to be decoded from box regression output.
Returns:

ret

Return type:

tuple of tvm.relay.Expr

Non-maximum suppression operations.

tvm.relay.op.vision.nms.get_valid_counts(data, score_threshold)

Get valid count of bounding boxes given a score threshold. Also moves valid boxes to the top of input data.

Parameters:
  • data (relay.Expr) – Input data. 3-D tensor with shape [batch_size, num_anchors, 6].
  • score_threshold (optional, float) – Lower limit of score for valid bounding boxes.
Returns:

  • valid_count (relay.Expr) – 1-D tensor for valid number of boxes.
  • out_tensor (relay.Expr) – Rearranged data tensor.

tvm.relay.op.vision.nms.non_max_suppression(data, valid_count, max_output_size=-1, iou_threshold=0.5, force_suppress=False, top_k=-1, id_index=0, return_indices=True, invalid_to_bottom=False)

Non-maximum suppression operator for object detection.

Parameters:
  • data (relay.Expr) – 3-D tensor with shape [batch_size, num_anchors, 6]. The last dimension should be in format of [class_id, score, box_left, box_top, box_right, box_bottom].
  • valid_count (relay.Expr) – 1-D tensor for valid number of boxes.
  • max_output_size (int, optional) – Max number of output valid boxes for each instance. By default all valid boxes are returned.
  • iou_threshold (float, optional) – Non-maximum suppression threshold.
  • force_suppress (bool, optional) – Suppress all detections regardless of class_id.
  • top_k (int, optional) – Keep maximum top k detections before nms, -1 for no limit.
  • id_index (int, optional) – index of the class categories, -1 to disable.
  • return_indices (bool, optional) – Whether to return box indices in input data.
  • invalid_to_bottom (bool, optional) – Whether to move all valid bounding boxes to the top.
Returns:

out – 3-D tensor with shape [batch_size, num_anchors, 6].

Return type:

relay.Expr