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
cb52d620
Commit
cb52d620
authored
Jun 04, 2018
by
vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resizeLayer
parent
42e41f1e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
54 deletions
+65
-54
index.ts
src/faceDetectionNet/index.ts
+27
-0
index.ts
src/faceDetectionNet/preprocessor/index.ts
+0
-30
whileLayer.ts
src/faceDetectionNet/preprocessor/whileLayer.ts
+0
-10
resizeLayer.ts
src/faceDetectionNet/resizeLayer.ts
+12
-0
index.ts
src/index.ts
+3
-0
TensorArray.ts
src/tfcpatches/TensorArray.ts
+23
-14
No files found.
src/faceDetectionNet/index.ts
0 → 100644
View file @
cb52d620
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
{
resizeLayer
}
from
'./resizeLayer'
;
export
function
faceDetectionNet
()
{
async
function
forward
(
input
:
ImageData
|
ImageData
[])
{
const
imgTensors
=
(
input
instanceof
ImageData
?
[
input
]
:
input
)
.
map
(
data
=>
tf
.
fromPixels
(
data
))
.
map
(
data
=>
tf
.
expandDims
(
data
,
0
))
as
tf
.
Tensor4D
[]
const
imgTensor
=
tf
.
cast
(
tf
.
concat
(
imgTensors
,
0
),
'float32'
)
const
resized
=
resizeLayer
(
imgTensor
)
return
resized
}
return
{
forward
}
}
\ No newline at end of file
src/faceDetectionNet/preprocessor/index.ts
deleted
100644 → 0
View file @
42e41f1e
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
{
TensorArray
}
from
'../../tfcpatches/TensorArray'
;
import
{
whileLayer
}
from
'./whileLayer'
;
export
type
PreprocessorParams
=
any
// TODO: hardcoded params
const
elementShape
=
[
512
,
512
,
3
]
const
weight
=
tf
.
scalar
(
0.007843137718737125
)
const
bias
=
tf
.
scalar
(
1
)
export
function
preprocessor
(
imgTensor
:
tf
.
Tensor4D
,
params
:
PreprocessorParams
)
{
const
batchSize
=
imgTensor
.
shape
[
0
]
const
batchSizedArray1
=
new
TensorArray
(
batchSize
,
'float32'
)
const
batchSizedArray2
=
new
TensorArray
(
batchSize
,
'float32'
)
let
unusedFlow
=
null
const
indices
=
tf
.
range
(
0
,
batchSize
,
1
)
// unstack
unusedFlow
=
batchSizedArray1
.
scatter
(
indices
,
imgTensor
,
unusedFlow
)
unusedFlow
=
whileLayer
(
batchSizedArray1
,
batchSizedArray2
,
batchSize
,
unusedFlow
)
// stack
const
stacked
=
batchSizedArray2
.
gather
(
indices
,
unusedFlow
,
'float32'
,
elementShape
)
return
tf
.
add
(
tf
.
mul
(
stacked
,
weight
),
bias
)
}
\ No newline at end of file
src/faceDetectionNet/preprocessor/whileLayer.ts
deleted
100644 → 0
View file @
42e41f1e
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
{
TensorArray
}
from
'../../tfcpatches/TensorArray'
;
export
function
whileLayer
(
arr1
:
TensorArray
,
arr2
:
TensorArray
,
batchSize
:
number
,
unusedFlowIn
:
tf
.
Scalar
):
tf
.
Scalar
{
// TODO
const
unusedFlowOut
=
tf
.
scalar
(
0
)
return
unusedFlowOut
}
\ No newline at end of file
src/faceDetectionNet/resizeLayer.ts
0 → 100644
View file @
cb52d620
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
// TODO: hardcoded params
const
resizedImageSize
=
[
512
,
512
]
as
[
number
,
number
]
const
weight
=
tf
.
scalar
(
0.007843137718737125
)
const
bias
=
tf
.
scalar
(
1
)
export
function
resizeLayer
(
imgTensor
:
tf
.
Tensor4D
)
{
const
resizedImgs
=
tf
.
image
.
resizeBilinear
(
imgTensor
,
resizedImageSize
,
false
)
return
tf
.
sub
(
tf
.
mul
(
resizedImgs
,
weight
),
bias
)
}
\ No newline at end of file
src/index.ts
View file @
cb52d620
import
{
euclideanDistance
}
from
'./euclideanDistance'
;
import
{
euclideanDistance
}
from
'./euclideanDistance'
;
import
{
faceDetectionNet
}
from
'./faceDetectionNet'
;
import
{
faceRecognitionNet
}
from
'./faceRecognitionNet'
;
import
{
faceRecognitionNet
}
from
'./faceRecognitionNet'
;
import
{
normalize
}
from
'./normalize'
;
import
{
normalize
}
from
'./normalize'
;
export
{
export
{
euclideanDistance
,
euclideanDistance
,
faceDetectionNet
,
faceRecognitionNet
,
faceRecognitionNet
,
normalize
normalize
}
}
\ No newline at end of file
src/tfcpatches/TensorArray.ts
View file @
cb52d620
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
import
*
as
tf
from
'@tensorflow/tfjs-core'
;
export
class
TensorArray
{
export
class
TensorArray
{
private
_tensors
:
tf
.
Tensor
[]
|
undefined
private
_tensors
:
tf
.
Tensor
[]
constructor
(
constructor
(
private
_
size
:
number
,
size
:
number
,
private
_dtype
:
tf
.
DataType
=
null
,
private
_dtype
:
tf
.
DataType
|
null
=
null
,
private
_elementShape
:
number
[]
=
null
,
private
_elementShape
:
number
[]
|
null
=
null
,
private
_dynamicSize
:
boolean
=
false
,
private
_dynamicSize
:
boolean
=
false
,
private
_clearAfterRead
:
boolean
=
true
,
private
_clearAfterRead
:
boolean
=
true
,
private
_identicalElementShapes
:
boolean
=
false
,
private
_identicalElementShapes
:
boolean
=
false
,
private
_tensorArrayName
:
string
=
null
private
_tensorArrayName
:
string
=
''
)
{
)
{
if
(
_size
)
{
this
.
_tensors
=
size
this
.
_tensors
=
Array
(
_
size
).
fill
(
0
).
map
(
_
=>
tf
.
scalar
(
0
))
?
Array
(
size
).
fill
(
0
).
map
(
_
=>
tf
.
scalar
(
0
))
}
:
[]
}
}
public
scatter
(
indices
:
tf
.
Tensor1D
,
value
:
tf
.
Tensor
,
unusedFlow
:
tf
.
Scalar
):
tf
.
Scalar
{
public
scatter
(
indices
:
tf
.
Tensor1D
,
value
:
tf
.
Tensor
,
unusedFlow
:
tf
.
Scalar
):
tf
.
Scalar
{
this
.
expectValidSize
(
'scatter'
,
indices
)
if
(
indices
.
shape
.
length
!==
1
)
{
if
(
indices
.
shape
.
length
!==
1
)
{
throw
new
Error
(
`scatter - expected rank of indices (
${
indices
.
shape
.
length
}
) to be 1`
)
throw
new
Error
(
`scatter - expected rank of indices (
${
indices
.
shape
.
length
}
) to be 1`
)
}
}
if
(
indices
.
shape
[
0
]
>
this
.
_size
)
{
throw
new
Error
(
`scatter - expected indices.shape[0] (
${
indices
.
shape
[
0
]}
) to be >= this._size (
${
this
.
size
}
)`
)
}
if
(
indices
.
shape
[
0
]
!==
value
.
shape
[
0
])
{
if
(
indices
.
shape
[
0
]
!==
value
.
shape
[
0
])
{
throw
new
Error
(
`scatter - expected indices.shape[0] (
${
indices
.
shape
[
0
]}
) to equal value.shape[0] (
${
value
.
shape
[
0
]}
)`
)
throw
new
Error
(
`scatter - expected indices.shape[0] (
${
indices
.
shape
[
0
]}
) to equal value.shape[0] (
${
value
.
shape
[
0
]}
)`
)
}
}
const
unstacked
=
tf
.
unstack
(
value
,
0
)
const
unstacked
=
tf
.
unstack
(
value
,
0
)
Array
.
from
(
indices
.
dataSync
()).
forEach
((
idx
,
i
)
=>
{
Array
.
from
(
indices
.
dataSync
()).
forEach
((
idx
,
i
)
=>
{
this
.
_tensors
[
idx
]
=
unstacked
[
i
]
(
this
.
_tensors
as
tf
.
Tensor
[])
[
idx
]
=
unstacked
[
i
]
})
})
const
unusedFlowOut
=
tf
.
scalar
(
0
)
const
unusedFlowOut
=
tf
.
scalar
(
0
)
...
@@ -38,11 +36,21 @@ export class TensorArray {
...
@@ -38,11 +36,21 @@ export class TensorArray {
}
}
public
gather
(
indices
:
tf
.
Tensor1D
,
unusedFlow
:
tf
.
Scalar
,
dtype
?:
tf
.
DataType
,
elementShape
?:
number
[])
:
tf
.
Tensor
{
public
gather
(
indices
:
tf
.
Tensor1D
,
unusedFlow
:
tf
.
Scalar
,
dtype
?:
tf
.
DataType
,
elementShape
?:
number
[])
:
tf
.
Tensor
{
this
.
expectValidSize
(
'gather'
,
indices
)
const
tensors
=
Array
.
from
(
indices
.
dataSync
()).
map
(
idx
=>
this
.
_tensors
[
idx
])
const
tensors
=
Array
.
from
(
indices
.
dataSync
()).
map
(
idx
=>
this
.
_tensors
[
idx
])
return
tf
.
concat
(
tensors
)
return
tf
.
concat
(
tensors
)
}
}
public
size
(
unusedFlow
:
tf
.
Scalar
)
{
public
size
(
unusedFlow
?:
tf
.
Scalar
)
{
return
this
.
_size
return
this
.
_tensors
.
length
}
private
expectValidSize
(
methodName
:
string
,
indices
:
tf
.
Tensor1D
)
{
if
(
!
this
.
_tensors
)
{
throw
new
Error
(
'scatter - TensorArray is not initialized'
)
}
if
(
indices
.
shape
[
0
]
>
this
.
_tensors
.
length
)
{
throw
new
Error
(
`
${
methodName
}
- expected indices.shape[0] (
${
indices
.
shape
[
0
]}
) to be >= this.size() (
${
this
.
size
()}
)`
)
}
}
}
}
}
\ 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