Unverified Commit acf30e98 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

add some feature attributes to repr (#6468)

parent 857c0303
......@@ -41,6 +41,9 @@ class BoundingBox(_Feature):
return bounding_box
def __repr__(self, *, tensor_contents: Any = None) -> str: # type: ignore[override]
return self._make_repr(format=self.format, image_size=self.image_size)
@classmethod
def new_like(
cls,
......
......@@ -86,6 +86,12 @@ class _Feature(torch.Tensor):
else:
return output
def _make_repr(self, **kwargs: Any) -> str:
# This is a poor man's implementation of the proposal in https://github.com/pytorch/pytorch/issues/76532.
# If that ever gets implemented, remove this in favor of the solution on the `torch.Tensor` class.
extra_repr = ", ".join(f"{key}={value}" for key, value in kwargs.items())
return f"{super().__repr__()[:-1]}, {extra_repr})"
def horizontal_flip(self) -> _Feature:
return self
......
......@@ -64,6 +64,9 @@ class Image(_Feature):
return image
def __repr__(self, *, tensor_contents: Any = None) -> str: # type: ignore[override]
return self._make_repr(color_space=self.color_space)
@classmethod
def new_like(
cls, other: Image, data: Any, *, color_space: Optional[Union[ColorSpace, str]] = None, **kwargs: Any
......
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