Skip to content

Commit 5a7a40e

Browse files
added end to end tests faceLandmarkNet and faceRecognitionNet
1 parent 8127f9e commit 5a7a40e

File tree

6 files changed

+73
-16
lines changed

6 files changed

+73
-16
lines changed

karma.conf.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1+
const dataFiles = [
2+
'test/images/*.jpg',
3+
'test/images/*.png',
4+
'test/data/*.json',
5+
'weights/*.weights'
6+
].map(pattern => ({
7+
pattern,
8+
watched: false,
9+
included: false,
10+
served: true,
11+
nocache: false
12+
}))
13+
114
module.exports = function(config) {
215
config.set({
316
frameworks: ['jasmine', 'karma-typescript'],
417
files: [
518
'src/**/*.ts',
6-
'test/**/*.ts',
7-
{
8-
pattern: 'test/images/*.jpg',
9-
watched: false,
10-
included: false,
11-
served: true,
12-
nocache: false
13-
},
14-
{
15-
pattern: 'weights/*.weights',
16-
watched: false,
17-
included: false,
18-
served: true,
19-
nocache: false
20-
}
21-
],
19+
'test/**/*.ts'
20+
].concat(dataFiles),
2221
preprocessors: {
2322
'**/*.ts': ['karma-typescript']
2423
},

test/data/faceDescriptor.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[-0.04457738250494003, -0.043990395963191986, -0.025750599801540375, 0.016651155427098274, -0.05218124762177467, -0.05193494260311127, 0.0099308080971241, -0.016631772741675377, 0.1175108402967453, 0.04090115427970886, 0.22149613499641418, -0.08035797625780106, -0.23618969321250916, -0.02510468289256096, -0.02730529010295868, 0.10455037653446198, -0.12426768243312836, -0.0886617973446846, -0.14048148691654205, -0.040384188294410706, -0.041014235466718674, 0.11965534090995789, -0.015900742262601852, 0.08545806258916855, -0.10701242089271545, -0.2919914722442627, -0.09832733124494553, -0.15806683897972107, 0.007252881303429604, -0.09897305816411972, 0.02866348624229431, 0.17405937612056732, -0.17985646426677704, -0.11151747405529022, 0.1291065365076065, 0.023578189313411713, -0.04872015863656998, -0.023027952760457993, 0.24042242765426636, 0.09909330308437347, -0.14796072244644165, -0.034880466759204865, 0.023121334612369537, 0.35197964310646057, 0.13432590663433075, 0.025992823764681816, 0.027310356497764587, -0.07258806377649307, 0.09854947030544281, -0.2654016613960266, 0.09129738807678223, 0.18322113156318665, 0.14081577956676483, 0.08943498134613037, 0.07813337445259094, -0.1866082400083542, 0.012191163375973701, 0.13849540054798126, -0.1988903284072876, 0.14307452738285065, 0.04158562421798706, -0.0641125738620758, -0.0019705239683389664, -0.10619331151247025, 0.1386488378047943, 0.019395820796489716, -0.10675815492868423, -0.06835387647151947, 0.19760596752166748, -0.10146244615316391, -0.005424058996140957, 0.13664256036281586, -0.10927096754312515, -0.2449037879705429, -0.2788461446762085, 0.025820128619670868, 0.40477481484413147, 0.08949816972017288, -0.2150505781173706, -0.00494978204369545, -0.05536277964711189, -0.06972620636224747, -0.008085237815976143, 0.027283620089292526, -0.0860084593296051, 0.017455315217375755, -0.07179906964302063, 0.04873117804527283, 0.20279690623283386, 0.011654914356768131, -0.007634453475475311, 0.1842338889837265, -0.06324955075979233, -0.07316181063652039, 0.122040756046772, 0.08807040750980377, -0.0505395382642746, -0.08226525038480759, -0.11426772177219391, 0.000004230067133903503, 0.02770165540277958, -0.2017858773469925, -0.02197061851620674, 0.056306831538677216, -0.17306528985500336, 0.20115001499652863, 0.008511766791343689, -0.07041959464550018, -0.08531103283166885, -0.043383363634347916, -0.07298384606838226, 0.07277849316596985, 0.25687724351882935, -0.24525471031665802, 0.21955141425132751, 0.07719043642282486, 0.011913364753127098, 0.17791582643985748, -0.057796183973550797, 0.10519653558731079, -0.15350784361362457, -0.09388457238674164, -0.1587708741426468, -0.14040742814540863, 0.035962484776973724, 0.040929798036813736, 0.04888196289539337, 0.0146100465208292]

test/data/faceLandmarkPositions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"x": 15.145603939890862, "y": 42.00849384069443}, {"x": 16.228551417589188, "y": 58.02471041679382}, {"x": 18.641504645347595, "y": 73.78255426883698}, {"x": 21.99183627963066, "y": 89.28244113922119}, {"x": 27.241109311580658, "y": 103.89149487018585}, {"x": 35.77959090471268, "y": 117.20520257949829}, {"x": 47.162988781929016, "y": 128.52083444595337}, {"x": 60.60639023780823, "y": 137.3870998620987}, {"x": 76.22466087341309, "y": 139.8476779460907}, {"x": 91.47888422012329, "y": 136.8298441171646}, {"x": 104.65206205844879, "y": 127.64202654361725}, {"x": 115.92219471931458, "y": 116.16075038909912}, {"x": 124.51052069664001, "y": 102.82219648361206}, {"x": 129.76784706115723, "y": 87.81199157238007}, {"x": 132.6519101858139, "y": 72.15077430009842}, {"x": 134.51203107833862, "y": 56.30408674478531}, {"x": 135.33487915992737, "y": 40.10292738676071}, {"x": 24.932710826396942, "y": 32.96273946762085}, {"x": 32.57601857185364, "y": 28.00302878022194}, {"x": 42.381374537944794, "y": 27.10871994495392}, {"x": 52.198585867881775, "y": 29.124750941991806}, {"x": 61.5922674536705, "y": 32.90563523769379}, {"x": 85.18133461475372, "y": 31.272751092910767}, {"x": 94.89730596542358, "y": 26.85772553086281}, {"x": 105.1171749830246, "y": 24.783611297607422}, {"x": 115.2367115020752, "y": 25.725752860307693}, {"x": 123.13878536224365, "y": 30.079219490289688}, {"x": 73.67254793643951, "y": 43.12345236539841}, {"x": 73.7981915473938, "y": 55.55519610643387}, {"x": 73.8839328289032, "y": 67.69467741250992}, {"x": 73.96439015865326, "y": 79.91722226142883}, {"x": 62.394945323467255, "y": 85.0008487701416}, {"x": 68.01678389310837, "y": 87.24332749843597}, {"x": 74.27898198366165, "y": 88.8382226228714}, {"x": 80.42970299720764, "y": 86.84954345226288}, {"x": 85.87614297866821, "y": 84.31319296360016}, {"x": 35.7684463262558, "y": 44.57894414663315}, {"x": 42.30532944202423, "y": 41.117119789123535}, {"x": 50.501713156700134, "y": 41.50397926568985}, {"x": 56.56731426715851, "y": 45.83812057971954}, {"x": 50.084468722343445, "y": 48.037388920784}, {"x": 41.91972613334656, "y": 47.92611300945282}, {"x": 91.28680229187012, "y": 44.677162170410156}, {"x": 97.76994287967682, "y": 40.084308385849}, {"x": 105.72623312473297, "y": 39.8311972618103}, {"x": 111.95003092288971, "y": 42.97384321689606}, {"x": 106.4166247844696, "y": 46.30742222070694}, {"x": 98.37331473827362, "y": 46.70642763376236}, {"x": 51.94934159517288, "y": 102.49188244342804}, {"x": 60.71081757545471, "y": 101.18674635887146}, {"x": 68.67328137159348, "y": 100.15718936920166}, {"x": 74.38371777534485, "y": 101.07522904872894}, {"x": 80.5251270532608, "y": 99.71560835838318}, {"x": 88.56176733970642, "y": 100.32560527324677}, {"x": 96.980881690979, "y": 100.81177353858948}, {"x": 89.01146650314331, "y": 108.55080485343933}, {"x": 81.3762366771698, "y": 112.2200220823288}, {"x": 74.73004907369614, "y": 113.34742605686188}, {"x": 68.42194050550461, "y": 112.92429864406586}, {"x": 60.53387671709061, "y": 110.02114713191986}, {"x": 55.876149237155914, "y": 103.3714234828949}, {"x": 68.54872852563858, "y": 104.03825640678406}, {"x": 74.44304376840591, "y": 104.46503162384033}, {"x": 80.63703775405884, "y": 103.56011688709259}, {"x": 93.1486040353775, "y": 102.0165503025055}, {"x": 80.84633946418762, "y": 104.64600920677185}, {"x": 74.63692724704742, "y": 105.62551617622375}, {"x": 68.74832957983017, "y": 105.22661805152893}]

