Buckets:

mishig's picture
|
download
raw
28.7 kB

Được cấp phép theo Giấy phép Apache, Phiên bản 2.0 (gọi là "Giấy phép");

bạn có thể không sử dụng tệp này ngoại trừ tuân thủ theo Giấy phép.

Bạn có thể nhận được một bản sao của Giấy phép tại

http://www.apache.org/licenses/LICENSE-2.0

Trừ khi được yêu cầu bởi luật pháp có hiệu lực hoặc được thỏa thuận bằng văn bản, phần mềm

được phân phối theo Giấy phép được phân phối trên cơ sở

KHÔNG CÓ BẢO HÀNH HOẶC ĐIỀU KIỆN DƯỚI BẤT KỲ HÌNH THỨC NÀO, dù được nêu rõ hay ngụ ý.

Xem Giấy phép để biết ngôn ngữ cụ thể điều chỉnh các quyền và

giới hạn theo Giấy phép. -->

Framepack

Gói ngữ cảnh khung đầu vào trong các mô hình dự đoán khung tiếp theo cho việc tạo video của Lvmin Zhang và Maneesh Agrawala.

Chúng tôi giới thiệu một cấu trúc mạng nơ-ron, FramePack, để huấn luyện các mô hình dự đoán khung hình tiếp theo (hoặc phần khung hình tiếp theo) cho việc tạo video. FramePack nén các khung hình đầu vào để làm cho độ dài ngữ cảnh của transformer là một số cố định bất kể độ dài của video. Kết quả là, chúng tôi có thể xử lý một số lượng lớn các khung hình bằng cách sử dụng khuếch tán video với nút cổ chai tính toán tương tự như khuếch tán ảnh. Điều này cũng làm cho kích thước lô video trong quá trình huấn luyện cao hơn đáng kể (kích thước lô trở nên tương đương với huấn luyện khuếch tán ảnh). Chúng tôi cũng đề xuất một phương pháp lấy mẫu chống trôi dạt, tạo ra các khung hình theo thứ tự thời gian đảo ngược với các điểm cuối được thiết lập sớm để tránh thiên kiến phơi bày (sai số tích lũy qua các lần lặp). Cuối cùng, chúng tôi chỉ ra rằng các mô hình khuếch tán video hiện có có thể được tinh chỉnh với FramePack, và chất lượng hình ảnh của chúng có thể được cải thiện vì việc dự đoán khung hình tiếp theo hỗ trợ các trình lập lịch khuếch tán cân bằng hơn với các bước thời gian dịch chuyển dòng ít cực đoan hơn.

Hãy chắc chắn xem qua hướng dẫn về Schedulers để tìm hiểu cách khám phá sự đánh đổi giữa tốc độ và chất lượng của scheduler, và xem phần tái sử dụng các thành phần giữa các pipeline để tìm hiểu cách nạp các thành phần giống nhau vào nhiều pipeline một cách hiệu quả.

Các model khả dụng

Tên mô hình Mô tả
  • lllyasviel/FramePackI2V_HY | Được huấn luyện với chiến lược "inverted anti-drifting" như mô tả trong bài báo. Suy luận yêu cầu đặt sampling_type="inverted_anti_drifting" khi chạy pipeline. |
  • lllyasviel/FramePack_F1_I2V_HY_20250503 | Được huấn luyện với một chiến lược chống trôi mới, nhưng suy luận được thực hiện theo chiến lược "vanilla" như đã mô tả trong bài báo. Suy luận yêu cầu đặt sampling_type="vanilla" khi chạy pipeline. |

Cách sử dụng

Xem tài liệu pipeline để biết các ví dụ sử dụng cơ bản. Phần tiếp theo chứa các ví dụ về offloading, các phương pháp lấy mẫu khác nhau, lượng tử hóa và nhiều hơn nữa.

Khung đầu và khung cuối thành video

Ví dụ sau cho thấy cách sử dụng Framepack với các điều khiển ảnh bắt đầu và kết thúc, sử dụng mô hình lấy mẫu chống trôi ngược.

