| title | PicMatch: Your Visual Search Companion | ||||||
|---|---|---|---|---|---|---|---|
| emoji | 📷🔍 | ||||||
| colorFrom | blue | ||||||
| colorTo | green | ||||||
| sdk | gradio | ||||||
| python_version | 3.9 | ||||||
| sdk_version | 4.39.0 | ||||||
| suggested_hardware | t4-small | ||||||
| suggested_storage | medium | ||||||
| app_file | app.py | ||||||
| fullWidth | true | ||||||
| header | mini | ||||||
| short_description | Search images using text or other images as queries. | ||||||
| models |
|
||||||
| tags |
|
||||||
| thumbnail | https://example.com/thumbnail.png | ||||||
| pinned | true | ||||||
| hf_oauth | false | ||||||
| disable_embedding | false | ||||||
| startup_duration_timeout | 30m | ||||||
| custom_headers |
|
PicMatch lets you effortlessly search through your image archive using either a text description or another image as your query. Find those needle-in-a-haystack photos in a flash! ✨
Try PicMatch image search with 25,000 Unsplash images on this 🤗 Space
-
Prerequisites: Ensure you have Python 3.9 or higher installed on your system. 🐍
-
Create a Virtual Environment:
python -m venv env
-
Activate the Environment:
source ./venv/bin/activate -
Install Dependencies:
python -m pip install -r requirements.txt
-
Start the App (with Sample Data):
python app.py
-
Open Your Browser: Head to
localhost:7860to access the PicMatch interface. 🌐
Make sure you have the following folders in your project's root directory:
data
├── images
└── features
The engine/download_data.py Python script streamlines downloading and processing images from a list of URLs. It's designed for performance and reliability:
- Async Operations: Uses
asynciofor concurrent image downloading and processing. ⏩ - Rate Limiting: Follows API usage rules to prevent blocks with a
RateLimiter. 🚦 - Parallel Resizing: Employs a
ProcessPoolExecutorfor fast image resizing. ⚙️ - State Management: Saves progress in a JSON file so you can resume later. 💾
ImagePipelineClass: Manages the entire pipeline, its state, and rate limiting. 🎛️- Functions: Handle URL feeding (
url_feeder), downloading (image_downloader), and processing (image_processor). 📥 ImageSaverClass: Defines how images are processed and saved. 🖼️resize_imageFunction: Ensures image resizing maintains the correct aspect ratio. 📏
- Start: Configure the pipeline with your URL list, download limits, and rate settings.
- Feed URLs: Asynchronously read URLs from your file.
- Download: Download images concurrently while respecting rate limits.
- Process: Save the original images and resize them in parallel.
- Save State: Regularly save progress to avoid starting over if interrupted.
To get the sample data run the command
cd engine && python download_data.pyThis step prepares your images for searching. We generate two types of embeddings:
- Visual Embeddings (CLIP): Capture the visual content of your images. 👁️🗨️
- Textual Embeddings: Create embeddings from image captions for text-based search. 💬
To generate these features run the command
cd engine && python generate_features.pyThis process uses these awesome models from Hugging Face:
- TinyCLIP:
wkcn/TinyCLIP-ViT-8M-16-Text-3M-YFCC15M - BLIP Image Captioning:
Salesforce/blip-image-captioning-base - SentenceTransformer:
all-MiniLM-L6-v2
This script extracts image features (both visual and textual) efficiently:
- Asynchronous: Loads images, extracts features, and saves them concurrently. ⚡
- Dual Embeddings: Creates both CLIP (visual) and caption (textual) embeddings. 🖼️📝
- Checkpoints: Keeps track of progress and allows resuming from interruptions. 🔄
- Parallel: Uses multiple CPU cores for feature extraction. ⚙️
This module connects to the Milvus vector database to store and search your image embeddings:
- Milvus: A high-performance database built for handling vector data. 📊
- Easy Interface: Provides a simple way to manage embeddings and perform searches. 🔍
- Single Server: Ensures only one Milvus server is running for efficiency.
- Indexing: Automatically creates an index to speed up your searches. 🚀
- Similarity Search: Find the most similar images using cosine similarity. 💯
PicMatch leverages these incredible open-source projects:
-
TinyCLIP: The visual powerhouse for understanding your images.
-
Image Captioning: The wordsmith that describes your photos in detail.
-
Sentence Transformers: Turns captions into embeddings for text-based search.
-
Unsplash: Images used were taken from Unsplash's open source data
Let's give credit where credit is due! 🙌 These projects make PicMatch smarter and more capable.