Skip to content

sterin501/ImageSearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

ImageSearch

This is demo to upload image and create image vector in the neo4j database .

Later vector is used for image search


Flow :


We convert images to vectors using TensorFlow and store these vectors as properties in Neo4j.

By utilizing Neo4j's vector index feature, we can run cosine similarity algorithms on these vectors to find similarities.

Additionally, a website built on Flask can be used to upload images and perform searches based on these vectors.


There is different script for downloading images from internet and upload to neo4j


Configration in Neo4j


Neo4j version : 5.20.0

Install APOC : apoc-5.20.0-core.jar

Create vector index

CALL db.index.vector.createNodeIndex('imageCosine', 'Image', 'vectorCosine', 2048, 'cosine');
CALL db.index.vector.createNodeIndex('imageEuclidean', 'Image', 'vectorEuclidean', 2048, 'euclidean'); // Optional 

Configration for Flask website


  1. pip install -r requirment.txt
  2. export FLASK_APP=app.py
  3. Edit ImageSearchNeo4j.py (line 12) with correct neo4j connection string
  4. flask run --port 5002
driver = GraphDatabase.driver("neo4j+s://auraID.databases.neo4j.io", auth=("neo4j", "auraIDpassword"))

Bulk download and upload of images


To download use : ImageSearch/bulkUpload/upload/download.py

This will read images_full.csv and download as per that .

To get csv : https://storage.googleapis.com/openimages/2016_08/images_2016_08_v5.tar.gz

To upload to Neo4j : ImageSearch/bulkUpload/UploadToNeo.py

This will upload images to neo4j . Edit the connection string for neo4j connection


For better performance to create image vector install CUDS drivers

https://developer.nvidia.com/cuda-downloads


Cypher to upload image vector

CREATE (I:Image {name: $name,desc:$desc})-[:Original]->(:Originalbase64 {base64:$base64})
CREATE (I)-[:Compress]-> (:Compress{base64:$compressed_base64_str})  
WITH I 
CALL db.create.setNodeVectorProperty(I, "vectorCosine", $vector)

Cypher to search image vector

CALL db.index.vector.queryNodes('imageCosine', 5, $vector)
YIELD node AS similarAbstract, score
RETURN  similarAbstract.name,score

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published