- A demo application that uses the CLIP model for natural language media search (searching images with text, and searching related images with an image).
- Built using Phoenix Framework, Bumblebee, Axon, Nx and HNSWLib.
- This uses Nx Servings for serving the CLIP model. There are two sets of Nx Servings in the codebase:
- Nx Servings provided by Bumblebee for text & image embeddings: Using ready made Nx Servings provided by Bumblebee library.
- Hand rolled Nx Servings for text & image embeddings: Custom implemented Nx Servings intended to learn how to implement Nx Servings from scratch.
- Both provide the same output and can be used interchangeably. However, if you're interested in learning how Nx Serving works and how to implement them, the hand rolled Nx Serving files will be helpful.
- Uses Nix for dependency management. Install Nix if you don't have it already.
- Clone the repository and run
direnv allow
to activate the environment. - To install dependencies, execute
run deps
. - To start the server, execute
run server
.
- Create a directory
priv/images
and copy all your images to this directory. - Run the function
build_index
to create an index from the images. It will vectorize the images, create index and save it topriv/clip_index.ann
andpriv/clip_index_filenames.json
files. To run the function, start the server usingrun mix phx.server
and then run the function iniex
shell usingMediaSearchDemo.Clip.build_index()
.
- Download the dataset from https://unsplash.com/data/lite/latest.
- Extract and copy the
photos.tsv000
file topriv
directory. (You can directly download thephotos.tsv
file from here without downloading the whole dataset). - Run the script
download_unsplash_dataset.ex
byrun elixir priv/scripts/download_unsplash_dataset.ex
to download the images from the dataset. It will concurrently download images topriv/images
directory. - Once the images are downloaded to
priv/images
directory, you have two options:- Follow the steps in Using with Your Images section to create an index from the 25k Unsplash images. (will take some time)
- Download the pre-built index files from here and here and save both to
priv
directory.
- The application uses the CLIP model with Bumblebee and Nx to create an index of images and then search the index for related images.
- For more details, please check the talk slides. Slides can be found here