Commit 9c3c4d1c authored by 赵威's avatar 赵威

get faiss result

parent 9e9a45fa
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
.static_storage/
.media/
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
_index/
\ No newline at end of file
import json
import os
import time
import dlib
import faiss
import numpy as np
from utils.images import face_to_vec, url_to_ndarray
......@@ -9,28 +12,45 @@ from utils.images import face_to_vec, url_to_ndarray
def main():
img_url = "https://pic.igengmei.com/2020/07/03/1437/1b9975bb0b81-w"
img = url_to_ndarray(img_url)
print(img)
base_dir = os.getcwd()
print("base_dir: " + base_dir)
model_diry = os.path.join(base_dir, "_models")
facerec_model_path = os.path.join(model_diry, "dlib_face_recognition_resnet_model_v1.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")
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)
faces = face_to_vec(img, face_rec, face_detector, shape_predictor)
print("faces:")
print(faces)
print("============")
for face in faces:
print(face)
print("\n")
print("-------------")
if img:
faces = face_to_vec(img, face_rec, face_detector, shape_predictor)
if faces:
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)
index2.add_with_ids(faces_np, ids_np)
print("index2: ")
print(index2)
else:
print("no faces")
if __name__ == "__main__":
......@@ -38,4 +58,4 @@ if __name__ == "__main__":
main()
print("total cost: " + str(time.time() - begin_time))
print("total cost: {:.2f}s".format(time.time() - begin_time))
......@@ -31,7 +31,7 @@ def file_to_ndarray(path):
def face_to_vec(img, face_rec_f, face_detector_f, shape_predictor_f, max_size=700):
start = time.time()
orig_img = img
print("detect image...")
# print("detect image...")
scale = 1
height, width = img.shape[:2]
......
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