Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax Error #6

Open
stevenc317 opened this issue Feb 10, 2019 · 3 comments
Open

Syntax Error #6

stevenc317 opened this issue Feb 10, 2019 · 3 comments

Comments

@stevenc317
Copy link

stevenc317 commented Feb 10, 2019

@vearutop

I keep getting the error below when I attempt to run the codes:

error

Version: ('PostgreSQL 9.6.8 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.9.3, 64-bit',)

SELECT file FROM vectors WHERE sqrt(power(CUBE(array[-0.06887340545654297,0.10233059525489807,0.10160233080387115,-0.11301713436841965,-0.14592909812927246,0.0004851529374718666,-0.07629727572202682,-0.15829594433307648,0.17802439630031586,-0.20244725048542023,0.1285582333803177,-0.0815291479229927,-0.2074122577905655,0.05181701481342316,-0.09317518025636673,0.20535025000572205,-0.12158051133155823,-0.10021547228097916,-0.16869302093982697,-0.07119856029748917,0.05046587437391281,0.02677701786160469,-0.04388655722141266,0.08232736587524414,-0.0330679714679718,-0.24993793666362762,-0.01230323314666748,-0.021156763657927513,-0.024065084755420685,-0.10250875353813171,0.07079330086708069,0.0923762321472168,-0.1568349301815033,-0.042158711701631546,-0.03067936934530735,0.1020168662071228,-0.03939816355705261,-0.14659950137138367,0.1134253591299057,-0.06773674488067627,-0.23308363556861877,-0.04753703996539116,0.07696220278739929,0.2509799897670746,0.25111308693885803,0.01212252676486969,-0.006149983033537865,-0.11321106553077698,0.16601575911045074,-0.3408501148223877,0.003647993318736553,0.03599663823843002,0.03861365467309952,0.06754124164581299,0.12345699220895767,-0.21630609035491943,0.09604985266923904,0.09064231067895889,-0.16567929089069366,0.05914430692791939,0.08075124025344849,-0.14857527613639832,0.05424246937036514,-0.10456611216068268]) <-> vec_low, 2) + power(CUBE(array[0.2896047830581665,0.03638148680329323,-0.1253138780593872,-0.08614261448383331,0.18620777130126953,-0.16353394091129303,-0.002677353098988533,0.05688006430864334,-0.08217878639698029,-0.18610218167304993,-0.31303149461746216,-0.01724396087229252,0.41267284750938416,0.2345082312822342,-0.15557996928691864,0.051614779978990555,-0.07364267110824585,-0.02181013859808445,0.04583794251084328,0.1938910037279129,0.06229330226778984,-0.03562602400779724,-0.035322897136211395,0.01683807000517845,0.22577977180480957,-0.06433368474245071,-0.006460784003138542,0.38136932253837585,0.011478189378976822,-0.11730978637933731,-0.0712127685546875,-0.011202752590179443,-0.14718139171600342,0.04159972071647644,-0.11897310614585876,-0.013145100325345993,0.01094562653452158,-0.01778699830174446,0.05643612891435623,0.11900068819522858,-0.2009134441614151,0.16640324890613556,-0.0762849748134613,0.07192431390285492,0.03656899929046631,-0.06872530281543732,-0.11258184164762497,-0.05909983068704605,0.23055006563663483,-0.2217569500207901,0.07211996614933014,0.16576902568340302,0.12509778141975403,0.14771641790866852,0.08406543731689453,0.11484887450933456,0.12347398698329926,-0.03430244326591492,-0.17360427975654602,0.002648727037012577,0.06261187791824341,-0.08835550397634506,-0.0031046289950609207,0.12539289891719818]) <-> vec_high, 2)) <= 0.6 ORDER BY sqrt(power(CUBE(array[-0.06887340545654297,0.10233059525489807,0.10160233080387115,-0.11301713436841965,-0.14592909812927246,0.0004851529374718666,-0.07629727572202682,-0.15829594433307648,0.17802439630031586,-0.20244725048542023,0.1285582333803177,-0.0815291479229927,-0.2074122577905655,0.05181701481342316,-0.09317518025636673,0.20535025000572205,-0.12158051133155823,-0.10021547228097916,-0.16869302093982697,-0.07119856029748917,0.05046587437391281,0.02677701786160469,-0.04388655722141266,0.08232736587524414,-0.0330679714679718,-0.24993793666362762,-0.01230323314666748,-0.021156763657927513,-0.024065084755420685,-0.10250875353813171,0.07079330086708069,0.0923762321472168,-0.1568349301815033,-0.042158711701631546,-0.03067936934530735,0.1020168662071228,-0.03939816355705261,-0.14659950137138367,0.1134253591299057,-0.06773674488067627,-0.23308363556861877,-0.04753703996539116,0.07696220278739929,0.2509799897670746,0.25111308693885803,0.01212252676486969,-0.006149983033537865,-0.11321106553077698,0.16601575911045074,-0.3408501148223877,0.003647993318736553,0.03599663823843002,0.03861365467309952,0.06754124164581299,0.12345699220895767,-0.21630609035491943,0.09604985266923904,0.09064231067895889,-0.16567929089069366,0.05914430692791939,0.08075124025344849,-0.14857527613639832,0.05424246937036514,-0.10456611216068268]) <-> vec_low, 2) + power(CUBE(array[0.2896047830581665,0.03638148680329323,-0.1253138780593872,-0.08614261448383331,0.18620777130126953,-0.16353394091129303,-0.002677353098988533,0.05688006430864334,-0.08217878639698029,-0.18610218167304993,-0.31303149461746216,-0.01724396087229252,0.41267284750938416,0.2345082312822342,-0.15557996928691864,0.051614779978990555,-0.07364267110824585,-0.02181013859808445,0.04583794251084328,0.1938910037279129,0.06229330226778984,-0.03562602400779724,-0.035322897136211395,0.01683807000517845,0.22577977180480957,-0.06433368474245071,-0.006460784003138542,0.38136932253837585,0.011478189378976822,-0.11730978637933731,-0.0712127685546875,-0.011202752590179443,-0.14718139171600342,0.04159972071647644,-0.11897310614585876,-0.013145100325345993,0.01094562653452158,-0.01778699830174446,0.05643612891435623,0.11900068819522858,-0.2009134441614151,0.16640324890613556,-0.0762849748134613,0.07192431390285492,0.03656899929046631,-0.06872530281543732,-0.11258184164762497,-0.05909983068704605,0.23055006563663483,-0.2217569500207901,0.07211996614933014,0.16576902568340302,0.12509778141975403,0.14771641790866852,0.08406543731689453,0.11484887450933456,0.12347398698329926,-0.03430244326591492,-0.17360427975654602,0.002648727037012577,0.06261187791824341,-0.08835550397634506,-0.0031046289950609207,0.12539289891719818]) <-> vec_high, 2)) <-> vec_high) ASC LIMIT 1

