MCPcopy Create free account
hub / github.com/SLDGroup/MERIT / inference

Function inference

test_ACDC.py:16–37  ·  view source on GitHub ↗
(args, model, testloader, test_save_path=None)

Source from the content-addressed store, hash-verified

14from lib.networks import MaxViT, MaxViT4Out, MaxViT_CASCADE, MERIT_Parallel, MERIT_Cascaded
15
16def inference(args, model, testloader, test_save_path=None):
17 logging.info("{} test iterations per epoch".format(len(testloader)))
18 model.eval()
19 metric_list = 0.0
20 with torch.no_grad():
21 for i_batch, sampled_batch in tqdm(enumerate(testloader)):
22 h, w = sampled_batch["image"].size()[2:]
23 image, label, case_name = sampled_batch["image"], sampled_batch["label"], sampled_batch['case_name'][0]
24 metric_i = test_single_volume(image, label, model, classes=args.num_classes, patch_size=[args.img_size, args.img_size],
25 test_save_path=test_save_path, case=case_name, z_spacing=args.z_spacing)
26 metric_list += np.array(metric_i)
27 logging.info('idx %d case %s mean_dice %f mean_hd95 %f, mean_jacard %f mean_asd %f' % (i_batch, case_name, np.mean(metric_i, axis=0)[0], np.mean(metric_i, axis=0)[1], np.mean(metric_i, axis=0)[2], np.mean(metric_i, axis=0)[3]))
28 metric_list = metric_list / len(testloader)
29 for i in range(1, args.num_classes):
30 logging.info('Mean class (%d) mean_dice %f mean_hd95 %f, mean_jacard %f mean_asd %f' % (i, metric_list[i-1][0], metric_list[i-1][1], metric_list[i-1][2], metric_list[i-1][3]))
31 performance = np.mean(metric_list, axis=0)[0]
32 mean_hd95 = np.mean(metric_list, axis=0)[1]
33 mean_jacard = np.mean(metric_list, axis=0)[2]
34 mean_asd = np.mean(metric_list, axis=0)[3]
35 logging.info('Testing performance in best val model: mean_dice : %f mean_hd95 : %f, mean_jacard : %f mean_asd : %f' % (performance, mean_hd95, mean_jacard, mean_asd))
36 logging.info("Testing Finished!")
37 return performance, mean_hd95, mean_jacard, mean_asd
38
39if __name__ == "__main__":
40

Callers 2

train_ACDC.pyFile · 0.90
test_ACDC.pyFile · 0.70

Calls 1

test_single_volumeFunction · 0.90

Tested by

no test coverage detected