KerasHub: Pretrained Models / API documentation / Model Architectures / RetinaNet / RetinaNetObjectDetectorPreprocessor layer

RetinaNetObjectDetectorPreprocessor layer

[source]

RetinaNetObjectDetectorPreprocessor class

keras_hub.models.RetinaNetObjectDetectorPreprocessor(image_converter=None, **kwargs)

Base class for object detector preprocessing layers.

ObjectDetectorPreprocessor tasks wraps a keras_hub.layers.Preprocessor to create a preprocessing layer for object detection tasks. It is intended to be paired with a keras_hub.models.ImageObjectDetector task.

All ObjectDetectorPreprocessor take three inputs, x, y, and sample_weight. x, the first input, should always be included. It can be a image or batch of images. See examples below. y and sample_weight are optional inputs that will be passed through unaltered. Usually, y will be the a dict of `{"boxes": Tensor(batch_size, num_boxes, 4), "classes": (batch_size, num_boxes)}.

The layer will returns either x, an (x, y) tuple if labels were provided, or an (x, y, sample_weight) tuple if labels and sample weight were provided. x will be the input images after all model preprocessing has been applied.

All ObjectDetectorPreprocessor tasks include a from_preset() constructor which can be used to load a pre-trained config and vocabularies. You can call the from_preset() constructor directly on this base class, in which case the correct class for your model will be automatically instantiated.

Arguments

  • image_converter: Preprocessing pipeline for images.

Examples.

preprocessor = keras_hub.models.ObjectDetectorPreprocessor.from_preset(
    "retinanet_resnet50",
)


----

<span style="float:right;">[[source]](https://github.com/keras-team/keras-hub/tree/v0.19.3/keras_hub/src/models/preprocessor.py#L132)</span>

### `from_preset` method


```python
RetinaNetObjectDetectorPreprocessor.from_preset(
    preset, config_file="preprocessor.json", **kwargs
)

Instantiate a keras_hub.models.Preprocessor 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 Preprocessor subclass, you can run cls.presets.keys() to list all built-in presets available on the class.

As there are usually multiple preprocessing classes for a given model, this method should be called on a specific subclass like keras_hub.models.BertTextClassifierPreprocessor.from_preset().

Arguments

  • preset: string. A built-in preset identifier, a Kaggle Models handle, a Hugging Face handle, or a path to a local directory.

Examples

# Load a preprocessor for Gemma generation.
preprocessor = keras_hub.models.CausalLMPreprocessor.from_preset(
    "gemma_2b_en",
)

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

image_converter property

keras_hub.models.RetinaNetObjectDetectorPreprocessor.image_converter

The image converter used to preprocess image data.