Sanjay Jayaram's solution to image search for the OA#1
Open
sanjaycal wants to merge 2 commits intoadanomad:mainfrom
Open
Sanjay Jayaram's solution to image search for the OA#1sanjaycal wants to merge 2 commits intoadanomad:mainfrom
sanjaycal wants to merge 2 commits intoadanomad:mainfrom
Conversation
sunapi386
reviewed
Oct 2, 2024
| image_features /= image_features.norm(dim=-1, keepdim=True) | ||
| text_features /= text_features.norm(dim=-1, keepdim=True) | ||
| text_probs = image_features @ text_features.T | ||
| return text_probs.item() > 0.2 |
Contributor
There was a problem hiding this comment.
How have you determined 0.2 as a threshold?
Contributor
There was a problem hiding this comment.
What kind of distance is this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Setup:
Since, I created a python webserver, to run this, python>=3.10 must be installed on the machine.
My environment setup script also assumes a linux machine, however it might work on a Mac.
to setup the environment for the webserver, simply run the setupServer.sh file in the pythonWebServer folder,
then to start the server, simply run
python3 main.pythen start the npm(I have only tested in dev mode, so that will be part of my setup process) with
npm run devin the main folderIdeally the machine that is running these servers has a NVIDIA GPU to accelerate the image embeddings.
Explanation of the approach
I just exported the computation to a python webserver, the python webserver then does all of the heavy embedding effort with a CLIP model.
the process
So, first of all, I spent way too long trying to get this to work in the JS side of things, however JS doesn't have anywhere near as mature of a ML ecosystem as python. Thus, after failing to get JS inference of a CLIP model to work, I just decided to make the python webserver and did it in <1/4 the time I spent trying to get it to work in entirely JS. After I decided to just export the computation to the python webserver, and had the javascript just call it, it became a lot easier as I have a lot more experience working with ML and other AI projects in Python as opposed to Javascript.