当前位置: 首页 > news >正文

生成视频 zeroscope_v2_576w 学习笔记

目录

生成视频代码:

维度报错:

解决方法,修改代码:


已开源:

视频生成模型 Zeroscope开源 免费无水印

 

视频生成模型 Zeroscope_v2_576w 开源 - 腾讯云开发者社区-腾讯云

生成视频代码:

import torch
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
from diffusers.utils import export_to_video
import os
# os.environ['HTTP_PROXY'] = 'http://127.0.0.1:7890'os.environ["HF_TOKEN"] = "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"
# os.environ['HTTPS_PROXY'] = 'https://127.0.0.1:7890'# pipe = DiffusionPipeline.from_pretrained(r"D:\360安全浏览器下载", torch_dtype=torch.float16)
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16,use_auth_token=os.environ["HF_TOKEN"])
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()prompt = "Darth Vader is surfing on waves"
video_frames = pipe(prompt, num_inference_steps=40, height=320, width=576, num_frames=24).frames
video_path = export_to_video(video_frames)
print(video_path)

维度报错:

Traceback (most recent call last):File "E:\project\jijia\aaa.py", line 18, in <module>video_path = export_to_video(video_frames)File "D:\ProgramData\miniconda3\envs\pysd\lib\site-packages\diffusers\utils\export_utils.py", line 135, in export_to_videoh, w, c = video_frames[0].shape
ValueError: too many values to unpack (expected 3)

解决方法,修改代码:

def export_to_video(video_frames: Union[List[np.ndarray], List[PIL.Image.Image]], output_video_path: str = None, fps: int = 10
) -> str:if is_opencv_available():import cv2else:raise ImportError(BACKENDS_MAPPING["opencv"][1].format("export_to_video"))if output_video_path is None:output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").name# Convert PIL images to numpy arrays if neededif isinstance(video_frames[0], PIL.Image.Image):video_frames = [np.array(frame) for frame in video_frames]# Ensure the frames are in the correct formatif isinstance(video_frames[0], np.ndarray):# Check if frames are 4-dimensional and handle accordinglyif len(video_frames[0].shape) == 4:video_frames = [frame[0] for frame in video_frames]# Convert frames to uint8video_frames = [(frame * 255).astype(np.uint8) for frame in video_frames]# Ensure all frames are in (height, width, channels) formath, w, c = video_frames[0].shapefourcc = cv2.VideoWriter_fourcc(*"mp4v")video_writer = cv2.VideoWriter(output_video_path, fourcc, fps=fps, frameSize=(w, h))for frame in video_frames:img = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)video_writer.write(img)video_writer.release()return output_video_pathdef export_to_video_o(video_frames: Union[List[np.ndarray], List[PIL.Image.Image]], output_video_path: str = None, fps: int = 10
) -> str:if is_opencv_available():import cv2else:raise ImportError(BACKENDS_MAPPING["opencv"][1].format("export_to_video"))if output_video_path is None:output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").nameif isinstance(video_frames[0], np.ndarray):video_frames = [(frame * 255).astype(np.uint8) for frame in video_frames]elif isinstance(video_frames[0], PIL.Image.Image):video_frames = [np.array(frame) for frame in video_frames]fourcc = cv2.VideoWriter_fourcc(*"mp4v")h, w, c = video_frames[0].shapevideo_writer = cv2.VideoWriter(output_video_path, fourcc, fps=fps, frameSize=(w, h))for i in range(len(video_frames)):img = cv2.cvtColor(video_frames[i], cv2.COLOR_RGB2BGR)video_writer.write(img)return output_video_path

http://www.lryc.cn/news/378882.html

相关文章:

  • H3C综合实验
  • QThread 与QObject::moveToThread在UI中的应用
  • 安卓逆向案例——X酷APP逆向分析
  • 创新案例|星巴克中国市场创新之路: 2025目标9000家店的挑战与策略
  • 计算机网络 MAC地址表管理
  • 【免费API推荐】:各类API资源免费获取【11】
  • 技术驱动会展:展位导航系统的架构与实现
  • 适用于轨道交通专用的板卡式网管型工业以太网交换机
  • excel基本操作
  • C++系统相关操作2 - 获取系统环境变量
  • 适合小白学习的项目1906java Web智慧食堂管理系统idea开发mysql数据库web结构java编程计算机网页源码servlet项目
  • AI通用大模型不及垂直大模型?各有各的好
  • 农产品价格信息系统小程序
  • 【LLM-多模态】高效多模态大型语言模型综述
  • ASP .Net Core创建一个httppost请求并添加证书
  • Redis入门篇
  • 变电站智能巡检机器人解决方案
  • Linux Kernel入门到精通系列讲解(QEMU-虚拟化篇) 2.5 Qemu实现RTC设备
  • 【自动驾驶】通过下位机发送的加速度、角速度计算机器人在世界坐标系中的姿态
  • Python 设计模式(第2版) -- 第四部分(其他设计模式)
  • gitlab升级16.11.3-ee
  • 剑指offer 算法题(搜索二维矩阵)
  • SaaS平台数据对接为什么要选择API对接?
  • 力扣136. 只出现一次的数字
  • 重学java 74.Lombok的使用
  • 数据结构6---树
  • 一键制作,打造高质量的数字刊物
  • Java面试题:对比继承Thread类和实现Runnable接口两种创建线程的方法,以及它们的优缺点
  • 编译原理-各章典型题型+思路求解
  • 【绝对有用】C++ vector排序