import torch
from diffusers import HunyuanVideoFramepackPipeline, HunyuanVideoFramepackTransformer3DModel
from diffusers.utils import export_to_video, load_image
from transformers import SiglipImageProcessor, SiglipVisionModel

transformer = HunyuanVideoFramepackTransformer3DModel.from_pretrained(
    "lllyasviel/FramePackI2V_HY", dtype=torch.bfloat16
)
feature_extractor = SiglipImageProcessor.from_pretrained(
    "lllyasviel/flux_redux_bfl", subfolder="feature_extractor"
)
image_encoder = SiglipVisionModel.from_pretrained(
    "lllyasviel/flux_redux_bfl", subfolder="image_encoder", dtype=torch.float16
)
pipe = HunyuanVideoFramepackPipeline.from_pretrained(
    "hunyuanvideo-community/HunyuanVideo",
    transformer=transformer,
    feature_extractor=feature_extractor,
    image_encoder=image_encoder,
    dtype=torch.float16,
)

# Enable memory optimizations
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()

prompt = "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective."
first_image = load_image(
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png"
)
last_image = load_image(
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png"
)
output = pipe(
    image=first_image,
    last_image=last_image,
    prompt=prompt,
    height=512,
    width=512,
    num_frames=91,
    num_inference_steps=30,
    guidance_scale=9.0,
    generator=torch.Generator().manual_seed(0),
    sampling_type="inverted_anti_drifting",
).frames[0]
export_to_video(output, "output.mp4", fps=30)

Mẫu hóa thông thường

Ví dụ sau cho thấy cách sử dụng Framepack với mô hình F1 được huấn luyện bằng phương pháp lấy mẫu thuần túy nhưng áp dụng cách tiếp cận điều chỉnh mới để chống trôi.

import torch
from diffusers import HunyuanVideoFramepackPipeline, HunyuanVideoFramepackTransformer3DModel
from diffusers.utils import export_to_video, load_image
from transformers import SiglipImageProcessor, SiglipVisionModel

transformer = HunyuanVideoFramepackTransformer3DModel.from_pretrained(
    "lllyasviel/FramePack_F1_I2V_HY_20250503", dtype=torch.bfloat16
)
feature_extractor = SiglipImageProcessor.from_pretrained(
    "lllyasviel/flux_redux_bfl", subfolder="feature_extractor"
)
image_encoder = SiglipVisionModel.from_pretrained(
    "lllyasviel/flux_redux_bfl", subfolder="image_encoder", dtype=torch.float16
)
pipe = HunyuanVideoFramepackPipeline.from_pretrained(
    "hunyuanvideo-community/HunyuanVideo",
    transformer=transformer,
    feature_extractor=feature_extractor,
    image_encoder=image_encoder,
    dtype=torch.float16,
)

# Enable memory optimizations
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()

image = load_image(
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/penguin.png"
)
output = pipe(
    image=image,
    prompt="A penguin dancing in the snow",
    height=832,
    width=480,
    num_frames=91,
    num_inference_steps=30,
    guidance_scale=9.0,
    generator=torch.Generator().manual_seed(0),
    sampling_type="vanilla",
).frames[0]
export_to_video(output, "output.mp4", fps=30)

Tải xuống nhóm

Group offloading (apply_group_offloading()) cung cấp các tối ưu hóa bộ nhớ mạnh mẽ để offload các phần bên trong của bất kỳ model nào sang CPU, có thể không gây thêm chi phí nào cho thời gian generation. Nếu bạn có VRAM rất thấp, cách tiếp cận này có thể phù hợp với bạn tùy thuộc vào lượng RAM CPU khả dụng.

import torch
from diffusers import HunyuanVideoFramepackPipeline, HunyuanVideoFramepackTransformer3DModel
from diffusers.hooks import apply_group_offloading
from diffusers.utils import export_to_video, load_image
from transformers import SiglipImageProcessor, SiglipVisionModel

