def yuv_to_rgb(x: torch.Tensor) -> torch.Tensor: transformation_matrix = torch.tensor( ((1.000, 0.000, 1.140), (1.000, -0.395, -0.581), (1.000, 2.032, 0.000)), **tensor_meta(x), ) return transform_channels_linearly(x, transformation_matrix)
def rgb_to_yuv(x: torch.Tensor) -> torch.Tensor: transformation_matrix = torch.tensor( ((0.299, 0.587, 0.114), (-0.147, -0.289, 0.436), (0.615, -0.515, -0.100)), **tensor_meta(x), ) return transform_channels_linearly(x, transformation_matrix)
def test_tensor_meta_kwargs(self): dtype = torch.bool x = torch.empty(()) actual = meta.tensor_meta(x, dtype=dtype)["dtype"] desired = dtype self.assertEqual(actual, desired)
def test_tensor_meta(self): tensor_meta = {"dtype": torch.bool, "device": torch.device("cpu")} x = torch.empty((), **tensor_meta) actual = meta.tensor_meta(x) desired = tensor_meta self.assertDictEqual(actual, desired)
def test_kwargs(main): dtype = torch.bool x = torch.empty(()) actual = meta.tensor_meta(x, dtype=dtype)["dtype"] desired = dtype assert actual == desired
def test_main(self): tensor_meta = {"dtype": torch.bool, "device": torch.device("cpu")} x = torch.empty((), **tensor_meta) actual = meta.tensor_meta(x) desired = tensor_meta assert actual == desired
def rgb_to_grayscale(x: torch.Tensor) -> torch.Tensor: transformation_matrix = torch.tensor(((0.299, 0.587, 0.114), ), **tensor_meta(x)) return transform_channels_linearly(x, transformation_matrix)
def forward(self, input: torch.Tensor) -> torch.Tensor: size = self._extract_size(input) meta = meta_.tensor_meta(input) noise = torch.rand(size, **meta) return join_channelwise(input, noise)