Automated image description generation for remote sensing datasets using Gemini API.
TRSLLAVA/
├── config.py # Configuration file
├── gemini_processor.py # Main processing script
├── token_estimator.py # Token usage estimation
├── requirements.txt # Python dependencies
├── README.md # This file
├── results/ # Output directory
│ ├── rsicd_descriptions.json
│ └── rsitmd_descriptions.json
├── cache/ # Intermediate cache
└── logs/ # Processing logs
cd ~/TRSLLAVA
pip install -r requirements.txtEdit config.py and set your Gemini API key:
GEMINI_API_KEY = "your_actual_api_key_here"Or set via environment variable:
export GEMINI_API_KEY="your_actual_api_key_here"python token_estimator.pyProcess both datasets:
python gemini_processor.py --dataset bothProcess only RSICD:
python gemini_processor.py --dataset rsicdProcess only RSITMD:
python gemini_processor.py --dataset rsitmdResults are saved in results/ directory as JSON files:
# View statistics
python -m json.tool results/rsicd_descriptions.json | head -50
# Count descriptions
python -c "import json; data=json.load(open('results/rsicd_descriptions.json')); print(f'Total: {len(data)}, Success: {sum(1 for v in data.values() if v.get(\"description\"))}')"| Dataset | Images | Input Tokens | Output Tokens | Cost (Pro) | Cost (Flash) |
|---|---|---|---|---|---|
| RSICD | 10,921 | ~14M | ~1.6M | ~$50 | ~$1.5 |
| RSITMD | 4,743 | ~6M | ~0.7M | ~$22 | ~$0.7 |
| Total | 15,664 | ~20M | ~2.3M | ~$72 | ~$2.2 |
Recommendation: Use Gemini 1.5 Flash (gemini-1.5-flash) to save ~97% on costs.
Edit config.py to customize:
- Model:
gemini-1.5-pro(quality) orgemini-1.5-flash(speed/cost) - Batch size: How often to save intermediate results
- Retry settings: For failed API calls
- Rate limiting: Delay between requests
- Prompt: Customize description generation prompt
- ✅ Automatic checkpointing: Resume from where you left off
- ✅ Batch processing: Save progress periodically
- ✅ Error handling: Automatic retries with exponential backoff
- ✅ Token tracking: Monitor usage during processing
- ✅ Detailed logging: Full logs in
logs/directory - ✅ Progress statistics: Real-time progress updates
Each description JSON file contains:
{
"image_name.jpg": {
"description": "A detailed natural language description of the remote sensing image...",
"path": "/full/path/to/image.jpg",
"timestamp": "2026-01-20T12:34:56.789012"
},
"failed_image.jpg": {
"description": null,
"path": "/path/to/failed_image.jpg",
"error": "Failed to generate",
"timestamp": "2026-01-20T12:34:56.789012"
}
}If you hit rate limits, increase RATE_LIMIT_DELAY in config.py:
RATE_LIMIT_DELAY = 2 # Increase from 1 to 2 secondsIf processing large datasets, reduce BATCH_SIZE:
BATCH_SIZE = 5 # Reduce from 10 to 5Check your logs in logs/processing_*.log for detailed error messages.
- Use descriptions for retrieval: Implement BERT encoding
- Evaluate quality: Compare with ground truth captions
- Optimize prompts: Test different prompts for better descriptions
- Beyond Pixels paper: [Link to paper]
- Gemini API docs: https://ai.google.dev/gemini-api/docs
- RSICD dataset: https://github.com/201528014227051/RSICD_optimal
- RSITMD dataset: https://github.com/201528014227051/RSITMD