Unverified Commit fad476a2 authored by Vasilis Vryniotis's avatar Vasilis Vryniotis Committed by GitHub
Browse files

Remove aliases for `PILToTensor` and `pil_to_tensor()` (#6588)

* Remove alias for `pil_to_tensor()`

* Remove alias for `PILToTensor`

* Leave `to_tensor()` as-is.

* Fix linter
parent 1c3eedc4
......@@ -487,7 +487,7 @@ class AugMix(_AutoAugmentBase):
if isinstance(orig_image, torch.Tensor):
image = orig_image
else: # isinstance(inpt, PIL.Image.Image):
image = F.to_image_tensor(orig_image)
image = F.pil_to_tensor(orig_image)
augmentation_space = self._AUGMENTATION_SPACE if self.all_ops else self._PARTIAL_AUGMENTATION_SPACE
......
......@@ -114,7 +114,7 @@ class RandomPhotometricDistort(Transform):
def _permute_channels(self, inpt: Any, permutation: torch.Tensor) -> Any:
if isinstance(inpt, PIL.Image.Image):
inpt = F.to_image_tensor(inpt)
inpt = F.pil_to_tensor(inpt)
output = inpt[..., permutation, :, :]
......
......@@ -37,6 +37,13 @@ class LabelToOneHot(Transform):
return f"num_categories={self.num_categories}"
class PILToTensor(Transform):
_transformed_types = (PIL.Image.Image,)
def _transform(self, inpt: Union[PIL.Image.Image], params: Dict[str, Any]) -> torch.Tensor:
return F.pil_to_tensor(inpt)
class ToImageTensor(Transform):
_transformed_types = (features.is_simple_tensor, PIL.Image.Image, np.ndarray)
......@@ -59,7 +66,6 @@ class ToImagePIL(Transform):
return F.to_image_pil(inpt, mode=self.mode)
# We changed the names to align them with the new naming scheme. Still, `PILToTensor` and `ToPILImage` are
# prevalent and well understood. Thus, we just alias them without deprecating the old names.
PILToTensor = ToImageTensor
# We changed the name to align them with the new naming scheme. Still, `ToPILImage` is
# prevalent and well understood. Thus, we just alias it without deprecating the old name.
ToPILImage = ToImagePIL
......@@ -25,16 +25,18 @@ def decode_video_with_av(encoded_video: torch.Tensor) -> Tuple[torch.Tensor, tor
def to_image_tensor(image: Union[torch.Tensor, PIL.Image.Image, np.ndarray]) -> features.Image:
if isinstance(image, np.ndarray):
output = torch.from_numpy(image)
else:
output = _F.pil_to_tensor(image)
elif isinstance(image, PIL.Image.Image):
output = pil_to_tensor(image)
else: # isinstance(inpt, torch.Tensor):
output = image
return features.Image(output)
to_image_pil = _F.to_pil_image
pil_to_tensor = _F.pil_to_tensor
# We changed the names to align them with the new naming scheme. Still, `to_pil_image` and `pil_to_tensor` are
# prevalent and well understood. Thus, we just alias them without deprecating the old names.
# We changed the names to align them with the new naming scheme. Still, `to_pil_image` is
# prevalent and well understood. Thus, we just alias it without deprecating the old name.
to_pil_image = to_image_pil
pil_to_tensor = to_image_tensor
convert_image_dtype = _F.convert_image_dtype
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment