Stable Video Diffusion(SVD)安装和测试

Stable Video Diffusion(SVD)安装和测试

官网

  • github | https://github.com/Stability-AI/generative-models
  • Hugging Face | https://huggingface.co/stabilityai/stable-video-diffusion-img2vid-xt
  • Paper | https://stability.ai/research/stable-video-diffusion-scaling-latent-video-diffusion-models-to-large-datasets

准备工作

我的系统环境

  • 内存 64G
  • 显存3090,24G显存

下载

git clone https://github.com/Stability-AI/generative-models
cd generative-models

下载模型

  • SVD | https://huggingface.co/stabilityai/stable-video-diffusion-img2vid-xt
  • SVD-XT | https://huggingface.co/stabilityai/stable-video-diffusion-img2vid

模型有4个,任意一个都可以使用,存放目录:

generative-models/checkpoints/

在这里插入图片描述

python环境配置

conda create --name svd python=3.10 -y

source activate svd
pip3 install -r requirements/pt2.txt
pip3 install .

运行

cd generative-models
streamlit run scripts/demo/video_sampling.py  --server.address  0.0.0.0  --server.port 7862

启动时,还会下载两个模型,可以手动去下载,放到以下目录:

  • /root/.cache/huggingface/hub/models–laion–CLIP-ViT-H-14-laion2B-s32B-b79K
  • /root/.cache/clip/ViT-L-14.pt

下载地址:

  • https://huggingface.co/laion/CLIP-ViT-H-14-laion2B-s32B-b79K/tree/main
  • https://openaipublic.azureedge.net/clip/models/b8cca3fd41ae0c99ba7e8951adf17d267cdb84cd88be6f7c2e0eca1737a03836/ViT-L-14.pt

或者,可以在百度云盘下载:
链接:https://pan.baidu.com/s/19SlbJp0GbZCj9VFZdCLnwQ
提取码:1234

关于models–laion–CLIP-ViT-H-14-laion2B-s32B-b79K,下载后
执行一下命令:

cp models--laion--CLIP-ViT-H-14-laion2B-s32B-b79K.tar /root/.cache/huggingface/hub/
cd /root/.cache/huggingface/hub/
tar -zxvf models--laion--CLIP-ViT-H-14-laion2B-s32B-b79K.tar

继续运行,如果报错

from scripts.demo.streamlit_helpers import *
ModuleNotFoundError: No module named 'scripts'

添加环境变量

RUN echo 'export PYTHONPATH=/generative-models:$PYTHONPATH' >>  /root/.bashrc
source /root/.bashrc

再次启动
在这里插入图片描述
Okay, 没有问题了

测试

访问: 0.0.0.0:7862, 页面可以正常打开了。
在这里插入图片描述

开始操作,选择模型版本,然后打钩,速度看机器配置,在我们的电脑需要2-3分钟。
在这里插入图片描述

查看一下后台的情况
在这里插入图片描述
报错

  File "/opt/miniconda3/envs/svd/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "/root/workspace/generative-models/scripts/demo/video_sampling.py", line 142, in <module>
    value_dict["cond_frames"] = img + cond_aug * torch.randn_like(img)
TypeError: randn_like(): argument 'input' (position 1) must be Tensor, not NoneType

在这里插入图片描述

这是因为我们没有选择图片的缘故,上传图片
在这里插入图片描述
我们用官方提供的图片,先做测试
在这里插入图片描述
红色框的帧数改为 2,太大了,容易报显存错误,其他参数保持不变。点击 ‘Sample’,然后看一下后台
在这里插入图片描述
Okay,处理完之后,可以看一下视频,视频保存在:

generative-models/outputs/demo/vid/svd_image_decoder/samples

可以看到一个2秒的视频,已经生成了
在这里插入图片描述在这里插入图片描述

如果在最后生成视频时报错

OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mp4 / MP4 (MPEG-4 Part 14)'                                                                            
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'                                                                                                                                      
sh: 1: ffmpeg: not found                                                                                                                                                                   
2023-11-30 02:09:51.201 Uncaught app exception                                                                                                                                             
Traceback (most recent call last):                                                                                                                                                         
  File "/opt/miniconda3/envs/svd/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script                                                   
    exec(code, module.__dict__)                                                                                                                                                            
  File "/root/workspace/generative-models/scripts/demo/video_sampling.py", line 200, in <module>                                                                                           
    save_video_as_grid_and_mp4(samples, save_path, T, fps=saving_fps)                                                                                                                      
  File "/root/workspace/generative-models/scripts/demo/streamlit_helpers.py", line 883, in save_video_as_grid_and_mp4                                                                      
    with open(video_path_h264, "rb") as f:                                                                                                                                                 
FileNotFoundError: [Errno 2] No such file or directory: 'outputs/demo/vid/svd_image_decoder/samples/000041_h264.mp4'

解决办法:

cd generative-models
vim ./scripts/demo/streamlit_helpers.py

找到“cv2.VideoWriter_fourcc”, 修改为
在这里插入图片描述

如果没有安装ffmpeg,就安装安装一下

apt install ffmpeg

Okay 搞定


AIGC群交流

在这里插入图片描述
在这里插入图片描述

  • 29
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

且漫CN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值