A powerful computer vision application that enables intelligent image searching similar to Google Photos. Search through your image collection using object detection and advanced filtering capabilities.
- Object Detection: Automatically detect and catalog objects in your images using state-of-the-art YOLO models
- Smart Search: Find images based on detected objects (e.g., "apple", "person", "bus", "car")
- Advanced Filtering:
- OR Mode: Find images containing ANY of the selected objects.
- AND Mode: Find images containing ALL selected objects simultaneously.
- Count Thresholds: Filter by minimum/maximum occurrence of objects in images.
- Visual Results: Display search results with bounding boxes and confidence scores.
- Metadata Export: Save and load detection metadata for quick future searches.
- Clean, responsive web interface built with Streamlit
- Grid view with customizable columns (2-5)
- Hover effects and smooth animations
- Toggle bounding boxes on/off
- Highlight matching objects vs. all detected objects
- Export search results as JSON
- Python 3.11 or higher
- uv package manager
- Clone the repository
git clone https://github.com/prakhar175/count-aware-image-search.git
cd count-aware-image-search- Create a virtual environment (recommended)
uv venv
.venv/Scripts/activate
- Install dependencies
uv syncOrganize your images in a directory:
my_photos/
βββ vacation_2024/
β βββ beach1.jpg
β βββ beach2.png
β βββ sunset.jpg
βββ family/
βββ birthday.jpg
βββ picnic.png
streamlit run main.py- Select "Process the new images"
- Enter your image directory path
- Enter model path (e.g.,
yolo11n.pt,yolo11m.pt,yolo11l.pt) - Click "Start Inference"
- Wait for processing to complete
- Select search mode (OR / AND)
- Choose object classes from the dropdown
- Optionally set count thresholds
- Click "Search Images"
- View and export results!
When you first use the application, you need to process your images:
-
Image Directory Path: Full path to your image folder
/path/to/your/images Example -> C:\Users\prakhar\Pictures\MyPhotos (Windows) -
Model Selection: Choose a YOLO model based on your needs:
yolo11n.pt- Nano (fastest, less accurate)yolo11s.pt- Small (balanced)yolo11m.pt- Medium (recommended)yolo11l.pt- Large (slower, more accurate)yolo11x.pt- Extra Large (most accurate)
-
Processing: The app will:
- Scan all images in the directory
- Detect objects using YOLO
- Save metadata to
processed/[dirname]/metadata.json
Skip reprocessing by loading previously generated metadata:
- Select "Load existing"
- Enter the path to your
metadata.jsonfile - Click "Load Metadata"
Finds images containing at least one of the selected objects.
Example: Select "person" OR "dog"
- β Image with only a person
- β Image with only a dog
- β Image with both person and dog
- β Image with neither
Finds images containing all selected objects simultaneously.
Example: Select "person" AND "dog"
- β Image with only a person
- β Image with only a dog
- β Image with both person and dog
- β Image with neither
Refine searches by object occurrence:
Example: "person" with threshold "3"
- Finds images with 1-2 people (but not 3 or more)
Use Case: "car" with threshold "5"
- Finds parking lots with a few cars, excludes highway traffic
- Show Bounding Boxes: Toggle object detection boxes
- Grid Columns: Adjust layout (2-5 columns)
- Show Highlights:
- ON: Only show boxes for searched objects
- OFF: Show all detected objects
smart-image-search/
β
βββ main.py # Main Streamlit application
βββ .python-version
βββ pyproject.toml # Python dependencies
βββ README.md # This file
β
βββ src/
β βββ __init__.py
β βββ inference.py # YOLO inference logic
β βββ utils.py # Utility functions
β
βββ configs/
β βββ __init__.py
β βββ config.py # Configuration settings
β
βββ data/
β βββ raw/ # Original images
β βββ processed/ # Metadata and results
β
βββ yolo11m.pt # YOLO model weights
Edit configs/config.py to customize:
# Detection confidence threshold
CONF_THRESHOLD = 0.25 # Lower = more detections, higher = more accurate
# YOLO model
YOLO_MODEL = "yolo11m.pt"
# Supported image formats
IMAGE_EXTENSION = ["*.jpg", "*.jpeg", "*.png", "*.bmp", "*.webp"]| Parameter | Description | Default | Range |
|---|---|---|---|
CONF_THRESHOLD |
Minimum confidence for detections | 0.25 | 0.0 - 1.0 |
YOLO_MODEL |
Default YOLO model | yolo11m.pt | n/s/m/l/x |
IMAGE_EXTENSION |
Supported formats | jpg, png, etc. | - |
Search Mode: OR
Selected Classes: ["person", "umbrella", "surfboard"]
Result: All beach and vacation photos
Search Mode: AND
Selected Classes: ["person", "dining table", "fork"]
Result: Photos with people eating at tables
Search Mode: OR
Selected Classes: ["dog", "cat"]
Thresholds: dog=3, cat=3
Result: Photos with 1-2 dogs or cats (excludes shelter/kennel photos)
Search Mode: AND
Selected Classes: ["car", "traffic light", "person"]
Result: City street photographs
Each processed image generates metadata:
{
"img_path": "/path/to/image.jpg",
"detections": [
{
"class": "person",
"conf": 0.89,
"bbox": [100, 150, 300, 450],
"count": 2
}
],
"total_objects": 5,
"unique_classes": ["person", "car", "dog"],
"class_counts": {
"person": 2,
"car": 2,
"dog": 1
}
}If you find this project useful, please consider giving it a β on GitHub!