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
ec38720f
Commit
ec38720f
authored
Sep 09, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try get faces
parent
b41ed690
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
31 deletions
+34
-31
diary_cover_similarity.py
src/diary_cover_similarity.py
+34
-31
No files found.
src/diary_cover_similarity.py
View file @
ec38720f
...
@@ -10,7 +10,7 @@ from utils.es import es_query
...
@@ -10,7 +10,7 @@ from utils.es import es_query
from
utils.images
import
face_to_vec
,
url_to_ndarray
from
utils.images
import
face_to_vec
,
url_to_ndarray
def
save_diary_image_info
(
file
):
def
save_diary_image_info
(
file
,
face_to_vec_f
):
q
=
{
q
=
{
"query"
:
{
"query"
:
{
"bool"
:
{
"bool"
:
{
...
@@ -47,7 +47,10 @@ def save_diary_image_info(file):
...
@@ -47,7 +47,10 @@ def save_diary_image_info(file):
diary_id
=
item
[
"_source"
][
"id"
]
diary_id
=
item
[
"_source"
][
"id"
]
before_cover_url
=
item
[
"_source"
][
"before_cover_url"
]
+
"-w"
before_cover_url
=
item
[
"_source"
][
"before_cover_url"
]
+
"-w"
after_cover_url
=
item
[
"_source"
][
"after_cover_url"
]
+
"-w"
after_cover_url
=
item
[
"_source"
][
"after_cover_url"
]
+
"-w"
print
(
str
(
diary_id
)
+
" "
+
after_cover_url
)
# print(str(diary_id) + " " + after_cover_url)
img
=
url_to_ndarray
(
after_cover_url
)
faces
=
face_to_vec_f
(
img
)
print
(
faces
)
def
main
():
def
main
():
...
@@ -63,40 +66,40 @@ def main():
...
@@ -63,40 +66,40 @@ def main():
diary_after_cover_vec_file
=
"./diary_after_cover_vec.txt"
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_rec
=
dlib
.
face_recognition_model_v1
(
facerec_model_path
)
face_detector
=
dlib
.
get_frontal_face_detector
()
face_detector
=
dlib
.
get_frontal_face_detector
()
shape_predictor
=
dlib
.
shape_predictor
(
shape_model_path
)
shape_predictor
=
dlib
.
shape_predictor
(
shape_model_path
)
face_to_vec_f
=
lambda
img
:
face_to_vec
(
img
,
face_rec
,
face_detector
,
shape_predictor
)
face_to_vec_f
=
lambda
img
:
face_to_vec
(
img
,
face_rec
,
face_detector
,
shape_predictor
)
if
img
.
any
():
save_diary_image_info
(
diary_after_cover_vec_file
,
face_to_vec_f
)
faces
=
face_to_vec_f
(
img
)
# if img.any():
if
len
(
faces
)
>
0
:
# faces = face_to_vec_f(img)
for
face
in
faces
:
print
(
face
)
# if len(faces) > 0:
print
(
"
\n
"
)
# for face in faces:
print
(
"-------------"
)
# print(face)
face_feature
=
np
.
array
(
json
.
loads
(
face
[
"feature"
]))
# print("\n")
# print("-------------")
ids
=
[
17418645
]
# face_feature = np.array(json.loads(face["feature"]))
ids_np
=
np
.
array
(
ids
)
.
astype
(
"int"
)
faces_np
=
np
.
array
([
face_feature
])
.
astype
(
"float32"
)
# ids = [17418645]
print
(
ids_np
)
# ids_np = np.array(ids).astype("int")
print
(
faces_np
)
# faces_np = np.array([face_feature]).astype("float32")
# print(ids_np)
index
=
faiss
.
IndexHNSWFlat
(
128
,
32
)
# print(faces_np)
print
(
"index: "
)
print
(
index
)
# index = faiss.IndexHNSWFlat(128, 32)
index2
=
faiss
.
IndexIDMap
(
index
)
# print("index: ")
print
(
"index2: "
)
# print(index)
print
(
index2
)
# index2 = faiss.IndexIDMap(index)
res
=
index2
.
add_with_ids
(
faces_np
,
ids_np
)
# print("index2: ")
print
(
"res: "
)
# print(index2)
print
(
res
)
# index2.add_with_ids(faces_np, ids_np)
else
:
# print("index2: ")
print
(
"no faces"
)
# print(index2)
# else:
# print("no faces")
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
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