Skip to content

element

DatasetElement

An element of the dataset.

Attributes:

Name Type Description
x tuple[ElementImage, ...]

The image(s) of the dataset element.

y ElementClass

The class of the dataset element.

original_dataset str

The name of the original dataset from which the element was taken. It is equal to the dataset name specified in the configuration file.

dataset_root_path Path

The path to the root directory of the dataset.

Source code in revelio/dataset/element.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
class DatasetElement:
    """
    An element of the dataset.

    Attributes:
        x: The image(s) of the dataset element.
        y: The class of the dataset element.
        original_dataset: The name of the original dataset from which the element
            was taken. It is equal to the dataset name specified in the configuration
            file.
        dataset_root_path: The path to the root directory of the dataset.
    """

    _dataset_root_path: Path
    _original_dataset: str
    _x: tuple[ElementImage, ...]
    _y: ElementClass

    def __init__(
        self,
        x: tuple[ElementImage, ...],
        y: ElementClass,
        *,
        dataset_root_path: Path,
        original_dataset: str,
    ) -> None:
        """
        Creates a new dataset element.

        Args:
            x: The image(s) of the dataset element.
            y: The class of the dataset element.
            dataset_root_path: The path to the root directory of the dataset.
            original_dataset: The name of the original dataset from which the element
                was taken.
        """
        self._x = x
        self._y = y
        self._dataset_root_path = dataset_root_path
        self._original_dataset = original_dataset

    @property
    def dataset_root_path(self) -> Path:
        """
        Gets the path to the root directory of the dataset.
        """
        return self._dataset_root_path

    @property
    def original_dataset(self) -> str:
        """
        Gets the name of the original dataset from which the element was taken.
        """
        return self._original_dataset

    @property
    def x(self) -> tuple[ElementImage, ...]:
        """
        Gets the image(s) of the dataset element.
        """
        return self._x

    @property
    def y(self) -> ElementClass:
        """
        Gets the class of the dataset element.
        """
        return self._y

    def __repr__(self) -> str:
        return f"DatasetElement(x={self.x}, y={self.y})"

__init__(x: tuple[ElementImage, ...], y: ElementClass, *, dataset_root_path: Path, original_dataset: str) -> None

Creates a new dataset element.

Parameters:

Name Type Description Default
x tuple[ElementImage, ...]

The image(s) of the dataset element.

required
y ElementClass

The class of the dataset element.

required
dataset_root_path Path

The path to the root directory of the dataset.

required
original_dataset str

The name of the original dataset from which the element was taken.

required
Source code in revelio/dataset/element.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
def __init__(
    self,
    x: tuple[ElementImage, ...],
    y: ElementClass,
    *,
    dataset_root_path: Path,
    original_dataset: str,
) -> None:
    """
    Creates a new dataset element.

    Args:
        x: The image(s) of the dataset element.
        y: The class of the dataset element.
        dataset_root_path: The path to the root directory of the dataset.
        original_dataset: The name of the original dataset from which the element
            was taken.
    """
    self._x = x
    self._y = y
    self._dataset_root_path = dataset_root_path
    self._original_dataset = original_dataset

dataset_root_path() -> Path property

Gets the path to the root directory of the dataset.

Source code in revelio/dataset/element.py
193
194
195
196
197
198
@property
def dataset_root_path(self) -> Path:
    """
    Gets the path to the root directory of the dataset.
    """
    return self._dataset_root_path

original_dataset() -> str property

Gets the name of the original dataset from which the element was taken.

Source code in revelio/dataset/element.py
200
201
202
203
204
205
@property
def original_dataset(self) -> str:
    """
    Gets the name of the original dataset from which the element was taken.
    """
    return self._original_dataset

x() -> tuple[ElementImage, ...] property

Gets the image(s) of the dataset element.

Source code in revelio/dataset/element.py
207
208
209
210
211
212
@property
def x(self) -> tuple[ElementImage, ...]:
    """
    Gets the image(s) of the dataset element.
    """
    return self._x

y() -> ElementClass property

Gets the class of the dataset element.

Source code in revelio/dataset/element.py
214
215
216
217
218
219
@property
def y(self) -> ElementClass:
    """
    Gets the class of the dataset element.
    """
    return self._y

DatasetElementDescriptor

A descriptor of a dataset element before it is loaded into memory.

Attributes:

Name Type Description
x tuple[Path, ...]

The path to the image file(s).

y ElementClass

The class of the dataset element.

Source code in revelio/dataset/element.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class DatasetElementDescriptor:
    """
    A descriptor of a dataset element before it is loaded into memory.

    Attributes:
        x: The path to the image file(s).
        y: The class of the dataset element.
    """

    _x: tuple[Path, ...]
    _y: ElementClass
    _root_path: Path
    _dataset_name: str

    def __init__(self, x: tuple[Path, ...], y: ElementClass) -> None:
        """
        Creates a new dataset element descriptor.

        Args:
            x: The path to the image file(s).
            y: The class of the dataset element.
        """
        self._x = x
        self._y = y

    @property
    def x(self) -> tuple[Path, ...]:
        """
        Gets the path to the image file(s).
        """
        return self._x

    @property
    def y(self) -> ElementClass:
        """
        Gets the class of the dataset element.
        """
        return self._y

    def __repr__(self) -> str:
        return f"DatasetElementDescriptor(x={self.x}, y={self.y})"

    def __eq__(self, other: Any) -> bool:
        if not isinstance(other, DatasetElementDescriptor):
            return NotImplemented
        return (
            self.x == other.x
            and self.y == other.y
            and self._root_path == other._root_path
            and self._dataset_name == other._dataset_name
        )

    def __hash__(self) -> int:
        return hash((self.x, self.y, self._root_path, self._dataset_name))

