> 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/transformersimageclassification.md).

# TransformersImageClassification

Basic image classification 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 = AutoModelForImageClassification.from_pretrained(
    "facebook/deit-base-distilled-patch16-384"
)
predictor=TransformersModel(
    TransformersModelConfig(
        model=model
    ),
    input_class=TransformersImageModelInput,
    output_class=TransformersLogitsOutput,
)
```

{% endcode %}

#### See:

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

## 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: \
  [**ImagePad**](/datasources/image.md#imagepad) **|** [**ImageClassificationPreprocessor**](#imageclassificationpreprocessor)\
  \
  If default chain is used, [**ImageClassificationPreprocessor** ](#imageclassificationpreprocessor)will use **AutoImageProcessor** 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: \
  [**ImageClassificationSingleLabelPostprocessor**](#imageclassificationsinglelabelpostprocessor)\
  \
  If default chain is used, [**ImageClassificationSingleLabelPostprocessor** ](#imageclassificationsinglelabelpostprocessor)will use 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 [**TransformersImageClassificationInput**](#transformersimageclassificationinput)**.**
* <mark style="color:orange;">**output\_class**</mark>**&#x20;(Type\[**[**Output**](/core/schemas.md#output)**], optional):** Class for output validation. Defaults to [**TransformersImageClassificationOutput**](#transformersimageclassificationoutput)**.**
* <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;">**TransformersImageClassificationInput**</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;">**TransformersImageClassificationOutput**</mark>

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

***

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

#### Arguments:

* <mark style="color:orange;">**label**</mark>**&#x20;(Optional\[Tuple\[str, float]]):** Classified label and score.

***

***

***

## <mark style="color:green;">**TransformersImageClassification**</mark><mark style="color:green;">Multilabel</mark><mark style="color:green;">**Output**</mark>

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

***

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

#### Arguments:

* <mark style="color:orange;">**labels**</mark>**&#x20;(Dict\[str, float]):** Classified labels and scores.

***

***

***

## <mark style="color:green;">ImageClassificationPreprocessor</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;">ImageClassificationSingleLabelPostprocessor</mark>

Process model output. Subclass of [**ImageClassificationMultilabelPostprocessor**](#imageclassificationmultilabelpostprocessor).

***

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

#### Arguments:

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

#### Returns:

* **Dict\[str, Any]:** \
  Expected keys:
  * <mark style="color:red;">**"label"**</mark>**&#x20;(Optional\[Tuple\[str, float]]):** Label with highest score, if score higher or equal to threshold, else - None.

***

***

***

## &#x20;<mark style="color:green;">ImageClassificationMultilabelPostprocessor</mark>

Process model output. 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;">**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;">**"logits"**</mark>**&#x20;(Any):** Model output;

#### Returns:

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

***

***
