Automated image dataset generation

From LUNARTECH-X/superpowers · View interactive version

Automated image dataset generation is an AI agent skill from the GitHub repository LUNARTECH-X/superpowers. Generate large-scale image datasets automatically using web scraping and Large Multimodal Models (LMMs) like Gemini Vision. This skill implements the methodology from the research paper "Automated Image Dataset Generation Using Web Scraping and Large Multimodal Models for Construction Applications"

How to use this skill

Skill file

Automated Image Dataset Generation with LMMs

Overview

This skill provides a scalable, reusable framework for automatically generating labeled image datasets using web scraping combined with Large Multimodal Models (LMMs) for metadata generation. The methodology addresses the challenge of manual data collection being resource-intensive, error-prone, and time-consuming.

Key Capabilities:

When to Use This Skill

Use this skill when:

Core Workflow

Phase 1: Query Design and Planning

  1. Define Target Categories:
  1. Design Search Queries:

```python

# Generate diverse search queries

categories = ["structural steel beam", "steel column construction", "roof truss"]

query_variations = [

f"{cat} {mod}"

for cat in categories

for mod in ["photo", "site", "construction", "building"]

]

```

  1. Set Collection Parameters:

Phase 2: Web Scraping

  1. Implement Multi-Source Scraping:

```python

import requests

from bs4 import BeautifulSoup

from selenium import webdriver

def scrape_images(query, num_images=1000):

"""

Scrape images from multiple sources:

"""

images = []

# Use appropriate rate limiting

# Respect robots.txt

# Store source URLs for attribution

return images

```

  1. Image Download and Storage:

```python

def download_images(image_urls, output_dir):

"""

Download images with:

"""

pass

```

  1. Initial Filtering:

Phase 3: LMM-Based Metadata Generation

  1. Configure LMM (Gemini Vision or equivalent):

```python

import google.generativeai as genai

genai.configure(api_key=os.environ['GOOGLE_API_KEY'])

model = genai.GenerativeModel('gemini-1.5-flash')

def generate_metadata(image_path, categories):

"""

Use LMM to analyze image and generate metadata

"""

image = PIL.Image.open(image_path)

prompt = f"""

Analyze this image and determine:

1. Does it contain any of these objects: {categories}?

2. If yes, which specific category?

3. Confidence level (high/medium/low)

4. Object location description (for detection tasks)

5. Image quality assessment

Return structured JSON response.

"""

response = model.generate_content([prompt, image])

return parse_response(response.text)

```

  1. Batch Processing:

```python

def process_dataset(image_dir, categories, batch_size=100):

"""

Process images in batches with:

"""

results = []

for batch in get_batches(image_dir, batch_size):

batch_results = [

generate_metadata(img, categories)

for img in batch

]

results.extend(batch_results)

save_checkpoint(results)

return results

```

  1. Quality Metrics:

Phase 4: Rule-Based Filtering

  1. Apply Category Rules:

```python

def filter_by_rules(metadata, rules):

"""

Apply domain-specific rules:

"""

filtered = []

for item in metadata:

if item['confidence'] >= rules['min_confidence']:

if validate_category(item, rules):

filtered.append(item)

return filtered

```

  1. Handle Edge Cases:

Phase 5: Dataset Finalization

  1. Generate Dataset Structure:

```

dataset/

├── images/

│ ├── category_1/

│ ├── category_2/

│ └── ...

├── annotations/

│ ├── metadata.json

│ └── labels.csv

├── splits/

│ ├── train.txt

│ ├── val.txt

│ └── test.txt

└── README.md

```

  1. Create Annotation Files:

```python

def create_annotations(filtered_data, output_dir):

"""

Generate standard annotation formats:

"""

pass

```

  1. Split Dataset:

Best Practices

Web Scraping

  1. Respect rate limits: 1-2 requests per second
  2. Rotate user agents: Avoid detection
  3. Use proxies: For large-scale collection
  4. Cache responses: Avoid redundant downloads
  5. Store source URLs: For attribution and verification

LMM Usage

  1. Use appropriate prompts: Be specific about expected output format
  2. Batch processing: Optimize API costs
  3. Handle API errors: Implement retry logic with exponential backoff
  4. Validate responses: Parse and validate JSON responses

Data Quality

  1. Verify sample manually: Check 100-200 random samples
  2. Calculate inter-annotator agreement: If using multiple LMMs
  3. Document accuracy metrics: Report precision/recall per category
  4. Version your dataset: Track changes over time

Legal & Ethical

  1. Check image licenses: Prefer CC-licensed content
  2. Respect robots.txt: Don't scrape disallowed pages
  3. Attribute sources: Maintain source URLs
  4. Consider privacy: Filter personal/sensitive content

Expected Results

Based on the original research:

Integration with Other Skills

Dependencies

# Core
pip install requests beautifulsoup4 selenium pillow

# LMM
pip install google-generativeai  # or openai for GPT-4V

# Image processing
pip install imagehash opencv-python

# Dataset tools
pip install pandas scikit-learn

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.