コード例 #1
0
 def test_raise_error_on_empty_matcher(self):
     matcher_text_proto = """
 """
     matcher_proto = matcher_pb2.Matcher()
     text_format.Merge(matcher_text_proto, matcher_proto)
     with self.assertRaises(ValueError):
         matcher_builder.build(matcher_proto)
コード例 #2
0
ファイル: model_builder.py プロジェクト: nbarreira/cartoonify
def _build_ssd_model(ssd_config, is_training):
  """Builds an SSD detection model based on the model config.

  Args:
    ssd_config: A ssd.proto object containing the config for the desired
      SSDMetaArch.
    is_training: True if this model is being built for training purposes.

  Returns:
    SSDMetaArch based on the config.
  Raises:
    ValueError: If ssd_config.type is not recognized (i.e. not registered in
      model_class_map).
  """
  num_classes = ssd_config.num_classes

  # Feature extractor
  feature_extractor = _build_ssd_feature_extractor(ssd_config.feature_extractor,
                                                   is_training)

  box_coder = box_coder_builder.build(ssd_config.box_coder)
  matcher = matcher_builder.build(ssd_config.matcher)
  region_similarity_calculator = sim_calc.build(
      ssd_config.similarity_calculator)
  ssd_box_predictor = box_predictor_builder.build(hyperparams_builder.build,
                                                  ssd_config.box_predictor,
                                                  is_training, num_classes)
  anchor_generator = anchor_generator_builder.build(
      ssd_config.anchor_generator)
  image_resizer_fn = image_resizer_builder.build(ssd_config.image_resizer)
  non_max_suppression_fn, score_conversion_fn = post_processing_builder.build(
      ssd_config.post_processing)
  (classification_loss, localization_loss, classification_weight,
   localization_weight,
   hard_example_miner) = losses_builder.build(ssd_config.loss)
  normalize_loss_by_num_matches = ssd_config.normalize_loss_by_num_matches

  return ssd_meta_arch.SSDMetaArch(
      is_training,
      anchor_generator,
      ssd_box_predictor,
      box_coder,
      feature_extractor,
      matcher,
      region_similarity_calculator,
      image_resizer_fn,
      non_max_suppression_fn,
      score_conversion_fn,
      classification_loss,
      localization_loss,
      classification_weight,
      localization_weight,
      normalize_loss_by_num_matches,
      hard_example_miner)
コード例 #3
0
 def test_build_bipartite_matcher(self):
     matcher_text_proto = """
   bipartite_matcher {
   }
 """
     matcher_proto = matcher_pb2.Matcher()
     text_format.Merge(matcher_text_proto, matcher_proto)
     matcher_object = matcher_builder.build(matcher_proto)
     self.assertTrue(
         isinstance(matcher_object,
                    bipartite_matcher.GreedyBipartiteMatcher))
コード例 #4
0
 def test_build_arg_max_matcher_with_defaults(self):
     matcher_text_proto = """
   argmax_matcher {
   }
 """
     matcher_proto = matcher_pb2.Matcher()
     text_format.Merge(matcher_text_proto, matcher_proto)
     matcher_object = matcher_builder.build(matcher_proto)
     self.assertTrue(
         isinstance(matcher_object, argmax_matcher.ArgMaxMatcher))
     self.assertAlmostEqual(matcher_object._matched_threshold, 0.5)
     self.assertAlmostEqual(matcher_object._unmatched_threshold, 0.5)
     self.assertTrue(matcher_object._negatives_lower_than_unmatched)
     self.assertFalse(matcher_object._force_match_for_each_row)