Add fast image processor for ViViT #40209
Open
msminhas93 wants to merge 2 commits into
Open
Conversation
Author
|
Hi @yonigozlan! Could you please take a look. Thank you. |
yonigozlan
reviewed
Sep 8, 2025
yonigozlan
left a comment
Contributor
There was a problem hiding this comment.
Hi @msminhas93, thanks for contributing, a few things can be simplified!
Comment on lines
+31
to
+39
| def make_batched(videos) -> list[list]: | ||
| """Make videos batched for processing.""" | ||
| if isinstance(videos, (list, tuple)) and isinstance(videos[0], (list, tuple)): | ||
| return videos | ||
| elif isinstance(videos, (list, tuple)): | ||
| return [videos] | ||
| else: | ||
| return [[videos]] | ||
|
|
Contributor
There was a problem hiding this comment.
We have make_nested_list_of_images in image_utils for that
Comment on lines
+240
to
+273
| processed_videos = [] | ||
| for video in images: # images is a list of videos, each video is a list of frames | ||
| # Process each frame in the video | ||
| processed_frames = [] | ||
| for frame in video: | ||
| # Apply transformations to individual frame | ||
| if do_resize: | ||
| frame = self.resize(image=frame, size=size, interpolation=interpolation) | ||
|
|
||
| if do_center_crop: | ||
| frame = self.center_crop(frame, crop_size) | ||
|
|
||
| # Handle rescaling with offset parameter | ||
| if do_rescale: | ||
| frame = self.rescale(frame, rescale_factor, offset=offset) | ||
|
|
||
| # Handle normalization | ||
| if do_normalize: | ||
| frame = self.normalize(frame, image_mean, image_std) | ||
|
|
||
| processed_frames.append(frame) | ||
|
|
||
| # Stack frames for this video | ||
| if return_tensors: | ||
| video_tensor = torch.stack(processed_frames, dim=0) | ||
| processed_videos.append(video_tensor) | ||
| else: | ||
| processed_videos.append(processed_frames) | ||
|
|
||
| # Stack videos if returning tensors | ||
| if return_tensors: | ||
| processed_videos = torch.stack(processed_videos, dim=0) | ||
|
|
||
| return BatchFeature(data={"pixel_values": processed_videos}, tensor_type=return_tensors) |
Contributor
There was a problem hiding this comment.
You can process fully by batch still. just use the code from the parent class, and set is_nested=True in group_images_by_shape and reorder_images
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto, vivit |
Author
|
Thank you for the comments! I've updated my PR @yonigozlan |
Author
|
@yonigozlan If you could please look at the PR that'll be awesome Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR implements a fast PyTorch image processor for ViViT (
VivitImageProcessorFast) that extends the existingBaseImageProcessorFastclass. The new processor provides optimized image processing capabilities specifically designed for video understanding tasks using the ViViT model.Key Features
Before submitting
Who can review?
@yonigozlan