class_docstr: A ``TargetFormatter`` is used to convert targets of a given type to a standard format required by the loss
  function. To implement a custom ``TargetFormatter``, simply override the ``format`` method with your own logic.
  
  Examples
  ________
  
  .. doctest::
  
      >>> from dataclasses import dataclass
      >>> from typing import ClassVar, Optional
      >>> from flash.core.data.utilities.classification import TargetFormatter
      >>>
      >>> @dataclass
      ... class CustomStringTargetFormatter(TargetFormatter):
      ...     "A ``TargetFormatter`` which converts strings of the format '#<index>' to integers."
      ...     multi_label: ClassVar[Optional[bool]] = False
      ...     def format(self, target: str) -> int:
      ...         return int(target.strip("#"))
      ...
      >>> formatter = CustomStringTargetFormatter()
      >>> formatter("#1")
      1
class_docstr_tok: ["A","``","TargetFormatter","``","is","used","to","convert","targets","of","a","given","type","to","a","standard","format","required","by","the","loss","function",".","To","implement","a","custom","``","TargetFormatter","``",",","simply","override","the","``","format","``","method","with","your","own","logic",".","Examples","________","..","doctest",":",":",">",">",">","from","dataclasses","import","dataclass",">",">",">","from","typing","import","ClassVar",",","Optional",">",">",">","from","flash.core.data.utilities.classification","import","TargetFormatter",">",">",">",">",">",">","@","dataclass","...","class","CustomStringTargetFormatter","(","TargetFormatter",")",":","...","``","A","``","TargetFormatter","``","which","converts","strings","of","the","format","'","#","<","index",">","'","to","integers",".","''","...","multi_label",":","ClassVar","[","Optional","[","bool","]","]","=","False","...","def","format","(","self",",","target",":","str",")","-",">","int",":","...","return","int","(","target.strip","(","``","#","''",")",")","...",">",">",">","formatter","=","CustomStringTargetFormatter","(",")",">",">",">","formatter","(","``","#","1","''",")","1"]
code: def __post_init__(self):
      self.num_classes = (
          len(self.labels)
          if self.labels is not None
          else self.num_classes
      )
  
imports: from dataclasses import dataclass
  from functools import reduce
  from typing import Any, ClassVar, Dict, List, Optional, Tuple, Type, Union, cast
  import numpy
  import torch
  from torch import Tensor
  from flash.core.data.utilities.sort import sorted_alphanumeric
  from flash.core.utilities.imports import _TOPIC_CORE_AVAILABLE
label_desc: Use image node_id 1 for calling the TargetFormatter obj's underlying member method code with example usage: obj.__post_init__() without return types