Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuyu: improve image processing #27007

Merged
merged 11 commits into from
Nov 2, 2023
27 changes: 17 additions & 10 deletions src/transformers/feature_extraction_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,9 @@ def values(self):
def items(self):
return self.data.items()

def convert_to_tensors(self, tensor_type: Optional[Union[str, TensorType]] = None):
"""
Convert the inner content to tensors.

Args:
tensor_type (`str` or [`~utils.TensorType`], *optional*):
The type of tensors to use. If `str`, should be one of the values of the enum [`~utils.TensorType`]. If
`None`, no modification is done.
"""
def _get_is_as_tensor_fns(self, tensor_type: Optional[Union[str, TensorType]] = None):
if tensor_type is None:
return self
return None, None

# Convert to TensorType
if not isinstance(tensor_type, TensorType):
Expand Down Expand Up @@ -167,6 +159,21 @@ def as_tensor(value, dtype=None):
return np.asarray(value, dtype=dtype)

is_tensor = is_numpy_array
return is_tensor, as_tensor

def convert_to_tensors(self, tensor_type: Optional[Union[str, TensorType]] = None):
"""
Convert the inner content to tensors.

Args:
tensor_type (`str` or [`~utils.TensorType`], *optional*):
The type of tensors to use. If `str`, should be one of the values of the enum [`~utils.TensorType`]. If
`None`, no modification is done.
"""
if tensor_type is None:
return self

is_tensor, as_tensor = self._get_is_as_tensor_fns(tensor_type)

# Do the tensor conversion in batch
for key, value in self.items():
Expand Down
Loading
Loading