Python object_detection.core.post_processing.batch_multiclass_non_max_suppression() Examples

The following are 30 code examples of object_detection.core.post_processing.batch_multiclass_non_max_suppression(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module object_detection.core.post_processing , or try the search function .
Example #1
Source File: post_processing_builder.py    From Traffic-Rule-Violation-Detection-System with MIT License 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #2
Source File: post_processing_builder.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` `masks, and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_classes` `nms_masks` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter,
      post_processing_config.logit_scale)
  return non_max_suppressor_fn, score_converter_fn 
Example #3
Source File: post_processing_builder.py    From ros_tensorflow with Apache License 2.0 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` `masks, and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_classes` `nms_masks` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter,
      post_processing_config.logit_scale)
  return non_max_suppressor_fn, score_converter_fn 
Example #4
Source File: post_processing_builder.py    From object_detector_app with MIT License 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #5
Source File: post_processing_test.py    From moveo_ros with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_1(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]],
                          [[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0],
                           [.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 999, 2, 1004],
                        [0, 100, 1, 101]]]
    exp_nms_scores = [[.95, .9, .85, .3]]
    exp_nms_classes = [[0, 0, 1, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertEqual(nms_output['num_detections'], [4]) 
Example #6
Source File: post_processing_test.py    From object_detector_app with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_2(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]]],
                         [[[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0]],
                          [[.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 0, 0, 0],
                        [0, 0, 0, 0]],
                       [[0, 999, 2, 1004],
                        [0, 10.1, 1, 11.1],
                        [0, 100, 1, 101],
                        [0, 0, 0, 0]]]
    exp_nms_scores = [[.95, .9, 0, 0],
                      [.85, .5, .3, 0]]
    exp_nms_classes = [[0, 0, 0, 0],
                       [1, 0, 0, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertAllClose(nms_output['num_detections'], [2, 3]) 
Example #7
Source File: post_processing_test.py    From object_detector_app with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_1(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]],
                          [[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0],
                           [.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 999, 2, 1004],
                        [0, 100, 1, 101]]]
    exp_nms_scores = [[.95, .9, .85, .3]]
    exp_nms_classes = [[0, 0, 1, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertEqual(nms_output['num_detections'], [4]) 
Example #8
Source File: post_processing_test.py    From moveo_ros with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_2(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]]],
                         [[[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0]],
                          [[.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 0, 0, 0],
                        [0, 0, 0, 0]],
                       [[0, 999, 2, 1004],
                        [0, 10.1, 1, 11.1],
                        [0, 100, 1, 101],
                        [0, 0, 0, 0]]]
    exp_nms_scores = [[.95, .9, 0, 0],
                      [.85, .5, .3, 0]]
    exp_nms_classes = [[0, 0, 0, 0],
                       [1, 0, 0, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertAllClose(nms_output['num_detections'], [2, 3]) 
Example #9
Source File: post_processing_builder.py    From DOTA_models with Apache License 2.0 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #10
Source File: post_processing_test.py    From DOTA_models with Apache License 2.0 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_2(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]]],
                         [[[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0]],
                          [[.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 0, 0, 0],
                        [0, 0, 0, 0]],
                       [[0, 999, 2, 1004],
                        [0, 10.1, 1, 11.1],
                        [0, 100, 1, 101],
                        [0, 0, 0, 0]]]
    exp_nms_scores = [[.95, .9, 0, 0],
                      [.85, .5, .3, 0]]
    exp_nms_classes = [[0, 0, 0, 0],
                       [1, 0, 0, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertAllClose(nms_output['num_detections'], [2, 3]) 
Example #11
Source File: post_processing_test.py    From DOTA_models with Apache License 2.0 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_1(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]],
                          [[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0],
                           [.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 999, 2, 1004],
                        [0, 100, 1, 101]]]
    exp_nms_scores = [[.95, .9, .85, .3]]
    exp_nms_classes = [[0, 0, 1, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertEqual(nms_output['num_detections'], [4]) 
Example #12
Source File: post_processing_builder.py    From BMW-TensorFlow-Training-GUI with Apache License 2.0 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` `masks, and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_classes` `nms_masks` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter,
      post_processing_config.logit_scale)
  return non_max_suppressor_fn, score_converter_fn 
Example #13
Source File: post_processing_builder.py    From ros_people_object_detection_tensorflow with Apache License 2.0 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #14
Source File: post_processing_builder.py    From Person-Detection-and-Tracking with MIT License 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` `masks, and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_classes` `nms_masks` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter,
      post_processing_config.logit_scale)
  return non_max_suppressor_fn, score_converter_fn 
Example #15
Source File: post_processing_test.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_1(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]],
                          [[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0],
                           [.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 999, 2, 1004],
                        [0, 100, 1, 101]]]
    exp_nms_scores = [[.95, .9, .85, .3]]
    exp_nms_classes = [[0, 0, 1, 0]]

    (nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_masks,
     num_detections) = post_processing.batch_multiclass_non_max_suppression(
         boxes, scores, score_thresh, iou_thresh,
         max_size_per_class=max_output_size, max_total_size=max_output_size)

    self.assertIsNone(nmsed_masks)

    with self.test_session() as sess:
      (nmsed_boxes, nmsed_scores, nmsed_classes,
       num_detections) = sess.run([nmsed_boxes, nmsed_scores, nmsed_classes,
                                   num_detections])
      self.assertAllClose(nmsed_boxes, exp_nms_corners)
      self.assertAllClose(nmsed_scores, exp_nms_scores)
      self.assertAllClose(nmsed_classes, exp_nms_classes)
      self.assertEqual(num_detections, [4]) 
