NewEden/CivitAI-SD-Prompts
收藏资源简介:
--- license: apache-2.0 language: - en pretty_name: CivitAI SD Prompts --- # CivitAI SD Prompts Dataset is a collection of both synthetic and organic descriptions of images with prompts for Stable Diffusion series of models associated to them. It works best with SDXL, but should probably work with others too. ## Synthetic part "Synthetic" means that the end result of the sample (SD prompt) was produced by a large language model (Claude Opus). Select characters from CharGen v2 datasets were used as prompts for Claude Opus to generate their appearance and then, in another run, make an SD prompt out of that appearance. ## Organic part "Organic" means that the prompts are taken from actual SD-generated images metadata and then filtered/processed. Initial set of images was obtained from CivitAI, filtered by originating from a SDXL-derived model with NSFW filter on, and having both width and height over 1024 pixels. Every image was passed through a multimodal language model (CogVLM, LLaVA 1.6/Next, Claude Opus) to create a textual representation of the image. Then, from such textual representation, a prompt for [CharGen v2](https://huggingface.co/kubernetes-bad/chargen-v2) was created and a full character was generated. Based on this prompt and the image, Claude Opus Vision was used to describe the character. ## Image deduplication Initial scrape of CivitAI had 742,021 images in it. This includes all the images for all SDXL-based models as of February 2024, except for original SDXL itself - that model has more than 2M images, so to keep the dataset balanced, only around 70k images were included - which matches counts for other SDXL-based models on CivitAI. These images were mostly very similar generations with just minor tweaks to the prompt - or just re-generations with no prompt change, and since it's the prompts is what we're after - these images needed to be deduplicated. To deduplicate images, they were grouped by author (assumption that most authors write prompts from scratch) and then each authors' image prompts were passed through Diff-Match-Patch library with each of the other author's images. Image was considered to be unique if there were no other images with not more than 5 sequential words repeat in the prompt. At this same step, images with prompts shorter than 80 characters were discarded. Resulting set was 66,374 images. ## Portraits In the scope of this project, only the "portrait" images are relevant, since we're trying to make character portraits. For this use case, a portrait is a picture that is taller than it is wider and that has exactly 1 human face in it. To detect number of faces in the picture, `retinaface` library was used. Result of this step was 33,827 images. ## Vision model Each image was passed to a vision language model (mix of CogVLM, LLaVA1.6 (Llava-Next) and Claude Opus Vision) to generate a character-like representation of the person in the image. LLaVA has internal resolutions of just 336x672 (1:2 aspect ratio), 672x672 (square aspect ratio) and 336x1008 (1:3 aspect ratio). When an image is not conforming to these aspect raios, it is either naively cropped, or padded. Most of SDXL-generated images aren't 1:2 or square, so most of them had potential of being cropped wrong, hindering vision results. To overcome this, all images that weren't 1:2 or square were resized to square with a smart crop algorithm set called [smartcrop.js](https://github.com/jwagner/smartcrop.js). Similar technique was used for CogVLM and Claude Opus, just with different aspect ratios and resolutions. ## Prompt adherence To select the images with best prompt-to-image correspondence, two methods were incorporated: 1. CLIP model was used ([openai/clip-vit-large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336)) to create embeddings for both images and character appearance. Then, the embedding pair elements were compared with each other using cosine similarity. 2. Keywords were extracted from characters' appearances and, along with whole SD prompt, passed into [Salesforce/SFR-Embedding-2_R](https://huggingface.co/Salesforce/SFR-Embedding-2_R) for embedding. Then these embedding pairs were also compared. Samples were scored by sum of both scores and around top 30% were picked as the final set. Empirically, it was established that prompt adherence becomes pretty low under around selected threshold.
许可证:Apache-2.0 语言:英语 规范名称:CivitAI SD提示词 # CivitAI SD提示词数据集 本数据集收录了各类图像的合成与原生描述文本,以及与之匹配的稳定扩散(Stable Diffusion)系列模型专用提示词。 该数据集适配SDXL模型效果最佳,理论上也可兼容其他同系列模型。 ## 合成数据部分 “合成数据”指样本的最终输出(SD提示词)由大语言模型(Large Language Model,LLM)Claude Opus生成。 研究团队从CharGen v2数据集中选取部分角色作为Claude Opus的输入提示,先生成角色外观描述,随后在第二轮处理中将该外观描述转换为SD提示词。 ## 原生数据部分 “原生数据”指提示词源自实际SD生成图像的元数据,经筛选与预处理后得到的数据集。 初始图像集采集自CivitAI平台,筛选条件为:由基于SDXL的模型生成、开启NSFW过滤、图像宽高均超过1024像素。 对每张图像,使用多模态大语言模型(CogVLM、LLaVA 1.6/Next、Claude Opus)生成图像的文本描述。 基于该文本描述,生成适配[CharGen v2](https://huggingface.co/kubernetes-bad/chargen-v2)的提示词,并完整生成对应角色。 结合该提示词与原始图像,使用Claude Opus Vision对角色进行描述。 ## 图像去重 初始爬取的CivitAI图像共计742,021张,涵盖2024年2月前所有基于SDXL的模型生成的图像(原始SDXL模型除外——该模型生成图像超200万张,为平衡数据集规模,仅纳入约7万张图像,与CivitAI平台上其他基于SDXL的模型的图像数量相匹配)。 这批图像大多为提示词仅微调或完全未修改的重复生成结果,而我们的目标是获取高质量提示词,因此需要对图像进行去重处理。 去重流程为:先按作者分组(假设多数作者会自主编写提示词),随后使用Diff-Match-Patch库比对每位作者的图像提示词与其他作者的图像提示词。若两张图像的提示词中连续重复单词数未超过5个,则判定该图像为唯一样本。 同时,本步骤会过滤掉提示词长度不足80个字符的图像。 最终去重后得到66,374张图像。 ## 肖像筛选 本项目仅关注“肖像”类图像,因我们的目标是生成角色肖像。 本项目定义的肖像需满足:图像高度大于宽度,且仅包含一张人脸。 使用retinaface库检测图像中的人脸数量。 经此步骤筛选后,最终得到33,827张图像。 ## 视觉模型适配 将每张图像送入视觉语言模型(混合使用CogVLM、LLaVA 1.6(Llava-Next)与Claude Opus Vision),以生成图像中人物的角色化文本描述。 LLaVA支持的固有分辨率比例为1:2(336×672)、1:1(672×672)与1:3(336×1008)。 若图像比例不符合上述规格,将采用简单裁剪或填充的方式进行适配。多数SDXL生成的图像比例不符合要求,因此直接裁剪可能导致适配错误,影响视觉模型的处理效果。 为解决该问题,所有非1:2或1:1比例的图像将通过[smartcrop.js](https://github.com/jwagner/smartcrop.js)提供的智能裁剪算法调整为正方形。 CogVLM与Claude Opus也采用了类似的适配策略,仅适配的分辨率与比例参数有所不同。 ## 提示词匹配度评估 为筛选出提示词与图像对应性最佳的样本,研究团队采用了两种评估方法: 1. 使用CLIP(Contrastive Language-Image Pre-training)模型([openai/clip-vit-large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336))分别为图像与角色外观描述生成嵌入向量,随后通过余弦相似度比对两组嵌入向量的相似性。 2. 从角色外观描述中提取关键词,结合完整SD提示词送入[SALESFORCE/SFR-Embedding-2_R](https://huggingface.co/Salesforce/SFR-Embedding-2_R)生成嵌入向量,同样通过余弦相似度进行比对。 样本最终得分由两种方法的得分相加得到,选取得分排名前30%的样本作为最终数据集。经实验验证,低于该阈值的样本的提示词匹配度会显著下降。