Traceback (most recent call last):
File "gen_128D_vector.py", line 63, in
cur.execute(query)
psycopg2.ProgrammingError: syntax error at or near ")"
LINE 1: ...12539289891719818]) <-> vec_high, 2)) <-> vec_high) ASC LIMI...
^

@nakornsoft
Copy link

nakornsoft commented Feb 15, 2019

import sys
import dlib
import cv2
import face_recognition
import os
import psycopg2

if len(sys.argv) < 2:
print("Usage: face-find ")
exit(1)

file_name = sys.argv[1]

face_detector = dlib.get_frontal_face_detector()

image = cv2.imread(file_name)

detected_faces = face_detector(image, 1)

print("Found {} faces in the image file {}".format(
len(detected_faces), file_name))

if not os.path.exists("./.faces"):
os.mkdir("./.faces")

connection_db = psycopg2.connect(
"user='postgres' password='adasoft' host='localhost' dbname='test_face'")
db = connection_db.cursor()

for i, face_rect in enumerate(detected_faces):
print("- Face #{} found at Left: {} Top: {} Right: {} Bottom: {}".format(i, face_rect.left(), face_rect.top(), face_rect.right(), face_rect.bottom()))
crop = image[face_rect.top():face_rect.bottom(),
face_rect.left():face_rect.right()]

