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
896371af
Commit
896371af
authored
Aug 14, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
square images before converting them to tensors to prevent gpu memory leak issue
parent
5e50b9dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
15 deletions
+49
-15
train.html
tools/train/tinyYolov2/train.html
+8
-9
train.js
tools/train/tinyYolov2/train.js
+39
-5
verify.html
tools/train/tinyYolov2/verify.html
+2
-1
No files found.
tools/train/tinyYolov2/train.html
View file @
896371af
...
@@ -24,11 +24,13 @@
...
@@ -24,11 +24,13 @@
const
weightsUrl
=
`/tmp/tmp__224_
${
startIdx224
}
__320_
${
startIdx320
}
__416_
${
startIdx416
}
__608_
${
startIdx608
}
.weights`
const
weightsUrl
=
`/tmp/tmp__224_
${
startIdx224
}
__320_
${
startIdx320
}
__416_
${
startIdx416
}
__608_
${
startIdx608
}
.weights`
//const weightsUrl = '/tmp/tmp_2_count_41000.weights'
const
fromEpoch
=
0
const
fromEpoch
=
0
const
trainOnlyMultibox
=
false
const
trainOnlyMultibox
=
false
const
trainSizes
=
[
160
,
224
,
320
,
416
]
//const trainSizes = [608]
window
.
debug
=
false
window
.
debug
=
false
window
.
logTrainSteps
=
true
window
.
logTrainSteps
=
true
...
@@ -38,8 +40,8 @@
...
@@ -38,8 +40,8 @@
window
.
noObjectScale
=
1
window
.
noObjectScale
=
1
window
.
coordScale
=
1
window
.
coordScale
=
1
const
rescaleEveryNthBatch
=
Infinity
const
rescaleEveryNthBatch
=
100
window
.
saveEveryNthDataIdx
=
100
window
.
saveEveryNthDataIdx
=
trainSizes
.
length
*
rescaleEveryNthBatch
window
.
trainSteps
=
4000
window
.
trainSteps
=
4000
//window.optimizer = tf.train.sgd(0.001)
//window.optimizer = tf.train.sgd(0.001)
window
.
optimizer
=
tf
.
train
.
adam
(
0.001
,
0.9
,
0.999
,
1
e
-
8
)
window
.
optimizer
=
tf
.
train
.
adam
(
0.001
,
0.9
,
0.999
,
1
e
-
8
)
...
@@ -78,9 +80,6 @@
...
@@ -78,9 +80,6 @@
console
.
log
(
'ready'
)
console
.
log
(
'ready'
)
}
}
//const trainSizes = [224, 320, 416]
const
trainSizes
=
[
608
]
function
logLossChange
(
lossType
)
{
function
logLossChange
(
lossType
)
{
const
{
currentLoss
,
prevLoss
,
detectionFilenames
}
=
window
const
{
currentLoss
,
prevLoss
,
detectionFilenames
}
=
window
log
(
`
${
lossType
}
:
${
faceapi
.
round
(
currentLoss
[
lossType
])}
(avg:
${
faceapi
.
round
(
currentLoss
[
lossType
]
/
detectionFilenames
.
length
)}
) (delta:
${
currentLoss
[
lossType
]
-
prevLoss
[
lossType
]}
)`
)
log
(
`
${
lossType
}
:
${
faceapi
.
round
(
currentLoss
[
lossType
])}
(avg:
${
faceapi
.
round
(
currentLoss
[
lossType
]
/
detectionFilenames
.
length
)}
) (delta:
${
currentLoss
[
lossType
]
-
prevLoss
[
lossType
]}
)`
)
...
@@ -88,16 +87,16 @@
...
@@ -88,16 +87,16 @@
window
.
count
=
0
window
.
count
=
0
function
_
onBatchProcessed
(
dataIdx
,
inputSize
)
{
function
onBatchProcessed
(
dataIdx
,
inputSize
)
{
window
.
count
++
window
.
count
++
const
idx
=
(
dataIdx
+
1
)
+
(
window
.
epoch
*
window
.
detectionFilenames
.
length
)
const
idx
=
(
dataIdx
+
1
)
+
(
window
.
epoch
*
window
.
detectionFilenames
.
length
)
console
.
log
(
'dataIdx'
,
dataIdx
)
console
.
log
(
'dataIdx'
,
dataIdx
)
if
((
window
.
count
%
saveEveryNthDataIdx
)
===
0
)
{
if
((
window
.
count
%
saveEveryNthDataIdx
)
===
0
)
{
saveWeights
(
window
.
net
,
`tmp_
2
_count_
${
window
.
count
}
.weights`
)
saveWeights
(
window
.
net
,
`tmp_
multiscale
_count_
${
window
.
count
}
.weights`
)
}
}
}
}
function
onBatchProcessed
(
dataIdx
,
inputSize
)
{
function
_
onBatchProcessed
(
dataIdx
,
inputSize
)
{
const
idx
=
(
dataIdx
+
1
)
+
(
window
.
epoch
*
window
.
detectionFilenames
.
length
)
const
idx
=
(
dataIdx
+
1
)
+
(
window
.
epoch
*
window
.
detectionFilenames
.
length
)
console
.
log
(
'idx'
,
idx
)
console
.
log
(
'idx'
,
idx
)
if
((
idx
%
saveEveryNthDataIdx
)
===
0
)
{
if
((
idx
%
saveEveryNthDataIdx
)
===
0
)
{
...
...
tools/train/tinyYolov2/train.js
View file @
896371af
const
batchIdx
=
0
const
batchIdx
=
0
function
minimize
(
groundTruthBoxes
,
batchInput
,
inputSize
,
batch
)
{
function
minimize
(
groundTruthBoxes
,
batchInput
,
inputSize
,
batch
,
{
reshapedImgDims
,
paddings
}
)
{
const
filename
=
batch
.
filenames
[
batchIdx
]
const
filename
=
batch
.
filenames
[
batchIdx
]
const
{
dataIdx
}
=
batch
const
{
dataIdx
}
=
batch
...
@@ -16,8 +16,8 @@ function minimize(groundTruthBoxes, batchInput, inputSize, batch) {
...
@@ -16,8 +16,8 @@ function minimize(groundTruthBoxes, batchInput, inputSize, batch) {
}
=
computeLoss
(
}
=
computeLoss
(
outTensor
,
outTensor
,
groundTruthBoxes
,
groundTruthBoxes
,
batchInput
.
getReshapedInputDimensions
(
batchIdx
)
,
reshapedImgDims
,
batchInput
.
getRelativePaddings
(
batchIdx
)
paddings
)
)
const
losses
=
{
const
losses
=
{
...
@@ -47,6 +47,35 @@ function minimize(groundTruthBoxes, batchInput, inputSize, batch) {
...
@@ -47,6 +47,35 @@ function minimize(groundTruthBoxes, batchInput, inputSize, batch) {
},
true
)
},
true
)
}
}
function
imageToSquare
(
img
)
{
const
scale
=
608
/
Math
.
max
(
img
.
height
,
img
.
width
)
const
width
=
scale
*
img
.
width
const
height
=
scale
*
img
.
height
const
canvas1
=
faceapi
.
createCanvasFromMedia
(
img
)
const
targetCanvas
=
faceapi
.
createCanvas
({
width
:
608
,
height
:
608
})
targetCanvas
.
getContext
(
'2d'
).
putImageData
(
canvas1
.
getContext
(
'2d'
).
getImageData
(
0
,
0
,
width
,
height
),
0
,
0
)
return
targetCanvas
}
function
getPaddingsAndReshapedSize
(
img
,
inputSize
)
{
const
[
h
,
w
]
=
[
img
.
height
,
img
.
width
]
const
maxDim
=
Math
.
max
(
h
,
w
)
const
f
=
inputSize
/
maxDim
const
reshapedImgDims
=
{
height
:
Math
.
floor
(
h
*
f
),
width
:
Math
.
floor
(
w
*
f
)
}
const
paddings
=
new
faceapi
.
Point
(
maxDim
/
img
.
width
,
maxDim
/
img
.
height
)
return
{
paddings
,
reshapedImgDims
}
}
async
function
trainStep
(
batchCreators
,
inputSizes
,
rescaleEveryNthBatch
,
onBatchProcessed
=
()
=>
{})
{
async
function
trainStep
(
batchCreators
,
inputSizes
,
rescaleEveryNthBatch
,
onBatchProcessed
=
()
=>
{})
{
async
function
step
(
currentBatchCreators
)
{
async
function
step
(
currentBatchCreators
)
{
...
@@ -61,7 +90,11 @@ async function trainStep(batchCreators, inputSizes, rescaleEveryNthBatch, onBatc
...
@@ -61,7 +90,11 @@ async function trainStep(batchCreators, inputSizes, rescaleEveryNthBatch, onBatc
const
batch
=
await
batchCreator
()
const
batch
=
await
batchCreator
()
const
{
imgs
,
groundTruthBoxes
,
filenames
,
dataIdx
}
=
batch
const
{
imgs
,
groundTruthBoxes
,
filenames
,
dataIdx
}
=
batch
const
batchInput
=
await
faceapi
.
toNetInput
(
imgs
)
const
img
=
imgs
[
0
]
const
{
reshapedImgDims
,
paddings
}
=
getPaddingsAndReshapedSize
(
img
,
inputSize
)
const
squareImg
=
imageToSquare
(
img
)
const
batchInput
=
await
faceapi
.
toNetInput
(
squareImg
)
const
[
imgHeight
,
imgWidth
]
=
batchInput
.
inputs
[
batchIdx
].
shape
const
[
imgHeight
,
imgWidth
]
=
batchInput
.
inputs
[
batchIdx
].
shape
...
@@ -90,7 +123,8 @@ async function trainStep(batchCreators, inputSizes, rescaleEveryNthBatch, onBatc
...
@@ -90,7 +123,8 @@ async function trainStep(batchCreators, inputSizes, rescaleEveryNthBatch, onBatc
}
}
let
ts
=
Date
.
now
()
let
ts
=
Date
.
now
()
const
loss
=
minimize
(
filteredGroundTruthBoxes
,
batchInput
,
inputSize
,
batch
)
const
loss
=
minimize
(
filteredGroundTruthBoxes
,
batchInput
,
inputSize
,
batch
,
{
reshapedImgDims
,
paddings
})
ts
=
Date
.
now
()
-
ts
ts
=
Date
.
now
()
-
ts
if
(
window
.
logTrainSteps
)
{
if
(
window
.
logTrainSteps
)
{
log
(
`trainStep time for dataIdx
${
dataIdx
}
(
${
inputSize
}
):
${
ts
}
ms`
)
log
(
`trainStep time for dataIdx
${
dataIdx
}
(
${
inputSize
}
):
${
ts
}
ms`
)
...
...
tools/train/tinyYolov2/verify.html
View file @
896371af
...
@@ -144,7 +144,8 @@
...
@@ -144,7 +144,8 @@
const
startIdx416
=
31050
const
startIdx416
=
31050
const
startIdx608
=
16520
const
startIdx608
=
16520
const
weightsUrl
=
`/tmp/tmp__224_
${
startIdx224
}
__320_
${
startIdx320
}
__416_
${
startIdx416
}
__608_
${
startIdx608
}
.weights`
//const weightsUrl = `/tmp/tmp__224_${startIdx224}__320_${startIdx320}__416_${startIdx416}__608_${startIdx608}.weights`
const
weightsUrl
=
`/tmp/overfit_count_1500.weights`
const
weights
=
await
loadNetWeights
(
weightsUrl
)
const
weights
=
await
loadNetWeights
(
weightsUrl
)
window
.
net
=
new
faceapi
.
TinyYolov2
(
true
)
window
.
net
=
new
faceapi
.
TinyYolov2
(
true
)
...
...
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