Commit b41ed690 authored by 赵威's avatar 赵威

try get faiss info

parent a9bf1a63
......@@ -42,7 +42,6 @@ def save_diary_image_info(file):
step = 100
# for i in range(0, 500000, step):
res_dict = es_query("diary", q, 0, step)
print(res_dict)
for item in res_dict["hits"]["hits"]:
diary_id = item["_source"]["id"]
......@@ -64,39 +63,40 @@ def main():
diary_after_cover_vec_file = "./diary_after_cover_vec.txt"
save_diary_image_info(diary_after_cover_vec_file)
# face_rec = dlib.face_recognition_model_v1(facerec_model_path)
# face_detector = dlib.get_frontal_face_detector()
# shape_predictor = dlib.shape_predictor(shape_model_path)
# if img.any():
# faces = face_to_vec(img, face_rec, face_detector, shape_predictor)
# if len(faces) > 0:
# for face in faces:
# print(face)
# print("\n")
# print("-------------")
# face_feature = np.array(json.loads(face["feature"]))
# ids = [17418645]
# ids_np = np.array(ids).astype("int")
# faces_np = np.array([face_feature]).astype("float32")
# print(ids_np)
# print(faces_np)
# index = faiss.IndexHNSWFlat(128, 32)
# print("index: ")
# print(index)
# index2 = faiss.IndexIDMap(index)
# print("index2: ")
# print(index2)
# res = index2.add_with_ids(faces_np, ids_np)
# print("res: ")
# print(res)
# else:
# print("no faces")
# save_diary_image_info(diary_after_cover_vec_file)
face_rec = dlib.face_recognition_model_v1(facerec_model_path)
face_detector = dlib.get_frontal_face_detector()
shape_predictor = dlib.shape_predictor(shape_model_path)
face_to_vec_f = lambda img: face_to_vec(img, face_rec, face_detector, shape_predictor)
if img.any():
faces = face_to_vec_f(img)
if len(faces) > 0:
for face in faces:
print(face)
print("\n")
print("-------------")
face_feature = np.array(json.loads(face["feature"]))
ids = [17418645]
ids_np = np.array(ids).astype("int")
faces_np = np.array([face_feature]).astype("float32")
print(ids_np)
print(faces_np)
index = faiss.IndexHNSWFlat(128, 32)
print("index: ")
print(index)
index2 = faiss.IndexIDMap(index)
print("index2: ")
print(index2)
res = index2.add_with_ids(faces_np, ids_np)
print("res: ")
print(res)
else:
print("no faces")
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment