def test_read_img_as_tensor(mock_image_path): img = read_img_as_tensor(mock_image_path) assert isinstance(img, tf.Tensor) assert img.dtype == tf.float32 assert img.shape == (900, 1200, 3) img = read_img_as_tensor(mock_image_path, dtype=tf.float16) assert img.dtype == tf.float16 img = read_img_as_tensor(mock_image_path, dtype=tf.uint8) assert img.dtype == tf.uint8
def _read_sample(self, index: int) -> Tuple[torch.Tensor, Any]: img_name, target = self.data[index] # Read image img = read_img_as_tensor(os.path.join(self.root, img_name), dtype=torch.float32) return img, target
def _read_sample(self, index: int) -> Tuple[torch.Tensor, Any]: img_name, target = self.data[index] # Read image img = (tensor_from_numpy(img_name, dtype=torch.float32) if isinstance( img_name, np.ndarray) else read_img_as_tensor( os.path.join(self.root, img_name), dtype=torch.float32)) return img, deepcopy(target)