encodings = face_recognition.face_encodings(crop)
threshold = 0.6
if len(encodings) > 0:
    query = "SELECT file FROM vectors WHERE sqrt(power(CUBE(array[{}]) <-> vec_low, 2) + power(CUBE(array[{}]) <-> vec_high, 2)) <= {} ".format(
        ','.join(str(s) for s in encodings[0][0:64]),
        ','.join(str(s) for s in encodings[0][64:128]),
        threshold,
    ) + \
        "ORDER BY sqrt((CUBE(array[{}]) <-> vec_low) + (CUBE(array[{}]) <-> vec_high)) ASC LIMIT 1".format(
        ','.join(str(s) for s in encodings[0][0:64]),
        ','.join(str(s) for s in encodings[0][64:128]),
    )
    # print(query)
    db.execute(query)
    print("The number of parts: ", db.rowcount)
    if (int(db.rowcount) == 0):
        print("Unknown")
    row = db.fetchone()
    while row is not None:
        print(row)
        row = db.fetchone()

    db.close()
else:
    print("No encodings")

if connection_db is not None:
connection_db.close()

@nakornsoft
Copy link

for me is work

@thakurritesh19
Copy link

import sys
import dlib
import cv2
import face_recognition
import os
import psycopg2

if len(sys.argv) < 2:
print("Usage: face-find ")
exit(1)

file_name = sys.argv[1]

face_detector = dlib.get_frontal_face_detector()

image = cv2.imread(file_name)

detected_faces = face_detector(image, 1)

print("Found {} faces in the image file {}".format(
len(detected_faces), file_name))

if not os.path.exists("./.faces"):
os.mkdir("./.faces")

connection_db = psycopg2.connect(
"user='postgres' password='adasoft' host='localhost' dbname='test_face'")
db = connection_db.cursor()

for i, face_rect in enumerate(detected_faces):
print("- Face #{} found at Left: {} Top: {} Right: {} Bottom: {}".format(i, face_rect.left(), face_rect.top(), face_rect.right(), face_rect.bottom()))
crop = image[face_rect.top():face_rect.bottom(),
face_rect.left():face_rect.right()]

encodings = face_recognition.face_encodings(crop)
threshold = 0.6
if len(encodings) > 0:
query = "SELECT file FROM vectors WHERE sqrt(power(CUBE(array[{}]) <-> vec_low, 2) + power(CUBE(array[{}]) <-> vec_high, 2)) <= {} ".format(
','.join(str(s) for s in encodings[0][0:64]),
','.join(str(s) for s in encodings[0][64:128]),
threshold,
) +
"ORDER BY sqrt((CUBE(array[{}]) <-> vec_low) + (CUBE(array[{}]) <-> vec_high)) ASC LIMIT 1".format(
','.join(str(s) for s in encodings[0][0:64]),
','.join(str(s) for s in encodings[0][64:128]),
)
# print(query)
db.execute(query)
print("The number of parts: ", db.rowcount)
if (int(db.rowcount) == 0):
print("Unknown")
row = db.fetchone()
while row is not None:
print(row)
row = db.fetchone()

db.close()

else:
print("No encodings")

if connection_db is not None:
connection_db.close()

This always returns "none" despite saving proper encodings in DB like this:

query = "INSERT INTO vectors (file, vec_low, vec_high) VALUES ('{}', CUBE(array[{}]), CUBE(array[{}]))".format(
name,
','.join(str(s) for s in encoding[0:63]),
','.join(str(s) for s in encoding[64:127]),
)

Any suggestions ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants