-
Notifications
You must be signed in to change notification settings - Fork 1
/
inference.py
44 lines (33 loc) · 1.46 KB
/
inference.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
import torch
import argparse
from models import DeeperGCN, GCNModelWithEdgeAFPreadout
from dataset import smiles2graph, feature_to_dgl_graph,get_node_dim, get_edge_dim
def main():
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = GCNModelWithEdgeAFPreadout(node_in_dim=get_node_dim(), edge_in_dim=get_edge_dim(), hidden_feats=[200] * 16,
dropout=0.1)
'''load best model params'''
best_model_path = args.model_path
checkpoint = torch.load(best_model_path, map_location=device) # 加载断点
model.load_state_dict(checkpoint) # 加载模型可学习参数
print(f"model loaded from: {best_model_path}")
model.to(device)
# test = "O=C(c1ccc2c(c1)N(CC(O)=NCc1ccco1)C(=O)[C@@H]1CCCCN21)N1CCCCC1"
test = args.SMILES
g = feature_to_dgl_graph(smiles2graph(test))
g = g.to(device)
model.eval()
with torch.no_grad():
output = model(g)
print(output)
print(f"The predicted RT for {test}\nis \n {output.cpu().numpy()}")
if __name__ == '__main__':
"""
Model Hyperparameters
"""
parser = argparse.ArgumentParser(description='GNN_RT_MODEL_inference')
parser.add_argument('--SMILES', type=str, required=True, help='SMILES of the small molecule')
parser.add_argument('--model_path', type=str,default="model_path/best_model_weight.pth", help='model path for DeepGCN-RT')
args = parser.parse_args()
print(args)
main()