forked from Mariewelt/OpenChem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict_classifier.py
33 lines (22 loc) · 1004 Bytes
/
predict_classifier.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
import runpy
import torch
import copy
from torch.nn.parallel import DataParallel
from openchem.models.openchem_model import predict
from openchem.data.utils import create_loader
config_file = r'example_configs/tox21_rnn_config.py'
config_module = runpy.run_path(config_file)
model_config = config_module.get('model_params', None)
model_config['use_cuda'] = torch.cuda.is_available()
model_object = config_module.get('model', None)
model = model_object(params=model_config)
model = DataParallel(model)
model.load_state_dict(torch.load(r'logs/tox21_rnn_log/checkpoint/epoch_10'))
predict_dataset = copy.deepcopy(model_config['predict_data_layer'])
predict_loader = create_loader(predict_dataset,
batch_size=model_config['batch_size'],
shuffle=False,
num_workers=1,
pin_memory=True)
predict(model, predict_loader)
torch.save(model.module.state_dict(), 'model_LOL.pth')