forked from vyasn30/image_search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (35 loc) · 1.06 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from re import I
from PIL import Image
import cv2
import faiss
from datastore import Datastore
import utils
import numpy as np
from vectorizer_deepface import Vectorizer
if __name__ == "__main__":
store = Datastore()
mappings = utils.get_mappings()
representations = utils.get_representations()
names, vectors = utils.get_vectors()
print(len(names))
print(len(vectors))
idx = 0
for name, vector in zip(names, vectors):
name = np.array(name)
vector = np.array(vector)
# print(vector.shape)
store.add(vector, idx, name)
idx+=1
faiss.write_index(store.index, "vecdata/vector.index")
image = Image.open("test_data/laura.jpg")
opencvImage = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
vec = Vectorizer()
emb_2 = vec.vectorize_single(opencvImage)
emb_2 = np.array(emb_2, dtype=np.float32)
emb_2 = emb_2.reshape(1, 128)
print(emb_2.shape)
D, I = store.search(emb_2)
print(D , I)
for id in I[0]:
print(id)
print(names[id])