Skip to content

Commit

Permalink
Separate out kwargs in processor (huggingface#30193)
Browse files Browse the repository at this point in the history
* Separate out kwargs in processor

* Fix up
  • Loading branch information
amyeroberts authored and zucchini-nlp committed Apr 18, 2024
1 parent b8563bb commit f3d8635
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/transformers/models/clip/processing_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,21 @@ def __call__(self, text=None, images=None, return_tensors=None, **kwargs):
`None`).
- **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
"""
tokenizer_kwargs, image_processor_kwargs = {}, {}
if kwargs:
tokenizer_kwargs = {k: v for k, v in kwargs.items() if k not in self.image_processor._valid_processor_keys}
image_processor_kwargs = {
k: v for k, v in kwargs.items() if k in self.image_processor._valid_processor_keys
}

if text is None and images is None:
raise ValueError("You have to specify either text or images. Both cannot be none.")

if text is not None:
encoding = self.tokenizer(text, return_tensors=return_tensors, **kwargs)
encoding = self.tokenizer(text, return_tensors=return_tensors, **tokenizer_kwargs)

if images is not None:
image_features = self.image_processor(images, return_tensors=return_tensors, **kwargs)
image_features = self.image_processor(images, return_tensors=return_tensors, **image_processor_kwargs)

if text is not None and images is not None:
encoding["pixel_values"] = image_features.pixel_values
Expand Down

0 comments on commit f3d8635

Please sign in to comment.