MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / test_shape

Method test_shape

tests/inferers/test_saliency_inferer.py:33–51  ·  view source on GitHub ↗
(self, cam_name)

Source from the content-addressed store, hash-verified

31
32 @parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3])
33 def test_shape(self, cam_name):
34 model = DenseNet(
35 spatial_dims=3, in_channels=1, out_channels=3, init_features=2, growth_rate=2, block_config=(6,)
36 )
37 device = "cuda:0" if torch.cuda.is_available() else "cpu"
38 model.to(device)
39 model.eval()
40
41 image = torch.rand((2, 1, 6, 6, 6), device=device)
42 target_layer = "class_layers.relu"
43 fc_layer = "class_layers.out"
44 if cam_name == "CAM":
45 inferer = SaliencyInferer(cam_name, target_layer, None, fc_layer, upsampler=default_upsampler)
46 result = inferer(inputs=image, network=model, layer_idx=-1)
47 else:
48 inferer = SaliencyInferer(cam_name, target_layer, None, upsampler=default_upsampler)
49 result = inferer(image, model, -1, retain_graph=False)
50
51 self.assertTupleEqual(result.shape, (2, 1, 6, 6, 6))
52
53
54if __name__ == "__main__":

Callers

nothing calls this directly

Calls 2

DenseNetClass · 0.90
SaliencyInfererClass · 0.90

Tested by

no test coverage detected