Пример #1
0
 def test_builder(self, backbone_type, input_size):
     num_classes = 2
     input_specs = tf.keras.layers.InputSpec(
         shape=[None, input_size[0], input_size[1], 3])
     model_config = maskrcnn_cfg.MaskRCNN(
         num_classes=num_classes,
         backbone=backbones.Backbone(type=backbone_type))
     l2_regularizer = tf.keras.regularizers.l2(5e-5)
     _ = factory.build_maskrcnn(input_specs=input_specs,
                                model_config=model_config,
                                l2_regularizer=l2_regularizer)
Пример #2
0
    def build_model(self):
        """Build Mask R-CNN model."""

        input_specs = tf.keras.layers.InputSpec(
            shape=[None] + self.task_config.model.input_size)

        l2_weight_decay = self.task_config.losses.l2_weight_decay
        # Divide weight decay by 2.0 to match the implementation of tf.nn.l2_loss.
        # (https://www.tensorflow.org/api_docs/python/tf/keras/regularizers/l2)
        # (https://www.tensorflow.org/api_docs/python/tf/nn/l2_loss)
        l2_regularizer = (tf.keras.regularizers.l2(l2_weight_decay / 2.0)
                          if l2_weight_decay else None)

        model = factory.build_maskrcnn(input_specs=input_specs,
                                       model_config=self.task_config.model,
                                       l2_regularizer=l2_regularizer)
        return model
Пример #3
0
  def _build_model(self):

    if self._batch_size is None:
      raise ValueError('batch_size cannot be None for detection models.')
    input_specs = tf.keras.layers.InputSpec(shape=[self._batch_size] +
                                            self._input_image_size + [3])

    if isinstance(self.params.task.model, configs.maskrcnn.MaskRCNN):
      model = factory.build_maskrcnn(
          input_specs=input_specs, model_config=self.params.task.model)
    elif isinstance(self.params.task.model, configs.retinanet.RetinaNet):
      model = factory.build_retinanet(
          input_specs=input_specs, model_config=self.params.task.model)
    else:
      raise ValueError('Detection module not implemented for {} model.'.format(
          type(self.params.task.model)))

    return model
Пример #4
0
    def _build_model(self):

        if self._batch_size is None:
            # Only batched NMS is supported with dynamic batch size.
            self.params.task.model.detection_generator.nms_version = 'batched'
            logging.info(
                'nms_version is set to `batched` because only batched NMS is '
                'supported with dynamic batch size.')

        input_specs = tf.keras.layers.InputSpec(shape=[self._batch_size] +
                                                self._input_image_size + [3])

        if isinstance(self.params.task.model, configs.maskrcnn.MaskRCNN):
            model = factory.build_maskrcnn(input_specs=input_specs,
                                           model_config=self.params.task.model)
        elif isinstance(self.params.task.model, configs.retinanet.RetinaNet):
            model = factory.build_retinanet(
                input_specs=input_specs, model_config=self.params.task.model)
        else:
            raise ValueError(
                'Detection module not implemented for {} model.'.format(
                    type(self.params.task.model)))

        return model