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

Method multi_inverse

tests/croppers.py:81–107  ·  view source on GitHub ↗
(self, input_shape, init_params)

Source from the content-addressed store, hash-verified

79 assert_allclose(out_im, expected_array, type_test=False)
80
81 def multi_inverse(self, input_shape, init_params):
82 input_data = np.arange(np.prod(input_shape)).reshape(*input_shape) + 1
83 xform = self.Cropper(**init_params)
84 xform.set_random_state(1234)
85 out = xform(input_data)
86 if "num_samples" in init_params:
87 self.assertEqual(len(out), init_params["num_samples"])
88 inv = xform.inverse(out)
89 self.assertIsInstance(inv, MetaTensor)
90 self.assertEqual(inv.applied_operations, [])
91 self.assertTrue("patch_index" not in inv.meta)
92 self.assertTupleEqual(inv.shape, input_shape)
93 inv_np = inv.numpy()
94
95 # get list of all numbers that exist inside the crops
96 uniques = set()
97 for o in out:
98 uniques.update(set(o.flatten().tolist()))
99
100 # make sure that
101 for i in uniques:
102 a = np.where(input_data == i)
103 b = np.where(inv_np == i)
104 self.assertTupleEqual(a, b)
105 # there should be as many zeros as elements missing from uniques
106 missing = input_data.size - len(uniques)
107 self.assertEqual((inv_np == 0).sum(), missing)
108
109 def crop_test_pending_ops(self, input_param, input_shape, align_corners=False):
110 crop_fn = self.Cropper(**input_param)

Callers

nothing calls this directly

Calls 4

set_random_stateMethod · 0.45
inverseMethod · 0.45
updateMethod · 0.45
flattenMethod · 0.45

Tested by

no test coverage detected