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
72d280cf
Commit
72d280cf
authored
Jun 16, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented faceLandmarkNet
parent
fa5a59a6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
29 deletions
+59
-29
convLayer.ts
src/commons/convLayer.ts
+17
-0
boxPredictionLayer.ts
src/faceDetectionNet/boxPredictionLayer.ts
+3
-14
fullyConnectedLayer.ts
src/faceLandmarkNet/fullyConnectedLayer.ts
+16
-0
index.ts
src/faceLandmarkNet/index.ts
+17
-10
convLayer.ts
src/faceRecognitionNet/convLayer.ts
+6
-5
No files found.
src/commons/convLayer.ts
0 → 100644
View file @
72d280cf
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
{
ConvParams
}
from
'./types'
;
export
function
convLayer
(
x
:
tf
.
Tensor4D
,
params
:
ConvParams
,
padding
:
'valid'
|
'same'
=
'same'
):
tf
.
Tensor4D
{
return
tf
.
tidy
(()
=>
tf
.
add
(
tf
.
conv2d
(
x
,
params
.
filters
,
[
1
,
1
],
padding
),
params
.
bias
)
)
}
\ No newline at end of file
src/faceDetectionNet/boxPredictionLayer.ts
View file @
72d280cf
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
{
ConvParams
}
from
'../commons/types
'
;
import
{
convLayer
}
from
'../commons/convLayer
'
;
import
{
FaceDetectionNet
}
from
'./types'
;
import
{
FaceDetectionNet
}
from
'./types'
;
function
convWithBias
(
x
:
tf
.
Tensor4D
,
params
:
ConvParams
)
{
return
tf
.
tidy
(()
=>
tf
.
add
(
tf
.
conv2d
(
x
,
params
.
filters
,
[
1
,
1
],
'same'
),
params
.
bias
)
)
}
export
function
boxPredictionLayer
(
export
function
boxPredictionLayer
(
x
:
tf
.
Tensor4D
,
x
:
tf
.
Tensor4D
,
...
@@ -24,11 +13,11 @@ export function boxPredictionLayer(
...
@@ -24,11 +13,11 @@ export function boxPredictionLayer(
const
batchSize
=
x
.
shape
[
0
]
const
batchSize
=
x
.
shape
[
0
]
const
boxPredictionEncoding
=
tf
.
reshape
(
const
boxPredictionEncoding
=
tf
.
reshape
(
conv
WithBias
(
x
,
params
.
box_encoding_predictor_params
),
conv
Layer
(
x
,
params
.
box_encoding_predictor_params
),
[
batchSize
,
-
1
,
1
,
4
]
[
batchSize
,
-
1
,
1
,
4
]
)
)
const
classPrediction
=
tf
.
reshape
(
const
classPrediction
=
tf
.
reshape
(
conv
WithBias
(
x
,
params
.
class_predictor_params
),
conv
Layer
(
x
,
params
.
class_predictor_params
),
[
batchSize
,
-
1
,
3
]
[
batchSize
,
-
1
,
3
]
)
)
...
...
src/faceLandmarkNet/fullyConnectedLayer.ts
0 → 100644
View file @
72d280cf
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
{
FaceLandmarkNet
}
from
'./types'
;
export
function
fullyConnectedLayer
(
x
:
tf
.
Tensor2D
,
params
:
FaceLandmarkNet
.
FCParams
):
tf
.
Tensor2D
{
return
tf
.
tidy
(()
=>
tf
.
add
(
tf
.
matMul
(
x
,
params
.
weights
),
params
.
bias
)
)
}
\ No newline at end of file
src/faceLandmarkNet/index.ts
View file @
72d280cf
...
@@ -5,6 +5,8 @@ import { NetInput } from '../NetInput';
...
@@ -5,6 +5,8 @@ import { NetInput } from '../NetInput';
import
{
padToSquare
}
from
'../padToSquare'
;
import
{
padToSquare
}
from
'../padToSquare'
;
import
{
TNetInput
}
from
'../types'
;
import
{
TNetInput
}
from
'../types'
;
import
{
extractParams
}
from
'./extractParams'
;
import
{
extractParams
}
from
'./extractParams'
;
import
{
convLayer
}
from
'../commons/convLayer'
;
import
{
fullyConnectedLayer
}
from
'./fullyConnectedLayer'
;
export
function
faceLandmarkNet
(
weights
:
Float32Array
)
{
export
function
faceLandmarkNet
(
weights
:
Float32Array
)
{
const
params
=
extractParams
(
weights
)
const
params
=
extractParams
(
weights
)
...
@@ -18,17 +20,22 @@ export function faceLandmarkNet(weights: Float32Array) {
...
@@ -18,17 +20,22 @@ export function faceLandmarkNet(weights: Float32Array) {
x
=
tf
.
image
.
resizeBilinear
(
x
,
[
128
,
128
])
x
=
tf
.
image
.
resizeBilinear
(
x
,
[
128
,
128
])
}
}
// pool 1
let
out
=
convLayer
(
x
,
params
.
conv0_params
,
'valid'
)
tf
.
maxPool
(
x
,
[
2
,
2
],
[
2
,
2
],
'valid'
)
out
=
tf
.
maxPool
(
out
,
[
2
,
2
],
[
2
,
2
],
'valid'
)
// pool 2
out
=
convLayer
(
out
,
params
.
conv1_params
,
'valid'
)
tf
.
maxPool
(
x
,
[
2
,
2
],
[
2
,
2
],
'valid'
)
out
=
convLayer
(
out
,
params
.
conv2_params
,
'valid'
)
// pool 3
out
=
tf
.
maxPool
(
out
,
[
2
,
2
],
[
2
,
2
],
'valid'
)
tf
.
maxPool
(
x
,
[
2
,
2
],
[
2
,
2
],
'valid'
)
out
=
convLayer
(
out
,
params
.
conv3_params
,
'valid'
)
// pool 4
out
=
convLayer
(
out
,
params
.
conv4_params
,
'valid'
)
tf
.
maxPool
(
x
,
[
2
,
2
],
[
1
,
1
],
'valid'
)
out
=
tf
.
maxPool
(
out
,
[
2
,
2
],
[
2
,
2
],
'valid'
)
// TODO
out
=
convLayer
(
out
,
params
.
conv5_params
,
'valid'
)
out
=
convLayer
(
out
,
params
.
conv6_params
,
'valid'
)
out
=
tf
.
maxPool
(
out
,
[
2
,
2
],
[
1
,
1
],
'valid'
)
out
=
convLayer
(
out
,
params
.
conv7_params
,
'valid'
)
const
fc0
=
fullyConnectedLayer
(
out
.
as2D
(
out
.
shape
[
0
],
-
1
),
params
.
fc0_params
)
const
fc1
=
fullyConnectedLayer
(
fc0
,
params
.
fc1_params
)
return
x
return
fc1
})
})
}
}
...
...
src/faceRecognitionNet/convLayer.ts
View file @
72d280cf
...
@@ -7,26 +7,26 @@ import { FaceRecognitionNet } from './types';
...
@@ -7,26 +7,26 @@ import { FaceRecognitionNet } from './types';
function
convLayer
(
function
convLayer
(
x
:
tf
.
Tensor4D
,
x
:
tf
.
Tensor4D
,
params
:
FaceRecognitionNet
.
ConvLayerParams
,
params
:
FaceRecognitionNet
.
ConvLayerParams
,
stride
:
number
,
stride
s
:
[
number
,
number
]
,
withRelu
:
boolean
,
withRelu
:
boolean
,
padding
:
'valid'
|
'same'
=
'same'
padding
:
'valid'
|
'same'
=
'same'
):
tf
.
Tensor4D
{
):
tf
.
Tensor4D
{
const
{
filters
,
bias
}
=
params
.
conv
const
{
filters
,
bias
}
=
params
.
conv
let
out
=
tf
.
conv2d
(
x
,
filters
,
[
stride
,
stride
]
,
padding
)
let
out
=
tf
.
conv2d
(
x
,
filters
,
strides
,
padding
)
out
=
tf
.
add
(
out
,
bias
)
out
=
tf
.
add
(
out
,
bias
)
out
=
scale
(
out
,
params
.
scale
)
out
=
scale
(
out
,
params
.
scale
)
return
withRelu
?
tf
.
relu
(
out
)
:
out
return
withRelu
?
tf
.
relu
(
out
)
:
out
}
}
export
function
conv
(
x
:
tf
.
Tensor4D
,
params
:
FaceRecognitionNet
.
ConvLayerParams
)
{
export
function
conv
(
x
:
tf
.
Tensor4D
,
params
:
FaceRecognitionNet
.
ConvLayerParams
)
{
return
convLayer
(
x
,
params
,
1
,
true
)
return
convLayer
(
x
,
params
,
[
1
,
1
]
,
true
)
}
}
export
function
convNoRelu
(
x
:
tf
.
Tensor4D
,
params
:
FaceRecognitionNet
.
ConvLayerParams
)
{
export
function
convNoRelu
(
x
:
tf
.
Tensor4D
,
params
:
FaceRecognitionNet
.
ConvLayerParams
)
{
return
convLayer
(
x
,
params
,
1
,
false
)
return
convLayer
(
x
,
params
,
[
1
,
1
]
,
false
)
}
}
export
function
convDown
(
x
:
tf
.
Tensor4D
,
params
:
FaceRecognitionNet
.
ConvLayerParams
)
{
export
function
convDown
(
x
:
tf
.
Tensor4D
,
params
:
FaceRecognitionNet
.
ConvLayerParams
)
{
return
convLayer
(
x
,
params
,
2
,
true
,
'valid'
)
return
convLayer
(
x
,
params
,
[
2
,
2
]
,
true
,
'valid'
)
}
}
\ 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