{"id":18439174,"url":"https://github.com/wsh032/image-deduplicate-cluster-webui","last_synced_at":"2025-04-07T21:32:14.164Z","repository":{"id":171976208,"uuid":"648642959","full_name":"WSH032/image-deduplicate-cluster-webui","owner":"WSH032","description":"A WebUI script that deduplicates images or clusters them by tags or WD14.  一个用于图像查重和基于tags或者WD14提取的特征进行聚类的WebUI脚本","archived":false,"fork":false,"pushed_at":"2023-08-08T13:44:04.000Z","size":15365,"stargazers_count":12,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T01:01:39.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WSH032.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-02T12:59:44.000Z","updated_at":"2025-03-15T11:49:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"dda2c79e-c0c6-40e0-b203-7455116a0b8d","html_url":"https://github.com/WSH032/image-deduplicate-cluster-webui","commit_stats":null,"previous_names":["wsh032/image-deduplicate-cluster-webui"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WSH032%2Fimage-deduplicate-cluster-webui","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WSH032%2Fimage-deduplicate-cluster-webui/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WSH032%2Fimage-deduplicate-cluster-webui/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WSH032%2Fimage-deduplicate-cluster-webui/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WSH032","download_url":"https://codeload.github.com/WSH032/image-deduplicate-cluster-webui/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247732659,"owners_count":20986898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T06:23:38.944Z","updated_at":"2025-04-07T21:32:14.145Z","avatar_url":"https://github.com/WSH032.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# image-deduplicate-cluster-webui\n A `A1111-WebUI` extension for deduplicates images or cluster images. \n\n 一个用于图像查重和图片聚类的 `A1111-WebUI` 扩展\n\n## 现在我们有什么？\n - 基于imagededup库，进行图片去重的WebUI\n - 基于sklearn库，以tags文本为特征，或者以WD14 tagger模型提取的特征向量进行图片聚类WebUI\n - 高效的 WD14 图片标记脚本及WebUI\n\n## 部分展示\n### 查重演示\n\n\u003cdetails\u003e\n\u003csummary\u003e旧版查重演示\u003c/summary\u003e\n\n![deduplicate_demo](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/093198c5-89b3-4f88-8ccc-4412e662cf35)\n\n\u003c/details\u003e\n\n![deduplicate_demo](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/fc1774cd-c705-4e6b-b4cd-07ccd543e2dc)\n\n### 聚类演示\n![images_cluster_show_0](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/213b1370-80b5-4c41-8e49-0c8003acbd62)\n\n### WD14-Tagger 演示\n![wd14_show_1](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/29b52bf7-316d-4bb6-850d-e40e1caa3afc)\n\n### 其他\n**另一张复杂情况的8聚类效果请看[这里`images_cluster_show_1`](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/1b7ecffb-14a8-492c-a629-e4d93850e54c)**\n\n[聚类-Tagger说明 `title_show`](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/4dab7fcf-3048-4cce-8441-347d8a3c2a68)\n\n## Credit\n - 我不训练模型，WD14模型来自于这个项目[SmilingWolf/WD14](https://huggingface.co/SmilingWolf)\n - 聚类方法和特征提取来着于sklearn库\n - 查重方法来自于imagededup库\n - tag_images_by_wd14_tagger来自[kohya/sd-scripts](https://github.com/kohya-ss/sd-scripts/blob/main/finetune/tag_images_by_wd14_tagger.py)\n\n## Change History\n如果你不会使用git命令，可以运行`update.ps1`完成更新，并再次运行`install.ps1`来更新依赖环境\n\n### V 2.0.1\n05 Aug.2023 2023/08/05\n#### Other Changes:\n - 为解决做为 `SD-WebUI` 扩展运行时潜在的包名冲突问题，重命名 `./ui` -\u003e `./img_dedup_clust`\n\n### V 2.0.0\n01 Aug.2023 2023/08/01\n#### New Features:\n- **[破坏性]** 大更新，优化并调整几乎全部WebUI部分代码结构、组织\n  - ~~所有ui界面和几乎所有后端函数被移至 `./ui` 文件夹下~~\n    - 在V 2.0.1 被更名为 `./ui` -\u003e `./img_dedup_clust`\n- 为聚类增加更多参数\n  - 支持自定义的 `tag文件`、`npz矩阵文件` 扩展名选择\n  - 增加SVD降维功能\n  - 聚类分析中增加样本分布可视化图，帮助确认n值\n  - wd14聚类支持更多参数\n    - 可选择 `压缩层` 或 `全向量` 层做为特征向量\n\t- 在 `全向量` 模式下，可以自定义选择部分类别特征\n\t  - 您可以在[https://huggingface.co/WSH032/wd-v1-4-tagger-feature-extractor/blob/main/wd14_tags.toml](https://huggingface.co/WSH032/wd-v1-4-tagger-feature-extractor/blob/main/wd14_tags.toml)查看各个标签种类所包含的tags\n\t  - `rating` 依据 nsfw 进行聚类\n\t  - `general` 依据图片标签tag进行聚类\n\t  - `characters` 依据booru上已知的角色tag进行聚类\n- 为查重增加更多参数\n  - 增加 `js` 的支持\n    - 可通过键盘快捷键 `Enter` 和 `Backspace` 来进行选择和取消\n  - 支持 `CNN模型` 查重\n    - 如果有GPU的支持，CNN模型查重将会比原来的 `Hash查重` 更快\n  - 增加查重阈值设置\n  - 查重结果新增 `移动`，`重命名` 选项\n    - 现在查重结果的操作将采用和聚类一样的操作方式\n\t- 增加附带文件处理功能，可以一起 `移动`，`重命名`，`删除` 附带文件\n- 重构 `WD14-tagger` 的 `tag_images_by_wd14_tagger` 为类\n  - 将直接下载huggingface上编译好的onnx模型，不再进行编译\n  - 删除 `tensorflow`, `onnx`, `tf2onnx` 等和编译模型有关的部分\n  - 增加离线模式选项\n  - 增加 `wd-v1-4-convnextv2-tagger-v2` 模型\n    - 除此，还有先前的 `wd-v1-4-moat-tagger-v2` 模型可以选择\n  - 暂时弃用并删除命令行WD14-tagger脚本 `run_tagger.ps1`\n    - 可能会在未来回归\n- 不再支持只安装部分模块，默认安装全部依赖\n#### Other Changes:\n- 优化UI显示\n- A1111-WebUI中现在`聚类-WD14`和`查重`被分为两个选项卡\n  - `聚类-WD14` 对应 `Cluster-Tagger`\n  - `查重` 对应 `Deduplicate`\n- 删除 `./docs` 中所有展示图片，更换为 `github/assets` 链接以减小仓库体积\n  - 使用 `git clone --depth=1` 时，将不再下载多余图片，以方便快速克隆\n- 调整部分logging日志等级\n- 在使用WD14-Tagger时，对于重名但扩展名不同的图片，其的标签文本将会被相互覆盖，此时会发出警告\n#### Bug Fixes:\n- 为所有后端函数添加异常处理装饰器，以避免未知错误造成 A1111-WebUI 中永久无返回结果\n- 当缓存图片失败时，将自动退回到原图模式\n- 修正特征重要性分析算法中的错误\n  - 现在，在某个聚类结果中，只有某个特征tag占比超过或低于设置的阈值时，才会被判断为 `prompt` 和 `negetive`\n\n\n### 以前的更新内容请查看[CHANGELOG.md](CHANGELOG.md)\n\n## 安装 Install\n\n### Colab使用\n[![](https://img.shields.io/static/v1?message=Open%20in%20Colab\u0026logo=googlecolab\u0026labelColor=5c5c5c\u0026color=0f80c1\u0026label=%20\u0026style=flat)](https://colab.research.google.com/github/WSH032/sd-webui-fast-dataset-maker/blob/main/fast_dataset_maker.ipynb)\n\n### （一）做为[AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui)的扩展使用\n\n**请尽量在`gradio\u003e=3.31.0`的版本下使用，此扩展在 2023年第22周 [`SD-WebUI v1.3.1`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/b6af0a3809ea869fb180633f9affcae4b199ffcf)下经过测试**\n\n`https://github.com/WSH032/kohya-config-webui.git`\n\n将这个仓库连接复制到SD-WebUi的`扩展 extensions`-\u003e`从网址安装 Install from URL`界面下载完成后，**重启SD-WebUI**即可，会自动安装所需依赖\n\n - 中国区用户可尝试用`https://ghproxy.com/https://github.com/WSH032/kohya-config-webui.git`代理加速下载\n - 在SD-WebUI中使用本扩展的`WD14tagger`功能时，若出现**模型下载失败**情况，可以按照本扩展WebUI内的指示从`https://huggingface.co/WSH032/wd-v1-4-tagger-feature-extractor`手动下载模型并放入WebUI内指定的文件夹中\n - tensorrt自动增量脚本[utils/run_install_tensorrt_lib.ps1](utils/run_install_tensorrt_lib.ps1)在此仓库做为扩展使用时不被支持，但你仍可以自行手动安装tensorrt环境来使用加速功能\n![Install-SD-WebUI-extension](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/0b5d628f-91f4-471f-bf0f-e56965193446)\n\n #### 关于依赖环境\n 做为SD-WebUI扩展使用时，会**自动安装和使用SD-WebUI的依赖环境**，**本项目的三个模块都会被安装**,不需要任何操作\n\n 首次安装时，中国区用户可能会因网络原因安装较久，请耐心等待\n\n### （二）独立使用\n \u003cblockquote\u003e \n\n**[2323/07/04] 在独立使用时，强烈建议使用此整合项目[WSH032/sd-webui-fast-dataset-maker](https://github.com/WSH032/sd-webui-fast-dataset-maker)，以获得更好的体验**\n\n图示为整合了[zanllp/sd-webui-infinite-image-browsing](https://github.com/zanllp/sd-webui-infinite-image-browsing)\n![sd-webui-infinite-image-browsing](https://github.com/WSH032/sd-webui-fast-dataset-maker/assets/126865849/b98a293f-a3a0-4d59-a997-cae86e7f25b4)\n\n \u003c/blockquote\u003e \n\n**在python3.9下完成编写，可能之前版本也可以使用，不保证**\n\n克隆本仓库\n```shell\ngit clone https://github.com/WSH032/image-deduplicate-cluster-webui.git  # --depth=1\n```\n\n每个模块所需的依赖已经写在[requirements.txt](requirements.txt)\n\n**一键运行`install.ps1`即可**\n\n\u003cdetails\u003e\n\u003csummary\u003e旧版 \u003ccode\u003einstall.ps1\u003c/code\u003e 界面\u003c/summary\u003e\n\n![install](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/eacb082e-55e1-40c6-b5a4-cea1a6a202fb)\n\n\u003c/details\u003e\n\n![install](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/bf421b54-5547-4426-a018-03b46199cfb6)\n\n### 关于 `Torch` 和 `CUDA` 环境\n`requirements.txt`中并没指定 `Torch` 的版本，请根据你的需求自行决定并修改\n\u003e 推荐安装带有cuda依赖的torch版本\n\u003e ```shell\n\u003e torch==2.0.0+cu118  --extra-index-url https://download.pytorch.org/whl/cu118\n\u003e ```\n\n涉及到深度学习模型的部分，可以进行CPU或者GPU的推理，其中GPU的推理速度快，但是要求 `CUDA` 环境\n\n运行`install.ps1`时会提问你是否需要安装 `Torch==2.0.0 + cuda118`，其能够在虚拟环境中配置 `CUDA` 环境\n\n如果你配置过系统级的 `CUDA` 环境，或者你不需要使用GPU进行推理，可以选择否\n\n### 关于WD14模型下载失败\n请按照本项目 `Tagger` WebUI 中的 `模型下载说明` 选项卡指示进行操作\n![model_download_info](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/93221e33-06bf-49ff-97d9-c712a362776d)\n\n## 使用Tips\n### SD-WebUI内使用演示\n与独立使用方法相同\n - [SD-WebUI 查重演示](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/a4ad9926-8ee4-47d9-9f5a-bd2a3515563f)\n - [SD-WebUI 聚类演示](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/f62fb1a6-88a6-4aad-8071-16b2f22dd248)\n - [SD-WebUI WD14演示](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/0dc9ed5e-8d6b-4f3c-b383-620ceaf7d715)\n\n### 图片查重\n图片查重不依赖任何tag文本或者WD14模型\n\n一键运行`run_deduplicate_images.ps1`，或在 `A1111-WebUI` 中以扩展形式使用，其将会生成一个WebUI，进行操作即可\n\n![deduplicate_tips](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/fb37e242-ecc2-4847-99e0-433e775951c3)\n\n ![deduplicate_demo](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/fc1774cd-c705-4e6b-b4cd-07ccd543e2dc)\n\n\n### 图片聚类\n一键运行`run_cluster_images.ps1`，或在 `A1111-WebUI` 中以扩展形式使用，其将会生成一个WebUI，进行操作即可\n\n图片聚类依赖与图片同名的 `txt文本` **或者** `npz文件` 进行聚类，这取决于你在WebUI中选择的特征提取方式\n\n![vectorize_method](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/b0f81098-3de0-4924-88cd-9e8f673f32f1)\n\n#### 选择 `tf-idf` 或者 `countvectorizer` 提取特征，则需要 `txt文本`\n其中txt内容为与图片对应的booru风格的tag标签，例如\n`1girl, solo, yellow eyes`\n\n![image_with_tag](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/499e7e19-4eb2-4bd3-8337-0cb9168faa76)\n\n#### `wd14` 提取特征，则需要 `npz文件`\n其中 `npz文件` 储存着WD14模型提取的特征向量矩阵，其的生成**必须**使用本项目自带的 `tag_images_by_wd14_tagger.py` ，或者在 `WD14-Tagger` WebUI中生成\n\n\n![image_witg_npz](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/a83eb86c-709d-416f-826f-eb6478f60de7)\n\n### WD14 tagger\n本项目自带的WD14 tagger模型来自于[SmilingWolf/WD14](https://huggingface.co/SmilingWolf)，我对其结构进行了调整，增加了后四层的输出，并采取倒数第三层做为特征向量\n\n你可以使用`tag_images_by_wd14_tagger.py`进行图片打标，获取txt文本，这与[toriato/stable-diffusion-webui-wd14-tagger](https://github.com/toriato/stable-diffusion-webui-wd14-tagger)的打标结果并无太大差异\n\n\n同时其会输出同名的npz文件，其中包含了WD14模型的倒数前四层的输出，你可以在聚类模块中使用\n\n~~[run_tagger](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/9681a7d1-b66e-4ac2-a47e-dc443145cd90)~~(弃用)\n\n**2023/06/6，新增WD14的WebUI界面**\n\n![wd14_show_1](https://github.com/WSH032/image-deduplicate-cluster-webui/assets/126865849/ff6ef49c-e5a4-4cc7-b5c7-24357e4ffa83)\n\n## Todo\n\n- [x] 在Colab上部署\n- [x] 完成本地部署封装\n- [x] 完成A111-SD-WebUI部署\n- [x] 增加WD14提取特征和生成tags文本\n\t- [x] 使用WD14生成特征向量到npz文件，避免多次聚类时重复运行耗时\n\t- [x] 增加释放模型功能\n\t- [x] 增加使用倒数第三层模型\n- 聚类\n\t- [x] 为图片聚类增加SVD降维\n\t- ~~[ ] 增加tags文本字符串预处理（如将空格变为逗号）~~\n\t  - 已经取消，因为Gelbooru-API-Downloader已经自带了这个功能\n\t- [ ] 为聚类文件夹增加标签\n\t- [x] 修正特征重要性分析的标签错误(应用占比50判断)\n\t- [ ] 增加手动选择是否应用某个聚类的功能\n\t- [x] 增加更多分析方法\n\t  - 现在有轮廓系数和Davids系数\n\t- [x] 更多聚类方式\n\t  - 现在有kmeans，谱聚类、层次聚类，OPTICS聚类\n\t  - [ ] 为不同聚类方式增加参数选择功能\n\t  - ~~[ ] 将聚类方法选择独立出来~~\n\t    - 已经取消,因为使用npz文件后，读取特征向量已经很快了\n- 查重\n\t- [x] 为查重添加选择全部选项\n\t- [x] 为查重添加更多查重方式和查重阈值\n\t- [x] 重写查重启发式选择算法\n\t- [x] 为查重添加移动图片功能\n\t- [x] 为查重删除添加删除tag文本功能\n\n## 结尾\n\n **考虑使用onnx加载模型，两个方案**\n  - [x] 先把keras模型下载，调整输出后再本地导出onnx格式\n  - ~~[ ] 直接下载onnx模型，用onnx库来调输出层~~（似乎层不一样）\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsh032%2Fimage-deduplicate-cluster-webui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwsh032%2Fimage-deduplicate-cluster-webui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsh032%2Fimage-deduplicate-cluster-webui/lists"}