【bug】可图文生图模型 KolorsPipeline IndexError: list index out of range

【bug】可图文生图模型 KolorsPipeline IndexError: list index out of range

环境

shell 复制代码
linux
diffusers     0.30.0

问题详情

报错详情

python 复制代码
from diffusers import KolorsPipeline

Traceback (most recent call last):
  File "Kolors/demo.py", line 6, in <module>
    pipe = KolorsPipeline.from_pretrained(
  File ".conda/envs/xxx/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File ".conda/envs/xxx/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 732, in from_pretrained
    variant_exists = is_folder and any(
  File ".conda/envs/xxx/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 733, in <genexpr>
    p.split(".")[1].startswith(variant) for p in os.listdir(folder_path)
IndexError: list index out of range

运行代码

python 复制代码
import torch
from diffusers import KolorsPipeline

# 模型地址,可以改为本地离线地址
root_dir = "Kwai-Kolors/Kolors-diffusers"

pipe = KolorsPipeline.from_pretrained(
    root_dir, 
    torch_dtype=torch.float16, 
    variant="fp16"
).to("cuda")
prompt = '一张瓢虫的照片,微距,变焦,高质量,电影,拿着一个牌子,写着"可图"'
image = pipe(
    prompt=prompt,
    negative_prompt="",
    guidance_scale=5.0,
    num_inference_steps=50,
    generator=torch.Generator(pipe.device).manual_seed(66),
).images[0]
# image.show()

image.save("image.jpg")

错误说明

这个错误是由于模型中text_encoder文件夹下存在 __pycache__文件夹导致模型加载错误。

解决方法

解决方法是删除 text_encoder 文件夹下的 __pycache__文件夹。

我的模型是在可图 · 模型库 (modelscope.cn)下载的,官方没有去掉 __pycache__

如果是在Kwai-Kolors/Kolors-diffusers at main (huggingface.co) 下载,官方去掉了 __pycache__文件夹,因此不会出现这个错误

参考

Support for Kolors · Issue #8801 · huggingface/diffusers (github.com)

相关推荐
小龙在山东5 分钟前
Python 包管理工具 uv
windows·python·uv
weixin_3077791326 分钟前
批量OCR的GitHub项目
python·github·ocr
孤狼warrior1 小时前
灰色预测模型
人工智能·python·算法·数学建模
神仙别闹1 小时前
基于Python实现LSTM对股票走势的预测
开发语言·python·lstm
机器学习之心2 小时前
小波增强型KAN网络 + SHAP可解释性分析(Pytorch实现)
人工智能·pytorch·python·kan网络
JavaEdge在掘金2 小时前
MySQL 8.0 的隐藏索引:索引管理的利器,还是性能陷阱?
python
站大爷IP2 小时前
Python办公自动化实战:手把手教你打造智能邮件发送工具
python
chao_7892 小时前
回溯题解——子集【LeetCode】二进制枚举法
开发语言·数据结构·python·算法·leetcode
zdw3 小时前
fit parse解析佳明.fit 运动数据,模仿zwift数据展示
python
剑桥折刀s3 小时前
Python打卡:Day46
python