RetinaNetObjectDetector model

[source]

RetinaNetObjectDetector class

keras_hub.models.RetinaNetObjectDetector(
    backbone,
    num_classes,
    bounding_box_format="yxyx",
    anchor_generator=None,
    label_encoder=None,
    use_prediction_head_norm=False,
    classification_head_prior_probability=0.01,
    pre_logits_num_conv_layers=4,
    preprocessor=None,
    activation=None,
    dtype=None,
    prediction_decoder=None,
    **kwargs
)

RetinaNet object detector model.

This class implements the RetinaNet object detection architecture. It consists of a feature extractor backbone, a feature pyramid network(FPN), and two prediction heads (for classification and bounding box regression).

Arguments

  • backbone: keras.Model. A keras.models.RetinaNetBackbone class, defining the backbone network architecture. Provides feature maps for detection.
  • anchor_generator: A keras_hub.layers.AnchorGenerator instance. Generates anchor boxes at different scales and aspect ratios across the image. If None, a default AnchorGenerator is created with the following parameters: - bounding_box_format: Same as the model's bounding_box_format. - min_level: The backbone's min_level. - max_level: The backbone's max_level. - num_scales: 3. - aspect_ratios: [0.5, 1.0, 2.0]. - anchor_size: 4.0. You can create a custom AnchorGenerator by instantiating the keras_hub.layers.AnchorGenerator class and passing the desired arguments.
  • num_classes: int. The number of object classes to be detected.
  • bounding_box_format: str. Dataset bounding box format (e.g., "xyxy", "yxyx"). Defaults to yxyx.
  • label_encoder: Optional. A RetinaNetLabelEncoder instance. Encodes ground truth boxes and classes into training targets. It matches ground truth boxes to anchors based on IoU and encodes box coordinates as offsets. If None, a default encoder is created. See the RetinaNetLabelEncoder class for details. If None, a default encoder is created with standard parameters. - anchor_generator: Same as the model's. - bounding_box_format: Same as the model's bounding_box_format. - positive_threshold: 0.5 - negative_threshold: 0.4 - encoding_format: "center_xywh" - box_variance: [1.0, 1.0, 1.0, 1.0] - background_class: -1 - ignore_class: -2
  • use_prediction_head_norm: bool. Whether to use Group Normalization after the convolution layers in the prediction heads. Defaults to False.
  • classification_head_prior_probability: float. Prior probability for the classification head (used for focal loss). Defaults to 0.01.
  • pre_logits_num_conv_layers: int. The number of convolutional layers in the head before the logits layer. These convolutional layers are applied before the final linear layer (logits) that produces the output predictions (bounding box regressions, classification scores).
  • preprocessor: Optional. An instance of RetinaNetObjectDetectorPreprocessoror a custom preprocessor. Handles image preprocessing before feeding into the backbone.
  • activation: Optional. The activation function to be used in the classification head. If None, sigmoid is used.
  • dtype: Optional. The data type for the prediction heads. Defaults to the backbone's dtype policy.
  • prediction_decoder: Optional. A keras.layers.Layer instance responsible for transforming RetinaNet predictions (box regressions and classifications) into final bounding boxes and classes with confidence scores. Defaults to a NonMaxSuppression instance.

[source]

from_preset method

RetinaNetObjectDetector.from_preset(preset, load_weights=True, **kwargs)

Instantiate a keras_hub.models.Task from a model preset.

A preset is a directory of configs, weights and other file assets used to save and load a pre-trained model. The preset can be passed as one of:

  1. a built-in preset identifier like 'bert_base_en'
  2. a Kaggle Models handle like 'kaggle://user/bert/keras/bert_base_en'
  3. a Hugging Face handle like 'hf://user/bert_base_en'
  4. a path to a local preset directory like './bert_base_en'

For any Task subclass, you can run cls.presets.keys() to list all built-in presets available on the class.

This constructor can be called in one of two ways. Either from a task specific base class like keras_hub.models.CausalLM.from_preset(), or from a model class like keras_hub.models.BertTextClassifier.from_preset(). If calling from the a base class, the subclass of the returning object will be inferred from the config in the preset directory.

Arguments

  • preset: string. A built-in preset identifier, a Kaggle Models handle, a Hugging Face handle, or a path to a local directory.
  • load_weights: bool. If True, saved weights will be loaded into the model architecture. If False, all weights will be randomly initialized.

Examples

# Load a Gemma generative task.
causal_lm = keras_hub.models.CausalLM.from_preset(
    "gemma_2b_en",
)

# Load a Bert classification task.
model = keras_hub.models.TextClassifier.from_preset(
    "bert_base_en",
    num_classes=2,
)
Preset Parameters Description
retinanet_resnet50_fpn_coco 34.12M RetinaNet model with ResNet50 backbone fine-tuned on COCO in 800x800 resolution.

backbone property

keras_hub.models.RetinaNetObjectDetector.backbone

A keras_hub.models.Backbone model with the core architecture.


preprocessor property

keras_hub.models.RetinaNetObjectDetector.preprocessor

A keras_hub.models.Preprocessor layer used to preprocess input.