Example #16
Source File: post_processing_builder.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_nms_classes` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter)
  return non_max_suppressor_fn, score_converter_fn 
Example #17
Source File: post_processing_builder.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #18
Source File: post_processing_builder.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #19
Source File: post_processing_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_1(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]],
                          [[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0],
                           [.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 999, 2, 1004],
                        [0, 100, 1, 101]]]
    exp_nms_scores = [[.95, .9, .85, .3]]
    exp_nms_classes = [[0, 0, 1, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertEqual(nms_output['num_detections'], [4]) 
Example #20
Source File: post_processing_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_2(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]]],
                         [[[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0]],
                          [[.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 0, 0, 0],
                        [0, 0, 0, 0]],
                       [[0, 999, 2, 1004],
                        [0, 10.1, 1, 11.1],
                        [0, 100, 1, 101],
                        [0, 0, 0, 0]]]
    exp_nms_scores = [[.95, .9, 0, 0],
                      [.85, .5, .3, 0]]
    exp_nms_classes = [[0, 0, 0, 0],
                       [1, 0, 0, 0]]

    nms_dict = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)
    with self.test_session() as sess:
      nms_output = sess.run(nms_dict)
      self.assertAllClose(nms_output['detection_boxes'], exp_nms_corners)
      self.assertAllClose(nms_output['detection_scores'], exp_nms_scores)
      self.assertAllClose(nms_output['detection_classes'], exp_nms_classes)
      self.assertAllClose(nms_output['num_detections'], [2, 3]) 
Example #21
Source File: post_processing_builder.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_nms_classes` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter)
  return non_max_suppressor_fn, score_converter_fn 
Example #22
Source File: post_processing_builder.py    From HereIsWally with MIT License 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #23
Source File: post_processing_test.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_1(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]],
                          [[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0],
                           [.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 999, 2, 1004],
                        [0, 100, 1, 101]]]
    exp_nms_scores = [[.95, .9, .85, .3]]
    exp_nms_classes = [[0, 0, 1, 0]]

    (nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_masks,
     num_detections) = post_processing.batch_multiclass_non_max_suppression(
         boxes, scores, score_thresh, iou_thresh,
         max_size_per_class=max_output_size, max_total_size=max_output_size)

    self.assertIsNone(nmsed_masks)

    with self.test_session() as sess:
      (nmsed_boxes, nmsed_scores, nmsed_classes,
       num_detections) = sess.run([nmsed_boxes, nmsed_scores, nmsed_classes,
                                   num_detections])
      self.assertAllClose(nmsed_boxes, exp_nms_corners)
      self.assertAllClose(nmsed_scores, exp_nms_scores)
      self.assertAllClose(nmsed_classes, exp_nms_classes)
      self.assertEqual(num_detections, [4]) 
