Skip to content

Base writer

Bases: ABC

Abstract base class for all data writers in DataForge.

This class defines the standard interface for saving processed annotation data into various file formats (such as YOLO .txt or Pascal VOC .xml). Specific writer implementations must provide their own 'write' logic.

Source code in tools/annotation_converter/writer/base.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class BaseWriter(ABC):
    """
    Abstract base class for all data writers in DataForge.

    This class defines the standard interface for saving processed annotation
    data into various file formats (such as YOLO .txt or Pascal VOC .xml).
    Specific writer implementations must provide their own 'write' logic.
    """
    def __init__(self):
        """ Initializes the base writer instance. """
        pass


    @abstractmethod
    def write(self, data: Union[tuple, list, dict, str], file_path: Path) -> None:
        """
        Writes data to the specified file path.

        Args:
            data (Union[tuple, list, dict, str]): The content to be written (can be a list, dictionary, or string
                depending on the specific writer).
            file_path (Path): The target path where the file will be saved.

        Raises:
            IOError: If the file cannot be written to the disk.
            NotImplementedError: If the method is not implemented by a subclass.
        """
        pass

__init__()

Initializes the base writer instance.

Source code in tools/annotation_converter/writer/base.py
14
15
16
def __init__(self):
    """ Initializes the base writer instance. """
    pass

write(data, file_path) abstractmethod

Writes data to the specified file path.

Parameters:

Name Type Description Default
data Union[tuple, list, dict, str]

The content to be written (can be a list, dictionary, or string depending on the specific writer).

required
file_path Path

The target path where the file will be saved.

required

Raises:

Type Description
IOError

If the file cannot be written to the disk.

NotImplementedError

If the method is not implemented by a subclass.

Source code in tools/annotation_converter/writer/base.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@abstractmethod
def write(self, data: Union[tuple, list, dict, str], file_path: Path) -> None:
    """
    Writes data to the specified file path.

    Args:
        data (Union[tuple, list, dict, str]): The content to be written (can be a list, dictionary, or string
            depending on the specific writer).
        file_path (Path): The target path where the file will be saved.

    Raises:
        IOError: If the file cannot be written to the disk.
        NotImplementedError: If the method is not implemented by a subclass.
    """
    pass