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
0320da07
Commit
0320da07
authored
Aug 10, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log individual loss types and average losses
parent
3afe611f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
25 deletions
+44
-25
overfit.html
tools/train/tinyYolov2/overfit.html
+31
-16
train.js
tools/train/tinyYolov2/train.js
+12
-8
verify.html
tools/train/tinyYolov2/verify.html
+1
-1
No files found.
tools/train/tinyYolov2/overfit.html
View file @
0320da07
...
...
@@ -17,12 +17,12 @@
<script>
tf
=
faceapi
.
tf
const
weightsUrl
=
'/tmp/
test
.weights'
const
fromEpoch
=
80
0
const
weightsUrl
=
'/tmp/
initial_tiny_yolov2_glorot_normal
.weights'
const
fromEpoch
=
0
window
.
debug
=
tru
e
window
.
logTrainSteps
=
tru
e
window
.
debug
=
fals
e
window
.
logTrainSteps
=
fals
e
// hyper parameters
...
...
@@ -30,12 +30,13 @@
window
.
noObjectScale
=
1
window
.
coordScale
=
1
window
.
saveEveryNthIteration
=
50
window
.
saveEveryNthIteration
=
1
window
.
trainSteps
=
4000
//window.optimizer = tf.train.sgd(0.001)
window
.
optimizer
=
tf
.
train
.
adam
(
0.001
,
0.9
,
0.999
,
1
e
-
8
)
const
numTrainSamples
=
1
// all samples
const
numTrainSamples
=
Infinity
async
function
loadNetWeights
(
uri
)
{
return
new
Float32Array
(
await
(
await
fetch
(
uri
)).
arrayBuffer
())
...
...
@@ -50,13 +51,18 @@
window
.
net
=
new
faceapi
.
TinyYolov2
(
true
)
window
.
net
.
load
(
weights
)
window
.
net
.
variable
()
window
.
detectionFilenames
=
(
await
fetchDetectionFilenames
()).
slice
(
1
,
numTrainSamples
+
1
)
window
.
detectionFilenames
=
(
await
fetchDetectionFilenames
()).
slice
(
0
,
numTrainSamples
)
window
.
lossMap
=
{}
console
.
log
(
'ready'
)
}
const
trainSizes
=
[
608
]
const
trainSizes
=
[
320
]
function
logLossChange
(
lossType
)
{
const
{
currentLoss
,
prevLoss
,
detectionFilenames
}
=
window
log
(
`
${
lossType
}
:
${
faceapi
.
round
(
currentLoss
[
lossType
])}
(avg:
${
faceapi
.
round
(
currentLoss
[
lossType
]
/
detectionFilenames
.
length
)}
) (delta:
${
currentLoss
[
lossType
]
-
prevLoss
[
lossType
]}
)`
)
}
async
function
train
(
batchSize
=
1
)
{
for
(
let
i
=
fromEpoch
;
i
<
trainSteps
;
i
++
)
{
...
...
@@ -81,21 +87,30 @@
log
()
log
(
'step %s done (%s ms)'
,
i
,
ts
)
const
currentLoss
=
Object
.
keys
(
lossMap
).
map
(
k
=>
lossMap
[
k
]).
reduce
((
sum
,
l
)
=>
sum
+
l
)
window
.
prevLoss
=
window
.
currentLoss
window
.
currentLoss
=
Object
.
keys
(
lossMap
)
.
map
(
filename
=>
lossMap
[
filename
])
.
reduce
((
accumulatedLosses
,
losses
)
=>
Object
.
keys
(
losses
)
.
map
(
key
=>
({
[
key
]:
(
accumulatedLosses
[
key
]
||
0
)
+
losses
[
key
]
}))
.
reduce
((
map
,
curr
)
=>
({
...
map
,
...
curr
}),
{}),
{}
)
if
(
window
.
prevLoss
)
{
log
(
'prevLoss:'
,
window
.
prevLoss
)
log
(
'currentLoss:'
,
currentLoss
)
log
(
'loss change:'
,
currentLoss
-
window
.
prevLoss
)
logLossChange
(
'noObjectLoss'
)
logLossChange
(
'objectLoss'
)
logLossChange
(
'coordLoss'
)
logLossChange
(
'totalLoss'
)
}
log
()
log
(
'--------------------'
)
log
()
window
.
prevLoss
=
currentLoss
if
(((
i
+
1
)
%
saveEveryNthIteration
)
===
0
)
{
saveWeights
(
window
.
net
,
'adam_511_'
+
i
+
'.weights'
)
saveWeights
(
window
.
net
,
'adam_511_'
+
(
i
+
1
)
+
'.weights'
)
}
}
}
...
...
tools/train/tinyYolov2/train.js
View file @
0320da07
...
...
@@ -25,22 +25,26 @@ async function trainStep(batchCreators, inputSize) {
batchInput
.
getRelativePaddings
(
batchIdx
)
)
const
total
=
totalLoss
.
dataSync
()[
0
]
const
losses
=
{
totalLoss
:
totalLoss
.
dataSync
()[
0
],
noObjectLoss
:
noObjectLoss
.
dataSync
()[
0
],
objectLoss
:
objectLoss
.
dataSync
()[
0
],
coordLoss
:
coordLoss
.
dataSync
()[
0
]
}
if
(
window
.
logTrainSteps
)
{
log
(
`ground truth boxes:
${
groundTruthBoxes
[
batchIdx
].
length
}
`
)
log
(
`noObjectLoss[
${
dataIdx
}
]:
${
noObjectLoss
.
dataSync
()
}
`
)
log
(
`objectLoss[
${
dataIdx
}
]:
${
objectLoss
.
dataSync
()
}
`
)
log
(
`coordLoss[
${
dataIdx
}
]:
${
coordLoss
.
dataSync
()
}
`
)
log
(
`totalLoss[
${
dataIdx
}
]:
${
total
}
`
)
log
(
`noObjectLoss[
${
dataIdx
}
]:
${
losses
.
noObjectLoss
}
`
)
log
(
`objectLoss[
${
dataIdx
}
]:
${
losses
.
objectLoss
}
`
)
log
(
`coordLoss[
${
dataIdx
}
]:
${
losses
.
coordLoss
}
`
)
log
(
`totalLoss[
${
dataIdx
}
]:
${
losses
.
totalLoss
}
`
)
if
(
window
.
lossMap
[
filenames
])
{
log
(
`loss change:
${
total
-
window
.
lossMap
[
filenames
]
}
`
)
log
(
`loss change:
${
losses
.
totalLoss
-
window
.
lossMap
[
filenames
].
totalLoss
}
`
)
}
}
window
.
lossMap
[
filenames
]
=
total
window
.
lossMap
[
filenames
]
=
losses
return
totalLoss
},
true
)
...
...
tools/train/tinyYolov2/verify.html
View file @
0320da07
...
...
@@ -138,7 +138,7 @@
async
function
run
()
{
$
(
'#imgByNr'
).
keydown
(
onKeyDown
)
const
weights
=
await
loadNetWeights
(
'/tmp/test
2
.weights'
)
const
weights
=
await
loadNetWeights
(
'/tmp/test
_n100_320_114
.weights'
)
window
.
net
=
new
faceapi
.
TinyYolov2
(
true
)
await
window
.
net
.
load
(
weights
)
...
...
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