__init__(x: tuple[Path, ...], y: ElementClass) -> None

Creates a new dataset element descriptor.

Parameters:

Name Type Description Default
x tuple[Path, ...]

The path to the image file(s).

required
y ElementClass

The class of the dataset element.

required
Source code in revelio/dataset/element.py
35
36
37
38
39
40
41
42
43
44
def __init__(self, x: tuple[Path, ...], y: ElementClass) -> None:
    """
    Creates a new dataset element descriptor.

    Args:
        x: The path to the image file(s).
        y: The class of the dataset element.
    """
    self._x = x
    self._y = y

x() -> tuple[Path, ...] property

Gets the path to the image file(s).

Source code in revelio/dataset/element.py
46
47
48
49
50
51
@property
def x(self) -> tuple[Path, ...]:
    """
    Gets the path to the image file(s).
    """
    return self._x

y() -> ElementClass property

Gets the class of the dataset element.

Source code in revelio/dataset/element.py
53
54
55
56
57
58
@property
def y(self) -> ElementClass:
    """
    Gets the class of the dataset element.
    """
    return self._y

ElementClass

Bases: Enum

The class of a dataset element, which can be either bona fide or morphed.

Source code in revelio/dataset/element.py
12
13
14
15
16
17
18
class ElementClass(Enum):
    """
    The class of a dataset element, which can be either bona fide or morphed.
    """

    BONA_FIDE = 0.0
    MORPHED = 1.0

ElementImage

An image that is part of a dataset element.

An image is represented with a Numpy array with shape (height, width, channels) and dtype uint8 or float32. The channels are ordered as BGR, following the OpenCV convention.

Attributes:

Name Type Description
path Path

The path to the image file.

image Image

The image.

landmarks Optional[Landmarks]

The facial landmarks of the image (if present).

features dict[str, np.ndarray]

The features of the image produced by each feature extractor (if present).

Source code in revelio/dataset/element.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class ElementImage:
    """
    An image that is part of a dataset element.

    An image is represented with a Numpy array with shape (height, width, channels)
    and dtype uint8 or float32. The channels are ordered as BGR, following the OpenCV
    convention.

    Attributes:
        path: The path to the image file.
        image: The image.
        landmarks: The facial landmarks of the image (if present).
        features: The features of the image produced by each feature extractor
            (if present).
    """

    _path: Path
    _image: Image
    _landmarks: Optional[Landmarks]
    _features: dict[str, np.ndarray]

    def __init__(
        self,
        path: Path,
        image: Image,
        landmarks: Optional[Landmarks] = None,
        features: Optional[dict[str, np.ndarray]] = None,
    ) -> None:
        """
        Creates a new image of a dataset element.

        Args:
            path: The path to the image file.
            image: The image.
            landmarks: The facial landmarks of the image (if present).
            features: The features of the image produced by each feature extractor
                (if present).
        """
        self._path = path
        self._image = image
        self._landmarks = landmarks
        self._features = features or {}

    @property
    def path(self) -> Path:
        """
        Gets the path to the image file.
        """
        return self._path

    @property
    def image(self) -> Image:
        """
        Gets the image.
        """
        return self._image

    @property
    def landmarks(self) -> Optional[Landmarks]:
        """
        Gets the facial landmarks of the image (if present).
        """
        return self._landmarks

    @property
    def features(self) -> dict[str, np.ndarray]:
        """
        Gets the features of the image produced by each feature extractor (if present).
        """
        return self._features

    def __repr__(self) -> str:
        return f"ElementImage(path={self._path})"

__init__(path: Path, image: Image, landmarks: Optional[Landmarks] = None, features: Optional[dict[str, np.ndarray]] = None) -> None

Creates a new image of a dataset element.

Parameters:

Name Type Description Default
path Path

The path to the image file.

required
image Image

The image.

required
landmarks Optional[Landmarks]

The facial landmarks of the image (if present).

None
features Optional[dict[str, np.ndarray]]

The features of the image produced by each feature extractor (if present).

None
Source code in revelio/dataset/element.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def __init__(
    self,
    path: Path,
    image: Image,
    landmarks: Optional[Landmarks] = None,
    features: Optional[dict[str, np.ndarray]] = None,
) -> None:
    """
    Creates a new image of a dataset element.

    Args:
        path: The path to the image file.
        image: The image.
        landmarks: The facial landmarks of the image (if present).
        features: The features of the image produced by each feature extractor
            (if present).
    """
    self._path = path
    self._image = image
    self._landmarks = landmarks
    self._features = features or {}

features() -> dict[str, np.ndarray] property

Gets the features of the image produced by each feature extractor (if present).

Source code in revelio/dataset/element.py
141
142
143
144
145
146
@property
def features(self) -> dict[str, np.ndarray]:
    """
    Gets the features of the image produced by each feature extractor (if present).
    """
    return self._features

image() -> Image property

Gets the image.

Source code in revelio/dataset/element.py
127
128
129
130
131
132
@property
def image(self) -> Image:
    """
    Gets the image.
    """
    return self._image

landmarks() -> Optional[Landmarks] property

Gets the facial landmarks of the image (if present).

Source code in revelio/dataset/element.py
134
135
136
137
138
139
@property
def landmarks(self) -> Optional[Landmarks]:
    """
    Gets the facial landmarks of the image (if present).
    """
    return self._landmarks

path() -> Path property

Gets the path to the image file.

Source code in revelio/dataset/element.py
120
121
122
123
124
125
@property
def path(self) -> Path:
    """
    Gets the path to the image file.
    """
    return self._path