Example #24
Source File: post_processing_builder.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #25
Source File: post_processing_builder.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` `masks, and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_classes` `nms_masks` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter,
      post_processing_config.logit_scale)
  return non_max_suppressor_fn, score_converter_fn 
Example #26
Source File: post_processing_builder.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def _build_non_max_suppressor(nms_config):
  """Builds non-max suppresson based on the nms config.

  Args:
    nms_config: post_processing_pb2.PostProcessing.BatchNonMaxSuppression proto.

  Returns:
    non_max_suppressor_fn: Callable non-max suppressor.

  Raises:
    ValueError: On incorrect iou_threshold or on incompatible values of
      max_total_detections and max_detections_per_class.
  """
  if nms_config.iou_threshold < 0 or nms_config.iou_threshold > 1.0:
    raise ValueError('iou_threshold not in [0, 1.0].')
  if nms_config.max_detections_per_class > nms_config.max_total_detections:
    raise ValueError('max_detections_per_class should be no greater than '
                     'max_total_detections.')

  non_max_suppressor_fn = functools.partial(
      post_processing.batch_multiclass_non_max_suppression,
      score_thresh=nms_config.score_threshold,
      iou_thresh=nms_config.iou_threshold,
      max_size_per_class=nms_config.max_detections_per_class,
      max_total_size=nms_config.max_total_detections)
  return non_max_suppressor_fn 
Example #27
Source File: post_processing_builder.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_nms_classes` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter)
  return non_max_suppressor_fn, score_converter_fn 
