Shortcuts

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 custom TargetFormatter, simply override the format 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
Read the Docs v: stable
Versions
latest
stable
0.8.2
0.8.1.post0
0.8.1
0.8.0
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.2
0.5.1
0.5.0
0.4.0
0.3.2
0.3.1
0.3.0
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0post1
Downloads
html
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.