-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembeddings.py
More file actions
29 lines (27 loc) · 960 Bytes
/
Copy pathembeddings.py
File metadata and controls
29 lines (27 loc) · 960 Bytes
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
from imgbeddings import imgbeddings
from PIL import Image
import os
from database import get_db_connection
def upload_face_embeddings(folder):
conn = get_db_connection()
cur = conn.cursor()
for filename in os.listdir(f"{folder}"):
# opening the image
img = Image.open(f"{folder}/" + filename)
# loading the `imgbeddings`
ibed = imgbeddings()
# calculating the embeddings
embedding = ibed.to_embeddings(img)
cur = conn.cursor()
cur.execute("INSERT INTO pictures values (%s,%s)", (filename, embedding[0].tolist()))
print(filename)
conn.commit()
cur.close()
conn.close()
def create_embedding_string(file_path):
img = Image.open(file_path)
ibed = imgbeddings()
embedding = ibed.to_embeddings(img)
string_representation = "["+ ",".join(str(x) for x in embedding[0].tolist()) +"]"
#print(string_representation)
return string_representation