"src/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "826f43505d07cac92504bfc0637227d72f477f30"
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): ...@@ -487,7 +487,7 @@ class AugMix(_AutoAugmentBase):
if isinstance(orig_image, torch.Tensor): if isinstance(orig_image, torch.Tensor):
image = orig_image image = orig_image
else: # isinstance(inpt, PIL.Image.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 augmentation_space = self._AUGMENTATION_SPACE if self.all_ops else self._PARTIAL_AUGMENTATION_SPACE
......
...@@ -114,7 +114,7 @@ class RandomPhotometricDistort(Transform): ...@@ -114,7 +114,7 @@ class RandomPhotometricDistort(Transform):
def _permute_channels(self, inpt: Any, permutation: torch.Tensor) -> Any: def _permute_channels(self, inpt: Any, permutation: torch.Tensor) -> Any:
if isinstance(inpt, PIL.Image.Image): if isinstance(inpt, PIL.Image.Image):
inpt = F.to_image_tensor(inpt) inpt = F.pil_to_tensor(inpt)
output = inpt[..., permutation, :, :] output = inpt[..., permutation, :, :]
......
...@@ -37,6 +37,13 @@ class LabelToOneHot(Transform): ...@@ -37,6 +37,13 @@ class LabelToOneHot(Transform):
return f"num_categories={self.num_categories}" 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): class ToImageTensor(Transform):
_transformed_types = (features.is_simple_tensor, PIL.Image.Image, np.ndarray) _transformed_types = (features.is_simple_tensor, PIL.Image.Image, np.ndarray)
...@@ -59,7 +66,6 @@ class ToImagePIL(Transform): ...@@ -59,7 +66,6 @@ class ToImagePIL(Transform):
return F.to_image_pil(inpt, mode=self.mode) 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 # We changed the name to align them with the new naming scheme. Still, `ToPILImage` is
# prevalent and well understood. Thus, we just alias them without deprecating the old names. # prevalent and well understood. Thus, we just alias it without deprecating the old name.
PILToTensor = ToImageTensor
ToPILImage = ToImagePIL ToPILImage = ToImagePIL
...@@ -25,16 +25,18 @@ def decode_video_with_av(encoded_video: torch.Tensor) -> Tuple[torch.Tensor, tor ...@@ -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: def to_image_tensor(image: Union[torch.Tensor, PIL.Image.Image, np.ndarray]) -> features.Image:
if isinstance(image, np.ndarray): if isinstance(image, np.ndarray):
output = torch.from_numpy(image) output = torch.from_numpy(image)
else: elif isinstance(image, PIL.Image.Image):
output = _F.pil_to_tensor(image) output = pil_to_tensor(image)
else: # isinstance(inpt, torch.Tensor):
output = image
return features.Image(output) return features.Image(output)
to_image_pil = _F.to_pil_image 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 # 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 them without deprecating the old names. # prevalent and well understood. Thus, we just alias it without deprecating the old name.
to_pil_image = to_image_pil to_pil_image = to_image_pil
pil_to_tensor = to_image_tensor
convert_image_dtype = _F.convert_image_dtype 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