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] Replace it to BatchFeature #27109

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/transformers/models/fuyu/processing_fuyu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np

from ...image_processing_utils import BatchFeature
from ...image_utils import (
ChannelDimension,
get_image_size,
Expand Down Expand Up @@ -415,7 +416,7 @@ def _process_images(self, images):

return batch_images, torch.Tensor(image_unpadded_heights), torch.Tensor(image_unpadded_widths)

def __call__(self, text=None, images=None, return_tensors=None, **kwargs):
def __call__(self, text=None, images=None, return_tensors=None, **kwargs) -> BatchFeature:
"""
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to
Expand Down Expand Up @@ -541,11 +542,13 @@ def __call__(self, text=None, images=None, return_tensors=None, **kwargs):
)

image_patches_tensor = torch.stack([img[0] for img in model_image_input["image_patches"]]).unsqueeze(1)
return {
"input_ids": image_padded_unpacked_tokens[0].unsqueeze(0),
"image_patches": image_patches_tensor[0][0].unsqueeze(0),
"image_patches_indices": image_patch_input_indices,
}
return BatchFeature(
data={
"input_ids": image_padded_unpacked_tokens[0].unsqueeze(0),
"image_patches": image_patches_tensor[0][0].unsqueeze(0),
"image_patches_indices": image_patch_input_indices,
}
)

def batch_decode(self, *args, **kwargs):
"""
Expand Down
Loading