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
4d0b8c8f
Commit
4d0b8c8f
authored
Sep 14, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save result
parent
9c7f7536
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
19 deletions
+23
-19
diary_cover_similarity.py
src/diary_cover_similarity.py
+23
-19
No files found.
src/diary_cover_similarity.py
View file @
4d0b8c8f
...
@@ -120,9 +120,23 @@ def get_similar_diary_ids_by_url(url, index, face_to_vec_f, limit=0.1):
...
@@ -120,9 +120,23 @@ def get_similar_diary_ids_by_url(url, index, face_to_vec_f, limit=0.1):
return
[]
return
[]
def
save_diary_similarity
(
file
):
def
get_similar_diary_ids_by_face_features
(
feature
,
index
,
face_to_vec_f
,
limit
=
0.1
):
feature
=
np
.
array
(
feature
)
.
astype
(
"float32"
)
_sources
,
_ids
=
index
.
search
(
np
.
array
([
feature
]),
10
)
ids
=
_ids
.
flat
scores
=
_sources
.
flat
tmp
=
list
(
set
(
zip
(
ids
,
scores
)))
res
=
[]
for
(
id
,
score
)
in
tmp
:
if
score
>=
limit
:
res
.
append
((
id
,
score
))
res
.
sort
(
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
return
res
def
save_diary_similarity
(
load_file
,
index_path
,
face_to_vec_f
):
res_dict
=
{}
res_dict
=
{}
with
open
(
file
)
as
f
:
with
open
(
load_
file
)
as
f
:
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
print
(
"lines: "
+
str
(
len
(
lines
)))
print
(
"lines: "
+
str
(
len
(
lines
)))
count
=
0
count
=
0
...
@@ -132,7 +146,7 @@ def save_diary_similarity(file):
...
@@ -132,7 +146,7 @@ def save_diary_similarity(file):
id
=
tmp
[
0
]
id
=
tmp
[
0
]
feature
=
np
.
array
(
json
.
loads
(
tmp
[
1
]))
feature
=
np
.
array
(
json
.
loads
(
tmp
[
1
]))
print
(
"{} {}"
.
format
(
count
,
id
))
print
(
"{} {}"
.
format
(
count
,
id
))
tup_res
=
get_similar_diary_ids_by_face_features
(
feature
,
faiss_index
,
face_to_vec_f
)
tup_res
=
get_similar_diary_ids_by_face_features
(
feature
,
index_path
,
face_to_vec_f
)
if
tup_res
:
if
tup_res
:
res_dict
[
id
]
=
tup_res
res_dict
[
id
]
=
tup_res
print
(
"done: "
+
str
(
len
(
res_dict
)))
print
(
"done: "
+
str
(
len
(
res_dict
)))
...
@@ -143,20 +157,6 @@ def save_diary_similarity(file):
...
@@ -143,20 +157,6 @@ def save_diary_similarity(file):
redis_client3
.
hmset
(
redis_key
,
res_dict
)
redis_client3
.
hmset
(
redis_key
,
res_dict
)
def
get_similar_diary_ids_by_face_features
(
feature
,
index
,
face_to_vec_f
,
limit
=
0.1
):
feature
=
np
.
array
(
feature
)
.
astype
(
"float32"
)
_sources
,
_ids
=
index
.
search
(
np
.
array
([
feature
]),
10
)
ids
=
_ids
.
flat
scores
=
_sources
.
flat
tmp
=
list
(
set
(
zip
(
ids
,
scores
)))
res
=
[]
for
(
id
,
score
)
in
tmp
:
if
score
>=
limit
:
res
.
append
((
id
,
score
))
res
.
sort
(
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
return
res
def
main
():
def
main
():
base_dir
=
os
.
getcwd
()
base_dir
=
os
.
getcwd
()
print
(
"base_dir: "
+
base_dir
)
print
(
"base_dir: "
+
base_dir
)
...
@@ -175,7 +175,11 @@ def main():
...
@@ -175,7 +175,11 @@ def main():
# save_diary_image_info(diary_after_cover_vec_file, face_to_vec_f)
# save_diary_image_info(diary_after_cover_vec_file, face_to_vec_f)
# save_faiss_index(diary_after_cover_vec_file, faiss_index_path)
# save_faiss_index(diary_after_cover_vec_file, faiss_index_path)
faiss_index
=
faiss
.
read_index
(
faiss_index_path
)
faiss_index
=
faiss
.
read_index
(
faiss_index_path
,
faiss_index_path
,
face_to_vec_f
,
)
# imgs = [
# imgs = [
# "https://pic.igengmei.com/2020/07/03/1437/1b9975bb0b81-w", "https://pic.igengmei.com/2020/07/01/1812/ca64827a83da-w",
# "https://pic.igengmei.com/2020/07/03/1437/1b9975bb0b81-w", "https://pic.igengmei.com/2020/07/01/1812/ca64827a83da-w",
...
@@ -217,7 +221,7 @@ def main():
...
@@ -217,7 +221,7 @@ def main():
# res = get_similar_diary_ids_by_face_features(a, faiss_index, face_to_vec_f)
# res = get_similar_diary_ids_by_face_features(a, faiss_index, face_to_vec_f)
# print(res)
# print(res)
save_diary_similarity
(
diary_after_cover_vec_file
)
save_diary_similarity
(
diary_after_cover_vec_file
,
faiss_index
,
face_to_vec_f
)
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