Coverage for src/bob/bio/base/database/atnt.py: 50%
34 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-12 22:34 +0200
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-12 22:34 +0200
1#!/usr/bin/env python
2"""
3ATNT database implementation
4"""
6from pathlib import Path
8from sklearn.pipeline import make_pipeline
10import bob.io.base
12from bob.bio.base.database.utils import download_file, md5_hash
14from . import CSVDatabase, FileSampleLoader
17class AtntBioDatabase(CSVDatabase):
18 """
19 The AT&T (aka ORL) database of faces
20 (http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html). This
21 class defines a simple protocol for training, enrollment and probe by
22 splitting the few images of the database in a reasonable manner. Due to the
23 small size of the database, there is only a 'dev' group, and I did not
24 define an 'eval' group.
25 """
27 category = "base"
28 dataset_protocols_urls = [
29 "https://www.idiap.ch/software/bob/databases/latest/base/atnt-f529acef.tar.gz",
30 "http://www.idiap.ch/software/bob/databases/latest/base/atnt-f529acef.tar.gz",
31 ]
32 dataset_protocols_checksum = "f529acef"
34 def __init__(
35 self,
36 protocol="idiap_protocol",
37 dataset_original_directory=None,
38 **kwargs,
39 ):
40 """Custom init to download the raw data files."""
42 # Download the raw data (or use a cached local version)
43 if dataset_original_directory is None:
44 path = download_file(
45 urls=[
46 "http://www.idiap.ch/software/bob/data/bob/att_faces.zip"
47 ],
48 destination_sub_directory="datasets/atnt",
49 destination_filename="atnt_faces.zip",
50 checksum="6efb25cb0d40755e9492b9c012e3348d",
51 checksum_fct=md5_hash,
52 extract=True,
53 )
54 dataset_original_directory = Path(path).as_posix()
56 super().__init__(
57 name="atnt",
58 protocol=protocol,
59 transformer=make_pipeline(
60 FileSampleLoader(
61 data_loader=bob.io.base.load,
62 dataset_original_directory=dataset_original_directory,
63 extension=".pgm",
64 ),
65 ),
66 **kwargs,
67 )
68 # just expose original_directory for backward compatibility of tests
69 self.original_directory = dataset_original_directory
70 self.original_extension = ".pgm"
72 # define an objects method for compatibility with the old tests
73 def objects(
74 self, model_ids=None, groups=None, purposes=None, protocol=None
75 ):
76 samples = []
78 if groups is None:
79 groups = self.groups()
81 if "train" in groups or "world" in groups:
82 samples += self.background_model_samples()
84 if purposes is None:
85 purposes = ("enroll", "probe")
87 if "enroll" in purposes:
88 samples += self.references()
90 if "probe" in purposes:
91 samples += self.probes()
93 if model_ids:
94 samples = [s for s in samples if s.template_id in model_ids]
96 # create the old attributes
97 for s in samples:
98 s.client_id = s.template_id
99 s.path = s.id = s.key
101 return samples