Commit b0742984 authored by 赵威's avatar 赵威

get diary info

parent 4a5df282
...@@ -7,6 +7,42 @@ import faiss ...@@ -7,6 +7,42 @@ import faiss
import numpy as np import numpy as np
from utils.images import face_to_vec, url_to_ndarray from utils.images import face_to_vec, url_to_ndarray
from utils.es import es_query
def save_diary_image_info(file):
q = {
"query": {
"bool": {
"filter": [{
"term": {
"is_online": True
}
}, {
"term": {
"has_before_cover": True
}
}, {
"term": {
"has_after_cover": True
}
}, {
"exists": {
"field": "before_cover_url"
}
}]
}
},
"_source": {
"include": ["id", "before_cover_url", "after_cover_url"]
}
}
with open(file, "w"):
step = 100
for i in range(0, 500000, step):
res_dict = es_query("diary", q, 0, step)
print(res_dict)
def main(): def main():
...@@ -20,37 +56,41 @@ def main(): ...@@ -20,37 +56,41 @@ def main():
shape_model_path = os.path.join(model_diry, "shape_predictor_68_face_landmarks.dat") shape_model_path = os.path.join(model_diry, "shape_predictor_68_face_landmarks.dat")
faiss_index_path = os.path.join(base_dir, "_index", "current.index") faiss_index_path = os.path.join(base_dir, "_index", "current.index")
face_rec = dlib.face_recognition_model_v1(facerec_model_path) diary_after_cover_vec_file = "./diary_after_cover_vec.txt"
face_detector = dlib.get_frontal_face_detector()
shape_predictor = dlib.shape_predictor(shape_model_path) save_diary_image_info(diary_after_cover_vec_file)
if img.any(): # face_rec = dlib.face_recognition_model_v1(facerec_model_path)
faces = face_to_vec(img, face_rec, face_detector, shape_predictor) # face_detector = dlib.get_frontal_face_detector()
# shape_predictor = dlib.shape_predictor(shape_model_path)
if len(faces) > 0:
for face in faces: # if img.any():
print(face) # faces = face_to_vec(img, face_rec, face_detector, shape_predictor)
print("\n")
print("-------------") # if len(faces) > 0:
face_feature = np.array(json.loads(face["feature"])) # for face in faces:
# print(face)
ids = [17418645] # print("\n")
ids_np = np.array(ids).astype("int") # print("-------------")
faces_np = np.array([face_feature]).astype("float32") # face_feature = np.array(json.loads(face["feature"]))
print(ids_np)
print(faces_np) # ids = [17418645]
# ids_np = np.array(ids).astype("int")
index = faiss.IndexHNSWFlat(128, 32) # faces_np = np.array([face_feature]).astype("float32")
print("index: ") # print(ids_np)
print(index) # print(faces_np)
index2 = faiss.IndexIDMap(index)
print("index2: ") # index = faiss.IndexHNSWFlat(128, 32)
print(index2) # print("index: ")
res = index2.add_with_ids(faces_np, ids_np) # print(index)
print("res: ") # index2 = faiss.IndexIDMap(index)
print(res) # print("index2: ")
else: # print(index2)
print("no faces") # res = index2.add_with_ids(faces_np, ids_np)
# print("res: ")
# print(res)
# else:
# print("no faces")
if __name__ == "__main__": 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