Ejemplo n.º 1
0
 def test_alpha_1(self, im_shape, _, as_tensor_input):
     data = self.get_data(im_shape, as_tensor_input)
     alpha = [1.0, 1.0]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     out = t(deepcopy(data))
     for k in KEYS:
         np.testing.assert_allclose(0 * data[k], out[k])
 def test_0_prob(self, im_shape, input_type):
     data = self.get_data(im_shape, input_type)
     alpha = [0.5, 1.0]
     t = RandGibbsNoised(KEYS, 0.0, alpha)
     out = t(data)
     for k in KEYS:
         torch.testing.assert_allclose(data[k], out[k], rtol=1e-7, atol=0)
Ejemplo n.º 3
0
 def test_identity(self, im_shape, input_type):
     data = self.get_data(im_shape, input_type)
     alpha = [0.0, 0.0]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     out = t(deepcopy(data))
     for k in KEYS:
         assert_allclose(out[k], data[k], atol=1e-2, type_test="tensor")
Ejemplo n.º 4
0
 def test_0_prob(self, im_shape, as_tensor_output, as_tensor_input):
     data = self.get_data(im_shape, as_tensor_input)
     alpha = [0.5, 1.0]
     t = RandGibbsNoised(KEYS, 0.0, alpha, as_tensor_output)
     out = t(data)
     for k in KEYS:
         np.testing.assert_allclose(data[k], out[k])
Ejemplo n.º 5
0
 def test_alpha(self, im_shape, _, as_tensor_input):
     data = self.get_data(im_shape, as_tensor_input)
     alpha = [0.5, 0.51]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     _ = t(deepcopy(data))
     self.assertGreaterEqual(t.sampled_alpha, 0.5)
     self.assertLessEqual(t.sampled_alpha, 0.51)
Ejemplo n.º 6
0
 def test_dict_matches(self, im_shape, input_type):
     data = self.get_data(im_shape, input_type)
     # use same image for both dictionary entries to check same trans is applied to them
     data = {KEYS[0]: deepcopy(data[KEYS[0]]), KEYS[1]: deepcopy(data[KEYS[0]])}
     alpha = [0.5, 1.0]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     out = t(deepcopy(data))
     torch.testing.assert_allclose(out[KEYS[0]], out[KEYS[1]], rtol=1e-7, atol=0)
 def test_alpha_1(self, im_shape, input_type):
     data = self.get_data(im_shape, input_type)
     alpha = [1.0, 1.0]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     out = t(deepcopy(data))
     for k in KEYS:
         self.assertEqual(type(out[k]), type(data[k]))
         if isinstance(out[k], torch.Tensor):
             self.assertEqual(out[k].device, data[k].device)
             out[k], data[k] = out[k].cpu(), data[k].cpu()
         np.testing.assert_allclose(0.0 * data[k], out[k], atol=1e-2)
 def test_same_result(self, im_shape, input_type):
     data = self.get_data(im_shape, input_type)
     alpha = [0.5, 0.8]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     t.set_random_state(42)
     out1 = t(deepcopy(data))
     t.set_random_state(42)
     out2 = t(deepcopy(data))
     for k in KEYS:
         torch.testing.assert_allclose(out1[k], out2[k], rtol=1e-7, atol=0)
         self.assertIsInstance(out1[k], type(data[k]))
Ejemplo n.º 9
0
 def test_same_result(self, im_shape, as_tensor_output, as_tensor_input):
     data = self.get_data(im_shape, as_tensor_input)
     alpha = [0.5, 0.8]
     t = RandGibbsNoised(KEYS, 1.0, alpha, as_tensor_output)
     t.set_random_state(42)
     out1 = t(deepcopy(data))
     t.set_random_state(42)
     out2 = t(deepcopy(data))
     for k in KEYS:
         np.testing.assert_allclose(out1[k], out2[k])
         self.assertIsInstance(
             out1[k], torch.Tensor if as_tensor_output else np.ndarray)
Ejemplo n.º 10
0
 def test_same_result(self, im_shape, input_type):
     data = self.get_data(im_shape, input_type)
     alpha = [0.5, 0.8]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     t.set_random_state(42)
     out1 = t(deepcopy(data))
     t.set_random_state(42)
     out2 = t(deepcopy(data))
     for k in KEYS:
         assert_allclose(out1[k],
                         out2[k],
                         rtol=1e-7,
                         atol=0,
                         type_test="tensor")
 def test_alpha(self, im_shape, input_type):
     data = self.get_data(im_shape, input_type)
     alpha = [0.5, 0.51]
     t = RandGibbsNoised(KEYS, 1.0, alpha)
     _ = t(deepcopy(data))
     self.assertTrue(0.5 <= t.rand_gibbs_noise.sampled_alpha <= 0.51)