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

Function inference

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

Source from the content-addressed store, hash-verified

20from utils.utils import powerset, one_hot_encoder, DiceLoss, val_single_volume
21
22def inference(args, model, best_performance):
23 db_test = Synapse_dataset(base_dir=args.volume_path, split="test_vol", list_dir=args.list_dir, nclass=args.num_classes)
24
25 testloader = DataLoader(db_test, batch_size=1, shuffle=False, num_workers=1)
26 logging.info("{} test iterations per epoch".format(len(testloader)))
27 model.eval()
28 metric_list = 0.0
29 for i_batch, sampled_batch in tqdm(enumerate(testloader)):
30 h, w = sampled_batch["image"].size()[2:]
31 image, label, case_name = sampled_batch["image"], sampled_batch["label"], sampled_batch['case_name'][0]
32 metric_i = val_single_volume(image, label, model, classes=args.num_classes, patch_size=[args.img_size, args.img_size],
33 case=case_name, z_spacing=args.z_spacing)
34 metric_list += np.array(metric_i)
35 metric_list = metric_list / len(db_test)
36 performance = np.mean(metric_list, axis=0)
37 logging.info('Testing performance in val model: mean_dice : %f, best_dice : %f' % (performance, best_performance))
38 return performance
39
40def trainer_synapse(args, model, snapshot_path):
41 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