AttributeError: module transformers has no attribute CLIPImageProcessor的解决方法

问题描述

执行某py文件时,从网络下载模型后,不能加载,错误如下:

Fetching 15 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 15/15 [00:00<00:00, 2534.22it/s]
ftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.
Traceback (most recent call last):
  File "/home/gaoyi/example-app/waifu-model.py", line 5, in <module>
    pipe = StableDiffusionPipeline.from_pretrained(
  File "/home/gaoyi/anaconda3/lib/python3.9/site-packages/diffusers/pipeline_utils.py", line 659, in from_pretrained
    class_obj = getattr(library, class_name)
  File "/home/gaoyi/anaconda3/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 1069, in __getattr__
    raise AttributeError(f"module {self.__name__} has no attribute {name}")
AttributeError: module transformers has no attribute CLIPImageProcessor

产生原因

一般来说一个包当中找不到某个Attribute,大概率是包的版本不对,要么版本太低需要升级,要么版本太高淘汰了某些用法,按需执行以下命令:

# 查看包的版本
pip show <package name>

# 升级包
pip install --upgrade <package name>

# 卸载重装
pip uninstall <package name>
pip install <package name>

# 指定版本
pip install <package name>==<版本号>

解决方法

使用pip命令折腾了很久,相关检索的网页也看了很多,有不少人遇到了一样的问题,但是原因不尽相同,所以也没有办法套用相同的解决思路,这里我突然意识到是否是因为condapip对于包的管理是不一样的,毕竟这2个东西总会导致不少问题的出现,于是尝试在conda中安装transformers这个包:

# 执行一个就好了
conda install -c conda-forge transformers
conda install -c "conda-forge/label/cf202003" transformers

再次运行,成功!

更多链接

猜你喜欢

转载自blog.csdn.net/qq_45510888/article/details/129439684
今日推荐