MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / VideoProcessor

Class VideoProcessor

diffusers/src/diffusers/video_processor.py:25–113  ·  view source on GitHub ↗

r"""Simple video processor.

Source from the content-addressed store, hash-verified

23
24
25class VideoProcessor(VaeImageProcessor):
26 r"""Simple video processor."""
27
28 def preprocess_video(self, video, height: Optional[int] = None, width: Optional[int] = None) -> torch.Tensor:
29 r"""
30 Preprocesses input video(s).
31
32 Args:
33 video (`List[PIL.Image]`, `List[List[PIL.Image]]`, `torch.Tensor`, `np.array`, `List[torch.Tensor]`, `List[np.array]`):
34 The input video. It can be one of the following:
35 * List of the PIL images.
36 * List of list of PIL images.
37 * 4D Torch tensors (expected shape for each tensor `(num_frames, num_channels, height, width)`).
38 * 4D NumPy arrays (expected shape for each array `(num_frames, height, width, num_channels)`).
39 * List of 4D Torch tensors (expected shape for each tensor `(num_frames, num_channels, height,
40 width)`).
41 * List of 4D NumPy arrays (expected shape for each array `(num_frames, height, width, num_channels)`).
42 * 5D NumPy arrays: expected shape for each array `(batch_size, num_frames, height, width,
43 num_channels)`.
44 * 5D Torch tensors: expected shape for each array `(batch_size, num_frames, num_channels, height,
45 width)`.
46 height (`int`, *optional*, defaults to `None`):
47 The height in preprocessed frames of the video. If `None`, will use the `get_default_height_width()` to
48 get default height.
49 width (`int`, *optional*`, defaults to `None`):
50 The width in preprocessed frames of the video. If `None`, will use get_default_height_width()` to get
51 the default width.
52 """
53 if isinstance(video, list) and isinstance(video[0], np.ndarray) and video[0].ndim == 5:
54 warnings.warn(
55 "Passing `video` as a list of 5d np.ndarray is deprecated."
56 "Please concatenate the list along the batch dimension and pass it as a single 5d np.ndarray",
57 FutureWarning,
58 )
59 video = np.concatenate(video, axis=0)
60 if isinstance(video, list) and isinstance(video[0], torch.Tensor) and video[0].ndim == 5:
61 warnings.warn(
62 "Passing `video` as a list of 5d torch.Tensor is deprecated."
63 "Please concatenate the list along the batch dimension and pass it as a single 5d torch.Tensor",
64 FutureWarning,
65 )
66 video = torch.cat(video, axis=0)
67
68 # ensure the input is a list of videos:
69 # - if it is a batch of videos (5d torch.Tensor or np.ndarray), it is converted to a list of videos (a list of 4d torch.Tensor or np.ndarray)
70 # - if it is is a single video, it is convereted to a list of one video.
71 if isinstance(video, (np.ndarray, torch.Tensor)) and video.ndim == 5:
72 video = list(video)
73 elif isinstance(video, list) and is_valid_image(video[0]) or is_valid_image_imagelist(video):
74 video = [video]
75 elif isinstance(video, list) and is_valid_image_imagelist(video[0]):
76 video = video
77 else:
78 raise ValueError(
79 "Input is in incorrect format. Currently, we only support numpy.ndarray, torch.Tensor, PIL.Image.Image"
80 )
81
82 video = torch.stack([self.preprocess(img, height=height, width=width) for img in video], dim=0)

Callers 15

__init__Method · 0.90
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 3