transformer = HunyuanVideoFramepackTransformer3DModel.from_pretrained(
    "lllyasviel/FramePack_F1_I2V_HY_20250503", dtype=torch.bfloat16
)
feature_extractor = SiglipImageProcessor.from_pretrained(
    "lllyasviel/flux_redux_bfl", subfolder="feature_extractor"
)
image_encoder = SiglipVisionModel.from_pretrained(
    "lllyasviel/flux_redux_bfl", subfolder="image_encoder", dtype=torch.float16
)
pipe = HunyuanVideoFramepackPipeline.from_pretrained(
    "hunyuanvideo-community/HunyuanVideo",
    transformer=transformer,
    feature_extractor=feature_extractor,
    image_encoder=image_encoder,
    dtype=torch.float16,
)

# Enable group offloading
onload_device = torch.device("cuda")
offload_device = torch.device("cpu")
list(map(
    lambda x: apply_group_offloading(x, onload_device, offload_device, offload_type="leaf_level", use_stream=True, low_cpu_mem_usage=True),
    [pipe.text_encoder, pipe.text_encoder_2, pipe.transformer]
))
pipe.image_encoder.to(onload_device)
pipe.vae.to(onload_device)
pipe.vae.enable_tiling()

image = load_image(
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/penguin.png"
)
output = pipe(
    image=image,
    prompt="A penguin dancing in the snow",
    height=832,
    width=480,
    num_frames=91,
    num_inference_steps=30,
    guidance_scale=9.0,
    generator=torch.Generator().manual_seed(0),
    sampling_type="vanilla",
).frames[0]
print(f"Max memory: {torch.cuda.max_memory_allocated() / 1024**3:.3f} GB")
export_to_video(output, "output.mp4", fps=30)

HunyuanVideoFramepackPipeline[[diffusers.HunyuanVideoFramepackPipeline]]

diffusers.HunyuanVideoFramepackPipeline[[diffusers.HunyuanVideoFramepackPipeline]]

diffusers.HunyuanVideoFramepackPipeline(text_encoder: LlamaModel, tokenizer: LlamaTokenizer, transformer: HunyuanVideoFramepackTransformer3DModel, vae: AutoencoderKLHunyuanVideo, scheduler: FlowMatchEulerDiscreteScheduler, text_encoder_2: CLIPTextModel, tokenizer_2: CLIPTokenizer, image_encoder: SiglipVisionModel, feature_extractor: SiglipImageProcessorPil)

Nguồn

Tham số:

text_encoder (LlamaModel) : Llava Llama3-8B.

tokenizer (LlamaTokenizer) : Tokenizer từ Llava Llama3-8B.

transformer (HunyuanVideoTransformer3DModel) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa.

scheduler (FlowMatchEulerDiscreteScheduler) : Một trình lập lịch được sử dụng kết hợp với transformer để khử nhiễu các latent ảnh đã mã hóa.

vae (AutoencoderKLHunyuanVideo) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn.

text_encoder_2 (CLIPTextModel) : CLIP, cụ thể là biến thể clip-vit-large-patch14.

tokenizer_2 (CLIPTokenizer) : Tokenizer của lớp CLIPTokenizer.

Pipeline để tạo video từ văn bản sử dụng HunyuanVideo.

Mô hình này kế thừa từ DiffusionPipeline. Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.).

call[[diffusers.HunyuanVideoFramepackPipeline.call]]

__call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]], last_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, prompt: str | list[str] = None, prompt_2: str | list[str] = None, negative_prompt: str | list[str] = None, negative_prompt_2: str | list[str] = None, height: int = 720, width: int = 1280, num_frames: int = 129, latent_window_size: int = 9, num_inference_steps: int = 50, sigmas: list[float] = None, true_cfg_scale: float = 1.0, guidance_scale: float = 6.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, image_latents: typing.Optional[torch.Tensor] = None, last_image_latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, pooled_prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_attention_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_pooled_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], prompt_template: dict[str, typing.Any] = {'template': '<|start_header_id|>system<|end_header_id|>\n\nDescribe the video by detailing the following aspects: 1. The main content and theme of the video.2. The color, shape, size, texture, quantity, text, and spatial relationships of the objects.3. Actions, events, behaviors temporal relationships, physical movement changes of the objects.4. background environment, light, style and atmosphere.5. camera angles, movements, and transitions used in the video:<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{}<|eot_id|>', 'crop_start': 95}, max_sequence_length: int = 256, sampling_type: FramepackSamplingType = <FramepackSamplingType.INVERTED_ANTI_DRIFTING: 'inverted_anti_drifting'>)

