-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
47 lines (37 loc) · 1.22 KB
/
utils.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 psutil
import gc
import os
import pandas as pd
from typing import Dict
def get_exp_name(config_file: Dict) -> str:
""" Extracts the name of the experiment based on the ML model (separated by '-'):
'LR', 'NN', 'multilabel-NN', ...
Parameters:
config_file (Dict): The configuration file
Returns:
str: Name of the experiment
"""
multilabel = 'multilabel-NN'
exp_name = config_file.split('-')[-1].split('.')[0]
if multilabel in config_file:
exp_name = multilabel
elif exp_name == '10perc' or exp_name == 'ood':
exp_name = config_file.split('-')[-2]
return exp_name
def free_memory(evaluator, index, config, pivot_df):
""" Deletes the unused variables from the main memory.
Parameters:
evaluator: Evaluator instance
index: LMI, Mtree or Mindex instance
config (Dict): confguration file
pivot_df (pd.DataFrame): the pivots file
"""
del evaluator
del index
del config
if isinstance(pivot_df, pd.DataFrame):
del pivot_df
gc.collect()
def get_current_mem() -> float:
""" Finds the current memory usage of the process. """
return psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2