test/e2e/faceLandmarkNet.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import axios from 'axios';
2+
3+
import * as faceapi from '../../src';
4+
import { FaceLandmarks } from '../../src/faceLandmarkNet/FaceLandmarks';
5+
import { Point } from '../../src/Point';
6+
7+
describe('faceLandmarkNet', () => {
8+
9+
let faceLandmarkNet: any, imgEl: HTMLImageElement, faceLandmarkPositions: Point[]
10+
11+
beforeAll(async () => {
12+
const res = await axios.get('base/weights/face_landmark_68_model.weights', { responseType: 'arraybuffer' })
13+
const weights = new Float32Array(res.data)
14+
faceLandmarkNet = faceapi.faceLandmarkNet(weights)
15+
16+
const img = await axios.get('base/test/images/face.png', { responseType: 'blob' })
17+
imgEl = await faceapi.bufferToImage(img.data)
18+
faceLandmarkPositions = (await axios.get('base/test/data/faceLandmarkPositions.json')).data
19+
})
20+
21+
it('computes face descriptor', async () => {
22+
const { width, height } = imgEl
23+
24+
const result = await faceLandmarkNet.detectLandmarks(imgEl) as FaceLandmarks
25+
expect(result.getImageWidth()).toEqual(width)
26+
expect(result.getImageHeight()).toEqual(height)
27+
expect(result.getShift().x).toEqual(0)
28+
expect(result.getShift().y).toEqual(0)
29+
expect(result.getPositions().map(({ x, y }) => ({ x, y }))).toEqual(faceLandmarkPositions)
30+
})
31+
})
32+

test/e2e/faceRecognitionNet.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import axios from 'axios';
2+
3+
import * as faceapi from '../../src';
4+
5+
describe('faceRecognitionNet', () => {
6+
7+
let faceRecognitionNet: any, imgEl: HTMLImageElement, faceDescriptor: number[]
8+
9+
beforeAll(async () => {
10+
const res = await axios.get('base/weights/face_recognition_model.weights', { responseType: 'arraybuffer' })
11+
const weights = new Float32Array(res.data)
12+
faceRecognitionNet = faceapi.faceRecognitionNet(weights)
13+
14+
const img = await axios.get('base/test/images/face.png', { responseType: 'blob' })
15+
imgEl = await faceapi.bufferToImage(img.data)
16+
faceDescriptor = (await axios.get('base/test/data/faceDescriptor.json')).data
17+
})
18+
19+
it('computes face descriptor', async () => {
20+
const result = await faceRecognitionNet.computeFaceDescriptor(imgEl) as number[]
21+
expect(result.length).toEqual(128)
22+
expect(result).toEqual(new Float32Array(faceDescriptor))
23+
})
24+
})

test/images/face.png

15.6 KB
Loading

0 commit comments

Comments
 (0)