diff options
Diffstat (limited to 'data/face-test.py')
| -rwxr-xr-x | data/face-test.py | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/data/face-test.py b/data/face-test.py index a987c49..fed233a 100755 --- a/data/face-test.py +++ b/data/face-test.py @@ -1,54 +1,67 @@ #!/usr/bin/python -from subprocess import Popen import os import sys -from face_client import FaceClient +from face_client import FaceClient, FaceError +import time +from httplib import HTTPException +from urllib2 import HTTPError 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)]) - +def limits(response): + return response['remaining'],response['reset_time'] +remaining,reset_time = limits(client.account_limits()) +sframe = 0 +try: + sframe = int(sys.argv[4]) +except: + sframe = 0 +try: + eframe = int(sys.argv[5]) +except: + eframe = sys.maxint -if __name__ == "__main__": - test(sys.argv[1],sys.argv[2],sys.argv[3:]) - +ns = sys.argv[1] +dataset = sys.argv[2] +pic_dir = sys.argv[3] +exclude = ['Anmol', 'Nina', 'Scott'] +for line in open(dataset): + line = line.strip().split(',') + sub_dir,user,run,frame,zv,num,rec = line[0:7] + user = '_'.join(user.split()) + while remaining == 0: + time.sleep(max(reset_time - time.time(),0) + 10) + remaining,reset_time = limits(client) + if frame != 'frame' and int(frame) > sframe and int(frame) < eframe and int(num) == 1 and rec == 'True' and user not in exclude: + response = None + while response == None: + try: + img = open(pic_dir + sub_dir + '/' + frame + '.jpg') + response = client.faces_recognize('all',file=img,namespace=ns) + img.close() + remaining,reset_time = limits(response['usage']) + except (HTTPException, HTTPError): + sys.stderr.write("HTTP Exception\n") + time.sleep(5) + except FaceError: + sys.stderr.write("Face Exception\n") + sys.stderr.write(str(img)) + time.sleep(5) + out = line[0:5] + #try: + sys.stderr.write(frame) + sys.stderr.write(str(response['photos'][0]['tags'])+"\n") + photo = response['photos'][0] + out += [str(len(photo['tags'][0]['uids']))] + for tag in photo['tags'][0]['uids']: + out += [tag['uid'], str(tag['confidence'])] + #except: + # sys.stderr.write("Unexpexted error:"+str(sys.exc_info()[0])+" "+frame) + # out += ['0'] + #client.tags_remove(tids=','.join(tags)) + print ','.join(out) + time.sleep(0.3) |
