Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru)

这篇具有很好参考价值的文章主要介绍了Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

欢迎关注我的CSDN:https://spike.blog.csdn.net/
本文地址:https://spike.blog.csdn.net/article/details/131817599

Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru),大模型(LLM&AIGC),stable diffusion,图像反推,Interrogate

图像反推 (Interrogate) 功能,是指根据给定的图像生成一个或多个文本提示,这些提示可以描述图像的内容、风格、细节等方面。这个功能可以帮助用户快速找到合适的文本提示,从而生成自己想要的图像变体。图像反推功能,使用了 CLIP (BLIP) 和 DeepBooru 两种提示词反推算法,分别使用 视觉和语言的联合表示 和 基于标签的图像检索。

SD 启动程序:

cd stable_diffusion_webui_docker
conda deactivate
source venv/bin/activate

nohup python -u launch.py --listen --port 9301 --xformers --no-half-vae --enable-insecure-extension-access --theme dark --gradio-queue > nohup.sd.out &

启动日志,时间约 5.5 min (330.5s):

Python 3.8.16 (default, Mar  2 2023, 03:21:46) 
[GCC 11.2.0]
Version: v1.4.0
Commit hash: 394ffa7b0a7fff3ec484bcd084e673a8b301ccc8
Installing requirements

Launching Web UI with arguments: --listen --port 9301 --xformers --no-half-vae --enable-insecure-extension-access --theme dark --gradio-queue

[-] ADetailer initialized. version: 23.7.6, num models: 12
dirname:  stable_diffusion_webui_docker/localizations
localizations:  {'zh-Hans (Stable)': 'stable_diffusion_webui_docker/extensions/stable-diffusion-webui-localization-zh_Hans/localizations/zh-Hans (Stable).json', 'zh-Hans (Testing)': 'stable_diffusion_webui_docker/extensions/stable-diffusion-webui-localization-zh_Hans/localizations/zh-Hans (Testing).json'}
2023-07-19 12:56:33,823 - ControlNet - INFO - ControlNet v1.1.233
ControlNet preprocessor location: stable_diffusion_webui_docker/extensions/sd-webui-controlnet/annotator/downloads
2023-07-19 12:56:35,787 - ControlNet - INFO - ControlNet v1.1.233
sd-webui-prompt-all-in-one background API service started successfully.
Loading weights [4199bcdd14] from stable_diffusion_webui_docker/models/Stable-diffusion/RevAnimated_v122.safetensors
Creating model from config: stable_diffusion_webui_docker/configs/v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading VAE weights specified in settings: stable_diffusion_webui_docker/models/VAE/RevAnimated_Orangemix.vae.pt
Applying attention optimization: xformers... done.
Textual inversion embeddings loaded(5): bad-artist-anime, bad_prompt_version2-neg, badhandv4, EasyNegative, ng_deepnegative_v1_75t
Model loaded in 5.6s (load weights from disk: 0.3s, create model: 0.6s, apply weights to model: 1.8s, apply half(): 0.6s, load VAE: 1.0s, move model to device: 0.8s, load textual inversion embeddings: 0.3s).
preload_extensions_git_metadata for 18 extensions took 23.46s
Running on local URL:  http://0.0.0.0:9301

To create a public link, set `share=True` in `launch()`.
Startup time: 330.5s (import torch: 94.9s, import gradio: 28.4s, import ldm: 23.4s, other imports: 37.3s, opts onchange: 0.2s, setup codeformer: 2.2s, list SD models: 0.3s, load scripts: 105.7s, load upscalers: 0.2s, refresh VAE: 0.1s, initialize extra networks: 0.2s, create ui: 6.9s, gradio launch: 30.0s, app_started_callback: 0.6s).

1. 反推提示词

选择 图生图 通过图像,反推关键词功能,支持 CLIP (BLIP) 和 DeepBooru 两个算法,建议结合使用,即:

  • CLIP:类似图像的描述 (Caption);
  • DeepBooru:类似图像的分类;

即:
Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru),大模型(LLM&AIGC),stable diffusion,图像反推,Interrogate
例如,效果如下:

BLIP:

a woman sitting on a boat in the ocean wearing a hat and a white dress with a slit down the side,olive skin,aestheticism,Daphne Fedarb,a bronze sculpture,

DeepBooru,阈值不同,类别的数量有所差异:

score threshold: 0.35

1girl, bare legs, bare shoulders, barefoot, beach, blonde hair, blue sky, boat, day, dress, full body, hat, horizon, lips, long hair, looking at viewer, ocean, outdoors, pier, pool, poolside, railing, realistic, red lips, sitting, sky, sleeveless, sleeveless dress, smile, solo, stairs, sun hat, water, watercraft, white dress

score threshold: 0.5

1girl, barefoot, boat, day, dress, full body, hat, horizon, long hair, ocean, pier, pool, poolside, railing, realistic, sitting, solo, sun hat, water, watercraft, white dress

修改反推设置的建议:

  • num_beams: 增加到 2 。
  • score threshold: 降低至 0.35,一般而言,分类准确率 0.35 已经足够,影响 DeepBooru 的输出。

