def test_zero_mean_unit_variance_whole_image(self): print('Test test_zero_mean_unit_variance_whole_image. [START]') data = np.random.random((32, 4, 64, 56, 48)) data2 = 5 * np.ones((32, 4, 64, 56, 48)) data3 = np.array([]) data_normalized1 = zero_mean_unit_variance_normalization(data, per_channel=False, epsilon=0) data_normalized2 = zero_mean_unit_variance_normalization(data2, per_channel=False) data_normalized3 = zero_mean_unit_variance_normalization(data3, per_channel=False) print('Test standard use-case. [START]') for b in range(data.shape[0]): self.assertAlmostEqual(data_normalized1[b].mean(), 0, msg="mean not zeros") self.assertAlmostEqual(data_normalized1[b].std(), 1, msg="std not 1") print('Test standard use-case. [DONE]') print('Test constant input data. [START]') for b in range(data2.shape[0]): self.assertAlmostEqual(data_normalized2[b].mean(), 0, msg="mean not zeros") self.assertAlmostEqual(data_normalized2[b].std(), 0, msg="std not 1") print('Test constant input data. [DONE]') # print('Test RuntimeWarning of constant data with zero eps. [START]') # self.assertWarns(RuntimeWarning, zero_mean_unit_variance_normalization, data2, per_channel=False, epsilon=0) # print('Test RuntimeWarning of constant data with zero eps. [DONE]') print('Test normalization of empty data array. [START]') self.assertEqual(data_normalized3.size, 0, msg="not an empty array") print('Test normalization of empty data array. [DONE]') print('Test test_zero_mean_unit_variance_whole_image. [DONE]')
def test_zero_mean_unit_variance_whole_image(self): data = np.random.random((32, 4, 64, 56, 48)) data[:, 0, :, :] = 3 * data[:, 0, :, :] d = zero_mean_unit_variance_normalization(data, per_channel=False, epsilon=0) for b in range(data.shape[0]): self.assertAlmostEqual(d[b, :, :, :].mean(), 0, msg="mean not zeros") self.assertAlmostEqual(d[b, :, :, :].std(), 1, msg="std not 1")
def test_zero_mean_unit_variance_per_channel(self): data = np.random.random((32, 4, 64, 56, 48)) d = zero_mean_unit_variance_normalization(data, per_channel=True, epsilon=0) for b in range(data.shape[0]): for c in range(data.shape[1]): self.assertAlmostEqual(d[b, c, :, :].mean(), 0, msg="mean not zeros") self.assertAlmostEqual(d[b, c, :, :].std(), 1, msg="std not 1")
def __call__(self, **data_dict): data_dict['data'] = zero_mean_unit_variance_normalization( data_dict["data"], self.per_channel, self.epsilon) return data_dict
def __call__(self, **data_dict): data_dict[self.data_key] = zero_mean_unit_variance_normalization(data_dict[self.data_key], self.per_channel, self.epsilon) return data_dict