示例#1
0
 def test_uint8_image(self):
     '''
     Tests that uint8 image (pixel values in [0, 255]) is not changed
     '''
     test_image = np.random.randint(0, 256, size=(3, 32, 32), dtype=np.uint8)
     scale_factor = summary._calc_scale_factor(test_image)
     self.assertEqual(scale_factor, 1, msg='Values are already in [0, 255], scale factor should be 1')
示例#2
0
 def test_float32_image(self):
     '''
     Tests that float32 image (pixel values in [0, 1]) are scaled correctly
     to [0, 255]
     '''
     test_image = np.random.rand(3, 32, 32).astype(np.float32)
     scale_factor = summary._calc_scale_factor(test_image)
     self.assertEqual(scale_factor, 255, msg='Values are in [0, 1], scale factor should be 255')
示例#3
0
 def test_convert_to_HWC_dtype_remains_same(self):
     # test to ensure convert_to_HWC restores the dtype of input np array and
     # thus the scale_factor calculated for the image is 1
     test_image = torch.tensor([[[[1, 2, 3], [4, 5, 6]]]], dtype=torch.uint8)
     tensor = make_np(test_image)
     tensor = convert_to_HWC(tensor, 'NCHW')
     scale_factor = summary._calc_scale_factor(tensor)
     self.assertEqual(scale_factor, 1, msg='Values are already in [0, 255], scale factor should be 1')