即:

Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru),大模型(LLM&AIGC),stable diffusion,图像反推,Interrogate

2. 环境安装

2.1 BLIP (引导的语言-图像预训练)

  • Paper: BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation
  • BLIP:用于统一视觉语言理解和生成的语言-图像预训练引导方法

BLIP 的预训练模型架构和目标:BLIP 提出了多模态混合编码解码器,统一的视觉语言模型,可以在以下 3 种功能中运行:

  1. 单模态编码器使用 图像-文本对比(ITC)损失来对齐视觉和语言表示。
  2. 图像引导的文本编码器,使用额外的交叉注意力层来建模,视觉-语言交互,并且使用 图像-文本匹配(ITM)损失,来区分正负图像-文本对。
  3. 图像引导的文本解码器,用因果自注意力层替换双向自注意力层,并且与编码器共享相同的交叉注意力层和前馈网络。解码器使用语言建模(LM)损失,来生成给定图像的字幕。

Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru),大模型(LLM&AIGC),stable diffusion,图像反推,Interrogate

安装遇到Bug: (ReadTimeoutError("HTTPSConnectionPool(host='huggingface.co', port=443): Read timed out. (read timeout=10)")

即:

File "stable_diffusion_webui_docker/repositories/BLIP/models/blip.py", line 187, in init_tokenizer
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')

原因是 bert-base-uncased 依赖需要下载,下载命令:

cd repositories/BLIP/models/
bypy downdir /huggingface/bert-base-uncased bert-base-uncased

下载模型:

load checkpoint from stable_diffusion_webui_docker/models/BLIP/model_base_caption_capfilt_large.pth

手动下载:

bypy downfile /stable_diffusion/models/blip_models/model_base_caption_capfilt_large.pth model_base_caption_capfilt_large.pth 

注意:还需要依赖 CLIP 模型 (890M左右),默认下载地址 ~/.cache/clip,建议手动下载:

cd ~/.cache/clip

bypy downfile /stable_diffusion/models/blip_models/ViT-L-14_cache_clip.pt ViT-L-14_cache_clip.pt
ViT-L-14_cache_clip.pt ViT-L-14.pt

还需要依赖 CLIP 环境,即stable_diffusion_webui_docker/interrogate,以小文件为主,但是下载较慢。

Downloading CLIP categories...

在 GitHub - Bug interrogate CLIP crash in FileExistsError 链接中,下载 interrogate 文件夹,解压即可,这块 2 个算法 (BLIP & DeepBooru)都需要。

2.2 DeepBooru

  • GitHub:TorchDeepDanbooru、DeepDanbooru
  • 应用场景主要是在图片标签自动识别和生成方面,可以帮助用户更方便地搜索和浏览图片,也可以提高图片的可访问性和可利用性。

下载模型日志:

Downloading: "https://github.com/AUTOMATIC1111/TorchDeepDanbooru/releases/download/v1/model-resnet_custom_v3.pt" to stable_diffusion_webui_docker/models/torch_deepdanbooru/model-resnet_custom_v3.pt

手动下载:

wget https://ghproxy.com/https://github.com/AUTOMATIC1111/TorchDeepDanbooru/releases/download/v1/model-resnet_custom_v3.pt -O model-resnet_custom_v3.pt

其他

当修改文件夹名称之后,再次启动 virturalenv,则需要修改 virturalenvpip 的 python 路径,替换为最新路径,即可:

vim pip
vim venv/bin/activate

参考:

  • GitHub - load checkpoint from BLIP/model_base_caption_capfilt_large.pth is so slow

  • GitHub - ViT-L-14.pt的下载地址

  • StackOverflow - How to modify path where Torch Hub models are downloaded

  • StackOverflow - How to change huggingface transformers default cache directory

  • GitHub - CLIP工程的默认模型下载路径

  • GitHub - Bug interrogate CLIP crash in FileExistsError

测试图像:

Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru),大模型(LLM&AIGC),stable diffusion,图像反推,Interrogate文章来源地址https://www.toymoban.com/news/detail-606596.html

