-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize.py
102 lines (79 loc) · 3.66 KB
/
visualize.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
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
75
76
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
import argparse
import pandas as pd
import json
import numpy as np
from loguru import logger
from vizme.preprocessing import normalize, quantize
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)
if args['quant']:
dataset = quantize(dataset)
if args['norm']:
dataset = normalize(dataset)
if args['skip']:
args['visualization'].skip_existing()
if args['parameters']:
args['visualization'].setup(args['parameters'])
if args['parametersFile']:
args['visualization'].setup(json.load(args['parametersFile']))
args['visualization'].fit_transform(dataset, labels, args['output'])
if args['groups'] is not None:
args['visualization'].transform_group(dataset, labels, args['output'], args['groups'])
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
from visualizations import Parse as VisualizationParse
parser = argparse.ArgumentParser(description='Tool to convert data into image.')
parser.add_argument('--skip', '--skip-existing',
default=False,
action='store_true',
help='Skip existing files (do not generate them again)')
parser.add_argument('datasets',
choices=list(DatasetParse.choices.keys()),
action=DatasetParse,
help='Source datasets.')
parser.add_argument('--norm', '--normalize', '--normalization',
default=False,
action='store_true',
help='Normalization of features.')
parser.add_argument('--quant', '--quantize', '--quantization',
default=False,
action='store_true',
help='Quantization of features.')
parser.add_argument('visualization',
choices=list(VisualizationParse.choices.keys()),
action=VisualizationParse,
help='Visualization system.')
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.')
parameters = parser.add_mutually_exclusive_group(required=False)
parameters.add_argument('-p', '--parameters',
default=False,
type=json.loads,
help='The parameters of the visualization.')
parameters.add_argument('-f', '--parametersFile',
default=False,
type=argparse.FileType('r'),
help='The json file with parameters of the visualization.')
parser.add_argument('--groups',
default=None,
choices=['avg', 'med', 'special'],
type=str,
help='Generate visualization for group of data too.')
exit(main(vars(parser.parse_args())))