Beispiel #1
0
def train(user):
  pics = load_photos(user['id'])
  count = 0
  for pic in pics:
    try:
      rt = match_faces(pic, user['id'])
    except KeyError as ke:
      print 'KeyError', ke, 'in', pic['source']
    else:
      if rt:
        count += 1
        if count % 10 == 0: print count, 'pics added for', user['name']
    if count >= 40:
        print 'Reached 40 pics for ', user['name']
        break

  if count == 0:
    rsp = {'success': 'no_training_set'}
    return rsp;

  rsp = tagger.train_uid(user['id']+'@setoreh')
  rsp = json.loads(rsp.text)
  return rsp
Beispiel #2
0
if len(sys.argv) < 2: sys.exit()
links = open(sys.argv[1], 'r')

count = 0
for img in links.readlines():
  img = img.strip();
  detection = detector.detect_faces(img)
  
  if 'tags' not in detection: 
    print detection
    sys.exit()
  
  if len(detection['tags']) != 1:
    print "# of tags != ", img, len(detection['tags'])
    print json.dumps(detection, sort_keys = True, indent = 2)
    print 
    sys.exit()
    
  tag = detection['tags'][0]['tid']
  rsp = tagger.save_tag(uid, tag, img)
  count += 1

tagger.train_uid(uid)

f=open('/data/mugshots/trained.ix', 'a')
f.seek(0,2)
f.write(uid + ' ' + str(count))
f.write('\n')
f.close()