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
b7f300db
Commit
b7f300db
authored
Aug 30, 2019
by
Jonathan Derrough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made .toJSON() implementations instance methods taking a POJO argument
Made .fromJSON() implementations return a POJO Updated the unit tests
parent
2efd6f27
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
52 deletions
+32
-52
LabeledFaceDescriptors.ts
src/classes/LabeledFaceDescriptors.ts
+9
-9
FaceMatcher.ts
src/globalApi/FaceMatcher.ts
+10
-10
LabeledFaceDescriptors.test.ts
test/tests/classes/LabeledFaceDescriptors.test.ts
+6
-13
FaceMatcher.test.ts
test/tests/globalApi/FaceMatcher.test.ts
+7
-20
No files found.
src/classes/LabeledFaceDescriptors.ts
View file @
b7f300db
...
@@ -18,19 +18,18 @@ export class LabeledFaceDescriptors {
...
@@ -18,19 +18,18 @@ export class LabeledFaceDescriptors {
public
get
label
():
string
{
return
this
.
_label
}
public
get
label
():
string
{
return
this
.
_label
}
public
get
descriptors
():
Float32Array
[]
{
return
this
.
_descriptors
}
public
get
descriptors
():
Float32Array
[]
{
return
this
.
_descriptors
}
public
static
toJSON
(
ld
:
LabeledFaceDescriptors
):
string
{
public
toJSON
():
any
{
return
`{"label":"
${
ld
.
label
}
","descriptors":[
${
ld
.
descriptors
.
map
((
d
)
=>
`[
${
Array
.
from
(
d
)}
]`
)}
]}`
;
return
{
label
:
this
.
label
,
descriptors
:
this
.
descriptors
.
map
((
d
)
=>
Array
.
from
(
d
))
};
}
}
public
static
fromJSON
(
jsonString
:
string
):
LabeledFaceDescriptors
{
public
static
fromJSON
(
json
:
any
):
LabeledFaceDescriptors
{
return
LabeledFaceDescriptors
.
fromPOJO
(
JSON
.
parse
(
jsonString
));
const
descriptors
=
json
.
descriptors
.
map
((
d
:
any
)
=>
{
}
public
static
fromPOJO
(
pojo
:
any
):
LabeledFaceDescriptors
{
const
descriptors
=
pojo
.
descriptors
.
map
((
d
:
any
)
=>
{
return
new
Float32Array
(
d
);
return
new
Float32Array
(
d
);
});
});
return
new
LabeledFaceDescriptors
(
pojo
.
label
,
descriptors
);
return
new
LabeledFaceDescriptors
(
json
.
label
,
descriptors
);
}
}
}
}
\ No newline at end of file
src/globalApi/FaceMatcher.ts
View file @
b7f300db
...
@@ -67,18 +67,17 @@ export class FaceMatcher {
...
@@ -67,18 +67,17 @@ export class FaceMatcher {
:
new
FaceMatch
(
'unknown'
,
bestMatch
.
distance
)
:
new
FaceMatch
(
'unknown'
,
bestMatch
.
distance
)
}
}
public
static
toJSON
(
matcher
:
FaceMatcher
):
string
{
public
toJSON
():
any
{
return
`{"distanceThreshold":
${
matcher
.
distanceThreshold
}
,"labeledDescriptors":[
${
matcher
.
labeledDescriptors
.
map
((
ld
)
=>
LabeledFaceDescriptors
.
toJSON
(
ld
))}
]}`
;
return
{
distanceThreshold
:
this
.
distanceThreshold
,
labeledDescriptors
:
this
.
labeledDescriptors
.
map
((
ld
)
=>
ld
.
toJSON
())
};
}
}
public
static
fromJSON
(
jsonString
:
string
):
FaceMatcher
{
public
static
fromJSON
(
json
:
any
):
FaceMatcher
{
return
FaceMatcher
.
fromPOJO
(
JSON
.
parse
(
jsonString
));
const
labeledDescriptors
=
json
.
labeledDescriptors
}
.
map
((
ld
:
any
)
=>
LabeledFaceDescriptors
.
fromJSON
(
ld
));
return
new
FaceMatcher
(
labeledDescriptors
,
json
.
distanceThreshold
);
public
static
fromPOJO
(
pojo
:
any
):
FaceMatcher
{
const
labeledDescriptors
=
pojo
.
labeledDescriptors
.
map
((
ld
:
any
)
=>
LabeledFaceDescriptors
.
fromPOJO
(
ld
));
return
new
FaceMatcher
(
labeledDescriptors
,
pojo
.
distanceThreshold
);
}
}
}
}
\ No newline at end of file
test/tests/classes/LabeledFaceDescriptors.test.ts
View file @
b7f300db
...
@@ -9,21 +9,14 @@ describe('globalApi', () => {
...
@@ -9,21 +9,14 @@ describe('globalApi', () => {
const
f1
=
new
Float32Array
([
1
,
2
,
3
]);
const
f1
=
new
Float32Array
([
1
,
2
,
3
]);
const
f2
=
new
Float32Array
([
4
,
5
,
6
]);
const
f2
=
new
Float32Array
([
4
,
5
,
6
]);
it
(
'toJSON()'
,
()
=>
{
it
(
'JSON.stringify()'
,
()
=>
{
expect
(
LabeledFaceDescriptors
.
toJSON
(
new
LabeledFaceDescriptors
(
l1
,
[
f1
,
f2
]))).
toBe
(
json
);
expect
(
JSON
.
stringify
(
new
LabeledFaceDescriptors
(
l1
,
[
f1
,
f2
]))).
toBe
(
json
);
expect
(
JSON
.
stringify
({
ld
:
new
LabeledFaceDescriptors
(
l1
,
[
f1
,
f2
])
})).
toBe
(
`{"ld":
${
json
}
}`
);
expect
(
JSON
.
stringify
([
new
LabeledFaceDescriptors
(
l1
,
[
f1
,
f2
])
])).
toBe
(
`[
${
json
}
]`
);
});
});
it
(
'fromJSON()'
,
()
=>
{
it
(
'fromJSON()'
,
()
=>
{
const
ld
=
LabeledFaceDescriptors
.
fromJSON
(
json
);
const
ld
=
LabeledFaceDescriptors
.
fromJSON
(
JSON
.
parse
(
json
));
expect
(
ld
.
label
).
toBe
(
l1
);
expect
(
ld
.
descriptors
.
length
).
toBe
(
2
);
expect
(
ld
.
descriptors
[
0
]).
toEqual
(
f1
);
expect
(
ld
.
descriptors
[
1
]).
toEqual
(
f2
);
});
it
(
'fromPOJO()'
,
()
=>
{
const
ld
=
LabeledFaceDescriptors
.
fromPOJO
(
JSON
.
parse
(
json
));
expect
(
ld
.
label
).
toBe
(
l1
);
expect
(
ld
.
label
).
toBe
(
l1
);
expect
(
ld
.
descriptors
.
length
).
toBe
(
2
);
expect
(
ld
.
descriptors
.
length
).
toBe
(
2
);
...
@@ -32,7 +25,7 @@ describe('globalApi', () => {
...
@@ -32,7 +25,7 @@ describe('globalApi', () => {
});
});
it
(
'toJSON() => fromJSON()'
,
()
=>
{
it
(
'toJSON() => fromJSON()'
,
()
=>
{
const
ld
=
LabeledFaceDescriptors
.
fromJSON
(
LabeledFaceDescriptors
.
toJSON
(
new
LabeledFaceDescriptors
(
l1
,
[
f1
,
f2
])
));
const
ld
=
LabeledFaceDescriptors
.
fromJSON
(
new
LabeledFaceDescriptors
(
l1
,
[
f1
,
f2
]).
toJSON
(
));
expect
(
ld
.
label
).
toBe
(
l1
);
expect
(
ld
.
label
).
toBe
(
l1
);
expect
(
ld
.
descriptors
.
length
).
toBe
(
2
);
expect
(
ld
.
descriptors
.
length
).
toBe
(
2
);
...
...
test/tests/globalApi/FaceMatcher.test.ts
View file @
b7f300db
...
@@ -18,12 +18,14 @@ describe('globalApi', () => {
...
@@ -18,12 +18,14 @@ describe('globalApi', () => {
new
LabeledFaceDescriptors
(
l2
,
[
f3
,
f4
])
new
LabeledFaceDescriptors
(
l2
,
[
f3
,
f4
])
];
];
it
(
'toJSON()'
,
()
=>
{
it
(
'JSON.stringify()'
,
()
=>
{
expect
(
FaceMatcher
.
toJSON
(
new
FaceMatcher
(
lds
,
dt
))).
toBe
(
json
);
expect
(
JSON
.
stringify
(
new
FaceMatcher
(
lds
,
dt
))).
toBe
(
json
);
expect
(
JSON
.
stringify
({
m
:
new
FaceMatcher
(
lds
,
dt
)
})).
toBe
(
`{"m":
${
json
}
}`
);
expect
(
JSON
.
stringify
([
new
FaceMatcher
(
lds
,
dt
)
])).
toBe
(
`[
${
json
}
]`
);
});
});
it
(
'fromJSON()'
,
()
=>
{
it
(
'fromJSON()'
,
()
=>
{
const
fm
=
FaceMatcher
.
fromJSON
(
json
);
const
fm
=
FaceMatcher
.
fromJSON
(
JSON
.
parse
(
json
)
);
expect
(
fm
.
distanceThreshold
).
toBe
(
dt
);
expect
(
fm
.
distanceThreshold
).
toBe
(
dt
);
expect
(
fm
.
labeledDescriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
.
length
).
toBe
(
2
);
...
@@ -37,23 +39,8 @@ describe('globalApi', () => {
...
@@ -37,23 +39,8 @@ describe('globalApi', () => {
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
1
]).
toEqual
(
f4
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
1
]).
toEqual
(
f4
);
});
});
it
(
'fromPOJO()'
,
()
=>
{
it
(
'toJSON() => fromJSON()'
,
()
=>
{
const
fm
=
FaceMatcher
.
fromPOJO
(
JSON
.
parse
(
json
));
const
fm
=
FaceMatcher
.
fromJSON
(
new
FaceMatcher
(
lds
,
dt
).
toJSON
());
expect
(
fm
.
distanceThreshold
).
toBe
(
dt
);
expect
(
fm
.
labeledDescriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
0
].
label
).
toBe
(
l1
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
[
0
]).
toEqual
(
f1
);
expect
(
fm
.
labeledDescriptors
[
0
].
descriptors
[
1
]).
toEqual
(
f2
);
expect
(
fm
.
labeledDescriptors
[
1
].
label
).
toBe
(
l2
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
0
]).
toEqual
(
f3
);
expect
(
fm
.
labeledDescriptors
[
1
].
descriptors
[
1
]).
toEqual
(
f4
);
});
it
(
'JSON.stringify() => fromJSON()'
,
()
=>
{
const
fm
=
FaceMatcher
.
fromJSON
(
FaceMatcher
.
toJSON
(
new
FaceMatcher
(
lds
,
dt
)));
expect
(
fm
.
distanceThreshold
).
toBe
(
dt
);
expect
(
fm
.
distanceThreshold
).
toBe
(
dt
);
expect
(
fm
.
labeledDescriptors
.
length
).
toBe
(
2
);
expect
(
fm
.
labeledDescriptors
.
length
).
toBe
(
2
);
...
...
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