> For the complete documentation index, see [llms.txt](https://utca.knowledgator.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://utca.knowledgator.com/tasks/transformersobjectdetection.md).

# TransformersObjectDetection

Basic object detection task

Subclass of [**Task**](/tasks/task.md)**.**&#x20;

## Module: [implementation](/framework-structure.md#implementation).tasks

## Default predictor

This task uses [**TransformersModel**](/predictors/transformers-predictors.md#transformersmodel) by default with this configuration:

{% code overflow="wrap" fullWidth="false" %}

```python
model = DetrForObjectDetection.from_pretrained(
    "facebook/detr-resnet-50", revision="no_timm"
)
predictor=TransformersModel(
    TransformersModelConfig(
        model=model
    ),
    input_class=TransformersImageClassificationModelInput,
    output_class=TransformersDETROutput,
)
```

{% endcode %}

#### See:

* [**TransformersModel**](/predictors/transformers-predictors.md#transformersmodel)&#x20;
* [**TransformersModelConfig**](/predictors/transformers-predictors.md#transformersmodelconfig)
* [**TransformersImageClassificationModelInput**](/predictors/transformers-schemas.md#transformersimageclassificationmodelinput)
* [**TransformersDETROutput**](/predictors/transformers-schemas.md#transformersdetroutput)

## Methods and properties

Main methods and properties

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**predictor**</mark>**&#x20;(**[**Predictor**](/predictors/predictor.md)**\[Any, Any], optional):** Predictor that will be used in task. If equals to None, [**default predictor**](#default-predictor) will be used. Defaults to None.
* <mark style="color:orange;">**preprocess**</mark>**&#x20;(Optional\[**[**Component**](/core/component.md)**], optional):** Component executed before predictor. If equals to None, default component will be used. Defaults to None.\
  \
  Default component: \
  [**ObjectDetectionPreprocessor**](#objectdetectionpreprocessor)\
  \
  If default chain is used, **ObjectDetectionPreprocessor** will use **DetrImageProcessor** from model used in **predictor**.
* <mark style="color:orange;">**postprocess**</mark>**&#x20;(Optional\[**[**Component**](/core/component.md)**], optional):** Component executed after predictor. If equals to None, default component will be used. Defaults to None.\
  \
  Default component: \
  [**DETRPostprocessor**](#detrpostprocessor)\
  \
  If default chain is used, **DETRPostprocessor** will use **DetrImageProcessor** and labels from model used in **predictor**.
* <mark style="color:orange;">**input\_class**</mark>**&#x20;(Type\[**[**Input**](/core/schemas.md#input)**], optional):** Class for input validation. Defaults to [**TransformersObjectDetectionInput**](#transformersobjectdetectioninput)**.**
* <mark style="color:orange;">**output\_class**</mark>**&#x20;(Type\[**[**Output**](/core/schemas.md#output)**], optional):** Class for output validation. Defaults to [**TransformersObjectDetectionOutput**](#transformersobjectdetectionoutput)**.**
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

***

***

## <mark style="color:green;">TransformersObjectDetectionInput</mark>

Subclass of [**IOModel**](/core/schemas.md#iomodel)**.**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**image**</mark>**&#x20;(Image.Image):** Image to process.

***

***

***

## <mark style="color:green;">TransformersObjectDetectionOutput</mark>

Subclass of [**IOModel**](/core/schemas.md#iomodel)**.**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**scores**</mark>**&#x20;(List\[float]):** Probability scores.
* <mark style="color:orange;">**labels**</mark>**&#x20;(List\[str]):** Classified labels.
* <mark style="color:orange;">**boxes**</mark>**&#x20;(List\[Tuple\[float, float, float, float]]):** Bounding boxes.

***

***

***

## <mark style="color:green;">**ObjectDetectionPreprocessor**</mark>

Prepare model input. Subclass of [**Action**](/core/action.md). Type of [**Action**](/core/action.md)**\[Dict\[str, Any], Dict\[str, Any]].**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**processor**</mark>**&#x20;(Processor):** Feature extractor.
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):** \
  Expected keys:
  * <mark style="color:red;">**"image"**</mark> **(Image.Image):** Image to analyze;

#### Returns:

* **Dict\[str, Any]:** \
  Expected keys:
  * <mark style="color:red;">**"pixel\_values"**</mark>**&#x20;(Any);**

***

***

***

## <mark style="color:green;">DETRPostprocessor</mark>

Process model output. Subclass of [**VisualQandAMultianswerPostprocessor**](#visualqandamultianswerpostprocessor).

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**processor**</mark>**&#x20;(DetrImageProcessor):** Feature extractor.
* <mark style="color:orange;">**labels**</mark>**&#x20;(Mapping\[Any, str]):** Labels for classification.
* <mark style="color:orange;">**threshold**</mark>**&#x20;(float):** Labels threshold score. Defaults to 0.
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):** \
  Expected keys:
  * <mark style="color:red;">**"image"**</mark>**&#x20;(Image.Image):** Processed image;
  * <mark style="color:red;">**"logits"**</mark>**&#x20;(Any):** Model output;
  * <mark style="color:red;">**"pred\_boxes"**</mark>**&#x20;(Any)**;

#### Returns:

* **Dict\[str, Any]:** \
  Expected keys:
  * <mark style="color:red;">**"scores"**</mark>**&#x20;(List\[float]):** Probability scores.&#x20;
  * <mark style="color:red;">**"labels"**</mark>**&#x20;(List\[str]):** Classified labels.&#x20;
  * <mark style="color:red;">**"boxes"**</mark>**&#x20;(List\[Tuple\[float, float, float, float]]):** Bounding boxes.

***

***
