【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)

相关推荐
灵活用工平台18 分钟前
灵活用工平台注册流程图
python·流程图
2501_9059673321 分钟前
双目视觉:CREStereo论文超详细解读
人工智能·python·计算机视觉·双目视觉
狗狗学不会23 分钟前
Pybind11 封装 RK3588 全流程服务:Python 写逻辑,C++ 跑并发,性能起飞!
c++·人工智能·python·目标检测
清水白石00827 分钟前
深入理解 Python 字典的有序性:从 3.6 的“意外之喜”到 3.7 的官方承诺
开发语言·python
心枢AI研习社32 分钟前
python学习笔记8--破茧与连接:Python HTTP 全球协作实战复盘
笔记·python·学习
写代码的【黑咖啡】42 分钟前
Python 中的 Requests 库:轻松进行 HTTP 请求
开发语言·python·http
栗子叶42 分钟前
Spring 中 Servlet 容器和 Python FastAPI 对比
python·spring·servlet·fastapi
杨杨杨大侠1 小时前
DeepAgents 框架深度解析:从理论到实践的智能代理架构
后端·python·llm
袁袁袁袁满1 小时前
Python读取doc文件打印内容
开发语言·python·python读取doc文件
m0_748252381 小时前
Ruby 模块(Module)的基本概念
开发语言·python·ruby