Buckets:
| # | |
| # Đượ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. --> | |
| # ChronoEdit | |
| [ChronoEdit: Hướng tới suy luận thời gian cho chỉnh sửa ảnh và mô phỏng thế giới](https://huggingface.co/papers/2510.04290) từ NVIDIA và Đại học Toronto, bởi Jay Zhangjie Wu, Xuanchi Ren, Tianchang Shen, Tianshi Cao, Kai He, Yifan Lu, Ruiyuan Gao, Enze Xie, Shiyi Lan, Jose M. Alvarez, Jun Gao, Sanja Fidler, Zian Wang, Huan Ling. | |
| > **Tóm tắt:** ChronoEdit định hình lại việc chỉnh sửa ảnh như một tác vụ tạo video, sử dụng ảnh đầu vào và ảnh đã chỉnh sửa làm khung đầu/cuối để tận dụng các mô hình video được huấn luyện trước với tính nhất quán theo thời gian. Một giai đoạn suy luận theo thời gian đưa vào các token suy luận để đảm bảo các chỉnh sửa hợp lý về mặt vật lý và trực quan hóa quỹ đạo chỉnh sửa. | |
| *Những tiến bộ gần đây trong các mô hình sinh lớn đã nâng cao đáng kể cả việc chỉnh sửa hình ảnh lẫn sinh hình ảnh theo ngữ cảnh, tuy nhiên vẫn còn một khoảng trống quan trọng trong việc đảm bảo tính nhất quán vật lý, nơi các đối tượng được chỉnh sửa phải duy trì sự nhất quán. Khả năng này đặc biệt quan trọng đối với các tác vụ liên quan đến mô phỏng thế giới. Trong bài báo này, chúng tôi giới thiệu ChronoEdit, một khung làm việc tái định nghĩa việc chỉnh sửa hình ảnh như một bài toán sinh video. Trước tiên, ChronoEdit coi hình ảnh đầu vào và hình ảnh đã chỉnh sửa là khung đầu tiên và cuối cùng của một video, cho phép khai thác các mô hình sinh video được huấn luyện trước có quy mô lớn, vốn nắm bắt không chỉ ngoại hình của đối tượng mà còn cả vật lý ẩn của chuyển động và tương tác thông qua tính nhất quán thời gian đã học. Thứ hai, ChronoEdit giới thiệu một giai đoạn suy luận thời gian thực hiện chỉnh sửa một cách tường minh tại thời điểm suy luận. Trong cài đặt này, khung đích được khử nhiễu đồng thời với các token suy luận để hình dung một quỹ đạo chỉnh sửa hợp lý, từ đó ràng buộc không gian nghiệm vào các phép biến đổi khả thi về mặt vật lý. Các token suy luận sau đó sẽ bị loại bỏ sau một vài bước để tránh chi phí tính toán cao khi render toàn bộ video. Để xác thực ChronoEdit, chúng tôi giới thiệu PBench-Edit, một bộ chuẩn mới gồm các cặp hình ảnh - prompt cho các ngữ cảnh đòi hỏi tính nhất quán vật lý, và chứng minh rằng ChronoEdit vượt trội so với các baseline tiên tiến nhất về cả độ trung thực thị giác lẫn tính hợp lý vật lý. Trang dự án cho mã nguồn và mô hình: [this https URL](https://research.nvidia.com/labs/toronto-ai/chronoedit).* | |
| Pipeline ChronoEdit được phát triển bởi ChronoEdit Team. Mã nguồn gốc có sẵn trên [GitHub](https://github.com/nv-tlabs/ChronoEdit), và các mô hình được huấn luyện trước có thể tìm thấy trong bộ sưu tập [nvidia/ChronoEdit](https://huggingface.co/collections/nvidia/chronoedit) trên Hugging Face. | |
| Các Mô hình/LoRA có sẵn: | |
| - [nvidia/ChronoEdit-14B-Diffusers](https://huggingface.co/nvidia/ChronoEdit-14B-Diffusers) | |
| - [nvidia/ChronoEdit-14B-Diffusers-Upscaler-Lora](https://huggingface.co/nvidia/ChronoEdit-14B-Diffusers-Upscaler-Lora) | |
| - [nvidia/ChronoEdit-14B-Diffusers-Paint-Brush-Lora](https://huggingface.co/nvidia/ChronoEdit-14B-Diffusers-Paint-Brush-Lora) | |
| ### Chỉnh sửa hình ảnh | |
| ```py | |
| import torch | |
| import numpy as np | |
| from diffusers import AutoencoderKLWan, ChronoEditTransformer3DModel, ChronoEditPipeline | |
| from diffusers.utils import export_to_video, load_image | |
| from transformers import CLIPVisionModel | |
| from PIL import Image | |
| model_id = "nvidia/ChronoEdit-14B-Diffusers" | |
| image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encoder", dtype=torch.float32) | |
| vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32) | |
| transformer = ChronoEditTransformer3DModel.from_pretrained(model_id, subfolder="transformer", dtype=torch.bfloat16) | |
| pipe = ChronoEditPipeline.from_pretrained(model_id, image_encoder=image_encoder, transformer=transformer, vae=vae, dtype=torch.bfloat16) | |
| pipe.to("cuda") # or "mps", "xpu", "cpu" | |
| image = load_image( | |
| "https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png" | |
| ) | |
| max_area = 720 * 1280 | |
| aspect_ratio = image.height / image.width | |
| mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1] | |
| height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value | |
| width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value | |
| print("width", width, "height", height) | |
| image = image.resize((width, height)) | |
| prompt = ( | |
| "The user wants to transform the image by adding a small, cute mouse sitting inside the floral teacup, enjoying a spa bath. The mouse should appear relaxed and cheerful, with a tiny white bath towel draped over its head like a turban. It should be positioned comfortably in the cup’s liquid, with gentle steam rising around it to blend with the cozy atmosphere. " | |
| "The mouse’s pose should be natural—perhaps sitting upright with paws resting lightly on the rim or submerged in the tea. The teacup’s floral design, gold trim, and warm lighting must remain unchanged to preserve the original aesthetic. The steam should softly swirl around the mouse, enhancing the spa-like, whimsical mood." | |
| ) | |
| output = pipe( | |
| image=image, | |
| prompt=prompt, | |
| height=height, | |
| width=width, | |
| num_frames=5, | |
| num_inference_steps=50, | |
| guidance_scale=5.0, | |
| enable_temporal_reasoning=False, | |
| num_temporal_reasoning_steps=0, | |
| ).frames[0] | |
| Image.fromarray((output[-1] * 255).clip(0, 255).astype("uint8")).save("output.png") | |
| ``` | |
| Tùy chọn, bật **suy luận thời gian** để cải thiện tính nhất quán vật lý: | |
| ```py | |
| output = pipe( | |
| image=image, | |
| prompt=prompt, | |
| height=height, | |
| width=width, | |
| num_frames=29, | |
| num_inference_steps=50, | |
| guidance_scale=5.0, | |
| enable_temporal_reasoning=True, | |
| num_temporal_reasoning_steps=50, | |
| ).frames[0] | |
| export_to_video(output, "output.mp4", fps=16) | |
| Image.fromarray((output[-1] * 255).clip(0, 255).astype("uint8")).save("output.png") | |
| ``` | |
| ### Suy luận với Lora Chưng cất 8 Bước | |
| ```py | |
| import torch | |
| import numpy as np | |
| from diffusers import AutoencoderKLWan, ChronoEditTransformer3DModel, ChronoEditPipeline | |
| from diffusers.schedulers import UniPCMultistepScheduler | |
| from diffusers.utils import export_to_video, load_image | |
| from transformers import CLIPVisionModel | |
| from PIL import Image | |
| model_id = "nvidia/ChronoEdit-14B-Diffusers" | |
| image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encoder", dtype=torch.float32) | |
| vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32) | |
| transformer = ChronoEditTransformer3DModel.from_pretrained(model_id, subfolder="transformer", dtype=torch.bfloat16) | |
| pipe = ChronoEditPipeline.from_pretrained(model_id, image_encoder=image_encoder, transformer=transformer, vae=vae, dtype=torch.bfloat16) | |
| pipe.load_lora_weights("nvidia/ChronoEdit-14B-Diffusers", weight_name="lora/chronoedit_distill_lora.safetensors", adapter_name="distill") | |
| pipe.fuse_lora(adapter_names=["distill"], lora_scale=1.0) | |
| pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=2.0) | |
| pipe.to("cuda") # or "mps", "xpu", "cpu" | |
| image = load_image( | |
| "https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png" | |
| ) | |
| max_area = 720 * 1280 | |
| aspect_ratio = image.height / image.width | |
| mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1] | |
| height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value | |
| width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value | |
| print("width", width, "height", height) | |
| image = image.resize((width, height)) | |
| prompt = ( | |
| "The user wants to transform the image by adding a small, cute mouse sitting inside the floral teacup, enjoying a spa bath. The mouse should appear relaxed and cheerful, with a tiny white bath towel draped over its head like a turban. It should be positioned comfortably in the cup’s liquid, with gentle steam rising around it to blend with the cozy atmosphere. " | |
| "The mouse’s pose should be natural—perhaps sitting upright with paws resting lightly on the rim or submerged in the tea. The teacup’s floral design, gold trim, and warm lighting must remain unchanged to preserve the original aesthetic. The steam should softly swirl around the mouse, enhancing the spa-like, whimsical mood." | |
| ) | |
| output = pipe( | |
| image=image, | |
| prompt=prompt, | |
| height=height, | |
| width=width, | |
| num_frames=5, | |
| num_inference_steps=8, | |
| guidance_scale=1.0, | |
| enable_temporal_reasoning=False, | |
| num_temporal_reasoning_steps=0, | |
| ).frames[0] | |
| export_to_video(output, "output.mp4", fps=16) | |
| Image.fromarray((output[-1] * 255).clip(0, 255).astype("uint8")).save("output.png") | |
| ``` | |
| ### Suy luận với nhiều LoRA | |
| ```py | |
| import torch | |
| import numpy as np | |
| from diffusers import AutoencoderKLWan, ChronoEditTransformer3DModel, ChronoEditPipeline | |
| from diffusers.schedulers import UniPCMultistepScheduler | |
| from diffusers.utils import export_to_video, load_image | |
| from transformers import CLIPVisionModel | |
| from PIL import Image | |
| model_id = "nvidia/ChronoEdit-14B-Diffusers" | |
| image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encoder", dtype=torch.float32) | |
| vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32) | |
| transformer = ChronoEditTransformer3DModel.from_pretrained(model_id, subfolder="transformer", dtype=torch.bfloat16) | |
| pipe = ChronoEditPipeline.from_pretrained(model_id, image_encoder=image_encoder, transformer=transformer, vae=vae, dtype=torch.bfloat16) | |
| pipe.load_lora_weights("nvidia/ChronoEdit-14B-Diffusers-Paint-Brush-Lora", weight_name="paintbrush_lora_diffusers.safetensors", adapter_name="paintbrush") | |
| pipe.load_lora_weights("nvidia/ChronoEdit-14B-Diffusers", weight_name="lora/chronoedit_distill_lora.safetensors", adapter_name="distill") | |
| pipe.fuse_lora(adapter_names=["paintbrush", "distill"], lora_scale=1.0) | |
| pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=2.0) | |
| pipe.to("cuda") # or "mps", "xpu", "cpu" | |
| image = load_image( | |
| "https://raw.githubusercontent.com/nv-tlabs/ChronoEdit/refs/heads/main/assets/images/input_paintbrush.png" | |
| ) | |
| max_area = 720 * 1280 | |
| aspect_ratio = image.height / image.width | |
| mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1] | |
| height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value | |
| width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value | |
| print("width", width, "height", height) | |
| image = image.resize((width, height)) | |
| prompt = ( | |
| "Turn the pencil sketch in the image into an actual object that is consistent with the image’s content. The user wants to change the sketch to a crown and a hat." | |
| ) | |
| output = pipe( | |
| image=image, | |
| prompt=prompt, | |
| height=height, | |
| width=width, | |
| num_frames=5, | |
| num_inference_steps=8, | |
| guidance_scale=1.0, | |
| enable_temporal_reasoning=False, | |
| num_temporal_reasoning_steps=0, | |
| ).frames[0] | |
| export_to_video(output, "output.mp4", fps=16) | |
| Image.fromarray((output[-1] * 255).clip(0, 255).astype("uint8")).save("output_1.png") | |
| ``` | |
| ## ChronoEditPipeline[[diffusers.ChronoEditPipeline]] | |
| #### diffusers.ChronoEditPipeline[[diffusers.ChronoEditPipeline]] | |
| ```python | |
| diffusers.ChronoEditPipeline(tokenizer: AutoTokenizer, text_encoder: UMT5EncoderModel, image_encoder: CLIPVisionModel, image_processor: CLIPImageProcessorPil, transformer: ChronoEditTransformer3DModel, vae: AutoencoderKLWan, scheduler: FlowMatchEulerDiscreteScheduler) | |
| ``` | |
| [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/chronoedit/pipeline_chronoedit.py#L128) | |
| **Tham số:** | |
| tokenizer (`T5Tokenizer`) : Tokenizer từ [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5Tokenizer), cụ thể là biến thể [google/umt5-xxl](https://huggingface.co/google/umt5-xxl). | |
| text_encoder (`T5EncoderModel`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel), cụ thể là biến thể [google/umt5-xxl](https://huggingface.co/google/umt5-xxl). | |
| image_encoder (`CLIPVisionModel`) : [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPVisionModel), cụ thể là biến thể [clip-vit-huge-patch14](https://github.com/mlfoundations/open_clip/blob/main/docs/PRETRAINED.md#vit-h14-xlm-roberta-large). | |
| transformer ([WanTransformer3DModel](/docs/diffusers/main/vi/api/models/wan_transformer_3d#diffusers.WanTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents đầu vào. | |
| scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/vi/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : 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 ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : 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. | |
| Pipeline để tạo video từ hình ảnh sử dụng Wan. | |
| Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.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.ChronoEditPipeline.__call__]] | |
| ```python | |
| __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]], prompt: str | list[str] = None, negative_prompt: str | list[str] = None, height: int = 480, width: int = 832, num_frames: int = 81, num_inference_steps: int = 50, guidance_scale: float = 5.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, image_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512, enable_temporal_reasoning: bool = False, num_temporal_reasoning_steps: int = 0) | |
| ``` | |
| [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/chronoedit/pipeline_chronoedit.py#L470) | |
| **Tham số:** | |
| image (`PipelineImageInput`) : Ảnh đầu vào để điều kiện cho quá trình tạo. Phải là một ảnh, một danh sách các ảnh hoặc một `torch.Tensor`. | |
| 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ế. | |
| 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 `guidance_scale` nhỏ hơn `1`). | |
| height (`int`, mặc định là `480`) : Chiều cao của video được tạo ra. | |
| width (`int`, mặc định là `832`) : Độ rộng của video được tạo ra. | |
| num_frames (`int`, mặc định là `81`) : Số khung hình trong video được tạo ra. | |
| 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. | |
| guidance_scale (`float`, mặc định là `5.0`) : Thang độ dẫn hướng như được định nghĩa trong [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598). `guidance_scale` được định nghĩa là `w` của phương trình 2. trong [Imagen Paper](https://arxiv.org/pdf/2205.11487.pdf). 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. | |
| 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`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để đảm bảo quá trình sinh là tất định. | |
| latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu được tạo trước, lấy mẫu từ phân phối Gaussian, dùng làm đầu vào cho việc tạo ảnh. Có thể dùng để tinh chỉnh cùng một quá trình tạo với các prompt khác nhau. Nếu không được cung cấp, một tensor latents sẽ được tạo bằng cách lấy mẫu sử dụng `generator` ngẫu nhiên được cung cấp. | |
| 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`. | |
| negative_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 `negative_prompt`. | |
| image_embeds (`torch.Tensor`, *tùy chọn*) : Các embedding hình ảnh đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh đầu vào hình ảnh (trọng số). Nếu không được cung cấp, các embedding hình ảnh sẽ được tạo từ đối số đầu vào `image`. | |
| output_type (`str`, *tùy chọn*, mặc định là `"np"`) : Đị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 `ChronoEditPipelineOutput` 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](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py). | |
| 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`, *tùy chọn*) : 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. | |
| max_sequence_length (`int`, mặc định là `512`) : Độ dài tối đa của chuỗi cho text encoder. Nếu prompt dài hơn giá trị này, nó sẽ bị cắt bớt. Nếu prompt ngắn hơn, nó sẽ được đệm (padding) đến độ dài này. | |
| enable_temporal_reasoning (`bool`, *tùy chọn*, mặc định là `False`) : Có bật suy luận thời gian hay không. | |
| num_temporal_reasoning_steps (`int`, *tuỳ chọn*, mặc định là `0`) : Số bước để kích hoạt suy luận thời gian. | |
| **Trả về:** `~ChronoEditPipelineOutput` hoặc `tuple` | |
| Nếu `return_dict` là `True`, `ChronoEditPipelineOutput` 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 được tạo ra và phần tử thứ hai là một danh sách các `bool` cho biết hình ảnh được tạo ra tương ứng có chứa nội dung "không an toàn cho công việc" (nsfw) hay không. | |
| Hàm gọi call của pipeline để tạo nội dung. | |
| Ví dụ: | |
| ```python | |
| >>> import torch | |
| >>> import numpy as np | |
| >>> from diffusers import AutoencoderKLWan, ChronoEditTransformer3DModel, ChronoEditPipeline | |
| >>> from diffusers.utils import export_to_video, load_image | |
| >>> from transformers import CLIPVisionModel | |
| >>> # Available models: nvidia/ChronoEdit-14B-Diffusers | |
| >>> model_id = "nvidia/ChronoEdit-14B-Diffusers" | |
| >>> image_encoder = CLIPVisionModel.from_pretrained( | |
| ... model_id, subfolder="image_encoder", torch_dtype=torch.float32 | |
| ... ) | |
| >>> vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32) | |
| >>> transformer = ChronoEditTransformer3DModel.from_pretrained( | |
| ... model_id, subfolder="transformer", torch_dtype=torch.bfloat16 | |
| ... ) | |
| >>> pipe = ChronoEditPipeline.from_pretrained( | |
| ... model_id, vae=vae, image_encoder=image_encoder, transformer=transformer, torch_dtype=torch.bfloat16 | |
| ... ) | |
| >>> pipe.to("cuda") | |
| >>> image = load_image("https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png") | |
| >>> max_area = 720 * 1280 | |
| >>> aspect_ratio = image.height / image.width | |
| >>> mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1] | |
| >>> height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value | |
| >>> width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value | |
| >>> image = image.resize((width, height)) | |
| >>> prompt = ( | |
| ... "The user wants to transform the image by adding a small, cute mouse sitting inside the floral teacup, enjoying a spa bath. The mouse should appear relaxed and cheerful, with a tiny white bath towel draped over its head like a turban. It should be positioned comfortably in the cup’s liquid, with gentle steam rising around it to blend with the cozy atmosphere. " | |
| ... "The mouse’s pose should be natural—perhaps sitting upright with paws resting lightly on the rim or submerged in the tea. The teacup’s floral design, gold trim, and warm lighting must remain unchanged to preserve the original aesthetic. The steam should softly swirl around the mouse, enhancing the spa-like, whimsical mood." | |
| ... ) | |
| >>> output = pipe( | |
| ... image=image, | |
| ... prompt=prompt, | |
| ... height=height, | |
| ... width=width, | |
| ... num_frames=5, | |
| ... guidance_scale=5.0, | |
| ... enable_temporal_reasoning=False, | |
| ... num_temporal_reasoning_steps=0, | |
| ... ).frames[0] | |
| >>> export_to_video(output, "output.mp4", fps=16) | |
| ``` | |
| #### encode_prompt[[diffusers.ChronoEditPipeline.encode_prompt]] | |
| ```python | |
| encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) | |
| ``` | |
| [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/chronoedit/pipeline_chronoedit.py#L242) | |
| **Tham số:** | |
| prompt (`str` hoặc `list[str]`, *tùy chọn*) : prompt cần được mã hóa | |
| 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 `guidance_scale` nhỏ hơn `1`). | |
| do_classifier_free_guidance (`bool`, *tùy chọn*, mặc định là `True`) : Có sử dụng classifier free guidance hay không. | |
| num_videos_per_prompt (`int`, *optional*, mặc định là 1) : Số lượng video cần được tạo cho mỗi prompt. Thiết bị torch để đặt các embeddings kết quả lên | |
| 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, *vd.* 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`. | |
| negative_prompt_embeds (`torch.Tensor`, *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`. | |
| device : (`torch.device`, *tùy chọn*): thiết bị torch | |
| dtype : (`torch.dtype`, *tùy chọn*): torch dtype | |
| Mã hóa prompt thành các trạng thái ẩn của text encoder. | |
| ## ChronoEditPipelineOutput[[diffusers.pipelines.chronoedit.pipeline_output.ChronoEditPipelineOutput]] | |
| #### diffusers.pipelines.chronoedit.pipeline_output.ChronoEditPipelineOutput[[diffusers.pipelines.chronoedit.pipeline_output.ChronoEditPipelineOutput]] | |
| ```python | |
| diffusers.pipelines.chronoedit.pipeline_output.ChronoEditPipelineOutput(frames: Tensor) | |
| ``` | |
| [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/chronoedit/pipeline_output.py#L9) | |
| **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 ChronoEdit. | |
Xet Storage Details
- Size:
- 28.2 kB
- Xet hash:
- b2861b794344ebd280c134a365bd1addf92677650f6772871ee5558225f1777a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.