TargetFormatter¶
- class flash.core.data.utilities.classification.TargetFormatter(labels=None, num_classes=None)[source]¶
A
TargetFormatter
is used to convert targets of a given type to a standard format required by the loss function. To implement a customTargetFormatter
, simply override theformat
method with your own logic.Examples
>>> 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