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
51
52
53
54
|
#!/usr/bin/python
from subprocess import Popen
import os
import sys
from face_client import FaceClient
api_key = '34a84a7835bf24df2d84b4bded84e838'
api_secret = '5bc9e8c5a9e3a2d916abbe3659a1b3f8'
url_base = 'http://74.95.195.225/static/img/jon/users/'
client = FaceClient(api_key, api_secret)
def test(ns,dataset,dirs):
f = open('test.log', 'w')
for d in dirs:
tids = []
nm = 0
nf = 0
fp = 0
count = 0
user = d.rstrip('/').split('/')[-1]
for line in open(d+'/'+dataset+'-test', 'r'):
pic = line.split(',')[-2].split('/')[-1].split('.')[0]+'.jpeg'
if pic != "face.jpeg":
count += 1
url = url_base+user+'/test/'+pic
try:
response = client.faces_recognize('all',url,namespace=ns)
sys.stderr.write(str(response)+"\n")
for photo in response['photos']:
if len(photo['tags']) > 0:
if len(photo['tags'][0]['uids']) > 0:
out = [user, pic]
for tag in photo['tags'][0]['uids']:
out += [tag['uid'], str(tag['confidence'])]
f.write("\t".join(out)+"\n")
if photo['tags'][0]['uids'][0]['uid'] != user+'@'+ns:
fp += 1
else:
f.write("\t".join([user, pic, "no-match", "1"])+"/n")
nm += 1
else:
f.write("\t".join([user, pic, "no-face", "0"])+"/n")
nf += 1
except:
sys.stderr.write("Unexpexted error:"+str(sys.exc_info()[0]))
pass
print ','.join([user,str(count),str(nf),str(nm),str(fp)])
if __name__ == "__main__":
test(sys.argv[1],sys.argv[2],sys.argv[3:])
|