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

news2024/10/6 22:30:08

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

Function

图像反推 (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:类似图像的分类;

即:
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 的输出。

即:

Config

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)损失,来生成给定图像的字幕。

BLIP

安装遇到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

测试图像:

Img

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/772365.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Linux--crontab命令详解--循环执行的计划任务

Linux–crontab命令详解–循环执行的计划任务 文章目录 Linux--crontab命令详解--循环执行的计划任务一、用户设置二、crontab三、/etc/crontab,/et/cron.d/*总结 一、用户设置 循环执行任务是由cron(crond)这个系统服务来控制的。用户想要建立循环的计划任务时,使用的是cront…

TypeScript 1 - 小记

文章目录 关于 TypeScript 关于 TypeScript TypeScript is a superset of JavaScript that compiles to clean JavaScript output. 官网:https://www.typescriptlang.orggithub : https://github.com/microsoft/TypeScriptplayground : https://www.typescriptlan…

Alibaba Cloud Toolkit部署操作

一、后端部署: 第一步 第二步: 第三步: 二、前端部署 第一步: 第二步: 第三步:

学会项目成本管理计算,PMP计算题就是送分题

学会项目成本管理计算&#xff0c;PMP计算题就是送分题 PMP中的计算主要在 <项目成本管理> 的控制成本部分&#xff0c;服务于挣值管理&#xff08;EVM&#xff0c;Earned Value Management&#xff09;、挣值分析&#xff08;EVA&#xff0c;Earned Value Analysis&…

【0】冒泡排序

前言 通过函数模板技术设计一个冒泡排序算法&#xff0c;领悟泛型编程的思想和冒泡排序的思想&#xff0c;然后使用QTest测试各种输入值&#xff0c;养成先写测试代码&#xff0c;后写程序代码的习惯 0x0 编写一个int版本的冒泡函数 1.不管要排序的数组长度多长&#xff0c;外…

Postman如何设置成中文?(汉化)

1. 点击下方这个链接&#xff0c;进入gitee&#xff0c;在里面下载一个插件 Releases hlmd/Postman-cn GitHub 进入之后是这个样子的&#xff1a; 2.看一下自己的postman是什么版本的&#xff0c;然后在gitee下载对应的APP包&#xff08;注意&#xff1a;是App.zit包。不要下…

中金:龙湖基本面稳健,股价超跌具备配置价值

恒大2.4万亿元的天量债务爆出后&#xff0c;让本就信心不足的房地产行业&#xff0c;越发雪上加霜&#xff0c;房企股价遭遇集体下挫&#xff0c;业内公认的万科、龙湖、保利、中海等“优等生”也不免被波及。多家证券机构提醒&#xff0c;行业预期降至冰点的情况下&#xff0c…

【精华】maven 生命周期 + 依赖传递+ scope【依赖范围】 + 排除依赖 可选依赖

目录 一 . lifecycle 生命周期 二. 依赖 与 依赖传递 三. scope 依赖范围 scope指定依赖范围 依赖传递依赖与原依赖冲突 四 maven的可选依赖与排除依赖 可选依赖 全部 排除依赖 显式的指定 maven官网技术文档&#xff1a; 一 . lifecycle 生命周期 * clean&…

java密码强度校验

一、代码 Testpublic void test(){//包含数字、大小写字母&#xff0c;长度10-20位 String regular "^(?.*\\d)(?.*[a-z])(?.*[A-Z]).{10,20}$";String example1 "1234567891";System.out.println(example1.matches(regular)); //falseString exa…

Python numpy求均值、保留几位小数

import numpy as nplist_test [0.21, 0.32]print(f{np.mean(list_test):.2f}) #保留两位小数 print(f{np.mean(list_test):.3f}) #保留三位小数

从输入URL到页面呈现

1、url解析 1、1地址解析 http和tcp的关系 tcp&#xff1a;传输通道http&#xff1a;传输协议https&#xff1a;比http多了ssl或者tsl&#xff08;证书验证&#xff09;ftp&#xff1a;大文件传输 客户端与服务器直接传送数据&#xff0c;http相当于快递小哥&#xff0c;tcp…

openGauss学习笔记-12 openGauss 简单数据管理-UPDATE语句

文章目录 openGauss学习笔记-12 openGauss 简单数据管理-UPDATE语句12.1 语法格式12.2 参数说明12.3 示例 openGauss学习笔记-12 openGauss 简单数据管理-UPDATE语句 修改已经存储在数据库中数据的行为叫做更新。用户可以更新单独一行&#xff0c;所有行或者指定的部分行。还可…

【自动化测试验证码处理】如何跳过验证码,直接自动登录呢?

在日常的测试过程中避免不了要遇到登录的测试&#xff0c;但是在登录时又常常遇到验证码&#xff0c;那么该如何跳过验证码&#xff0c;直接自动登录呢&#xff1f; 当前在市面上比较流行的方式有&#xff1a; &#xff08;1&#xff09;直接跳过验证码&#xff08;测试环境中…

快7月底了,让我康康有多少准备跳槽的

前两天跟朋友感慨&#xff0c;今年的铜三铁四、裁员、疫情影响导致好多人都没拿到offer!现在已经快7月底了&#xff0c;具体金九银十只剩下2个月。 对于想跳槽的职场人来说&#xff0c;绝对要从现在开始做准备了。这时候&#xff0c;很多高薪技术岗、管理岗的缺口和市场需求也…

Principle Component Analysis

简述PCA的计算过程 输入:数据集X={x1,x2,...,xn},需降到k维 ① 去中心化(去均值,即每个特征减去各自的均值) ② 计算协方差矩阵1/nX*X^T(1/n不影响特征向量) ③ 用特征值分解方法/SVD奇异值分解求解②协方差矩阵的特征值与特征向量 ④ 对特征值从大到小排序,选…

websocket发布到iis之后无法创建连接访问

在做websocket测试时在本地的服务可以正常访问&#xff0c;在调试成功之后发布到了iis中&#xff0c;发现无法连接&#xff0c;这时可能有以下几个原因。 WebSocket无法连接到IIS&#xff1a; IIS版本不支持WebSocket&#xff1a;IIS 8.0及更高版本才支持WebSocket&#xff0…

广西学子复读15年,不服从分配。网友:完全是浪费时间

广西学子复读15年&#xff0c;不服从分配。网友&#xff1a;完全是浪费时间 唐尚珺的复读行为引起了网友们的不同解读。有人认为他是一个执念深重的人&#xff0c;目标是考上清华北大&#xff0c;但这个说法是否真实&#xff0c;我们无法确定。无论如何&#xff0c;我们必须认识…

ThinkBook 14 G2-ARE(20VF)原厂Win10系统镜像

lenovo联想笔记本电脑ThinkBook 14 G2-ARE原装出厂系统(20VF)Windows10预装OEM系统 自带所有驱动、出厂主题壁纸LOGO、Office办公软件、联想电脑管家等预装程序 所需要工具&#xff1a;16G或以上的U盘 文件格式&#xff1a;ISO 文件大小&#xff1a;10.26GB 注&#x…

知识图谱推理的学习逻辑规则(上)

知识图谱推理的学习逻辑规则 摘要介绍相关工作模型知识图谱推理逻辑规则概率形式化参数化优化 实验实验设置实验结果 结论 原文&#xff1a; 摘要 本文研究了在知识图谱上进行推理的学习逻辑规则。 逻辑规则用于预测时提供了可解释性并且可以推广到其他任务中&#xff0c;因…

抖音矩阵系统源码:开发搭建与技术详解

一、 抖音矩阵系统源码开发概述 抖音短视频seo矩阵系统源码是一款在高速数据处理和分析方面表现卓越的系统。它结合了各种先进的技术&#xff0c;包括深度学习、大数据分析和可视化等&#xff0c;使得抖音在信息处理时更加高效和准确。 该系统源码的开发搭建需要多方面的技术支…