AI绘画:InstantID Win11本地安装记录!

2024-02-1520:11:37办公软件与工具应用Comments535 views字数 3236阅读模式

AI绘画:InstantID Win11本地安装记录!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

本想着介绍完InstantID的在线体验方式之后,立马接着把本地安装记录也发了。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

一放松,一眨眼,快过去一个星期了。。。。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

InstantID这个项目还是非常不错滴。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

玩在线版版不是我们的风格,只有装在自己电脑上,才能抵抗各种不确定性,充分把握自由度^_^!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

无限出图,无限制出图。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

下面就来记录下我的安装过程和遇到的问题,以及解决方法。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

我尽量详细,但是太基础的命令,我就不展开说了。可以参考以往的文章。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

我只记录,比较关键的,比较有用的部分。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

0.准备工作文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

准备一张3090或者4090或者显存24+的N卡。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

Windows11+Conda+git文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

1.克隆代码文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

打开CMD工具,通过CD命令进入到指定目录,然后克隆代码。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

git clone https://github.com/InstantID/InstantID.gitcd InstantID

2.创建虚拟环境并激活文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

使用Conda工具,创建一个Python的虚拟环境,创建成功之后激活虚拟环境。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

conda create -n instantid python=3.10conda activate instantid

3.安装依赖文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

使用项目自带的requirements.txt来快速安装所需依赖。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

pip install -r gradio_demo\requirements.txt

注意,这个req文件并没有在根目录,所以要加上gradio_demo\这个路径。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

另外,这个依赖文件并不是完全适配Windows系统。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

Windows下面单独安装一下Torch 2.0.0 GPU版本。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu118#conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 pytorch-cuda=11.8 -c pytorch -c nvidia

上面提供了两种安装方式,可以自由选择。我推荐还是用pip吧,conda东西比较多,镜像设置麻烦点。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

安装过程网络不好的,可以设置conda镜像pip镜像文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

4.下载模型文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

这个项目用到好几种模型。包括AI绘画相关的ControlNetModel,ip-adapter,YamerMIX_v8。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

还有一个人脸识别相关的antelopev2模型。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

这些模型可以使用代码的方式下载,也可以手动下载。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

代码方式:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

from huggingface_hub import hf_hub_downloadhf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/config.json", local_dir="./checkpoints")hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/diffusion_pytorch_model.safetensors", local_dir="./checkpoints")hf_hub_download(repo_id="InstantX/InstantID", filename="ip-adapter.bin", local_dir="./checkpoints")

创建一个名为down.py的文件,把这段点放里面。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

使用命令:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

python down.py

通过这种方式可以把两个模型下载到当前目录的checkpoints文件夹。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

还有一个YamerMIX_v8运行主程序的时候会自动下载。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

当然,你也可以手动下载。就是你得明白从哪里下载,放到哪里。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

模型默认会下载在C盘,会消耗若干G的空间。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

C盘扛不住的,可以设置环境变量:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

SET HF_HUB_CACHE=./checkpoints

这样C就解脱了,压力给到D>E>F。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

另外还有一个antelopev2的模型,本来主程序会自动下载,但是不知为何insightface取消了对这个模型的自动加载功能。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

所以这个模型必须手动下载,下载地址:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

https://drive.google.com/file/d/18wEUfMNohBJ4K3Ly5wpTejPfDzp-8fI8/view?usp=sharing

这个环节最大的难度可能就是...网络问题!这个问题我不能多说的,已经被警告了,大家各显神通吧!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

5. 运行测试文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

上面的问题全部解决之后,就可以运行APP了。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

python gradio_demo/app.py

运行成功之后,打开网址,就可以使用了。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

6. 遇到的问题文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

网络问题,就不算在这里了。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

缺少chardet模块文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

我是遇到了这个问题,具体提示如下。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

ModuleNotFoundError: No module named 'chardet'

解决方法:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

pip install chardet

下载 antelopev2 失败文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

错误提示如下:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

download_path: ./models\antelopev2Downloading ./models\antelopev2.zip from https://github.com/deepinsight/insightface/releases/download/v0.7/antelopev2.zip...Traceback (most recent call last):  File "E:\DEV\InstantID\gradio_demo\app.py", line 38, in <module>    app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])  File "E:\DEV\Miniconda3\envs\instantid\lib\site-packages\insightface\app\face_analysis.py", line 27, in __init__    self.model_dir = ensure_available('models', name, root=root)  File "E:\DEV\Miniconda3\envs\instantid\lib\site-packages\insightface\utils\storage.py", line 28, in ensure_available    return download(sub_dir, name, force=False, root=root)  File "E:\DEV\Miniconda3\envs\instantid\lib\site-packages\insightface\utils\storage.py", line 17, in download    download_file(model_url,  File "E:\DEV\Miniconda3\envs\instantid\lib\site-packages\insightface\utils\download.py", line 73, in download_file    raise RuntimeError("Failed downloading url %s" % url)RuntimeError: Failed downloading url https://github.com/deepinsight/insightface/releases/download/v0.7/antelopev2.zip

这个问题我在上面有提到了,需要单独下载这个模型,放到项目根目录的models文件夹下面。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

另外注意下,下载到的文件是zip压缩包,记得解压一下。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

解压到当前目录,不需移动。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

整体来说这个项目安装还是比较顺利,问题不是很多。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/office/59775.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/office/59775.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定