Nguồn

Tham số:

image (PIL.Image.Image hoặc np.ndarray hoặc torch.Tensor) : Ảnh được sử dụng làm điểm khởi đầu cho việc tạo video.

last_image (PIL.Image.Image hoặc np.ndarray hoặc torch.Tensor, tuỳ chọn) : Ảnh cuối cùng tuỳ chọn được sử dụng làm điểm kết thúc cho việc tạo video. Điều này hữu ích để tạo chuyển tiếp giữa hai ảnh.

prompt (str hoặc list[str], tùy chọn) : Prompt hoặc các prompt để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền prompt_embeds thay thế.

prompt_2 (str hoặc list[str], tùy chọn) : Prompt hoặc các prompt cần được gửi đến tokenizer_2 và text_encoder_2. Nếu không được định nghĩa, prompt sẽ được sử dụng thay thế.

negative_prompt (str hoặc list[str], tùy chọn) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền negative_prompt_embeds thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu true_cfg_scale không lớn hơn 1).

negative_prompt_2 (str hoặc list[str], tùy chọn) : Prompt hoặc các prompt không được dùng để hướng dẫn tạo ảnh, sẽ được gửi đến tokenizer_2 và text_encoder_2. Nếu không được định nghĩa, negative_prompt sẽ được sử dụng trong tất cả các text-encoder.

height (int, mặc định là 720) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel.

width (int, mặc định là 1280) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel.

num_frames (int, mặc định là 129) : Số khung hình trong video được tạo ra.

latent_window_size (int, mặc định là 9) : Số lượng khung hình tiềm ẩn (latent frames) được tạo ra trong mỗi cửa sổ lấy mẫu Framepack.

num_inference_steps (int, mặc định là 50) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến hình ảnh có chất lượng cao hơn, đổi lại là suy luận chậm hơn.

sigmas (list[float], optional) : Các sigma tùy chỉnh để sử dụng cho quá trình khử nhiễu với các trình lập lịch hỗ trợ tham số sigmas trong phương thức set_timesteps của chúng. Nếu không được định nghĩa, hành vi mặc định khi num_inference_steps được truyền vào sẽ được sử dụng.

true_cfg_scale (float, optional, mặc định là 1.0) : Khi > 1.0 và có negative_prompt được cung cấp, kích hoạt true classifier-free guidance.

guidance_scale (float, mặc định là 6.0) : Thang độ dẫn hướng như được định nghĩa trong Classifier-Free Diffusion Guidance. guidance_scale được định nghĩa là w của phương trình 2. trong Imagen Paper. Thang độ dẫn hướng được kích hoạt bằng cách đặt guidance_scale > 1. Thang độ dẫn hướng cao hơn khuyến khích tạo ra các hình ảnh gắn kết chặt chẽ với prompt văn bản, thường phải đánh đổi bằng chất lượng hình ảnh thấp hơn. Lưu ý rằng mô hình HunyuanVideo duy nhất có sẵn là mô hình đã được chưng cất CFG, điều này có nghĩa là việc dẫn hướng truyền thống giữa latent không điều kiện và latent có điều kiện không được áp dụng.

num_videos_per_prompt (int, tuỳ chọn, mặc định là 1) : Số lượng hình ảnh cần tạo cho mỗi prompt.

generator (torch.Generator hoặc list[torch.Generator], tùy chọn) : Một torch.Generator để đảm bảo quá trình sinh là tất định.

image_latents (torch.Tensor, tùy chọn) : Các latents của ảnh đã được mã hóa trước. Nếu không được cung cấp, ảnh sẽ được mã hóa bằng VAE.

last_image_latents (torch.Tensor, tùy chọn) : Latents của ảnh cuối cùng đã được mã hóa trước. Nếu không được cung cấp, ảnh cuối cùng sẽ được mã hóa bằng VAE.

