Skip to content

CroissanStudioDev/ai-image-captioner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Image Captioner

Python Version License Last Commit Code Style

⭐ 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.

🎯 About

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

✨ Features

Image Preprocessing

  • Automatic resizing to 1024x1024
  • Aspect ratio preservation with padding
  • RGB conversion (alpha channel removal)
  • Standardized JPEG output
  • Sequential naming (image0.jpg, image1.jpg, etc.)

Caption Generation

  • Intelligent captioning using GPT-4V
  • Gender and attribute detection
  • Consistent formatting
  • No introductory phrases
  • Focus on main subjects
  • Comma-separated elements

Batch Processing

  • Multiple file format support
  • Progress tracking
  • Error handling
  • Retry mechanism for API failures

Output Options

  • Individual caption files (.txt)
  • Dataset JSON file
  • CSV export
  • Customizable prefix/suffix

πŸ“¦ Prerequisites

  • Python 3.8+
  • Azure OpenAI API access with GPT-4V deployment
  • Required Python packages (see requirements.txt)

πŸš€ Installation

  1. Clone the repository:
git clone https://github.com/CroissanStudioDev/ai-image-captioner.git
cd ai-image-captioner
  1. 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
  1. Install the package in development mode:
pip install -e .
  1. Create a .env file 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_name

πŸ’‘ Usage

Basic Usage

Process images with default settings:

python -m ai_image_captioner.cli --input-folder input --output-folder output

Advanced Usage

Add 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 Format

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

Caption Examples

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

πŸ› οΈ Development

Project Structure

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

Code Style

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

❗ Troubleshooting

Common Issues

  1. ModuleNotFoundError: Ensure proper installation:
pip install -e .
  1. Import Error: Verify virtual environment:
which python  # Should point to .venv/bin/python
  1. API Errors: Check .env configuration

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ’¬ Support

For support:


Made with ❀️ by Croissan Studio

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

8 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages