-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_dataset.py
47 lines (35 loc) · 1.43 KB
/
preprocess_dataset.py
1
2
3
4
5
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import argparse
import pandas as pd
import numpy as np
from loguru import logger
from util.dataset import get_samples_for_labels
def main(args):
try:
dataset = args['datasets'].data()
assert isinstance(dataset, pd.DataFrame)
labels = args['datasets'].labels()
if args['n_samples']:
dataset, labels = get_samples_for_labels(args['n_samples'], dataset, labels)
dataset['_target'] = labels
dataset.to_csv(args['output'])
return 0
except FileNotFoundError as err:
logger.error(f'Cannot load datasets.')
logger.debug(err)
return 1
if __name__ == '__main__':
from datasets import Parse as DatasetParse
parser = argparse.ArgumentParser(description='Tool to convert data into image.')
parser.add_argument('datasets',
choices=list(DatasetParse.choices.keys()),
action=DatasetParse,
help='Source datasets.')
parser.add_argument('output',
type=str,
help='Directory where visualization should be saved.')
parser.add_argument('-s', '--n_samples',
default=np.inf,
type=np.int32,
required=False,
help='Number of samples of each target class. If not provided, all samples will be generated.')
exit(main(vars(parser.parse_args())))