-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode.py
75 lines (60 loc) · 3.03 KB
/
mode.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
import pandas as pd
import dataset
import datasets_manager
import runner
from base import BaseTrainer
from parse_config import ConfigParser
from utils.logger import get_logger
def multi_train_bootstrap(config: ConfigParser):
logger = get_logger('runner.multi_train_bootstrap')
data = {project_id: config.init_obj(f'datasets.{project_id}', dataset) for project_id in config['datasets']}
manager = getattr(datasets_manager, config['datasets_manager.type'])(datasets=data, config=config)
project_results = {}
for project_id in data:
logger.info('Training Start')
trainer_init_config = {
'config': config,
'train_data_loader': manager[project_id]['dataloaders']['train'],
'test_data_loader': manager[project_id]['dataloaders']['test']
}
trainer: BaseTrainer = getattr(runner, config['runner.type'])(**trainer_init_config)
result = trainer.run()
project_results[project_id] = result
logger.info('Training End')
return project_results
def multi_cross_validation_bootstrap(config: ConfigParser):
logger = get_logger('runner.multi_cross_validation_bootstrap')
data = {project_id: config.init_obj(f'datasets.{project_id}', dataset) for project_id in config['datasets']}
manager = getattr(datasets_manager, config['datasets_manager.type'])(datasets=data, config=config)
project_results = {'cross_validation': {}, 'bootstrap': {}}
for project_id in data:
project_cross_validation_result = {}
logger.info('Cross Validation Start')
for fold_index in manager[project_id]['dataloaders']:
if not isinstance(fold_index, int):
continue
logger.info(f'{fold_index + 1} Fold for {project_id}...')
trainer_init_config = {
'config': config,
'train_data_loader': manager[project_id]['dataloaders'][fold_index]['train'],
'valid_data_loader': manager[project_id]['dataloaders'][fold_index]['valid']
}
trainer: BaseTrainer = getattr(runner, config['runner.type'])(**trainer_init_config)
result = trainer.run()
project_cross_validation_result[fold_index] = {k: v['mean'] for k, v in result.items()}
project_results['cross_validation'][project_id] = pd.DataFrame.from_dict(
project_cross_validation_result,
'index'
).describe().T.loc[:, ['mean', 'std']].to_dict('index')
logger.info('Cross Validation End')
logger.info('Bootstrapping Start')
trainer_init_config = {
'config': config,
'train_data_loader': manager[project_id]['dataloaders']['train'],
'test_data_loader': manager[project_id]['dataloaders']['test']
}
trainer: BaseTrainer = getattr(runner, config['runner.type'])(**trainer_init_config)
project_bootstrap_result = trainer.run()
project_results['bootstrap'][project_id] = project_bootstrap_result
logger.info('Bootstrapping End')
return project_results