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

Function inference

trainer.py:26–42  ·  view source on GitHub ↗
(args, model, best_performance)

Source from the content-addressed store, hash-verified

24
25
26def inference(args, model, best_performance):
27 db_test = Synapse_dataset(base_dir=args.volume_path, split="test_vol", list_dir=args.list_dir, nclass=args.num_classes)
28
29 testloader = DataLoader(db_test, batch_size=1, shuffle=False, num_workers=1)
30 logging.info("{} test iterations per epoch".format(len(testloader)))
31 model.eval()
32 metric_list = 0.0
33 for i_batch, sampled_batch in tqdm(enumerate(testloader)):
34 h, w = sampled_batch["image"].size()[2:]
35 image, label, case_name = sampled_batch["image"], sampled_batch["label"], sampled_batch['case_name'][0]
36 metric_i = val_single_volume(image, label, model, classes=args.num_classes, patch_size=[args.img_size, args.img_size],
37 case=case_name, z_spacing=args.z_spacing)
38 metric_list += np.array(metric_i)
39 metric_list = metric_list / len(db_test)
40 performance = np.mean(metric_list, axis=0)
41 logging.info('Testing performance in val model: mean_dice : %f, best_dice : %f' % (performance, best_performance))
42 return performance
43
44def trainer_synapse(args, model, snapshot_path):
45 logging.basicConfig(filename=snapshot_path + "/log.txt", level=logging.INFO,

Callers 1

trainer_synapseFunction · 0.70

Calls 2

Synapse_datasetClass · 0.90
val_single_volumeFunction · 0.90

Tested by

no test coverage detected