MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / run_test

Method run_test

tests/integration/test_mapping_filed.py:60–95  ·  view source on GitHub ↗
(self, save_keys, write_keys)

Source from the content-addressed store, hash-verified

58 os.remove(self.mapping_file_path)
59
60 def run_test(self, save_keys, write_keys):
61 name = "test_image"
62 input_file = create_input_file(self.temp_dir, name)
63 output_file = os.path.join(self.output_dir, name, name + "_seg.nii.gz")
64 data = [{"image": input_file}]
65
66 test_transforms = Compose([LoadImaged(keys=["image"]), EnsureChannelFirstd(keys=["image"])])
67
68 post_transforms = Compose(
69 [
70 SaveImaged(
71 keys=save_keys,
72 meta_keys="image_meta_dict",
73 output_dir=self.output_dir,
74 output_postfix="seg",
75 savepath_in_metadict=True,
76 ),
77 WriteFileMappingd(keys=write_keys, mapping_file_path=self.mapping_file_path),
78 ]
79 )
80
81 dataset = Dataset(data=data, transform=test_transforms)
82 dataloader = DataLoader(dataset, batch_size=1)
83 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
84 model = UNet(spatial_dims=3, in_channels=1, out_channels=2, channels=(16, 32), strides=(2,)).to(device)
85 model.eval()
86
87 with torch.no_grad():
88 for batch_data in dataloader:
89 test_inputs = batch_data["image"].to(device)
90 roi_size = (64, 64, 64)
91 sw_batch_size = 2
92 batch_data["seg"] = sliding_window_inference(test_inputs, roi_size, sw_batch_size, model)
93 batch_data = [post_transforms(i) for i in decollate_batch(batch_data)]
94
95 return input_file, output_file
96
97 @parameterized.expand(SUCCESS_CASES)
98 def test_successful_mapping_filed(self, save_keys, write_keys):

Callers 2

Calls 11

ComposeClass · 0.90
LoadImagedClass · 0.90
EnsureChannelFirstdClass · 0.90
SaveImagedClass · 0.90
WriteFileMappingdClass · 0.90
DatasetClass · 0.90
DataLoaderClass · 0.90
UNetClass · 0.90
sliding_window_inferenceFunction · 0.90
decollate_batchFunction · 0.90
create_input_fileFunction · 0.70

Tested by

no test coverage detected