Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
face
Project
Overview
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
Иван Кубота
face
Commits
bdfaba24
Commit
bdfaba24
authored
Jun 10, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed detect and recognize example
parent
2b127e43
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
13 deletions
+24
-13
commons.js
examples/public/commons.js
+21
-10
detectAndRecognizeFaces.html
examples/views/detectAndRecognizeFaces.html
+3
-3
No files found.
examples/public/commons.js
View file @
bdfaba24
...
...
@@ -25,28 +25,39 @@ async function initFaceRecognitionNet() {
}
// fetch first image of each class and compute their descriptors
async
function
initTrainDescriptorsByClass
(
net
)
{
async
function
initTrainDescriptorsByClass
(
net
,
numImagesForTraining
=
1
)
{
const
maxAvailableImagesPerClass
=
5
numImagesForTraining
=
Math
.
min
(
numImagesForTraining
,
maxAvailableImagesPerClass
)
return
Promise
.
all
(
classes
.
map
(
async
className
=>
{
const
descriptors
=
[]
for
(
let
i
=
1
;
i
<
(
numImagesForTraining
+
1
);
i
++
)
{
const
img
=
await
facerecognition
.
bufferToImage
(
await
fetchImage
(
getFaceImageUri
(
className
,
1
))
await
fetchImage
(
getFaceImageUri
(
className
,
i
))
)
const
descriptor
=
await
net
.
computeFaceDescriptor
(
img
)
descriptors
.
push
(
await
net
.
computeFaceDescriptor
(
img
))
}
return
{
descriptor
,
descriptor
s
,
className
}
}
))
}
function
getBestMatch
(
allDescriptors
,
queryDescriptor
)
{
return
allDescriptors
function
getBestMatch
(
descriptorsByClass
,
queryDescriptor
)
{
function
computeMeanDistance
(
descriptorsOfClass
)
{
return
facerecognition
.
round
(
descriptorsOfClass
.
map
(
d
=>
facerecognition
.
euclideanDistance
(
d
,
queryDescriptor
))
.
reduce
((
d1
,
d2
)
=>
d1
+
d2
,
0
)
/
(
descriptorsOfClass
.
length
||
1
)
)
}
return
descriptorsByClass
.
map
(
({
descriptor
,
className
})
=>
({
distance
:
facerecognition
.
round
(
facerecognition
.
euclideanDistance
(
descriptor
,
queryDescriptor
)
),
({
descriptors
,
className
})
=>
({
distance
:
computeMeanDistance
(
descriptors
),
className
})
)
...
...
examples/views/detectAndRecognizeFaces.html
View file @
bdfaba24
...
...
@@ -41,7 +41,7 @@
</div>
<script>
const
threshold
=
0.
6
const
threshold
=
0.
8
let
minConfidence
=
0.7
let
detectionNet
,
recognitionNet
let
trainDescriptorsByClass
=
[]
...
...
@@ -71,7 +71,7 @@
const
detectionsForSize
=
detections
.
map
(
det
=>
det
.
forSize
(
width
,
height
))
facerecognition
.
drawDetection
(
'overlay'
,
detectionsForSize
,
{
withScore
:
false
})
const
faceTensors
=
await
facerecognition
.
extractFaceTensors
(
input
,
detections
)
const
faceTensors
=
(
await
facerecognition
.
extractFaceTensors
(
input
,
detections
)
)
const
descriptors
=
await
Promise
.
all
(
faceTensors
.
map
(
t
=>
recognitionNet
.
computeFaceDescriptor
(
t
)))
// free memory for face image tensors after we computed their descriptors
...
...
@@ -94,7 +94,7 @@
async
function
run
()
{
detectionNet
=
await
initFaceDetectionNet
()
recognitionNet
=
await
initFaceRecognitionNet
()
trainDescriptorsByClass
=
await
initTrainDescriptorsByClass
(
recognitionNet
)
trainDescriptorsByClass
=
await
initTrainDescriptorsByClass
(
recognitionNet
,
1
)
$
(
'#loader'
).
hide
()
onSelectionChanged
(
$
(
'#selectList select'
).
val
())
}
...
...
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