lingvo.tasks.car.ap_metric module

Average precision metric interface.

class lingvo.tasks.car.ap_metric.Boxes3D[source]

Bases: object

A container for a list of 7-DOF 3D boxes.

Each 3D box is represented by the 7-tuple [x, y, z, dx, dy, dz, phi], where x, y, z is the center of the box, dx, dy, dz represent the width, length, and height of the box, and phi is the rotation of the box.

Add(img_id, score, box, difficulty, distance, num_points, rotation, height_in_pixels, speed)[source]

Adds a bbox.

Parameters
  • img_id – A unique image identifier.

  • score – The confidence score.

  • box – [1 x 7] numpy array.

  • difficulty – The difficulty of a box. On KITTI this is one of [0, 1, 2, 3].

  • distance – The binned distance of a box.

  • num_points – Number of laser points in box.

  • rotation – The binned rotation of a box.

  • height_in_pixels – The height of the 2D bbox of this object in the camera image.

  • speed – A [1 x 2] numpy array with speed of object in world frame.

_Resize(arr)[source]
property imgids
property scores
property boxes
property difficulties
property distances
property num_points
property rotations
property heights_in_pixels
property speeds
class lingvo.tasks.car.ap_metric.APMetrics(params)[source]

Bases: lingvo.core.metrics.BaseMetric

Measure an assortment of precision-recall metrics on a dataset.

classmethod Params(metadata)[source]

Params builder for APMetrics.

_GetImageId(str_id)[source]
_AddGroundtruth(box)[source]

Record a ground truth box.

_LoadBoundingBoxes(box_type, class_id, distance=None, num_points=None, rotation=None)[source]

Load a specified set of bounding boxes.

If no boxes are found, return None.

Note that we do not specify ‘difficulty’ as an option due to how the KITTI evaluates bounding boxes across difficulty levels.

Parameters
  • box_type – string. Either ‘groundtruth’ or ‘prediction’

  • class_id – int32 specifying the class

  • distance – int32 specifying a binned Euclidean distance of the ground truth bounding box. If None is specified, all distances are selected.

  • num_points – int32 specifying a binned number of laser points within the ground truth bounding box. If None is specified, all boxes are selected.

  • rotation – int32 specifying a binned rotation within the ground truth bounding box. If None is specified, all boxes are selected.

Returns

Boxes3D containing bounding boxes or None if no bounding boxes available.

_GetData(classid, difficulty=None, distance=None, num_points=None, rotation=None)[source]

Returns groundtruth and prediction for the classid in a NestedMap.

Parameters
  • classid – int32 specifying the class

  • difficulty – String in [easy, moderate, hard]. If None specified, all difficulty levels are permitted.

  • distance – int32 specifying a binned Euclidean distance of the ground truth bounding box. If None is specified, all distances are selected.

  • num_points – int32 specifying a binned number of laser points within the ground truth bounding box. If None is specified, all boxes are selected.

  • rotation – int32 specifying a binned rotation within the ground truth bounding box. If None is specified, all boxes are selected.

Returns

NestedMap containing iou_threshold, groundtruth and predictions for specified, classid, difficulty level and binned distance. If no bboxes are found with these parameters, returns None.

_BuildMetric(feed_data, classid)[source]
_ComputeFinalMetrics(classids=None, difficulty=None, distance=None, num_points=None, rotation=None)[source]

Compute precision-recall curves as well as average precision.

Parameters
  • classids – A list of N int32.

  • difficulty – String in [easy, moderate, hard]. If None specified, all difficulty levels are permitted.

  • distance – int32 specifying a binned Euclidean distance of the ground truth bounding box. If None is specified, all distances are selected.

  • num_points – int32 specifying a binned number of laser points within the ground truth bounding box. If None is specified, all boxes are selected.

  • rotation – int32 specifying a binned rotation within the ground truth bounding box. If None is specified, all boxes are selected.

Returns

dict. Each entry in the dict is a list of C (number of classes) dicts containing mapping from metric names to individual results. Individual entries may be the following items. - scalars: A list of C (number of classes) dicts mapping metric names to scalar values. - curves: A list of C dicts mapping metrics names to np.float32 arrays of shape [NumberOfPrecisionRecallPoints()+1, 2]. In the last dimension, 0 indexes precision and 1 indexes recall. - calibrations: A list of C dicts mapping metrics names to np.float32 arrays of shape [number of predictions, 2]. The first column is the predicted probabilty and the second column is 0 or 1 indicating that the prediction matched a ground truth item.

Update(str_id, result)[source]

Update this metric with a newly evaluated image.

Parameters
  • str_id – A string. Unique identifier of an image.

  • result

    A NestedMap with these fields: groundtruth_labels - [N]. Groundtruth boxes’ labels.

    groundtruth_bboxes - [N, 7]. Groundtruth boxes coordinates.

    groundtruth_difficulties - [N]. Groundtruth boxes difficulties.

    groundtruth_num_points - [N]. Number of laser points in bounding boxes.

    groundtruth_speed - [N, 2] Speed in (vx, vy) of the ground truth

    object.

    detection_scores - [C, M] - For each class (C classes) we have (up to) M predicted boxes.

    detection_boxes - [C, M, 7] - [i, j, :] are coordinates for i-th classes j-th predicted box.

    detection_heights_in_pixels - [C, M]. [i, j] is the height of i-th classes j-th boxes 2D image coordinate (camera view).

_EvaluateIfNecessary()[source]

Evaluate all precision recall metrics.

property value

Current value of this metric.

_AveragePrecisionByDifficulty()[source]

Special case to identify mAP versus difficulty.

Summary(name)[source]

Converts the current state of this metric to a tf.Summary.

Parameters

name – A string to use as the summary value tag.

Returns

A tf.Summary proto.