到了这里,关于Stable Diffusion - 图像反推 (Interrogate) 提示词算法 (BLIP 和 DeepBooru)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 图像提示词攻略--基于 stable diffusion v2

    图像提示词攻略--基于 stable diffusion v2

    Stable Diffusion 是一种潜在的文本到图像扩散模型,能够在给定任何文本输入(称为提示)的情况下生成逼真的图像。 在本文中,我将讨论和探索一些提高提示有效性的方法。从在提示中添加某些和组合词、从更改单词顺序及其标点符号开始到更改画面,颜色比例。 添加

    2024年02月13日
    浏览(5)
  • Stable-Diffusion|从图片反推prompt的工具:Tagger(五)

    Stable-Diffusion|从图片反推prompt的工具:Tagger(五)

    stable-diffusion-webui-wd14-tagger 前面几篇: Stable-Diffusion|window10安装GPU版本的 Stable-Diffusion-WebUI遇到的一些问题(一) 【Stable-Diffusion|入门怎么下载与使用civitai网站的模型(二)】 Stable-Diffusion|文生图 拍立得纪实风格的Lora 图例(三) Stable-Diffusion|文生图 完蛋我被美女包围了人物

    2024年02月03日
    浏览(21)
  • 创建好的提示词来让 Stable Diffusion 生成 AI 艺术作品图像

    如何创建好的提示词来让 Stable Diffusion 生成 AI 艺术作品图像?

    2024年02月10日
    浏览(7)
  • CV多模态和AIGC的原理解析:从CLIP、BLIP到Stable Diffusion、Midjourney

    CV多模态和AIGC的原理解析:从CLIP、BLIP到Stable Diffusion、Midjourney

    终于开写本CV多模态系列的核心主题:stable diffusion相关的了,为何执着于想写这个stable diffusion呢,源于三点 去年stable diffusion和midjourney很火的时候,就想写,因为经常被刷屏,但那会时间错不开 去年11月底ChatGPT出来后,我今年1月初开始写ChatGPT背后的技术原理,而今年2月份

    2024年02月13日
    浏览(15)
  • CV多模态和AIGC原理解析:从CLIP、BLIP到DALLE 3、Stable Diffusion、MDJ

    CV多模态和AIGC原理解析:从CLIP、BLIP到DALLE 3、Stable Diffusion、MDJ

    终于开写本CV多模态系列的核心主题:stable diffusion相关的了,为何执着于想写这个stable diffusion呢,源于三点 去年stable diffusion和midjourney很火的时候,就想写,因为经常被刷屏,但那会时间错不开 去年11月底ChatGPT出来后,我今年1月初开始写ChatGPT背后的技术原理,而今年2月份

    2024年02月06日
    浏览(26)
  • 【stable diffusion】图片批量自动打标签、标签批量修改(BLIP、wd14)用于训练SD或者LORA模型

    【stable diffusion】图片批量自动打标签、标签批量修改(BLIP、wd14)用于训练SD或者LORA模型

    B站教学视频【:AI绘画】新手向!Lora训练!训练集准备、tag心得、批量编辑、正则化准备】 官方教程:https://github.com/darkstorm2150/sd-scripts/blob/main/docs/train_README-en.md#automatic-captioning 1.1 打标界面 根据需求,选择通用打标模型(BLIP)还是动漫打标模型(deepbooru) 设置好后,选择

    2024年02月12日
    浏览(11)
  • CV多模态和AIGC的原理解析:从CLIP、BLIP到DALLE 3、Stable Diffusion/MDJ

    CV多模态和AIGC的原理解析:从CLIP、BLIP到DALLE 3、Stable Diffusion/MDJ

    终于开写本CV多模态系列的核心主题:stable diffusion相关的了,为何执着于想写这个stable diffusion呢,源于三点 去年stable diffusion和midjourney很火的时候,就想写,因为经常被刷屏,但那会时间错不开 去年11月底ChatGPT出来后,我今年1月初开始写ChatGPT背后的技术原理,而今年2月份

    2024年02月08日
    浏览(12)
  • AIGC下的CV多模态原理解析:从CLIP/BLIP到stable diffusion/Midjourney、GPT4

    AIGC下的CV多模态原理解析:从CLIP/BLIP到stable diffusion/Midjourney、GPT4

    终于开写本CV多模态系列的核心主题:stable diffusion相关的了,为何执着于想写这个stable diffusion呢,源于三点 去年stable diffusion和midjourney很火的时候,就想写,因为经常被刷屏,但那会时间错不开 去年11月底ChatGPT出来后,我今年1月初开始写ChatGPT背后的技术原理,而今年2月份

    2024年02月10日
    浏览(11)
  • CV多模态和AIGC的原理解析:从CLIP、BLIP到DALLE三代、Stable Diffusion/MDJ

    CV多模态和AIGC的原理解析:从CLIP、BLIP到DALLE三代、Stable Diffusion/MDJ

    终于开写本CV多模态系列的核心主题:stable diffusion相关的了,为何执着于想写这个stable diffusion呢,源于三点 去年stable diffusion和midjourney很火的时候,就想写,因为经常被刷屏,但那会时间错不开 去年11月底ChatGPT出来后,我今年1月初开始写ChatGPT背后的技术原理,而今年2月份

    2024年02月08日
    浏览(14)
  • Stable Diffusion系列课程上:安装、提示词入门、常用模型(checkpoint、embedding、LORA)、放大算法、局部重绘、常用插件

    Stable Diffusion系列课程上:安装、提示词入门、常用模型(checkpoint、embedding、LORA)、放大算法、局部重绘、常用插件

    AUTOMATIC1111/stable-diffusion-webui 参考B站Nenly视频《零基础学会Stable Diffusion》、视频课件 推荐网站:stable-diffusion-art、Civitai(魔法) 、libilibi、AI艺术天堂 推荐Stable Diffusion整合资料: NovelAI资源整合、《AI绘图指南wiki》、AiDraw绘画手册 重 绘学派法术绪论1.2、 Stable Diffusion 潜工具

    2024年02月15日
    浏览(8)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包