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
aa7dd87c
Commit
aa7dd87c
authored
Aug 04, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init train data fetching
parent
ca47cbbd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
17 deletions
+84
-17
faceLandmarksTrain.js
tools/train/faceLandmarks/faceLandmarksTrain.js
+0
-10
serveFaceLandmarks.js
tools/train/serveFaceLandmarks.js
+1
-0
serveTinyYolov2.js
tools/train/serveTinyYolov2.js
+9
-3
trainUtils.js
tools/train/shared/trainUtils.js
+8
-0
train.html
tools/train/tinyYolov2/train.html
+4
-4
train.js
tools/train/tinyYolov2/train.js
+62
-0
No files found.
tools/train/faceLandmarks/faceLandmarksTrain.js
View file @
aa7dd87c
async
function
promiseSequential
(
promises
)
{
const
curr
=
promises
[
0
]
if
(
!
curr
)
{
return
}
await
curr
()
return
promiseSequential
(
promises
.
slice
(
1
))
}
async
function
trainStep
(
batchCreators
)
{
await
promiseSequential
(
batchCreators
.
map
((
batchCreator
,
dataIdx
)
=>
async
()
=>
{
...
...
tools/train/serveFaceLandmarks.js
View file @
aa7dd87c
...
...
@@ -7,6 +7,7 @@ const app = express()
const
publicDir
=
path
.
join
(
__dirname
,
'./faceLandmarks'
)
app
.
use
(
express
.
static
(
publicDir
))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'./shared'
)))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'./node_modules/file-saver'
)))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'../../examples/public'
)))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'../../weights'
)))
...
...
tools/train/serveTinyYolov2.js
View file @
aa7dd87c
...
...
@@ -2,21 +2,26 @@ require('./tinyYolov2/.env')
const
express
=
require
(
'express'
)
const
path
=
require
(
'path'
)
const
fs
=
require
(
'fs'
)
const
app
=
express
()
const
publicDir
=
path
.
join
(
__dirname
,
'./tinyYolov2'
)
app
.
use
(
express
.
static
(
publicDir
))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'./shared'
)))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'./node_modules/file-saver'
)))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'../../examples/public'
)))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'../../weights'
)))
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'../../dist'
)))
const
trainDataPath
=
path
.
resolve
(
process
.
env
.
TRAIN_DATA_PATH
)
const
imagesPath
=
path
.
join
(
trainDataPath
,
'./final_images'
)
const
detectionsPath
=
path
.
join
(
trainDataPath
,
'./final_detections'
)
const
detectionFilenames
=
fs
.
readdirSync
(
detectionsPath
)
app
.
use
(
express
.
static
(
trainDataPath
))
//app.get('/', (req, res) => res.sendFile(path.join(publicDir, 'train.html')))
//app.get('/', (req, res) => res.sendFile(path.join(publicDir, 'tinyYolov2FaceDetectionVideo.html')))
app
.
get
(
'/'
,
(
req
,
res
)
=>
res
.
sendFile
(
path
.
join
(
publicDir
,
'testLoss.html'
)))
app
.
get
(
'/detection_filenames'
,
(
req
,
res
)
=>
res
.
status
(
202
).
send
(
detectionFilenames
))
app
.
get
(
'/'
,
(
req
,
res
)
=>
res
.
sendFile
(
path
.
join
(
publicDir
,
'train.html'
)))
app
.
listen
(
3000
,
()
=>
console
.
log
(
'Listening on port 3000!'
))
\ No newline at end of file
tools/train/
faceLandmarks
/trainUtils.js
→
tools/train/
shared
/trainUtils.js
View file @
aa7dd87c
async
function
promiseSequential
(
promises
)
{
const
curr
=
promises
[
0
]
if
(
!
curr
)
{
return
}
await
curr
()
return
promiseSequential
(
promises
.
slice
(
1
))
}
// https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array
function
shuffle
(
a
)
{
...
...
tools/train/tinyYolov2/train.html
View file @
aa7dd87c
...
...
@@ -29,16 +29,16 @@
return
new
Float32Array
(
await
(
await
fetch
(
uri
)).
arrayBuffer
())
}
async
function
getTrainData
()
{
// TBD
async
function
fetchDetectionFilenames
()
{
return
fetch
(
'/detection_filenames'
).
then
(
res
=>
res
.
json
())
}
async
function
run
()
{
const
weights
=
await
loadNetWeights
(
weightsUrl
)
window
.
net
=
new
faceapi
.
TinyYolov2
(
true
)
window
.
net
.
load
(
weights
)
window
.
trainData
=
await
getTrainData
()
window
.
net
.
variable
()
window
.
detectionFilenames
=
await
fetchDetectionFilenames
()
}
/*
...
...
@@ -68,7 +68,7 @@
async
function
train
(
batchSize
=
1
)
{
for
(
let
i
=
0
;
i
<
trainSteps
;
i
++
)
{
console
.
log
(
'step'
,
i
)
const
batchCreators
=
createBatchCreators
(
shuffle
(
window
.
trainData
),
batchSize
)
const
batchCreators
=
createBatchCreators
(
shuffle
(
detectionFilenames
),
batchSize
)
let
ts
=
Date
.
now
()
await
trainStep
(
batchCreators
)
ts
=
Date
.
now
()
-
ts
...
...
tools/train/tinyYolov2/train.js
0 → 100644
View file @
aa7dd87c
async
function
trainStep
(
batchCreators
)
{
await
promiseSequential
(
batchCreators
.
map
((
batchCreator
,
dataIdx
)
=>
async
()
=>
{
const
{
batchInput
,
groundTruthBoxes
}
=
await
batchCreator
()
/*
let ts = Date.now()
const cost = optimizer.minimize(() => {
const out = window.trainNet.forwardInput(batchInput.managed())
const loss = lossFunction(
landmarksBatchTensor,
out
)
return loss
}, true)
ts = Date.now() - ts
console.log(`loss[${dataIdx}]: ${await cost.data()}, ${ts} ms (${ts / batchInput.batchSize} ms / batch element)`)
landmarksBatchTensor.dispose()
cost.dispose()
await tf.nextFrame()
}))
*/
}
function
createBatchCreators
(
batchSize
)
{
if
(
batchSize
<
1
)
{
throw
new
Error
(
'invalid batch size: '
+
batchSize
)
}
const
batches
=
[]
const
pushToBatch
=
(
remaining
)
=>
{
if
(
remaining
.
length
)
{
batches
.
push
(
remaining
.
slice
(
0
,
batchSize
))
pushToBatch
(
remaining
.
slice
(
batchSize
))
}
return
batches
}
pushToBatch
(
window
.
detectionFilenames
)
const
batchCreators
=
batches
.
map
(
detectionFilenames
=>
async
()
=>
{
const
imgs
=
detectionFilenames
.
map
(
detectionFilenames
.
map
(
file
=>
fetch
(
file
).
then
(
res
=>
res
.
json
()))
)
const
groundTruthBoxes
=
await
Promise
.
all
(
detectionFilenames
.
map
(
async
file
=>
await
faceapi
.
bufferToImage
(
await
fetchImage
(
file
.
replace
(
'.json'
,
''
))))
)
const
batchInput
=
await
faceapi
.
toNetInput
(
imgs
)
return
{
batchInput
,
groundTruthBoxes
}
})
return
batchCreators
}
\ 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