β Star us on GitHub β it motivates us a lot!
An intelligent image captioning tool using Azure OpenAI's GPT-4V model, specifically designed for training diffusion models. This tool preprocesses images and generates high-quality captions optimized for AI training.
AI Image Captioner is a Python library designed to provide comprehensive support for image captioning using Azure OpenAI's GPT-4V model. It adheres to high standards of:
- Modularity: Different components can function independently
- Testability: Improved separation of concerns
- Maintainability: Clear structure and organization
- Reliability: Robust error handling and retry mechanisms
- Automatic resizing to 1024x1024
- Aspect ratio preservation with padding
- RGB conversion (alpha channel removal)
- Standardized JPEG output
- Sequential naming (image0.jpg, image1.jpg, etc.)
- Intelligent captioning using GPT-4V
- Gender and attribute detection
- Consistent formatting
- No introductory phrases
- Focus on main subjects
- Comma-separated elements
- Multiple file format support
- Progress tracking
- Error handling
- Retry mechanism for API failures
- Individual caption files (.txt)
- Dataset JSON file
- CSV export
- Customizable prefix/suffix
- Python 3.8+
- Azure OpenAI API access with GPT-4V deployment
- Required Python packages (see requirements.txt)
- Clone the repository:
git clone https://github.com/CroissanStudioDev/ai-image-captioner.git
cd ai-image-captioner- Create and activate a virtual environment:
# Create virtual environment
python -m venv .venv
# Activate on Linux/macOS
source .venv/bin/activate
# Activate on Windows
.venv\Scripts\activate- Install the package in development mode:
pip install -e .- Create a
.envfile with your Azure OpenAI credentials:
AZURE_OPENAI_API_KEY=your_api_key_here
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
AZURE_OPENAI_DEPLOYMENT_NAME=your_deployment_nameProcess images with default settings:
python -m ai_image_captioner.cli --input-folder input --output-folder outputAdd style prefix and quality suffix:
python -m ai_image_captioner.cli \
--input-folder input \
--output-folder output \
--prefix "in the style of TOK" \
--suffix "high quality"output/
βββ image0.jpg # Preprocessed image
βββ image0.txt # Caption file
βββ image1.jpg
βββ image1.txt
βββ ...
βββ captions.csv # All captions in CSV format
βββ dataset.json # Complete dataset information
woman with pink hair wearing orange sunglasses, gray jumpsuit with orange accents
man in blue shirt and jeans standing with arms crossed
young girl holding a red balloon, wearing a white dress
ai-image-captioner/
βββ src/
β βββ ai_image_captioner/
β βββ __init__.py
β βββ cli.py
β βββ image_captioner.py
β βββ preprocessor.py
βββ tests/
βββ .env.example
βββ .gitignore
βββ LICENSE
βββ README.md
βββ requirements.txt
βββ setup.py
The project follows PEP 8 guidelines and uses Black for formatting:
# Format code
black src/ai_image_captioner
# Check style
flake8 src/ai_image_captioner- ModuleNotFoundError: Ensure proper installation:
pip install -e .- Import Error: Verify virtual environment:
which python # Should point to .venv/bin/python- API Errors: Check
.envconfiguration
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
For support:
- Open an issue in the GitHub repository
- Contact: serge@croissanstudio.ru
Made with β€οΈ by Croissan Studio