MCPcopy Create free account
hub / github.com/DrugLT/ImDrug / test

Function test

script/test.py:56–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54 pass
55
56def test():
57 utils.global_seed(cfg['seed'])
58 print('cfg',cfg)
59 device = utils.set_gpu_mode(cfg['use_gpu'], cfg['gpu_id'])
60 print('device', device)
61 local_rank = cfg['train']['local_rank']
62 rank = local_rank
63 logger, log_file, exp_id = create_logger(cfg, local_rank, test=True)
64 warnings.filterwarnings("ignore")
65
66 # close loop
67 model_dir = osp.join(cfg['output_dir'], cfg['dataset']['dataset_name'], "models", cfg['test']['exp_id'])
68 # code_dir = osp.join(cfg['output_dir'], cfg['dataset']['dataset_name'], "code")
69
70
71 # ----- BEGIN DATASET BUILDER -----
72 datasets = get_dataset(cfg, test=True)
73 test_set = datasets['test_set']
74 print('dataset', datasets)
75 entity_type = test_set.entity_type
76
77 # ----- END DATASET BUILDER -----
78
79 if cfg['setting']['type'] not in ['LT Regression', 'LT Generation']:
80 num_class_list = get_category_list(test_set)
81 num_classes = len(num_class_list) - 1 # the model was trained only with closes sets, without the outlier class in the open set
82 para_dict = {
83 "num_classes": num_classes,
84 "num_class_list": num_class_list,
85 "cfg": cfg,
86 "device": device,
87 }
88 cfg['setting']['num_class'] = num_classes # update the real number of classes based on the datasets
89
90 # ----- BEGIN MODEL BUILDER -----
91 model = get_model(cfg=cfg, device=device, logger=logger, entity_type=entity_type)
92 model_file = os.path.join(model_dir, cfg['test']['model_file'])
93 model.load_model(model_file)
94 model = torch.nn.DataParallel(model).cuda()
95
96 # ----- END MODEL BUILDER -----
97 params = {}
98 if (cfg['dataset']['drug_encoding'] == "MPNN"):
99 params['collate_fn'] = partial(mpnn_collate_func, entity_type=entity_type)
100 elif cfg['dataset']['drug_encoding'] in ['DGL_GCN', 'DGL_NeuralFP', 'DGL_GIN_AttrMasking', \
101 'DGL_GIN_ContextPred', 'DGL_AttentiveFP']:
102 params['collate_fn'] = partial(dgl_collate_func, entity_type=entity_type)
103 else:
104 params['collate_fn'] = partial(default_collate_func, entity_type=entity_type)
105
106
107 testLoader = DataLoader(
108 test_set,
109 batch_size=cfg['test']['batch_size'],
110 shuffle=False,
111 num_workers=cfg['test']['num_workers'],
112 pin_memory=False,
113 drop_last=False,

Callers 1

test.pyFile · 0.85

Calls 7

create_loggerFunction · 0.90
get_datasetFunction · 0.90
get_category_listFunction · 0.90
get_modelFunction · 0.90
DataLoaderClass · 0.90
test_modelFunction · 0.90
load_modelMethod · 0.80

Tested by

no test coverage detected