Add tqdm to show progress on slow database interfaces authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
......@@ -18,7 +18,7 @@ $ conda create -n bob8_py36 \
-c https://www.idiap.ch/software/bob/conda \
-c defaults \
-c https://www.idiap.ch/software/bob/conda/label/archive \
python=3.6 bob=8 bob.pad.face bob.db.replaymobile
python=3.6 bob=8 bob.pad.face bob.db.replaymobile click tqdm
# you would install the relevant bob.bio, bob.pad, and bob.db package
# now, save the script provided below in a `convert_pad_database.py` file and run:
......@@ -29,8 +29,10 @@ $ python convert_pad_database.py bob.pad.face.config.replay_mobile --output ~/te
```python
import os
import shutil
import click
import tqdm
from bob.extension.scripts.click_helper import ConfigCommand
from bob.extension.scripts.click_helper import ResourceOption
from bob.extension.scripts.click_helper import log_parameters
......@@ -49,7 +51,7 @@ from bob.extension.scripts.click_helper import verbosity_option
default=["train", "dev", "eval"],
)
@verbosity_option(cls=ResourceOption)
def convert_database(database, output, protocols, groups, verbose, **kwargs):
def convert_database(database, output, protocols, groups, **kwargs):
import csv
import tarfile
import logging
......@@ -64,6 +66,7 @@ def convert_database(database, output, protocols, groups, verbose, **kwargs):
click.echo(f"WARNING: failed to retrieve the list of protocols from the lower level db. The error was: {e}")
protocols = [database.protocol]
shutil.rmtree(output, ignore_errors=True)
os.makedirs(output, exist_ok=True)
for proto in protocols:
......@@ -74,16 +77,16 @@ def convert_database(database, output, protocols, groups, verbose, **kwargs):
path = os.path.join(output, proto, grp + ".csv")
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w", newline="") as f:
fieldnames = ["filename", "client_id", "attack_type"]
fieldnames = ["filename", "subject", "attack_type"]
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for padfile in all_files:
for padfile in tqdm.tqdm(all_files):
writer.writerow(
{
"filename": padfile.make_path(
"", database.original_extension
),
"client_id": padfile.client_id,
"subject": padfile.client_id,
"attack_type": padfile.attack_type,
}
)
......
......