-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGNN_Main.py
More file actions
executable file
·115 lines (97 loc) · 3.75 KB
/
Copy pathGNN_Main.py
File metadata and controls
executable file
·115 lines (97 loc) · 3.75 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
import matplotlib
matplotlib.use('Agg') # set non-interactive backend before other imports
import argparse
import os
# redirect PyTorch JIT cache to /scratch instead of /tmp (per IT request)
if os.path.isdir('/scratch'):
os.environ['TMPDIR'] = '/scratch/allierc'
os.makedirs('/scratch/allierc', exist_ok=True)
from neural_gnn.config import NeuralGraphConfig
from neural_gnn.generators.graph_data_generator import data_generate
from neural_gnn.models.graph_trainer import data_train, data_test
from neural_gnn.utils import set_device, add_pre_folder, load_and_display
from GNN_PlotFigure import data_plot, create_training_montage
import warnings
warnings.filterwarnings("ignore", message="pkg_resources is deprecated as an API")
if __name__ == "__main__":
warnings.filterwarnings("ignore", category=FutureWarning)
parser = argparse.ArgumentParser(description="NeuralGraph")
parser.add_argument(
"-o", "--option", nargs="+", help="option that takes multiple values"
)
print()
device = []
args = parser.parse_args()
if args.option:
print(f"Options: {args.option}")
if args.option is not None:
task = args.option[0]
config_list = [args.option[1]]
if len(args.option) > 2:
best_model = args.option[2]
else:
best_model = None
else:
best_model = ''
task = task = 'train'
config_list = ['signal_fig_supp_11']
for config_file_ in config_list:
print(" ")
config_root = os.path.dirname(os.path.abspath(__file__)) + "/config"
config_file, pre_folder = add_pre_folder(config_file_)
# load config
config = NeuralGraphConfig.from_yaml(f"{config_root}/{config_file}.yaml")
config.dataset = pre_folder + config.dataset
config.config_file = pre_folder + config_file_
if device == []:
device = set_device(config.training.device)
if "generate" in task:
data_generate(
config,
device=device,
visualize=False,
run_vizualized=0,
style="color",
alpha=1,
erase=False,
bSave=True,
step=2,
)
if 'train_NGP' in task:
# use new modular NGP trainer pipeline
data_train_NGP(config=config, device=device)
elif 'train_INR' in task:
print()
# pre-train nnr_f (SIREN) on external_input data before joint GNN learning
data_train_INR(config=config, device=device, total_steps=50000)
elif "train" in task:
data_train(
config=config,
erase=False,
best_model=best_model,
style='',
device=device,
)
if "test" in task:
config.simulation.noise_model_level = 0.0
if 'fly' in config_file_:
config.simulation.visual_input_type = 'optical_flow'
data_test(
config=config,
visualize=False,
style="color name continuous_slice",
verbose=False,
best_model='best',
run=0,
test_mode="",
sample_embedding=False,
step=10,
n_rollout_frames=1000,
device=device,
particle_of_interest=0,
new_params=None,
)
if 'plot' in task:
folder_name = './log/' + pre_folder + '/tmp_results/'
os.makedirs(folder_name, exist_ok=True)
data_plot(config=config, config_file=config_file, epoch_list=['best'], style='color', extended='plots', device=device, apply_weight_correction=True)