Skip to content

Base reader

Bases: ABC

Abstract base class for all data readers in DataForge.

This class defines the standard interface for reading and parsing annotation files of different formats (such as XML for Pascal VOC or TXT for YOLO). Every specific reader must implement the 'read' method.

Source code in tools/annotation_converter/reader/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 BaseReader(ABC):
    """
    Abstract base class for all data readers in DataForge.

    This class defines the standard interface for reading and parsing
    annotation files of different formats (such as XML for Pascal VOC
    or TXT for YOLO). Every specific reader must implement the 'read' method.
    """
    def __init__(self):
        """ Initializes the base reader instance. """
        pass

    @abstractmethod
    def read(self, file_path: Path) -> Dict[str, str]:
        """
        Reads an annotation file and converts its content into a dictionary.

        Args:
            file_path (Path): The path to the source file to be read.

        Returns:
            dict: A dictionary containing the structured data from the file.

        Raises:
            FileNotFoundError: If the file does not exist at the specified path.
            NotImplementedError: If the method is not implemented by a subclass.
        """
        pass

__init__()

Initializes the base reader instance.

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

read(file_path) abstractmethod

Reads an annotation file and converts its content into a dictionary.

Parameters:

Name Type Description Default
file_path Path

The path to the source file to be read.

required

Returns:

Name Type Description
dict Dict[str, str]

A dictionary containing the structured data from the file.

Raises:

Type Description
FileNotFoundError

If the file does not exist at the specified path.

NotImplementedError

If the method is not implemented by a subclass.

Source code in tools/annotation_converter/reader/base.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@abstractmethod
def read(self, file_path: Path) -> Dict[str, str]:
    """
    Reads an annotation file and converts its content into a dictionary.

    Args:
        file_path (Path): The path to the source file to be read.

    Returns:
        dict: A dictionary containing the structured data from the file.

    Raises:
        FileNotFoundError: If the file does not exist at the specified path.
        NotImplementedError: If the method is not implemented by a subclass.
    """
    pass