Utilities and scripts to build high‑quality image–caption datasets. This repo covers:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
# Extras used by various scripts:
pip install google-generativeai openai python-dotenv tqdm torch qwen-vl-utils ollama lmstudio
Notes:
pip install torch fails.Create a .env file in the repo root with your Gemini API key:
GEMINI_API_KEY=your_key_here
Scripts that call Gemini use either:
google.generativeai directly, oropenai client with base_url=https://generativelanguage.googleapis.com/v1beta/openai/{basename}.txt.p_{basename}.txt.cleaned/ subfolder with *_c.txt filenames.batch_*.txt and raw_response_batch_*.json, then moves them to results/.descriptions/ and prompts/ subfolders and logs to zero_processed_files.txt.tools/find_solo.py can move unpaired files to unpaired/.image_captions_gemini_1shotSingle.py (Gemini API)image_captions_florence.py (HF: Florence-2-Flux-Large)image_captions_moondream.py (HF: moondream2)image_captions_qwen25vl_cuda.py (HF: Qwen2-VL; CUDA)image_captions_qwen25vl_lmstudio.py (LM Studio; Qwen2.5-VL 7B instruct)caption_cleanup_gemini.py (general cleanup)caption_cleanup_gemini_pass2.py (optional second pass; removes depth/palette/atmosphere sentences)caption_cleanup_gemini.py
*.txt in a folder, cleans with Gemini via OpenAI-compatible client.cleaned/{name}_c.txt. Skips non-empty existing outputs.caption_cleanup_gemini_pass2.py
cleaned/{name}_c.txt.Usage (both):
python caption_cleanup_gemini.py
python caption_cleanup_gemini_pass2.py
image_captions_gemini_1shotSingle.py
p_{basename}.txt.image_captions_florence.py
gokaygokay/Florence-2-Flux-Large. Device auto-detect (CUDA/MPS/CPU).{basename}.txt. Removes common starters using tools.caption_starters.clean_caption().image_captions_moondream.py
vikhyatk/moondream2 (revision 2024-08-26). Device auto-detect.{basename}.txt. Removes common starters.image_captions_qwen25vl_cuda.py
Qwen/Qwen2-VL-7B-Instruct with qwen_vl_utils. CUDA required.{basename}.txt. Cleans common starters.image_captions_qwen25vl_lmstudio.py
lmstudio Python package with model mlx-community/qwen2.5-vl-7b-instruct.{basename}.txt. Cleans common starters.Legacy (Ollama-based):
legacy/image_captions_llamavision.py (model llama3.2-vision:11b-instruct-q8_0)legacy/image_captions_llava.py (model llava:34b)legacy/caption_cleanup_llama3-8B.py (cleanup using llama3.1:8b-instruct-fp16)Usage (generation):
python image_captions_gemini_1shotSingle.py
python image_captions_florence.py
python image_captions_moondream.py
python image_captions_qwen25vl_cuda.py
python image_captions_qwen25vl_lmstudio.py
tools/image_resize.py
tools/rename_files.py
image_0001.ext, image_0002.ext, … (skips already‑matching files). Picks the next available index.tools/findreplace_word.py
*.txt in a folder.tools/triggerword_removal.py
"BBCDFL, " and "WSBBC, " across all *.txt.tools/find_solo.py
unpaired/ subfolder.tools/gemini_ratelimit_test.py
Usage (tools):
python tools/image_resize.py
python tools/rename_files.py
python tools/findreplace_word.py
python tools/triggerword_removal.py
python tools/find_solo.py
python tools/gemini_ratelimit_test.py
# 1) Generate captions
python image_captions_florence.py
# 2) Clean captions (first pass)
python caption_cleanup_gemini.py
# 3) Optional: refine captions (second pass)
python caption_cleanup_gemini_pass2.py
---
## Troubleshooting & Notes
- Hugging Face models may require significant VRAM; reduce image size or switch models if OOM.
- Qwen2‑VL CUDA path requires a working CUDA setup and `qwen-vl-utils`.
- Gemini scripts use exponential backoff to mitigate rate limits.
- If `image_captions_gemini_1shotSingle.py` fails early, ensure the one‑shot sample image path points to a valid local image.
- On macOS with Apple Silicon, Florence/Moondream can run with MPS; first load may be slower due to compilation.
---
## License
Internal tooling for dataset preparation.
39 commits
Python
100.0%
Utilities and scripts to build high‑quality image–caption datasets. This repo covers:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
# Extras used by various scripts:
pip install google-generativeai openai python-dotenv tqdm torch qwen-vl-utils ollama lmstudio
Notes:
pip install torch fails.Create a .env file in the repo root with your Gemini API key:
GEMINI_API_KEY=your_key_here
Scripts that call Gemini use either:
google.generativeai directly, oropenai client with base_url=https://generativelanguage.googleapis.com/v1beta/openai/{basename}.txt.p_{basename}.txt.cleaned/ subfolder with *_c.txt filenames.batch_*.txt and raw_response_batch_*.json, then moves them to results/.descriptions/ and prompts/ subfolders and logs to zero_processed_files.txt.tools/find_solo.py can move unpaired files to unpaired/.image_captions_gemini_1shotSingle.py (Gemini API)image_captions_florence.py (HF: Florence-2-Flux-Large)image_captions_moondream.py (HF: moondream2)image_captions_qwen25vl_cuda.py (HF: Qwen2-VL; CUDA)image_captions_qwen25vl_lmstudio.py (LM Studio; Qwen2.5-VL 7B instruct)caption_cleanup_gemini.py (general cleanup)caption_cleanup_gemini_pass2.py (optional second pass; removes depth/palette/atmosphere sentences)caption_cleanup_gemini.py
*.txt in a folder, cleans with Gemini via OpenAI-compatible client.cleaned/{name}_c.txt. Skips non-empty existing outputs.caption_cleanup_gemini_pass2.py
cleaned/{name}_c.txt.Usage (both):
python caption_cleanup_gemini.py
python caption_cleanup_gemini_pass2.py
image_captions_gemini_1shotSingle.py
p_{basename}.txt.image_captions_florence.py
gokaygokay/Florence-2-Flux-Large. Device auto-detect (CUDA/MPS/CPU).{basename}.txt. Removes common starters using tools.caption_starters.clean_caption().image_captions_moondream.py
vikhyatk/moondream2 (revision 2024-08-26). Device auto-detect.{basename}.txt. Removes common starters.image_captions_qwen25vl_cuda.py
Qwen/Qwen2-VL-7B-Instruct with qwen_vl_utils. CUDA required.{basename}.txt. Cleans common starters.image_captions_qwen25vl_lmstudio.py
lmstudio Python package with model mlx-community/qwen2.5-vl-7b-instruct.{basename}.txt. Cleans common starters.Legacy (Ollama-based):
legacy/image_captions_llamavision.py (model llama3.2-vision:11b-instruct-q8_0)legacy/image_captions_llava.py (model llava:34b)legacy/caption_cleanup_llama3-8B.py (cleanup using llama3.1:8b-instruct-fp16)Usage (generation):
python image_captions_gemini_1shotSingle.py
python image_captions_florence.py
python image_captions_moondream.py
python image_captions_qwen25vl_cuda.py
python image_captions_qwen25vl_lmstudio.py
tools/image_resize.py
tools/rename_files.py
image_0001.ext, image_0002.ext, … (skips already‑matching files). Picks the next available index.tools/findreplace_word.py
*.txt in a folder.tools/triggerword_removal.py
"BBCDFL, " and "WSBBC, " across all *.txt.tools/find_solo.py
unpaired/ subfolder.tools/gemini_ratelimit_test.py
Usage (tools):
python tools/image_resize.py
python tools/rename_files.py
python tools/findreplace_word.py
python tools/triggerword_removal.py
python tools/find_solo.py
python tools/gemini_ratelimit_test.py
# 1) Generate captions
python image_captions_florence.py
# 2) Clean captions (first pass)
python caption_cleanup_gemini.py
# 3) Optional: refine captions (second pass)
python caption_cleanup_gemini_pass2.py
---
## Troubleshooting & Notes
- Hugging Face models may require significant VRAM; reduce image size or switch models if OOM.
- Qwen2‑VL CUDA path requires a working CUDA setup and `qwen-vl-utils`.
- Gemini scripts use exponential backoff to mitigate rate limits.
- If `image_captions_gemini_1shotSingle.py` fails early, ensure the one‑shot sample image path points to a valid local image.
- On macOS with Apple Silicon, Florence/Moondream can run with MPS; first load may be slower due to compilation.
---
## License
Internal tooling for dataset preparation.
39 commits
Python
100.0%