prompt_embeds (torch.Tensor, tùy chọn) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản (trọng số prompt). Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào prompt.

pooled_prompt_embeds (torch.FloatTensor, tùy chọn) : Các embedding văn bản đã được pool sẵn. Có thể dùng để dễ dàng điều chỉnh các đầu vào văn bản, vd. trọng số prompt. Nếu không được cung cấp, các embedding văn bản đã pool sẽ được tạo ra từ đối số đầu vào prompt.

negative_prompt_embeds (torch.FloatTensor, tùy chọn) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, vd. trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào negative_prompt.

negative_pooled_prompt_embeds (torch.FloatTensor, tùy chọn) : Các embedding văn bản pooled âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, vd. trọng số prompt. Nếu không được cung cấp, pooled negative_prompt_embeds sẽ được tạo từ đối số đầu vào negative_prompt.

prompt_attention_mask (torch.Tensor, tùy chọn) : Mặt nạ chú ý cho prompt_embeds. Bắt buộc khi prompt_embeds được truyền trực tiếp.

negative_prompt_attention_mask (torch.Tensor, tùy chọn) : Mặt nạ chú ý cho negative_prompt_embeds. Bắt buộc khi negative_prompt_embeds được truyền trực tiếp.

output_type (str, tùy chọn, mặc định là "pil") : Định dạng đầu ra của hình ảnh được tạo ra. Chọn giữa PIL.Image hoặc np.array.

return_dict (bool, tùy chọn, mặc định là True) : Có nên trả về một HunyuanVideoFramepackPipelineOutput thay vì một tuple thông thường hay không.

attention_kwargs (dict, tùy chọn) : Một từ điển kwargs mà nếu được chỉ định sẽ được truyền đến AttentionProcessor như đã định nghĩa dưới self.processor trong diffusers.models.attention_processor.

prompt_template (dict, tùy chọn) : Mẫu được sử dụng để định dạng prompt trước khi mã hóa. Mặc định là mẫu mặc định của model.

max_sequence_length (int, tuỳ chọn, mặc định là 256) : Độ dài tối đa của chuỗi được sử dụng cho trình mã hóa prompt.

sampling_type (FramepackSamplingType, tùy chọn) : Chiến lược lấy mẫu Framepack được sử dụng khi lặp qua các cửa sổ latent.

callback_on_step_end (Callable, PipelineCallback, MultiPipelineCallbacks, optional) : Một hàm hoặc một lớp con của PipelineCallback hoặc MultiPipelineCallbacks được gọi vào cuối mỗi bước khử nhiễu trong quá trình suy luận, với các đối số sau: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs sẽ bao gồm một danh sách tất cả các tensor như được chỉ định bởi callback_on_step_end_tensor_inputs.

callback_on_step_end_tensor_inputs (list, optional) : Danh sách các đầu vào tensor cho hàm callback_on_step_end. Các tensor được chỉ định trong danh sách sẽ được truyền dưới dạng tham số callback_kwargs. Bạn chỉ có thể bao gồm các biến được liệt kê trong thuộc tính ._callback_tensor_inputs của lớp pipeline của bạn.

Trả về: ~HunyuanVideoFramepackPipelineOutput hoặc tuple

Nếu return_dict là True, HunyuanVideoFramepackPipelineOutput sẽ được trả về, ngược lại một tuple sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo và phần tử thứ hai là một danh sách các bool cho biết hình ảnh tương ứng có chứa nội dung "không an toàn" (nsfw) hay không.

Hàm gọi call của pipeline để tạo nội dung.

Ví dụ:

Hình ảnh sang Video
>>> import torch
>>> from diffusers import HunyuanVideoFramepackPipeline, HunyuanVideoFramepackTransformer3DModel
>>> from diffusers.utils import export_to_video, load_image
>>> from transformers import SiglipImageProcessor, SiglipVisionModel