Example #28
Source File: post_processing_test.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_1(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]],
                          [[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0],
                           [.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = [[[0, 10, 1, 11],
                        [0, 0, 1, 1],
                        [0, 999, 2, 1004],
                        [0, 100, 1, 101]]]
    exp_nms_scores = [[.95, .9, .85, .3]]
    exp_nms_classes = [[0, 0, 1, 0]]

    (nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_masks,
     num_detections) = post_processing.batch_multiclass_non_max_suppression(
         boxes, scores, score_thresh, iou_thresh,
         max_size_per_class=max_output_size, max_total_size=max_output_size)

    self.assertIsNone(nmsed_masks)

    with self.test_session() as sess:
      (nmsed_boxes, nmsed_scores, nmsed_classes,
       num_detections) = sess.run([nmsed_boxes, nmsed_scores, nmsed_classes,
                                   num_detections])
      self.assertAllClose(nmsed_boxes, exp_nms_corners)
      self.assertAllClose(nmsed_scores, exp_nms_scores)
      self.assertAllClose(nmsed_classes, exp_nms_classes)
      self.assertEqual(num_detections, [4]) 
Example #29
Source File: post_processing_builder.py    From Gun-Detector with Apache License 2.0 5 votes vote down vote up
def build(post_processing_config):
  """Builds callables for post-processing operations.

  Builds callables for non-max suppression and score conversion based on the
  configuration.

  Non-max suppression callable takes `boxes`, `scores`, and optionally
  `clip_window`, `parallel_iterations` `masks, and `scope` as inputs. It returns
  `nms_boxes`, `nms_scores`, `nms_classes` `nms_masks` and `num_detections`. See
  post_processing.batch_multiclass_non_max_suppression for the type and shape
  of these tensors.

  Score converter callable should be called with `input` tensor. The callable
  returns the output from one of 3 tf operations based on the configuration -
  tf.identity, tf.sigmoid or tf.nn.softmax. See tensorflow documentation for
  argument and return value descriptions.

  Args:
    post_processing_config: post_processing.proto object containing the
      parameters for the post-processing operations.

  Returns:
    non_max_suppressor_fn: Callable for non-max suppression.
    score_converter_fn: Callable for score conversion.

  Raises:
    ValueError: if the post_processing_config is of incorrect type.
  """
  if not isinstance(post_processing_config, post_processing_pb2.PostProcessing):
    raise ValueError('post_processing_config not of type '
                     'post_processing_pb2.Postprocessing.')
  non_max_suppressor_fn = _build_non_max_suppressor(
      post_processing_config.batch_non_max_suppression)
  score_converter_fn = _build_score_converter(
      post_processing_config.score_converter,
      post_processing_config.logit_scale)
  return non_max_suppressor_fn, score_converter_fn 
Example #30
Source File: post_processing_test.py    From ros_tensorflow with Apache License 2.0 4 votes vote down vote up
def test_batch_multiclass_nms_with_batch_size_2(self):
    boxes = tf.constant([[[[0, 0, 1, 1], [0, 0, 4, 5]],
                          [[0, 0.1, 1, 1.1], [0, 0.1, 2, 1.1]],
                          [[0, -0.1, 1, 0.9], [0, -0.1, 1, 0.9]],
                          [[0, 10, 1, 11], [0, 10, 1, 11]]],
                         [[[0, 10.1, 1, 11.1], [0, 10.1, 1, 11.1]],
                          [[0, 100, 1, 101], [0, 100, 1, 101]],
                          [[0, 1000, 1, 1002], [0, 999, 2, 1004]],
                          [[0, 1000, 1, 1002.1], [0, 999, 2, 1002.7]]]],
                        tf.float32)
    scores = tf.constant([[[.9, 0.01], [.75, 0.05],
                           [.6, 0.01], [.95, 0]],
                          [[.5, 0.01], [.3, 0.01],
                           [.01, .85], [.01, .5]]])
    score_thresh = 0.1
    iou_thresh = .5
    max_output_size = 4

    exp_nms_corners = np.array([[[0, 10, 1, 11],
                                 [0, 0, 1, 1],
                                 [0, 0, 0, 0],
                                 [0, 0, 0, 0]],
                                [[0, 999, 2, 1004],
                                 [0, 10.1, 1, 11.1],
                                 [0, 100, 1, 101],
                                 [0, 0, 0, 0]]])
    exp_nms_scores = np.array([[.95, .9, 0, 0],
                               [.85, .5, .3, 0]])
    exp_nms_classes = np.array([[0, 0, 0, 0],
                                [1, 0, 0, 0]])

    (nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_masks,
     nmsed_additional_fields, num_detections
    ) = post_processing.batch_multiclass_non_max_suppression(
        boxes, scores, score_thresh, iou_thresh,
        max_size_per_class=max_output_size, max_total_size=max_output_size)

    self.assertIsNone(nmsed_masks)
    self.assertIsNone(nmsed_additional_fields)
    # Check static shapes
    self.assertAllEqual(nmsed_boxes.shape.as_list(),
                        exp_nms_corners.shape)
    self.assertAllEqual(nmsed_scores.shape.as_list(),
                        exp_nms_scores.shape)
    self.assertAllEqual(nmsed_classes.shape.as_list(),
                        exp_nms_classes.shape)
    self.assertEqual(num_detections.shape.as_list(), [2])

    with self.test_session() as sess:
      (nmsed_boxes, nmsed_scores, nmsed_classes,
       num_detections) = sess.run([nmsed_boxes, nmsed_scores, nmsed_classes,
                                   num_detections])
      self.assertAllClose(nmsed_boxes, exp_nms_corners)
      self.assertAllClose(nmsed_scores, exp_nms_scores)
      self.assertAllClose(nmsed_classes, exp_nms_classes)
      self.assertAllClose(num_detections, [2, 3])