Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
Face-Clock
Project
Project
Details
Activity
Releases
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
YONG-LIN SU
Face-Clock
Commits
2fbb3cf9
Commit
2fbb3cf9
authored
Jun 24, 2019
by
YONG-LIN SU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add func to create the folder for save snapshot
parent
50f8415a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
+29
-6
face_predict.py
notebook/face_predict.py
+29
-6
No files found.
notebook/face_predict.py
View file @
2fbb3cf9
...
...
@@ -10,6 +10,7 @@ from skimage.transform import resize
from
sklearn.preprocessing
import
LabelEncoder
from
keras.models
import
model_from_json
import
numpy
as
np
import
os
# In[2]:
...
...
@@ -34,12 +35,25 @@ print("Facenet預測模型載入完成")
# 載入SVM分類器
clf
=
joblib
.
load
(
'../model/2019062
2181256/20190622181256
.pkl'
)
clf
=
joblib
.
load
(
'../model/2019062
4135811/20190624135811
.pkl'
)
# 載入LabelEncoder
le
=
LabelEncoder
()
le
.
classes_
=
np
.
load
(
'../model/2019062
2181256
/classes.npy'
)
le
.
classes_
=
np
.
load
(
'../model/2019062
4135811
/classes.npy'
)
print
(
"SVM分類器載入完成"
)
# 建立儲存影像位置
with
open
(
'../model/20190624135811//labels.txt'
)
as
f
:
lines
=
f
.
readlines
()
for
i
in
range
(
len
(
lines
)):
name
=
lines
[
i
]
.
split
(
'
\n
'
)[
0
]
save_path
=
os
.
path
.
abspath
(
'../save/'
)
name_path
=
os
.
path
.
join
(
save_path
,
name
)
if
(
not
os
.
path
.
isdir
(
name_path
)):
os
.
mkdir
(
name_path
)
os
.
mkdir
(
os
.
path
.
join
(
name_path
,
'login_'
))
os
.
mkdir
(
os
.
path
.
join
(
name_path
,
'logout_'
))
os
.
mkdir
(
os
.
path
.
join
(
name_path
,
'error_'
))
# In[5]:
...
...
@@ -107,16 +121,25 @@ def infer(le, clf, img):
embs
=
calc_embs
(
face_cropped
(
img
,
faces
,
10
))
# pred = le.inverse_transform(clf.predict(embs))
pred
=
get_labels
(
le
,
clf
,
embs
)
return
[
faces
,
pred
]
# pred=get_labels(le,clf,embs)
results
,
confidences
=
get_labelsNconfidence
(
le
,
clf
,
embs
)
return
[
faces
,
results
,
confidences
]
# Labels 解析
def
get_labels
(
le
,
clf
,
embs
):
socres
=
clf
.
predict_proba
(
embs
)
results
=
[]
for
s
in
socres
:
print
(
s
)
if
(
s
[
s
.
argmax
()]
>
0.5
):
results
.
append
(
le
.
inverse_transform
([
s
.
argmax
()])[
0
])
else
:
results
.
append
(
'Unknow'
)
return
results
\ No newline at end of file
return
results
# Labels 解析回傳結果與分數
def
get_labelsNconfidence
(
le
,
clf
,
embs
):
socres
=
clf
.
predict_proba
(
embs
)
results
=
[]
confidences
=
[]
for
s
in
socres
:
results
.
append
(
le
.
inverse_transform
([
s
.
argmax
()])[
0
])
confidences
.
append
(
s
[
s
.
argmax
()])
return
results
,
confidences
\ No newline at end of file
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