You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.2 KiB

6 years ago
  1. # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """A function to build an object detection matcher from configuration."""
  16. from object_detection.matchers import argmax_matcher
  17. from object_detection.matchers import bipartite_matcher
  18. from object_detection.protos import matcher_pb2
  19. def build(matcher_config):
  20. """Builds a matcher object based on the matcher config.
  21. Args:
  22. matcher_config: A matcher.proto object containing the config for the desired
  23. Matcher.
  24. Returns:
  25. Matcher based on the config.
  26. Raises:
  27. ValueError: On empty matcher proto.
  28. """
  29. if not isinstance(matcher_config, matcher_pb2.Matcher):
  30. raise ValueError('matcher_config not of type matcher_pb2.Matcher.')
  31. if matcher_config.WhichOneof('matcher_oneof') == 'argmax_matcher':
  32. matcher = matcher_config.argmax_matcher
  33. matched_threshold = unmatched_threshold = None
  34. if not matcher.ignore_thresholds:
  35. matched_threshold = matcher.matched_threshold
  36. unmatched_threshold = matcher.unmatched_threshold
  37. return argmax_matcher.ArgMaxMatcher(
  38. matched_threshold=matched_threshold,
  39. unmatched_threshold=unmatched_threshold,
  40. negatives_lower_than_unmatched=matcher.negatives_lower_than_unmatched,
  41. force_match_for_each_row=matcher.force_match_for_each_row,
  42. use_matmul_gather=matcher.use_matmul_gather)
  43. if matcher_config.WhichOneof('matcher_oneof') == 'bipartite_matcher':
  44. matcher = matcher_config.bipartite_matcher
  45. return bipartite_matcher.GreedyBipartiteMatcher(matcher.use_matmul_gather)
  46. raise ValueError('Empty matcher.')