>>> transformer = HunyuanVideoFramepackTransformer3DModel.from_pretrained(
...     "lllyasviel/FramePackI2V_HY", torch_dtype=torch.bfloat16
... )
>>> feature_extractor = SiglipImageProcessor.from_pretrained(
...     "lllyasviel/flux_redux_bfl", subfolder="feature_extractor"
... )
>>> image_encoder = SiglipVisionModel.from_pretrained(
...     "lllyasviel/flux_redux_bfl", subfolder="image_encoder", torch_dtype=torch.float16
... )
>>> pipe = HunyuanVideoFramepackPipeline.from_pretrained(
...     "hunyuanvideo-community/HunyuanVideo",
...     transformer=transformer,
...     feature_extractor=feature_extractor,
...     image_encoder=image_encoder,
...     torch_dtype=torch.float16,
... )
>>> pipe.vae.enable_tiling()
>>> pipe.to("cuda")

>>> image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/penguin.png"
... )
>>> output = pipe(
...     image=image,
...     prompt="A penguin dancing in the snow",
...     height=832,
...     width=480,
...     num_frames=91,
...     num_inference_steps=30,
...     guidance_scale=9.0,
...     generator=torch.Generator().manual_seed(0),
...     sampling_type="inverted_anti_drifting",
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=30)
Hình ảnh đầu và cuối thành video
>>> import torch
>>> from diffusers import HunyuanVideoFramepackPipeline, HunyuanVideoFramepackTransformer3DModel
>>> from diffusers.utils import export_to_video, load_image
>>> from transformers import SiglipImageProcessor, SiglipVisionModel

>>> transformer = HunyuanVideoFramepackTransformer3DModel.from_pretrained(
...     "lllyasviel/FramePackI2V_HY", torch_dtype=torch.bfloat16
... )
>>> feature_extractor = SiglipImageProcessor.from_pretrained(
...     "lllyasviel/flux_redux_bfl", subfolder="feature_extractor"
... )
>>> image_encoder = SiglipVisionModel.from_pretrained(
...     "lllyasviel/flux_redux_bfl", subfolder="image_encoder", torch_dtype=torch.float16
... )
>>> pipe = HunyuanVideoFramepackPipeline.from_pretrained(
...     "hunyuanvideo-community/HunyuanVideo",
...     transformer=transformer,
...     feature_extractor=feature_extractor,
...     image_encoder=image_encoder,
...     torch_dtype=torch.float16,
... )
>>> pipe.to("cuda")

>>> prompt = "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective."
>>> first_image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png"
... )
>>> last_image = load_image(
...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png"
... )
>>> output = pipe(
...     image=first_image,
...     last_image=last_image,
...     prompt=prompt,
...     height=512,
...     width=512,
...     num_frames=91,
...     num_inference_steps=30,
...     guidance_scale=9.0,
...     generator=torch.Generator().manual_seed(0),
...     sampling_type="inverted_anti_drifting",
... ).frames[0]
>>> export_to_video(output, "output.mp4", fps=30)

HunyuanVideoPipelineOutput[[diffusers.pipelines.hunyuan_video.pipeline_output.HunyuanVideoPipelineOutput]]

diffusers.pipelines.hunyuan_video.pipeline_output.HunyuanVideoPipelineOutput[[diffusers.pipelines.hunyuan_video.pipeline_output.HunyuanVideoPipelineOutput]]

diffusers.pipelines.hunyuan_video.pipeline_output.HunyuanVideoPipelineOutput(frames: Tensor)

Nguồn

Tham số:

frames (torch.Tensor, np.ndarray, hoặc list[list[PIL.Image.Image]]) : danh sách các đầu ra video - Có thể là một danh sách lồng nhau có độ dài batch_size, trong đó mỗi danh sách con chứa các chuỗi hình ảnh PIL đã khử nhiễu có độ dài num_frames. Nó cũng có thể là một mảng NumPy hoặc tensor Torch có hình dạng (batch_size, num_frames, channels, height, width).

Lớp đầu ra cho các pipeline của HunyuanVideo.

Xet Storage Details

Size:
28.7 kB
·
Xet hash:
54925a30ffa398f0568a8314a1289b5748fe55f4155515f7fd6bf02877d3eb79

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.