图像数据集构建工具

LatentForge是一个交互式CLI工具,用于构建高质量图像数据集,支持Flux LoRA微调,通过自然语言对话实现搜索、下载、组织和标注图像。

  • by utensils
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 utensils/latentforge

使用说明

潜在遗忘

用于构建高质量图像数据集的交互式CLI 通量 LoRA微调,由 Claude代理SDK.

告诉代理你想要一个数据集做什么——它通过自然语言对话搜索、下载、组织、整理、消除重复、调整大小和为图像添加标题。

快速开始

直接运行(无需安装)

# With Nix
nix run github:utensils/latentforge

# With uv
uvx latentforge

安装

# With uv
uv tool install latentforge

# Run
latentforge                              # interactive — no config
latentforge --config configs/ghibli.yaml  # with a dataset config

发展

nix develop     # enters devshell with latentforge, ruff, pyright, gallery-dl, uv
latentforge     # run the agent
nix fmt         # format nix + python files

运作原理

latentforge → launches an interactive Claude agent
  → 22 custom MCP tools for image operations
  → Built-in vision to examine images
  → You chat to guide: "build me a dataset for X", "curate the logos", etc.

示例会话

> I want a dataset for Studio Ghibli art styles

  [tool: create_config]
  Created config: configs/ghibli.yaml with 5 categories

> Search for movie poster art and download them

  [tool: search_bing]
  Found 18 image URLs for 'Studio Ghibli movie poster art'
  [tool: download_images]
  Download complete: 15 saved, 2 skipped (dup), 1 failed

> Find duplicates and show me quality stats

  [tool: find_duplicates]
  Found 2 duplicate pairs (threshold=8)
  [tool: analyze_quality]
  Total: 15 images, avg 1340x1020, 12 at 1024+

工具

整个数据集工作流程中有22个自定义MCP工具:

类别 工具
配置 create_config, read_config, update_config, list_configs
搜索 search_bing, search_wikimedia
下载 download_images (MD5去噪), download_gallery (画廊dl,80多个网站)
浏览 list_images, get_image_info
组织 move_images, organize_images
质量 analyze_quality, find_duplicates, detect_screenshots
裁剪 crop_center, crop_smart, crop_faces
面孔 detect_faces
训练 resize_images, write_caption
出口 export_dataset (ai工具包格式)

该代理还具有内置 Read (具有观看图像的视觉), Write,以及 Bash 工具。

斜杠命令

在会话期间键入以下内容:

命令 描述
/help 显示可用命令
/config 显示活动数据集配置
/tools 列出所有代理工具
/cost 显示会话成本
/status 会话状态和上下文使用情况
/model <name> 切换克劳德模型(分叉会话)
/export [path] 将数据集导出为ai工具包格式
/compact 紧凑的背景(总结+新会议)
/quit 退出

数据集配置

每个数据集都是一个YAML文件 configs/。代理可以为您创建这些,或者您可以手写它们:

name: ghibli
subject: "Studio Ghibli"
trigger_word: "ghibli_style"
output_dir: ./datasets/ghibli
search_queries:
  posters:
    - "Studio Ghibli movie poster art"
    - "Spirited Away poster"
  backgrounds:
    - "Studio Ghibli background art landscape"
categories:
  posters: "Movie poster art"
  backgrounds: "Background paintings and landscapes"
curation:
  target_count: "50-150"
  min_resolution: 512
  training_resolution: 1024

数据集结构

数据集存储在 datasets/<name>/ 带有类别子目录:

datasets/
└── ghibli/
    ├── posters/
    │   ├── studio_ghibli_movie_poster_a1b2c3d4e5f6.jpg
    │   ├── studio_ghibli_movie_poster_a1b2c3d4e5f6.txt
    │   └── ...
    └── backgrounds/
        ├── ghibli_background_art_7g8h9i0j1k2l.png
        └── ...

图像遵循命名模式 {query_prefix}_{md5_hash}.{ext} --MD5哈希确保了跨运行的重复数据消除。

工作流程

  1. 配置 --创建一个YAML配置(或要求代理创建一个)
  2. 收集 --搜索Bing/维基媒体并使用MD5去重下载
  3. 组织 --使用文件名前缀按类别自动排序
  4. 策划 --Agent查看图像并帮助拒绝低质量的图像
  5. 去重 --感知哈希检测发现近似重复项
  6. 调整大小 --批量调整到训练分辨率(默认1024x1024)
  7. 字幕 --写 .txt 每张图片旁边都有带触发词的标题
  8. 出口 --使用自动生成的训练配置导出为ai工具包格式
  9. 火车 --使用 ai工具包, kohya ss/sd脚本,或类似

认证

设置以下选项之一:

  • ANTHROPIC_API_KEY -无烟煤API键
  • CLAUDE_CODE_OAUTH_TOKEN -OAuth令牌(当不存在API密钥时使用)

许可证

麻省理工学院