コード例 #1
0
ファイル: kitti_ap_metric.py プロジェクト: snsun/lingvo
  def _BuildMetric(self, feed_data, classid):
    """Construct tensors and the feed_dict for KITTI metric op.

    Args:
      feed_data: a NestedMap returned by _GetData()
      classid: integer. Unused in this implementation.

    Returns:
      scalar_metrics: a dict mapping all the metric names to fetch tensors.
      curves: a dict mapping all the curve names to fetch tensors.
      feed_dict: a dict mapping all the tensors in feed_tensors to feed values.
    """
    if feed_data is None:
      dummy_scalar = tf.constant(np.nan)
      dummy_curve = tf.zeros([self.metadata.NumberOfPrecisionRecallPoints(), 2],
                             tf.float32)
      scalar_metrics = {'ap': dummy_scalar}
      curve_metrics = {'pr': dummy_curve}
      return scalar_metrics, curve_metrics, {}

    feed_dict = {}

    f_iou = tf.placeholder(tf.float32)
    feed_dict[f_iou] = feed_data.iou_threshold

    f_gt_bbox = tf.placeholder(tf.float32)
    feed_dict[f_gt_bbox] = feed_data.gt.bbox

    f_gt_imgid = tf.placeholder(tf.int32)
    feed_dict[f_gt_imgid] = feed_data.gt.imgid

    f_gt_ignore = tf.placeholder(tf.int32)
    feed_dict[f_gt_ignore] = feed_data.gt.ignore

    f_pd_bbox = tf.placeholder(tf.float32)
    feed_dict[f_pd_bbox] = feed_data.pd.bbox

    f_pd_imgid = tf.placeholder(tf.int32)
    feed_dict[f_pd_imgid] = feed_data.pd.imgid

    f_pd_ignore = tf.placeholder(tf.int32)
    feed_dict[f_pd_ignore] = feed_data.pd.ignore

    f_pd_score = tf.placeholder(tf.float32)
    feed_dict[f_pd_score] = feed_data.pd.score

    ap, pr = ops.average_precision3d(
        iou_threshold=f_iou,
        groundtruth_bbox=f_gt_bbox,
        groundtruth_imageid=f_gt_imgid,
        groundtruth_ignore=f_gt_ignore,
        prediction_bbox=f_pd_bbox,
        prediction_imageid=f_pd_imgid,
        prediction_ignore=f_pd_ignore,
        prediction_score=f_pd_score,
        num_recall_points=self.metadata.NumberOfPrecisionRecallPoints())

    scalar_metrics = {'ap': ap}
    curve_metrics = {'pr': pr}
    return scalar_metrics, curve_metrics, feed_dict
コード例 #2
0
 def _GetAP(self, gt_bbox, gt_imgid, pd_bbox, pd_imgid, pd_score):
     g = tf.Graph()
     with g.as_default():
         iou, pr = ops.average_precision3d(
             iou_threshold=0.5,
             groundtruth_bbox=gt_bbox,
             groundtruth_imageid=gt_imgid,
             groundtruth_ignore=tf.zeros_like(gt_imgid, dtype=tf.int32),
             prediction_bbox=pd_bbox,
             prediction_imageid=pd_imgid,
             prediction_score=pd_score,
             prediction_ignore=tf.zeros_like(pd_imgid, dtype=tf.int32),
             num_recall_points=41,
             algorithm='KITTI')
     with self.session(graph=g) as sess:
         val = sess.run([iou, pr])
     return val
コード例 #3
0
ファイル: kitti_ap_metric.py プロジェクト: tensorflow/lingvo
    def _BuildMetric(self, feed_data, classid):
        """Construct tensors and the feed_dict for KITTI metric op.

    Args:
      feed_data: a NestedMap returned by _GetData()
      classid: integer. Unused in this implementation.

    Returns:
      A tuple of 3 dicts:

      - scalar_metrics: a dict mapping all the metric names to fetch tensors.
      - curves: a dict mapping all the curve names to fetch tensors.
      - feed_dict: a dict mapping the tensors in feed_tensors to feed values.
    """
        if feed_data is None:
            dummy_scalar = tf.constant(np.nan)
            dummy_calibration = tf.constant(np.nan)
            dummy_curve = tf.zeros(
                [self.metadata.NumberOfPrecisionRecallPoints(), 2], tf.float32)
            scalar_metrics = {'ap': dummy_scalar}
            curve_metrics = {'pr': dummy_curve}
            calibration_metrics = {'calibrations': dummy_calibration}

            return py_utils.NestedMap(feed_dict={},
                                      scalar_metrics=scalar_metrics,
                                      curve_metrics=curve_metrics,
                                      calibration_metrics=calibration_metrics)

        feed_dict = {}

        f_iou = tf.placeholder(tf.float32)
        feed_dict[f_iou] = feed_data.iou_threshold

        f_gt_bbox = tf.placeholder(tf.float32)
        feed_dict[f_gt_bbox] = feed_data.gt.bbox

        f_gt_imgid = tf.placeholder(tf.int32)
        feed_dict[f_gt_imgid] = feed_data.gt.imgid

        f_gt_ignore = tf.placeholder(tf.int32)
        feed_dict[f_gt_ignore] = feed_data.gt.ignore

        f_pd_bbox = tf.placeholder(tf.float32)
        feed_dict[f_pd_bbox] = feed_data.pd.bbox

        f_pd_imgid = tf.placeholder(tf.int32)
        feed_dict[f_pd_imgid] = feed_data.pd.imgid

        f_pd_ignore = tf.placeholder(tf.int32)
        feed_dict[f_pd_ignore] = feed_data.pd.ignore

        f_pd_score = tf.placeholder(tf.float32)
        feed_dict[f_pd_score] = feed_data.pd.score

        # TODO(shlens): The third returned argument contain statistics for measuring
        # the calibration error. Use it.
        ap, pr, calibration = ops.average_precision3d(
            iou_threshold=f_iou,
            groundtruth_bbox=f_gt_bbox,
            groundtruth_imageid=f_gt_imgid,
            groundtruth_ignore=f_gt_ignore,
            prediction_bbox=f_pd_bbox,
            prediction_imageid=f_pd_imgid,
            prediction_ignore=f_pd_ignore,
            prediction_score=f_pd_score,
            num_recall_points=self.metadata.NumberOfPrecisionRecallPoints())

        scalar_metrics = {'ap': ap}
        curve_metrics = {'pr': pr}
        calibration_metrics = {'calibrations': calibration}
        return py_utils.NestedMap(feed_dict=feed_dict,
                                  scalar_metrics=scalar_metrics,
                                  curve_metrics=curve_metrics,
                                  calibration_metrics=calibration_metrics)