Ejemplo n.º 1
0
def check_embedding_on_detected_person_forSVM_ByDir(current_groupid, embedding,
                                                    style, classid,
                                                    nrof_classes):
    total = 0
    found = 0
    people = None
    if SVM_TRAIN_WITHOUT_CATEGORY is True:
        facedir = '{}/data/faces/{}/{}/face_dataset/{}'.format(
            BASEDIR, current_groupid, 'front', classid)
    else:
        facedir = '{}/data/faces/{}/{}/face_dataset/{}'.format(
            BASEDIR, current_groupid, style, classid)
    print("check embedding: facedir = {}".format(facedir))
    embedding_array = []
    if os.path.isdir(facedir):
        image_paths = []
        images = os.listdir(facedir)
        if len(images) < 1:
            print(
                "Check embedding: Empty directory: facedir={}".format(facedir))
            return 0, 0
        for img in images:
            img_path = os.path.join(facedir, img)
            emb_path = save_embedding.get_embedding_path(img_path)
            emb = save_embedding.read_embedding_string(emb_path)
            emb = np.asarray(emb)
            embedding_array.append(emb)
    if len(embedding_array) > 0:
        for emb in embedding_array:
            val = compare2(embedding, emb)
            total = total + 1
            face_accuracy = val
            print('face_accuracy={}'.format(face_accuracy))
            '''
            threshold = 1.0
            if nrof_classes <= 5 and nrof_classes > 0:
                threshold = 1.0
            elif nrof_classes <= 10 and nrof_classes > 0:
                threshold = 1.0
            '''
            threshold = 0.42
            if face_accuracy > threshold:
                found = found + 1
            if total >= 500:
                break
    return found, total
Ejemplo n.º 2
0
def down_img_embedding(img_url, group_id, face_id, style='front'):
    # 下载图片及embedding
    img_path = get_image_path(img_url, group_id, face_id, style)
    embedding_path = get_embedding_path(img_path)
    embedding_url = img_url + SUFFIX
    if not os.path.exists(img_path):
        download_img_for_svm(img_url, group_id, face_id, style)
    embedding = None
    if not os.path.exists(embedding_path):
        status = down_embedding(embedding_url, embedding_path)
        if not status:
            # 下载embedding失败, 开始计算embedding
            embedding = featureCalculation(img_path)
            if embedding is None:
                return False, None
            create_embedding_string(embedding, embedding_path)

            # 上传一次
            key = img_url.rsplit('/', 1)[-1]
            embedding_string = ','.join(str(x) for x in embedding)
            embedding_bytes = embedding_string.encode('utf-8')

            if useAliyun is True:
                url = aliyun_upload_data(key, embedding_bytes)
            else:
                embedding_url = qiniu_upload_data(key, embedding_bytes)

            #print('Download embedding file failed, caculate it.')
        else:
            embedding = txt2embedding(embedding_path)
            #print('Download embedding file suc.')
    else:
        #print('embedding file exist.')
        embedding = txt2embedding(embedding_path)
    # print('need recover db')
    return True, embedding