问题清除指南|alimama-creative/FLUX-Controlnet-Inpainting 运行注意事项

前言:近日验证想法需要用到inpainting技术,选择了https://github.com/alimama-creative/FLUX-Controlnet-Inpainting进行测试,在实现过程中遇到几个小问题,在此分享一下解决经验。

1. 下载预训练模型到本地

由于在huggingface官网一个个点击下载⏬black-forest-labs/FLUX.1-dev模型太繁琐(文件太多),而且下载下来的文件要手动放到特定目录里(非常不方便),于是从这里找了一个脚本自动下载:

import os
from huggingface_hub import snapshot_download
# 如果需要代理的话,去掉此部分注释加入端口
# os.environ["http_proxy"] = "http://xxxxxxx:xxxx" # 代理设置
# os.environ["https_proxy"] = "http://xxxxxxx:xxxx" # 代理设置
repo_id = "black-forest-labs/FLUX.1-dev" # 模型在huggingface上的名称
cache_dir = "/newdata/proceeding/FLUX-Controlnet-Inpainting-main/cache/" #保存路径
local_dir = "/newdata/proceeding/FLUX-Controlnet-Inpainting-main/PMs/black-forest-labs" #保存路径
# 指定要创建的目录路径

local_dir_use_symlinks = False # 本地模型使用文件保存,而非blob形式保存
#
token = "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" # 在hugging face上生成的 access token

# 检查目录是否存在
if not os.path.exists(cache_dir):
 # 创建目录
    os.makedirs(cache_dir)
#
if not os.path.exists(local_dir):
 # 创建目录
    os.makedirs(local_dir)
#
snapshot_download(
 repo_id=repo_id,
 cache_dir=cache_dir,
 local_dir=local_dir,
 local_dir_use_symlinks=local_dir_use_symlinks,
 token=token,
 force_download=True,
 resume_download=True
)
print("======Download successful=====")

一开始下载不成功,后来多尝试了几次,莫名其妙就成功了,可能是网络不稳定。

将模型下载到本地后,修改main.py文件中from_pretrained()函数的第一个参数,变成模型的本地路径即可。


2. 安装必要的python库

经过数次报错后,总结出的必要安装库:

sentencepiece=0.2.0
protobuf=5.28.2
diffusers==0.30.3
transformers=4.44.0

注意⚠️:transformers如果版本不当,会引发「RuntimeError: “triu_tril_cuda_template“ not implemented for ‘BFloat16’」类似报错。


3. image_path 注意是str不是元组

在运行main.py文件,模型加载成功之后,报错如下:

Traceback (most recent call last):
  File "/newdata/proceeding/FLUX-Controlnet-Inpainting-main/main.py", line 23, in <module>
    image = load_image(image_path).convert("RGB").resize(size)
  File "/root/anaconda3/envs/flux/lib/python3.10/site-packages/diffusers/utils/loading_utils.py", line 41, in load_image
    raise ValueError(
ValueError: Incorrect format used for the image. Should be a URL linking to an image, a local path, or a PIL image.

一开始以为是函数的问题,后来发现是main函数中2️⃣个很小的逗号导致的:

# Set image path , mask path and prompt
image_path='https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/bucket.png',
mask_path='https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/bucket_mask.jpeg',

上述两行代码对两个变量赋值,image_pathmask_path字符串之后都有一个小小的逗号,删除即可解决上述报错。


4. RuntimeError: cuDNN Frontend error: [cudnn_frontend] Error: No execution plans support the graph.

把这个错误单独〇出来是因为当天没解决,卡了好久……后来在github找原因,受这个issue启发,发觉可能是torch的版本不对,于是,结合自己的cuda版本(nvidia-smi查询到 CUDA Version: 12.0),尝试不同的torch版本,一开始2.5.0🙅,2.4.0🙅,最后尝试2.3.1成功!

gpu版本的torch安装如下:

pip install torch==2.3.1+cu121 torchvision==0.18.1+cu121 -f https://download.pytorch.org/whl/torch_stable.html

上述问题全部解决后,运行成功~

╰─# python /newdata/proceeding/FLUX-Controlnet-Inpainting-main/main.py
Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00,  9.64it/s]
Loading pipeline components...:  29%|████████████████████████████████████                                                                                          | 2/7 [00:00<00:01,  4.51it/s]You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<00:00,  7.43it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:11<00:00,  2.34it/s]
Successfully inpaint image

在这里插入图片描述


参考资料

  1. https://zhuanlan.zhihu.com/p/661741304
  2. https://blog.csdn.net/qq_35357274/article/details/141157962
  3. https://github.com/huggingface/diffusers/issues/9704
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

_Meilinger_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值