-
Notifications
You must be signed in to change notification settings - Fork 222
Open
Description
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import paddle
from ppdiffusers import AutoencoderKLWan, WanImageToVideoPipeline
from ppdiffusers.transformers import CLIPVisionModel
from ppdiffusers.utils import export_to_video_2, load_image
# Available models: Wan-AI/Wan2.1-I2V-14B-480P-Diffusers, Wan-AI/Wan2.1-I2V-14B-720P-Diffusers
model_id = "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers"
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", paddle_dtype=paddle.float32)
image_encoder = CLIPVisionModel.from_pretrained(
model_id, subfolder="image_encoder", paddle_dtype=paddle.float32, cache_dir="/root/.cache/paddlenlp/ppdiffusers/"
)
pipe = WanImageToVideoPipeline.from_pretrained(
model_id, vae=vae, image_encoder=image_encoder, paddle_dtype=paddle.bfloat16
)
image = load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg"
)
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 = (
"An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in "
"the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot."
)
negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
output = pipe(
image=image,
prompt=prompt,
negative_prompt=negative_prompt,
height=height,
width=width,
num_frames=81,
guidance_scale=5.0,
).frames[0]
export_to_video_2(output, "output.mp4", fps=16)`执行到
image_encoder = CLIPVisionModel.from_pretrained(
model_id, subfolder="image_encoder", paddle_dtype=paddle.float32, cache_dir="/root/.cache/paddlenlp/ppdiffusers/"
)
报错:
OSError: Can't load the model for 'Wan-AI/Wan2.1-I2V-14B-480P-Diffusers'. If you were trying to load it from 'BOS', make sure you don't have a local directory with the same name. Otherwise, make sure 'Wan-AI/Wan2.1-I2V-14B-480P-Diffusers' is the correct path to a directory containing one of the ['config.json', 'model_config.json']
Metadata
Metadata
Assignees
Labels
No labels