set_SHAPES / README.md
Maazwaheed's picture
Update README.md
2a3bff2 verified
---
license: mpl-2.0
task_categories:
- image-to-text
- visual-question-answering
task_ids:
- image-captioning
language:
- en
size_categories:
- 1K<n<10K
tags:
- computer-vision
- synthetic-data
- geometric-shapes
- motion-analysis
- multi-object
- spatial-reasoning
---
# πŸŒ€ SHAPES Motion Dataset
<div align="center">
![Dataset Preview](https://img.shields.io/badge/πŸ“Š-10,000%20Images-blue)
![Resolution](https://img.shields.io/badge/πŸ–ΌοΈ-1024x1024-green)
![License](https://img.shields.io/badge/πŸ“œ-MPL--2.0-orange)
![Motion Types](https://img.shields.io/badge/🎯-Dynamic%20%2B%20Static-purple)
*A high-quality synthetic dataset of geometric shapes in motion with rich textual descriptions*
</div>
## 🌟 Dataset Highlights
- **10,000 high-resolution images** (1024Γ—1024 pixels)
- **Rich captions** with motion dynamics and spatial relationships
- **Diverse geometric shapes** with realistic motion trails
- **Multi-object scenes** with complex interactions
- **Synthetic but realistic** rendering with gradient backgrounds
## πŸ“Š Dataset Structure
```bash
set_SHAPES/
β”œβ”€β”€ images/
β”‚ β”œβ”€β”€ 00001.jpg
β”‚ β”œβ”€β”€ 00002.jpg
β”‚ └── ... (10,000 files)
└── captions.csv
```
### πŸ“‹ Metadata Columns
- `filename`: Unique image identifier
- `caption`: Detailed natural language description
- `motion_type`: [moving, sliding, drifting, streaking, arcing]
- `dynamics`: [constant, accelerating, decelerating, rotating, curving]
- `num_objects`: Number of objects in scene (1-3)
## 🎨 Visual Features
### 🟦 Geometric Shapes
- **Basic**: Circle, Square, Rectangle, Ellipse
- **Complex**: Triangle, Pentagon
- **Size Variations**: Tiny β†’ Huge (5 scales)
- **Color Palette**: 14 distinct colors with contrasting outlines
### 🎬 Motion Dynamics
```python
# Motion Types
MOTION_VERBS = ['moving', 'sliding', 'drifting', 'streaking', 'arcing']
# Dynamics
MOTION_DYNAMICS = [
'at constant speed',
'while accelerating',
'while decelerating',
'while rotating',
'in a curve while rotating'
]
```
### 🎯 Spatial Relations
- **Positional**: top-left, center, bottom-right, etc.
- **Relative**: passing by, near, adjacent to
- **Size comparisons**: larger than, smaller than
## πŸ“ Example Captions
**Motion Scene**:
*"A large wide blue rectangle with a yellow outline is sliding while accelerating from the top left towards the bottom center, passing by a static medium standard red circle with a black outline in the middle."*
**Static Scene**:
*"An image with a huge green pentagon with magenta outline in the bottom right and a tiny tall orange ellipse with cyan outline in the top center."*
## πŸš€ Quick Start
### Installation
```bash
pip install datasets pillow
```
### Load Dataset
```python
from datasets import load_dataset
dataset = load_dataset("Maazwaheed/set_SHAPES")
print(f"Dataset size: {len(dataset['train'])}")
print(f"Sample caption: {dataset['train'][0]['caption']}")
```
### fast load
```python
import os
import logging
from concurrent.futures import ThreadPoolExecutor, as_completed
from datasets import load_dataset
from PIL import Image
import pandas as pd
from tqdm import tqdm
import io
import threading
# Configuration
DATASET_NAME = "Maazwaheed/set_SHAPES"
OUTPUT_DIR = "advanced_motion_dataset"
IMAGES_DIR = os.path.join(OUTPUT_DIR, "images")
MAX_WORKERS = 16 # Adjust based on system capabilities
HF_TOKEN = os.getenv("HF_TOKEN") # Ensure HF_TOKEN is set in environment
LOG_DIR = "logs"
LOG_FILE = os.path.join(LOG_DIR, "download.log")
# Setup logging
os.makedirs(LOG_DIR, exist_ok=True)
logging.basicConfig(
filename=LOG_FILE,
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s"
)
# Thread-safe counter for tracking downloaded images
download_counter = 0
counter_lock = threading.Lock()
def setup_directories():
"""Create output directories if they don't exist."""
try:
os.makedirs(OUTPUT_DIR, exist_ok=True)
os.makedirs(IMAGES_DIR, exist_ok=True)
logging.info(f"Created directories: {OUTPUT_DIR}, {IMAGES_DIR}")
except Exception as e:
logging.error(f"Failed to create directories: {e}")
raise
def download_image(item, index):
"""Download and save a single image with its filename."""
try:
image = item["image"]
filename = item.get("filename", f"{str(index+1).zfill(5)}.jpg")
image_path = os.path.join(IMAGES_DIR, filename)
# Convert to RGB if needed and save as JPEG
if image.mode != "RGB":
image = image.convert("RGB")
image.save(image_path, "JPEG", quality=95)
# Increment counter thread-safely
global download_counter
with counter_lock:
download_counter += 1
return filename, item.get("caption", ""), None
except Exception as e:
logging.error(f"Failed to download image at index {index}: {e}")
return None, None, str(e)
def download_dataset():
"""Download the dataset efficiently using parallel processing."""
try:
# Load dataset
logging.info(f"Loading dataset: {DATASET_NAME}")
dataset = load_dataset(DATASET_NAME, split="train", use_auth_token=HF_TOKEN)
logging.info(f"Dataset loaded with {len(dataset)} items")
# Setup directories
setup_directories()
# Prepare metadata
metadata = []
# Download images in parallel
logging.info(f"Starting parallel download with {MAX_WORKERS} workers")
with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
future_to_index = {executor.submit(download_image, dataset[i], i): i for i in range(len(dataset))}
progress_bar = tqdm(total=len(dataset), desc="Downloading images")
for future in as_completed(future_to_index):
index = future_to_index[future]
filename, caption, error = future.result()
if filename and caption is not None:
metadata.append([filename, caption])
else:
logging.warning(f"Skipped item at index {index} due to error: {error}")
progress_bar.update(1)
progress_bar.close()
# Save captions.csv
try:
csv_path = os.path.join(OUTPUT_DIR, "captions.csv")
with open(csv_path, "w", newline="", encoding="utf-8") as f:
writer = pd.DataFrame(metadata, columns=["filename", "caption"])
writer.to_csv(f, index=False)
logging.info(f"Saved captions to {csv_path}")
except Exception as e:
logging.error(f"Failed to save captions.csv: {e}")
raise
logging.info(f"Downloaded {download_counter} images to {IMAGES_DIR}")
print(f"Dataset downloaded successfully! {download_counter} images saved to {IMAGES_DIR}, captions saved to {csv_path}")
except Exception as e:
logging.error(f"Dataset download failed: {e}")
raise
if __name__ == "__main__":
try:
download_dataset()
except Exception as e:
print(f"Error downloading dataset: {e}")
logging.error(f"Main execution failed: {e}")
raise
```
### Advanced Usage
```python
# Filter motion scenes
motion_scenes = [item for item in dataset['train']
if 'moving' in item['caption'] or 'sliding' in item['caption']]
# Get multi-object scenes
multi_object = [item for item in dataset['train']
if 'and' in item['caption']]
```
## πŸ“Š Statistics
| Metric | Value |
|--------|-------|
| Total Images | 10,000 |
| Motion Scenes | ~6,000 |
| Static Scenes | ~4,000 |
| Avg. Caption Length | 35 words |
| Color Variations | 14 colors |
| Shape Types | 6 shapes |
## 🎯 intended Use
### βœ… Primary Tasks
- **Image Captioning** - Rich descriptions for training
- **Visual Question Answering** - Spatial reasoning
- **Motion Understanding** - Dynamic scene analysis
- **Object Detection** - Multi-object recognition
- **Synthetic-to-Real Transfer** - Domain adaptation
### ⚠️ Limitations
- Synthetic data (not real-world)
- Limited to geometric shapes
- Predetermined color palette
- Simplified physics model
## πŸ”§ Technical Details
### Generation Process
1. **Background**: Gradient generation with smooth transitions
2. **Shapes**: Anti-aliased rendering with outlines
3. **Motion**: BΓ©zier curves with trail effects
4. **Composition**: Multi-object placement with occlusion handling
5. **Captions**: Rule-based natural language generation
### Technical Specs
- **Format**: JPEG (quality=95)
- **Color Space**: RGB
- **Resolution**: 1024Γ—1024
- **Size per Image**: ~150-250KB
- **Total Dataset Size**: 561MB
## πŸ“œ License
**MPL-2.0** - Allows commercial use, modification, and distribution with appropriate attribution.
## 🀝 Contributing
We welcome contributions! Please:
1. Fork the repository
2. Create a feature branch
3. Submit a pull request
4. Open issues for suggestions
## πŸ“ž Contact
**Maintainer**: Maaz Waheed
**Email**: [Your Email]
**Hugging Face**: [Maazwaheed](https://huggingface.co/Maazwaheed)
## πŸ™ Acknowledgments
- Hugging Face for dataset hosting
- PIL/Pillow community for image processing
- Open-source community for inspiration
---
<div align="center">
**⭐ Star this dataset if you find it useful!**
[![Hugging Face](https://img.shields.io/badge/πŸ€—-View%20on%20HF-yellow)](https://huggingface.co/datasets/Maazwaheed/set_SHAPES)
[![License](https://img.shields.io/badge/πŸ“œ-MPL--2.0-lightgrey)](https://www.mozilla.org/en-US/MPL/2.0/)
</div>