TransformersImageClassification

Basic image classification task

Subclass of Task.

Module: implementation.tasks

Default predictor

This task uses TransformersModel by default with this configuration:

model = AutoModelForImageClassification.from_pretrained(
    "facebook/deit-base-distilled-patch16-384"
)
predictor=TransformersModel(
    TransformersModelConfig(
        model=model
    ),
    input_class=TransformersImageModelInput,
    output_class=TransformersLogitsOutput,
)

See:

Methods and properties

Main methods and properties


__init__

Arguments:




TransformersImageClassificationInput

Subclass of IOModel.


__init__

Arguments:

  • image (Image.Image): Image to process.




TransformersImageClassificationOutput

Subclass of IOModel.


__init__

Arguments:

  • label (Optional[Tuple[str, float]]): Classified label and score.




TransformersImageClassificationMultilabelOutput

Subclass of IOModel.


__init__

Arguments:

  • labels (Dict[str, float]): Classified labels and scores.




ImageClassificationPreprocessor

Prepare model input. Subclass of Action. Type of Action[Dict[str, Any], Dict[str, Any]].


__init__

Arguments:

  • processor (Processor): Feature extractor.

  • name (Optional[str], optional): Name for identification. If equals to None, class name will be used. Defaults to None.


execute

Arguments:

  • input_data (Dict[str, Any]): Expected keys:

    • "image" (Image.Image): Image to analyze;

Returns:

  • Dict[str, Any]: Expected keys:

    • "pixel_values" (Any);




ImageClassificationSingleLabelPostprocessor

Process model output. Subclass of ImageClassificationMultilabelPostprocessor.


execute

Arguments:

  • input_data (Dict[str, Any]): Expected keys:

    • "logits" (Any): Model output;

Returns:

  • Dict[str, Any]: Expected keys:

    • "label" (Optional[Tuple[str, float]]): Label with highest score, if score higher or equal to threshold, else - None.




ImageClassificationMultilabelPostprocessor

Process model output. Subclass of Action. Type of Action[Dict[str, Any], Dict[str, Any]].


__init__

Arguments:

  • labels (Mapping[Any, str]): Labels for classification.

  • threshold (float): Labels threshold score. Defaults to 0.

  • name (Optional[str], optional): Name for identification. If equals to None, class name will be used. Defaults to None.


execute

Arguments:

  • input_data (Dict[str, Any]): Expected keys:

    • "logits" (Any): Model output;

Returns:

  • Dict[str, Any]: Expected keys:

    • "labels" (Dict[str, float]): Classified labels and scores.



Last updated