Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
strategy_embedding
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
strategy_embedding
Commits
9c3c4d1c
Commit
9c3c4d1c
authored
Sep 09, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get faiss result
parent
9e9a45fa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
13 deletions
+140
-13
.gitignore
.gitignore
+107
-0
diary_cover_similarity.py
src/diary_cover_similarity.py
+32
-12
images.py
src/utils/images.py
+1
-1
No files found.
.gitignore
0 → 100644
View file @
9c3c4d1c
# 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
src/diary_cover_similarity.py
View file @
9c3c4d1c
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
))
src/utils/images.py
View file @
9c3c4d1c
...
...
@@ -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
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment