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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
commons.js
examples/public/commons.js
+23
-12
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() {
...
@@ -25,28 +25,39 @@ async function initFaceRecognitionNet() {
}
}
// fetch first image of each class and compute their descriptors
// 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
(
return
Promise
.
all
(
classes
.
map
(
async
className
=>
{
async
className
=>
{
const
img
=
await
facerecognition
.
bufferToImage
(
const
descriptors
=
[]
await
fetchImage
(
getFaceImageUri
(
className
,
1
))
for
(
let
i
=
1
;
i
<
(
numImagesForTraining
+
1
);
i
++
)
{
)
const
img
=
await
facerecognition
.
bufferToImage
(
const
descriptor
=
await
net
.
computeFaceDescriptor
(
img
)
await
fetchImage
(
getFaceImageUri
(
className
,
i
))
)
descriptors
.
push
(
await
net
.
computeFaceDescriptor
(
img
))
}
return
{
return
{
descriptor
,
descriptor
s
,
className
className
}
}
}
}
))
))
}
}
function
getBestMatch
(
allDescriptors
,
queryDescriptor
)
{
function
getBestMatch
(
descriptorsByClass
,
queryDescriptor
)
{
return
allDescriptors
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
(
.
map
(
({
descriptor
,
className
})
=>
({
({
descriptors
,
className
})
=>
({
distance
:
facerecognition
.
round
(
distance
:
computeMeanDistance
(
descriptors
),
facerecognition
.
euclideanDistance
(
descriptor
,
queryDescriptor
)
),
className
className
})
})
)
)
...
...
examples/views/detectAndRecognizeFaces.html
View file @
bdfaba24
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
</div>
</div>
<script>
<script>
const
threshold
=
0.
6
const
threshold
=
0.
8
let
minConfidence
=
0.7
let
minConfidence
=
0.7
let
detectionNet
,
recognitionNet
let
detectionNet
,
recognitionNet
let
trainDescriptorsByClass
=
[]
let
trainDescriptorsByClass
=
[]
...
@@ -71,7 +71,7 @@
...
@@ -71,7 +71,7 @@
const
detectionsForSize
=
detections
.
map
(
det
=>
det
.
forSize
(
width
,
height
))
const
detectionsForSize
=
detections
.
map
(
det
=>
det
.
forSize
(
width
,
height
))
facerecognition
.
drawDetection
(
'overlay'
,
detectionsForSize
,
{
withScore
:
false
})
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
)))
const
descriptors
=
await
Promise
.
all
(
faceTensors
.
map
(
t
=>
recognitionNet
.
computeFaceDescriptor
(
t
)))
// free memory for face image tensors after we computed their descriptors
// free memory for face image tensors after we computed their descriptors
...
@@ -94,7 +94,7 @@
...
@@ -94,7 +94,7 @@
async
function
run
()
{
async
function
run
()
{
detectionNet
=
await
initFaceDetectionNet
()
detectionNet
=
await
initFaceDetectionNet
()
recognitionNet
=
await
initFaceRecognitionNet
()
recognitionNet
=
await
initFaceRecognitionNet
()
trainDescriptorsByClass
=
await
initTrainDescriptorsByClass
(
recognitionNet
)
trainDescriptorsByClass
=
await
initTrainDescriptorsByClass
(
recognitionNet
,
1
)
$
(
'#loader'
).
hide
()
$
(
'#loader'
).
hide
()
onSelectionChanged
(
$
(
'#selectList select'
).
val
())
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