-
Notifications
You must be signed in to change notification settings - Fork 1
/
feat_prop.py
73 lines (51 loc) · 2.18 KB
/
feat_prop.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os.path
import datetime
import argparse
from sklearn.model_selection import ParameterGrid
parser = argparse.ArgumentParser()
parser.add_argument('--data', type=str, default='Digital_Music', help='choose the dataset')
parser.add_argument('--model', type=str, default='vbpr', help='project name')
args = parser.parse_args()
hyperparams = ParameterGrid({
"--layers": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
"--top_k": [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
})
def summary(configuration):
final_list = [('%s=%s' % (k[2:], v)) for (k, v) in configuration.items()]
return '_'.join(final_list)
def to_cmd(c):
command = ' '.join([f'{k}={v}' for k, v in c.items()])
return command
def to_logfile(c):
outfile = "{}.log".format(summary(c).replace("/", "_"))
return outfile
def main():
logs_path = 'logs'
if not os.path.exists(logs_path + f'/{args.data}/feat_prop/{args.model}/'):
os.makedirs(logs_path + f'/{args.data}/feat_prop/{args.model}/')
command_lines = set()
script = 'run_multimodal.py'
for hyperparam in hyperparams:
logfile = to_logfile(hyperparam)
completed = False
if os.path.isfile(f'{logs_path}/{args.data}/feat_prop/{args.model}/{logfile}'):
with open(f'{logs_path}/{args.data}/feat_prop/{args.model}/{logfile}', 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
completed = ('Best Model params' in content)
if not completed:
command_line = (
f'CUBLAS_WORKSPACE_CONFIG=:4096:8 python {script} {to_cmd(hyperparam)} '
f'--data={args.data} '
f'--method=feat_prop '
f'--model={args.model}')
command_lines |= {command_line}
# Sort command lines and remove duplicates
sorted_command_lines = sorted(command_lines)
with open(f'run_multimodal_all_feat_prop_{args.data}_{args.model}.sh', 'w') as f:
print(f'#!/bin/bash', file=f)
for command_line in sorted_command_lines:
print(f'{command_line}', file=f)
if __name__ == '__main__':
main()