def test_raise_error_on_empty_box_coder(self):
     box_coder_text_proto = """
 """
     box_coder_proto = box_coder_pb2.BoxCoder()
     text_format.Merge(box_coder_text_proto, box_coder_proto)
     with self.assertRaises(ValueError):
         box_coder_builder.build(box_coder_proto)
 def test_build_square_box_coder_with_defaults(self):
     box_coder_text_proto = """
   square_box_coder {
   }
 """
     box_coder_proto = box_coder_pb2.BoxCoder()
     text_format.Merge(box_coder_text_proto, box_coder_proto)
     box_coder_object = box_coder_builder.build(box_coder_proto)
     self.assertTrue(
         isinstance(box_coder_object, square_box_coder.SquareBoxCoder))
     self.assertEqual(box_coder_object._scale_factors, [10.0, 10.0, 5.0])
 def test_build_mean_stddev_box_coder(self):
     box_coder_text_proto = """
   mean_stddev_box_coder {
   }
 """
     box_coder_proto = box_coder_pb2.BoxCoder()
     text_format.Merge(box_coder_text_proto, box_coder_proto)
     box_coder_object = box_coder_builder.build(box_coder_proto)
     self.assertTrue(
         isinstance(box_coder_object,
                    mean_stddev_box_coder.MeanStddevBoxCoder))
Ejemplo n.º 4
0
 def test_build_keypoint_box_coder_with_defaults(self):
     box_coder_text_proto = """
   keypoint_box_coder {
   }
 """
     box_coder_proto = box_coder_pb2.BoxCoder()
     text_format.Merge(box_coder_text_proto, box_coder_proto)
     box_coder_object = box_coder_builder.build(box_coder_proto)
     self.assertIsInstance(box_coder_object,
                           keypoint_box_coder.KeypointBoxCoder)
     self.assertEqual(box_coder_object._scale_factors,
                      [10.0, 10.0, 5.0, 5.0])
 def test_build_square_box_coder_with_non_default_parameters(self):
     box_coder_text_proto = """
   square_box_coder {
     y_scale: 6.0
     x_scale: 3.0
     length_scale: 7.0
   }
 """
     box_coder_proto = box_coder_pb2.BoxCoder()
     text_format.Merge(box_coder_text_proto, box_coder_proto)
     box_coder_object = box_coder_builder.build(box_coder_proto)
     self.assertTrue(
         isinstance(box_coder_object, square_box_coder.SquareBoxCoder))
     self.assertEqual(box_coder_object._scale_factors, [6.0, 3.0, 7.0])
 def test_build_faster_rcnn_box_coder_with_non_default_parameters(self):
     box_coder_text_proto = """
   faster_rcnn_box_coder {
     y_scale: 6.0
     x_scale: 3.0
     height_scale: 7.0
     width_scale: 8.0
   }
 """
     box_coder_proto = box_coder_pb2.BoxCoder()
     text_format.Merge(box_coder_text_proto, box_coder_proto)
     box_coder_object = box_coder_builder.build(box_coder_proto)
     self.assertTrue(isinstance(box_coder_object,
                                faster_rcnn_box_coder.FasterRcnnBoxCoder))
     self.assertEqual(box_coder_object._scale_factors, [6.0, 3.0, 7.0, 8.0])
Ejemplo n.º 7
0
 def test_build_keypoint_box_coder_with_non_default_parameters(self):
     box_coder_text_proto = """
   keypoint_box_coder {
     num_keypoints: 6
     y_scale: 6.0
     x_scale: 3.0
     height_scale: 7.0
     width_scale: 8.0
   }
 """
     box_coder_proto = box_coder_pb2.BoxCoder()
     text_format.Merge(box_coder_text_proto, box_coder_proto)
     box_coder_object = box_coder_builder.build(box_coder_proto)
     self.assertIsInstance(box_coder_object,
                           keypoint_box_coder.KeypointBoxCoder)
     self.assertEqual(box_coder_object._num_keypoints, 6)
     self.assertEqual(box_coder_object._scale_factors, [6.0, 3.0, 7.0, 8.0])
def generate_ssd_model(num_classes):

    ssd_config = ssd_pb2.Ssd()
    ssd_config.num_classes = num_classes

    # config box_coder
    from object_detection.protos import box_coder_pb2
    from object_detection.protos import faster_rcnn_box_coder_pb2
    box_coder = box_coder_pb2.BoxCoder()
    faster_rcnn_box_coder = faster_rcnn_box_coder_pb2.FasterRcnnBoxCoder()
    faster_rcnn_box_coder.y_scale = 10.0
    faster_rcnn_box_coder.x_scale = 10.0
    faster_rcnn_box_coder.height_scale = 5.0
    faster_rcnn_box_coder.width_scale = 5.0
    box_coder.faster_rcnn_box_coder.CopyFrom(faster_rcnn_box_coder)
    ssd_config.box_coder.CopyFrom(box_coder)

    # config matcher
    from object_detection.protos import matcher_pb2
    from object_detection.protos import argmax_matcher_pb2
    argmax_matcher = argmax_matcher_pb2.ArgMaxMatcher()
    argmax_matcher.matched_threshold = 0.5
    argmax_matcher.unmatched_threshold = 0.5
    argmax_matcher.ignore_thresholds = False
    argmax_matcher.negatives_lower_than_unmatched = True
    argmax_matcher.force_match_for_each_row = True
    matcher = matcher_pb2.Matcher()
    matcher.argmax_matcher.CopyFrom(argmax_matcher)
    ssd_config.matcher.CopyFrom(matcher)

    # config anchor generator
    from object_detection.protos import anchor_generator_pb2
    from object_detection.protos import ssd_anchor_generator_pb2
    ssd_anchor_generator = ssd_anchor_generator_pb2.SsdAnchorGenerator()
    ssd_anchor_generator.num_layers = 6
    ssd_anchor_generator.min_scale = 0.2
    ssd_anchor_generator.max_scale = 0.95
    ssd_anchor_generator.aspect_ratios.extend([1.0, 2.0, 0.5, 3.0, 0.3333])
    anchor_generator = anchor_generator_pb2.AnchorGenerator()
    anchor_generator.ssd_anchor_generator.CopyFrom(ssd_anchor_generator)
    ssd_config.anchor_generator.CopyFrom(anchor_generator)

    return ssd_config