(self, inferer)
| 58 | shutil.rmtree(self.data_dir) |
| 59 | |
| 60 | def _test_inferer(self, inferer): |
| 61 | # should initialize before parsing any bundle content |
| 62 | inferer.initialize() |
| 63 | # test required and optional properties |
| 64 | self.assertListEqual(inferer.check_properties(), []) |
| 65 | # test read / write the properties, note that we don't assume it as JSON or YAML config here |
| 66 | self.assertEqual(inferer.bundle_root, "will override") |
| 67 | self.assertEqual(inferer.device, torch.device("cpu")) |
| 68 | net = inferer.network_def |
| 69 | self.assertTrue(isinstance(net, UNet)) |
| 70 | sliding_window = inferer.inferer |
| 71 | self.assertTrue(isinstance(sliding_window, SlidingWindowInferer)) |
| 72 | preprocessing = inferer.preprocessing |
| 73 | self.assertTrue(isinstance(preprocessing, Compose)) |
| 74 | postprocessing = inferer.postprocessing |
| 75 | self.assertTrue(isinstance(postprocessing, Compose)) |
| 76 | # test optional properties get |
| 77 | self.assertTrue(inferer.key_metric is None) |
| 78 | inferer.bundle_root = "/workspace/data/spleen_ct_segmentation" |
| 79 | inferer.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") |
| 80 | inferer.network_def = deepcopy(net) |
| 81 | inferer.inferer = deepcopy(sliding_window) |
| 82 | inferer.preprocessing = deepcopy(preprocessing) |
| 83 | inferer.postprocessing = deepcopy(postprocessing) |
| 84 | # test optional properties set |
| 85 | inferer.key_metric = "set optional properties" |
| 86 | |
| 87 | # should initialize and parse again as changed the bundle content |
| 88 | inferer.initialize() |
| 89 | inferer.run() |
| 90 | inferer.finalize() |
| 91 | # verify inference output |
| 92 | loader = LoadImage(image_only=True) |
| 93 | pred_file = os.path.join(self.data_dir, "image", "image_seg.nii.gz") |
| 94 | self.assertTupleEqual(loader(pred_file).shape, self.expected_shape) |
| 95 | os.remove(pred_file) |
| 96 | |
| 97 | @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) |
| 98 | def test_inference_config(self, config_file): |
no test coverage detected