-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
107 lines (79 loc) · 2.86 KB
/
train.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
import argparse
import random
import time
import numpy as np
import tensorflow as tf
import yaml
from scann.models import SCANN
def set_seed(seed=2134):
# tf.keras.utils.set_random_seed(seed)
random.seed(seed)
np.random.seed(seed)
tf.random.set_seed(seed)
# When running on the CuDNN backend, two further options must be set
os.environ["TF_CUDNN_DETERMINISTIC"] = "1"
os.environ["TF_DETERMINISTIC_OPS"] = "1"
# Set a fixed value for the hash seed
os.environ["PYTHONHASHSEED"] = str(seed)
physical_devices = tf.config.experimental.list_physical_devices("GPU")
tf.config.experimental.set_memory_growth(physical_devices[0], True)
def main(args):
set_seed(0)
config = yaml.safe_load(open(args.dataset))
print("Create model use Ring Information: ", args.use_ring, "\n")
config["model"]["feature"] = args.feature
config["model"]["use_ring"] = args.use_ring
config["model"]["use_drop"] = args.use_drop
config["hyper"]["use_ref"] = args.use_ref
config["hyper"]["target"] = args.target
config["hyper"]["pretrained"] = args.pretrained
scann = SCANN(config, args.pretrained)
print("Load data for dataset: ", args.dataset, " with target: ", args.target, "\n")
scann.prepare_dataset()
if args.mode == "train":
print("Start Model training", "\n")
start = time.time()
scann.train(1000)
print("Training time: ", time.time() - start, "\n")
print("Start Model evaluation:")
# Evaluate for testset
scann.evaluate()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument("target", type=str, help="Target energy for training")
parser.add_argument("dataset", type=str, help="Path to dataset configs")
parser.add_argument(
"--use_ring",
type=bool,
default=False,
help="Whether to use ring/aromatic as extra emedding",
)
parser.add_argument(
"--use_ref",
type=bool,
default=False,
help="Whether to use ref optimization energy",
)
parser.add_argument(
"--use_drop",
type=bool,
default=False,
help="Whether to use dropout in training model",
)
parser.add_argument(
"--feature",
type=str,
default="atomic",
help="Whether to use atomic or cgcnn feature",
)
parser.add_argument("--pretrained", type=str, default="", help="Path to pretrained model (optional)")
parser.add_argument(
"--mode",
type=str,
default="train",
help="Whether to train new model or just run the evaluation on pretrained model",
)
args = parser.parse_args()
main(args)