A Python tool to search your meme (or image) collection using text queries!
Powered by OpenAIβs CLIP model, it finds and ranks images that match your descriptionβeven for fuzzy, creative prompts.
- β Search images with natural language queries
- π€ Uses OpenAIβs CLIP (ViT-B/32) model for zero-shot vision-language matching
- β‘οΈ Caches extracted image features for instant future searches
- ποΈ Supports multiple image formats: .jpg, .png, .gif, .bmp
- πΌοΈ Displays top matching images in notebook/console
- Python 3.x
- PyTorch
- Transformers (Hugging Face)
- NumPy
- Pillow (PIL)
- scikit-learn
- pickle
- glob
Install required packages:
pip install torch torchvision
pip install transformers
pip install numpy pillow scikit-learnyour_project/
β
βββ content/
β βββ memes/
β βββ meme1.jpg
β βββ meme2.png
β βββ ...
βββ meme_features.pkl (auto-generated)
βββ your_script.py
π All your images should be in
content/memes/.
1οΈβ£ Loads or extracts CLIP features for all images in your content/memes/ folder
2οΈβ£ Caches those features in meme_features.pkl for instant future runs
3οΈβ£ Processes your text query into CLIP embedding
4οΈβ£ Computes cosine similarity between query and images
5οΈβ£ Returns and displays the top matching images
from your_module_name import search_images
query = "funny cat with sunglasses"
result_path = search_images(query, top_k=5)
print("Best match:", result_path)- First run: Extracts and caches features
- Next runs: Loads cached features instantly
If you add new images, simply delete meme_features.pkl to regenerate features.
β See it in action here:
Md Shahriar Rahman Bhuiyan
π LinkedIn Profile
If you have feedback or want to collaborate, feel free to reach out via LinkedIn!