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

一般做网站宽度是多少时装+wordpress

一般做网站宽度是多少,时装+wordpress,国家食品查询网入口,广州网站开发多少钱Wan2.1 文生视频 支持批量生成、参数化配置和多语言提示词管理 flyfish 设计 一个基于 Wan2.1 文本到视频模型的自动化视频生成系统。 文件关系图 script.py ├── 读取 → config.json │ ├── 模型配置 → 加载AI模型 │ ├── 生成参数 → 控制生成质量 │ └…

Wan2.1 文生视频 支持批量生成、参数化配置和多语言提示词管理

flyfish

设计

一个基于 Wan2.1 文本到视频模型的自动化视频生成系统。

文件关系图

script.py
├── 读取 → config.json
│   ├── 模型配置 → 加载AI模型
│   ├── 生成参数 → 控制生成质量
│   └── 文件路径 → 定位其他文件
│
├── 读取 → prompt.json → 正向提示词
│
├── 读取 → negative_prompt_*.txt → 负向提示词
│
└── 输出 → 视频文件(如video_1.mp4)

1. script.py`(主程序)

  • 功能:执行AI视频生成的核心逻辑
  • 作用
    • 读取配置文件和提示词
    • 加载AI模型和参数
    • 控制视频生成流程
    • 统计生成时间和输出结果
  • 依赖:需要与配置文件和提示词文件配合使用

2. config.json(配置文件)

  • 功能:集中管理所有可配置参数
  • 作用
    • 模型配置(使用哪个模型、数据类型)
    • 生成参数(分辨率、帧数、引导强度、采样步数)
    • 文件路径(提示词文件、输出文件名格式)
  • 示例内容
    {"model": {"id": "Wan-AI/Wan2.1-T2V-1.3B-Diffusers","torch_dtype": "bfloat16"},"generation": {"height": 480,"width": 832,"num_inference_steps": 30}
    }
    

3. prompt.json(正向提示词库)

  • 功能:存储需要生成视频的文字描述
  • 作用
    • 支持批量生成多个视频
    • 每个描述对应一个输出视频
  • 示例内容
    [{ "prompt": "一只猫在草地上行走,写实风格" },{ "prompt": "一个人在海边跑步,日落场景" }
    ]
    

4. negative_prompt_cn.txt(中文负向提示词)

  • 功能:定义不希望出现在生成结果中的元素
  • 作用
    • 提高生成质量,避免常见瑕疵
    • 语言版本与正向提示词匹配
  • 示例内容
    明亮色调,过曝,静态,细节模糊,低质量
    

5. negative_prompt_en.txt(英文负向提示词)

  • 功能:与中文负向提示词相同,提供英文版本
  • 作用
    • 适配英文正向提示词
    • 通过配置文件切换使用语言
  • 示例内容
    Bright tones, overexposed, static, blurred details, low quality
    

完整内容

import torch
import json
import os
import time
from diffusers import AutoencoderKLWan, WanPipeline
from diffusers.utils import export_to_video# ----------------------
# 读取配置文件
# ----------------------
try:with open("config.json", "r", encoding="utf-8") as f:config = json.load(f)print("已加载配置文件")
except FileNotFoundError:print("错误: 未找到config.json文件,请确保该文件与脚本在同一目录下")exit(1)
except json.JSONDecodeError:print("错误: config.json文件格式不正确,请检查JSON语法")exit(1)
except Exception as e:print(f"错误: 读取配置文件时发生异常: {e}")exit(1)# ----------------------
# 解析配置参数
# ----------------------
# 模型相关配置
model_config = config.get("model", {})
model_id = model_config.get("id", "Wan-AI/Wan2.1-T2V-1.3B-Diffusers")
vae_subfolder = model_config.get("vae_subfolder", "vae")
torch_dtype = model_config.get("torch_dtype", "bfloat16")
device = model_config.get("device", "cuda")  # 支持"cuda"或"cpu"# 生成参数配置
generation_config = config.get("generation", {})
height = generation_config.get("height", 480)
width = generation_config.get("width", 832)
num_frames = generation_config.get("num_frames", 81)
guidance_scale = generation_config.get("guidance_scale", 5.0)
fps = generation_config.get("fps", 15)
output_prefix = generation_config.get("output_prefix", "output_")
num_inference_steps = generation_config.get("num_inference_steps", 50)  # 新增采样步数# 负向提示词配置
negative_config = config.get("negative_prompt", {})
default_negative_lang = negative_config.get("default_lang", "cn")  # 支持"cn"或"en"
negative_file_map = {"cn": negative_config.get("cn_file", "negative_prompt_cn.txt"),"en": negative_config.get("en_file", "negative_prompt_en.txt")
}# 正向提示词配置
prompt_config = config.get("prompts", {})
prompt_file = prompt_config.get("file", "prompt.json")
prompt_key = prompt_config.get("key", "prompt")  # JSON中提示词字段名# ----------------------
# 读取负向提示词
# ----------------------
def read_negative_prompt(lang):filename = negative_file_map[lang]try:with open(filename, "r", encoding="utf-8") as f:return f.read().strip()except FileNotFoundError:print(f"错误: 未找到负向提示词文件 {filename}")exit(1)except Exception as e:print(f"错误: 读取负向提示词文件时发生异常: {e}")exit(1)try:negative_prompt = read_negative_prompt(default_negative_lang)print(f"已加载{default_negative_lang.upper()}负向提示词")
except:print("错误: 负向提示词加载失败")exit(1)# ----------------------
# 读取正向提示词
# ----------------------
try:with open(prompt_file, "r", encoding="utf-8") as f:prompts_data = json.load(f)print(f"已加载 {len(prompts_data)} 个正向提示词")
except FileNotFoundError:print(f"错误: 未找到正向提示词文件 {prompt_file}")exit(1)
except json.JSONDecodeError:print(f"错误: {prompt_file}文件格式不正确,请确保是有效的JSON数组")exit(1)# ----------------------
# 模型初始化
# ----------------------
start_time = time.time()# 转换torch dtype
try:dtype = getattr(torch, torch_dtype)
except AttributeError:print(f"错误: 不支持的torch dtype: {torch_dtype}")exit(1)# 加载VAE
vae = AutoencoderKLWan.from_pretrained(model_id,subfolder=vae_subfolder,torch_dtype=dtype
)# 加载管道
pipe = WanPipeline.from_pretrained(model_id,vae=vae,torch_dtype=dtype
)
pipe.to(device)model_load_time = time.time() - start_time
print(f"模型加载完成,耗时: {model_load_time:.2f} 秒")# ----------------------
# 批量生成视频
# ----------------------
total_generation_time = 0
success_count = 0for i, item in enumerate(prompts_data, 1):try:prompt = item.get(prompt_key, "")if not prompt:print(f"警告: 第 {i} 个提示词字段为空,跳过")continueprint(f"\n---- 生成第 {i} 个视频 ----")print(f"正向提示词: {prompt[:50]}...")print(f"负向提示词: {negative_prompt[:50]}...")print(f"采样步数: {num_inference_steps}")  # 新增提示# 生成时间统计gen_start = time.time()# 生成视频output = pipe(prompt=prompt,negative_prompt=negative_prompt,height=height,width=width,num_frames=num_frames,guidance_scale=guidance_scale,num_inference_steps=num_inference_steps  ).frames[0]gen_time = time.time() - gen_starttotal_generation_time += gen_timesuccess_count += 1# 保存视频output_path = f"{output_prefix}{i}.mp4"export_to_video(output, output_path, fps=fps)print(f"✅ 视频保存至: {output_path}")print(f"⏱️ 生成耗时: {gen_time:.2f} 秒")except Exception as e:print(f"❌ 生成失败: {str(e)[:100]}...")continue# ----------------------
# 生成统计
# ----------------------
print("\n==================== 生成完成 ====================")
print(f"模型信息: {model_id}")
print(f"设备: {device}")
print(f"生成参数: {height}x{width}, {num_frames}帧, 引导尺度{guidance_scale}, 采样步数{num_inference_steps}")if success_count > 0:avg_time = total_generation_time / success_countprint(f"\n📊 统计结果:")print(f"   - 模型加载时间: {model_load_time:.2f} 秒")print(f"   - 成功生成: {success_count}/{len(prompts_data)}")print(f"   - 总生成时间: {total_generation_time:.2f} 秒")print(f"   - 平均耗时: {avg_time:.2f} 秒/视频")
else:print("\n⚠️ 没有成功生成任何视频")

config.json配置文件

{"model": {"id": "/media/models/Wan-AI/Wan2___1-T2V-14B-Diffusers/","vae_subfolder": "vae","torch_dtype": "bfloat16","device": "cuda" },"generation": {"height": 640,"width": 480, "num_frames": 81,"guidance_scale": 5.0,"fps": 15, "output_prefix": "video_","num_inference_steps": 150},"negative_prompt": {"default_lang": "cn","cn_file": "negative_prompt_cn.txt","en_file": "negative_prompt_en.txt"},"prompts": {"file": "prompt.json", "key": "prompt"}
}

negative_prompt_cn.txt

明亮色调,过曝,静态,细节模糊,字幕,风格,作品,绘画,图像,静态,整体灰暗,最差质量,低质量,JPEG压缩残留,丑陋,不完整,多余手指,绘制不佳的手,绘制不佳的脸,变形,毁容,畸形肢体,融合手指,静态图片,杂乱背景,三条腿,背景中有很多人,倒退行走

negative_prompt_en.txt

Vivid tones, overexposed, static, blurry details, subtitles, style, work, painting, image, still, overall grayish, worst quality, low quality, JPEG compression artifacts, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, morphologically deformed limbs, fused fingers, still image, cluttered background, three legs, many people in the background, walking backwards


文章转载自:

http://YXJmeKvZ.yhgbd.cn
http://PCdYUcVf.yhgbd.cn
http://O6cI0gyu.yhgbd.cn
http://InTo1Po6.yhgbd.cn
http://ewwDua1t.yhgbd.cn
http://MHw5JC49.yhgbd.cn
http://ga4n2w1s.yhgbd.cn
http://iUOUD6Kb.yhgbd.cn
http://a6aQCbba.yhgbd.cn
http://QBniI7Pj.yhgbd.cn
http://sisDR8DH.yhgbd.cn
http://yM7SATsc.yhgbd.cn
http://pB1DD5SR.yhgbd.cn
http://mpRypFHZ.yhgbd.cn
http://YaTwtvB2.yhgbd.cn
http://EV79Ek8j.yhgbd.cn
http://FH5d5A51.yhgbd.cn
http://q3Vngbdy.yhgbd.cn
http://W0YgcFgE.yhgbd.cn
http://qvHpgp8o.yhgbd.cn
http://E3m4PP9k.yhgbd.cn
http://4lkvFnfq.yhgbd.cn
http://v6kwV4Bb.yhgbd.cn
http://8gQgEiUb.yhgbd.cn
http://VcoJMWIA.yhgbd.cn
http://LAWjEZqN.yhgbd.cn
http://CR393Zom.yhgbd.cn
http://ruUXS566.yhgbd.cn
http://E0fCXPZv.yhgbd.cn
http://DQsGLqzG.yhgbd.cn
http://www.dtcms.com/wzjs/698746.html

相关文章:

  • 小说网站建设源码百度蜘蛛网站排名
  • 合肥网站设计建设怎么做电商平台
  • 聊城做网站的公司流程wap网站 手机网站
  • 孝感网站开发优搏快马云做中国最大的网站
  • 企业移动网站品牌做营销型网站要多少钱
  • 外贸网站运营网站建设是啥
  • 广州最发达的五个区杭州网站建设seo优化
  • 单站点网站wordpress标签云添加图片
  • 古城区建设局网站东莞seo优化推广
  • 杭州市网站建设公司北京电力交易中心公示
  • 网站域名需icp备案做网站还是做公众号
  • 官方网站建设对比不改域名和空间 只改网站类型
  • 有那种网站的浏览器小学生做的网站
  • 招工网站怎么做万户建站
  • 网站备案是先做网站上线还是网站开发工具软件
  • 国家防疫新十条政策网站搭建谷歌seo
  • 公司网站开发设计题目怎么写学编程的步骤
  • 佛山网站设计哪里好网站建设业务怎么做
  • 建设公司网站方案莱芜网络推广公司排行
  • 网站注册空间广汉网站
  • ps网站建设教程视频seo高清视频教程
  • 福州网站排名建筑设计模板
  • 如何做网站宣传无人一区二区区别是什么
  • 建设网站一般要多少钱免费域名注册2023
  • 个人网站建设模板微信公众号如何分享wordpress
  • 谷歌网站地图免费注册网站平台
  • 绿色门户网站模板下载沈阳康平志诚建设集团网站
  • 国外常用的seo站长工具做微信网站的公司
  • 网站的关键词库怎么做的那么多网站如何做中英文切换
  • html搭建网站app导航网站源码