Coverage for src/bob/bio/video/database/youtube.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-14 22:56 +0100
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-14 22:56 +0100
1import logging
2import os
4from clapper.rc import UserDefaults
6from bob.bio.base.database import CSVDatabase
8logger = logging.getLogger(__name__)
9rc = UserDefaults("bobrc.toml")
12class YoutubeDatabase(CSVDatabase):
14 """
15 This package contains the access API and descriptions for the `YouTube Faces` database.
16 It only contains the Bob accessor methods to use the DB directly from python, with our certified protocols.
17 The actual raw data for the `YouTube Faces` database should be downloaded from the original URL (though we were not able to contact the corresponding Professor).
19 .. warning::
21 To use this dataset protocol, you need to have the original files of the YOUTUBE datasets.
22 Once you have it downloaded, please run the following command to set the path for Bob
24 .. code-block:: sh
26 bob config set bob.bio.face.youtube.directory [YOUTUBE PATH]
30 In this interface we implement the 10 original protocols of the `YouTube Faces` database ('fold1', 'fold2', 'fold3', 'fold4', 'fold5', 'fold6', 'fold7', 'fold8', 'fold9', 'fold10')
33 The code below allows you to fetch the gallery and probes of the "fold0" protocol.
35 .. code-block:: python
37 >>> from bob.bio.video.database import YoutubeDatabase
38 >>> youtube = YoutubeDatabase(protocol="fold0")
39 >>>
40 >>> # Fetching the gallery
41 >>> references = youtube.references()
42 >>> # Fetching the probes
43 >>> probes = youtube.probes()
46 Parameters
47 ----------
49 protocol: str
50 One of the Youtube above mentioned protocols
52 annotation_type: str
53 One of the supported annotation types
55 original_directory: str
56 Original directory
58 extension: str
59 Default file extension
61 annotation_extension: str
63 frame_selector:
64 Pointer to a function that does frame selection.
66 """
68 name = "youtube"
69 category = "video"
70 dataset_protocols_name = "youtube.tar.gz"
71 dataset_protocols_urls = [
72 "https://www.idiap.ch/software/bob/databases/latest/video/youtube-51c1fb2a.tar.gz",
73 "http://www.idiap.ch/software/bob/databases/latest/video/youtube-51c1fb2a.tar.gz",
74 ]
75 dataset_protocols_hash = "51c1fb2a"
77 def __init__(
78 self,
79 protocol,
80 annotation_type="bounding-box",
81 fixed_positions=None,
82 original_directory=rc.get("bob.bio.video.youtube.directory", ""),
83 extension=".jpg",
84 annotation_extension=".labeled_faces.txt",
85 frame_selector=None,
86 ):
87 original_directory = original_directory or ""
88 if not os.path.exists(original_directory):
89 logger.warning(
90 f"Invalid or non existent `original_directory`: {original_directory}."
91 "Please, do `bob config set bob.bio.video.youtube.directory PATH` to set the Youtube data directory."
92 )
94 self.references_dict = {}
95 self.probes_dict = {}
97 # Dict that holds a `subject_id` as a key and has
98 # filenames as values
99 self.subject_id_files = {}
100 self.template_id_to_subject_id = None
101 self.template_id_to_sample = None
102 self.original_directory = original_directory
103 self.extension = extension
104 self.annotation_extension = annotation_extension
105 self.frame_selector = frame_selector
107 super().__init__(
108 name=self.name,
109 protocol=protocol,
110 annotation_type=annotation_type,
111 fixed_positions=fixed_positions,
112 memory_demanding=True,
113 )