-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
83 lines (73 loc) · 3.29 KB
/
run.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
'''
Read the hyperparameters.json file which stores the experimental parameters.
Each line represents a model strategy pair and its corresponding parameters.
Execute the expariment line by line for each repetition index using the file 'main.py'.
'''
#%%
import os
import sys
import json
import subprocess
#%%
# darwin is for macos
ENV = "local" if sys.platform == "darwin" else "server"
#%%
execute_file = 'main.py'
dataset_name = 'digits' # dataset_name_list = ['double_inter_twin_moon','triple_inter_twin_moon','digits', 'amazon', 'imageCLEF', 'office_31', 'office_home', 'PACs']
model_list = ['SDL_separate','MDNet','MAN'] # ['DANN','SDL_joint','SDL_separate','MDNet','MAN', 'CAN'] ['DANN','SDL_joint', 'CAN'] ['SDL_separate','MDNet','MAN']
strategy_list = ['Random'] # ['Random', 'Uncertainty', 'BADGE', 'EGL', 'Coreset']
# repetition_index_range = range(0,3) # range(5,10) # for each pair, execute 0 to 19
repetition_index_range = [0]
device_str = "cuda:2"
#%%
# processing control
while(True):
print()
device_name = device_str
print(f'We are going to submit the jobs: \nOn dataset: {dataset_name}. \nOn device: {device_name}. \nThe repitition indexes are: {repetition_index_range}.')
print(f'The model list: {model_list}.')
print(f'The strategy list: {strategy_list}.')
in_content = input('Proceed?[y/n]:')
if in_content == 'y':
print('Processing...')
break
elif in_content == 'n':
print('Exit!')
exit(0)
else:
print('Please input exactly y/n !!!')
#%%
'''
The execution command contains the execute_file, the index of model-strategy pair, the repetition index range, parameter file address.
For example:
python3 main.py 3 11 hyperparameters/hyperparameters_caltech.json &
'''
# Make directory
folder_address = './result/'+ dataset_name + '/'
folder_checkpoint_address = folder_address + 'folder_checkpoint/'
folder_init_weight_address = folder_address + 'folder_init_weight/'
folder_result_address = folder_address + 'folder_result/'
folder_log_address = folder_address + 'folder_log/'
if not os.path.isdir(folder_address):
os.mkdir(folder_address)
if not os.path.isdir(folder_checkpoint_address):
os.mkdir(folder_checkpoint_address)
if not os.path.isdir(folder_init_weight_address):
os.mkdir(folder_init_weight_address)
if not os.path.isdir(folder_result_address):
os.mkdir(folder_result_address)
if not os.path.isdir(folder_log_address):
os.mkdir(folder_log_address)
#%%
for strategy_name in strategy_list:
for model_name in model_list:
if ENV == 'local':
for repetition_index in repetition_index_range:
command = f'/Users/rui/miniconda3/envs/py3.8/bin/python {execute_file} --dataset_name={dataset_name} --model_name={model_name} --strategy_name={strategy_name} --repetition_index={repetition_index} --device={device_str}'
subprocess.Popen(command, shell=True)
else:
# Server
for repetition_index in repetition_index_range:
command = f'/home/herui/miniconda3/envs/py3.8/bin/python {execute_file} --dataset_name={dataset_name} --model_name={model_name} --strategy_name={strategy_name} --repetition_index={repetition_index} --device={device_str}'
subprocess.Popen(command, shell=True)
print('Already submit all the jobs!')