import os
import cv2
import fawn
import tensorflow as tf
import numpy as np
import face_detect_vectorize as fdv

IMAGE_SZ = 160
MODEL_PATH = '20180402-114759/model-20180402-114759'
client = fawn.Fawn('http://127.0.0.1:8000')

model = fdv.Model(path=MODEL_PATH, image_size=IMAGE_SZ)
config = tf.ConfigProto()
config.gpu_options.allow_growth = True

print("Load faceNet =>>>")
with tf.Session(config=config) as sess:
    sess.run(tf.global_variables_initializer())
    sess.run(tf.local_variables_initializer())
    model.loader(sess)
    print("Done!\n")

    face = fdv.Face('sample_input.png', None, 30)
    face.detect_face()
    face.write_clip(write_to_file=False)
    face.vectorize(sess=sess,
                   model=model,
                   model_input_size=(IMAGE_SZ, IMAGE_SZ))

    for feature in face.face_features:
        res = client.search(feature.reshape(512), K=5)
Example #2
0
    path = os.path.join('data', barcode[4:6], barcode[6:8], barcode)
    info = fdv.read_pickle(path, "info")
    if len(info['faces']) == 0:
        return faces
    else:
        features = np.load(path + '/features.npy')
        for face in info['faces']:
            faces[face['ID']] = features[int(face['ID'])]
        return faces


# log file for errors
logf = open(sys.argv[2], 'w')

# The server url of image database
client = fawn.Fawn('http://127.0.0.1:8888')

# insert the image information into the database
tasks = []
with open(BARCODE_URLs_FILE, 'r') as IMAGES:
    for line in IMAGES:
        key, thumb, _ = line.strip().split(',')
        tasks.append((key, thumb))

for task in tqdm(tasks):
    try:
        faceFeatures = extract_features(barcode=task[0])
        thumbnail = task[1]
    except Exception as ex:
        logf.write('%s: %s \n' % (barcode, ex))