Skip to content

Commit 58e1e11

Browse files
fix tests + let typescript automatically figure out return values of composable tasks
1 parent 5285804 commit 58e1e11

File tree

7 files changed

+52
-53
lines changed

7 files changed

+52
-53
lines changed

src/globalApi/ComputeFaceDescriptorsTasks.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export class ComputeAllFaceDescriptorsTask<
4545
return descriptors.map((descriptor, i) => extendWithFaceDescriptor<TSource>(parentResults[i], descriptor))
4646
}
4747

48-
withFaceExpressions(): PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
49-
return new PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
48+
withFaceExpressions() {
49+
return new PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input)
5050
}
5151

52-
withAgeAndGender(): PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
53-
return new PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
52+
withAgeAndGender() {
53+
return new PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input)
5454
}
5555
}
5656

@@ -75,11 +75,11 @@ export class ComputeSingleFaceDescriptorTask<
7575
return extendWithFaceDescriptor(parentResult, descriptor)
7676
}
7777

78-
withFaceExpressions(): PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
79-
return new PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
78+
withFaceExpressions() {
79+
return new PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input)
8080
}
8181

82-
withAgeAndGender(): PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
83-
return new PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
82+
withAgeAndGender() {
83+
return new PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input)
8484
}
8585
}

src/globalApi/DetectFaceLandmarksTasks.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ export class DetectAllFaceLandmarksTask<
5959
)
6060
}
6161

62-
withFaceExpressions(): PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
63-
return new PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
62+
withFaceExpressions() {
63+
return new PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input)
6464
}
6565

66-
withAgeAndGender(): PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
67-
return new PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
66+
withAgeAndGender() {
67+
return new PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input)
6868
}
6969

70-
withFaceDescriptors(): ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>> {
71-
return new ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>>(this, this.input)
70+
withFaceDescriptors() {
71+
return new ComputeAllFaceDescriptorsTask(this, this.input)
7272
}
7373
}
7474

@@ -95,15 +95,15 @@ export class DetectSingleFaceLandmarksTask<
9595
return extendWithFaceLandmarks<TSource>(parentResult, landmarks)
9696
}
9797

98-
withFaceExpressions(): PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
99-
return new PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
98+
withFaceExpressions() {
99+
return new PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input)
100100
}
101101

102-
withAgeAndGender(): PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
103-
return new PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
102+
withAgeAndGender() {
103+
return new PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input)
104104
}
105105

106-
withFaceDescriptor(): ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>> {
107-
return new ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>>(this, this.input)
106+
withFaceDescriptor() {
107+
return new ComputeSingleFaceDescriptorTask(this, this.input)
108108
}
109109
}

src/globalApi/DetectFacesTasks.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ export class DetectAllFacesTask extends DetectFacesTaskBase<FaceDetection[]> {
5757
})
5858
}
5959

60-
withFaceLandmarks(useTinyLandmarkNet: boolean = false): DetectAllFaceLandmarksTask<WithFaceDetection<{}>> {
61-
return new DetectAllFaceLandmarksTask<WithFaceDetection<{}>>(
60+
withFaceLandmarks(useTinyLandmarkNet: boolean = false) {
61+
return new DetectAllFaceLandmarksTask(
6262
this.runAndExtendWithFaceDetections(),
6363
this.input,
6464
useTinyLandmarkNet
6565
)
6666
}
6767

68-
withFaceExpressions(): PredictAllFaceExpressionsTask<WithFaceDetection<{}>> {
69-
return new PredictAllFaceExpressionsTask<WithFaceDetection<{}>>(
68+
withFaceExpressions() {
69+
return new PredictAllFaceExpressionsTask (
7070
this.runAndExtendWithFaceDetections(),
7171
this.input
7272
)
@@ -93,16 +93,16 @@ export class DetectSingleFaceTask extends DetectFacesTaskBase<FaceDetection | un
9393
})
9494
}
9595

96-
withFaceLandmarks(useTinyLandmarkNet: boolean = false): DetectSingleFaceLandmarksTask<WithFaceDetection<{}>> {
97-
return new DetectSingleFaceLandmarksTask<WithFaceDetection<{}>>(
96+
withFaceLandmarks(useTinyLandmarkNet: boolean = false) {
97+
return new DetectSingleFaceLandmarksTask(
9898
this.runAndExtendWithFaceDetection(),
9999
this.input,
100100
useTinyLandmarkNet
101101
)
102102
}
103103

104-
withFaceExpressions(): PredictSingleFaceExpressionsTask<WithFaceDetection<{}>> {
105-
return new PredictSingleFaceExpressionsTask<WithFaceDetection<{}>>(
104+
withFaceExpressions() {
105+
return new PredictSingleFaceExpressionsTask(
106106
this.runAndExtendWithFaceDetection(),
107107
this.input
108108
)

src/globalApi/PredictAgeAndGenderTask.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,24 @@ export class PredictAllAgeAndGenderWithFaceAlignmentTask<
7575
TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
7676
> extends PredictAllAgeAndGenderTask<TSource> {
7777

78-
withFaceExpressions(): PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
79-
return new PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
78+
withFaceExpressions() {
79+
return new PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input)
8080
}
8181

82-
withFaceDescriptors(): ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>> {
83-
return new ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>>(this, this.input)
82+
withFaceDescriptors() {
83+
return new ComputeAllFaceDescriptorsTask(this, this.input)
8484
}
8585
}
8686

8787
export class PredictSingleAgeAndGenderWithFaceAlignmentTask<
8888
TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
8989
> extends PredictSingleAgeAndGenderTask<TSource> {
9090

91-
withFaceExpressions(): PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
92-
return new PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
91+
withFaceExpressions() {
92+
return new PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input)
9393
}
9494

95-
withFaceDescriptor(): ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>> {
96-
return new ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>>(this, this.input)
95+
withFaceDescriptor() {
96+
return new ComputeSingleFaceDescriptorTask(this, this.input)
9797
}
9898
}

src/globalApi/PredictFaceExpressionsTask.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,24 @@ export class PredictAllFaceExpressionsWithFaceAlignmentTask<
7373
TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
7474
> extends PredictAllFaceExpressionsTask<TSource> {
7575

76-
withAgeAndGender(): PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
77-
return new PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
76+
withAgeAndGender() {
77+
return new PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input)
7878
}
7979

80-
withFaceDescriptors(): ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>> {
81-
return new ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>>(this, this.input)
80+
withFaceDescriptors() {
81+
return new ComputeAllFaceDescriptorsTask(this, this.input)
8282
}
8383
}
8484

8585
export class PredictSingleFaceExpressionsWithFaceAlignmentTask<
8686
TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
8787
> extends PredictSingleFaceExpressionsTask<TSource> {
8888

89-
withAgeAndGender(): PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> {
90-
return new PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input)
89+
withAgeAndGender() {
90+
return new PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input)
9191
}
9292

93-
withFaceDescriptor(): ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>> {
94-
return new ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>>(this, this.input)
93+
withFaceDescriptor() {
94+
return new ComputeSingleFaceDescriptorTask(this, this.input)
9595
}
9696
}

src/xception/TinyXception.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ export class TinyXception extends NeuralNetwork<TinyXceptionParams> {
5555

5656
return tf.tidy(() => {
5757
const batchTensor = input.toBatchTensor(112, true)
58-
const batchTensorRgb = bgrToRgbTensor(batchTensor)
5958
const meanRgb = [122.782, 117.001, 104.298]
60-
const normalized = normalize(batchTensorRgb, meanRgb).div(tf.scalar(256)) as tf.Tensor4D
59+
const normalized = normalize(batchTensor, meanRgb).div(tf.scalar(256)) as tf.Tensor4D
6160

6261
let out = tf.relu(conv(normalized, params.entry_flow.conv_in, [2, 2]))
6362
out = reductionBlock(out, params.entry_flow.reduction_block_0, false)

test/tests/tinyFaceDetector/tinyFaceDetector.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ describeWithBackend('tinyFaceDetector', () => {
7878
expectFaceExpressions(results)
7979
})
8080

81-
it('detectAllFaces.withFaceExpressions().withFaceLandmarks()', async () => {
81+
it('detectAllFaces.withFaceLandmarks().withFaceExpressions()', async () => {
8282
const options = new TinyFaceDetectorOptions({
8383
inputSize: 416
8484
})
8585

8686
const results = await faceapi
8787
.detectAllFaces(imgEl, options)
88-
.withFaceExpressions()
8988
.withFaceLandmarks()
89+
.withFaceExpressions()
9090

9191
expect(results.length).toEqual(6)
9292
expectFaceExpressions(results)
@@ -114,8 +114,8 @@ describeWithBackend('tinyFaceDetector', () => {
114114

115115
const results = await faceapi
116116
.detectAllFaces(imgEl, options)
117-
.withFaceExpressions()
118117
.withFaceLandmarks()
118+
.withFaceExpressions()
119119
.withFaceDescriptors()
120120

121121
expect(results.length).toEqual(6)
@@ -183,15 +183,15 @@ describeWithBackend('tinyFaceDetector', () => {
183183
result && expect(result.expressions.happy).toBeGreaterThanOrEqual(0.95)
184184
})
185185

186-
it('detectSingleFace.withFaceExpressions().withFaceLandmarks()', async () => {
186+
it('detectSingleFace.withFaceLandmarks().withFaceExpressions()', async () => {
187187
const options = new TinyFaceDetectorOptions({
188188
inputSize: 416
189189
})
190190

191191
const result = await faceapi
192192
.detectSingleFace(imgEl, options)
193-
.withFaceExpressions()
194193
.withFaceLandmarks()
194+
.withFaceExpressions()
195195

196196
expect(!!result).toBeTruthy()
197197
expectFaceDetectionsWithLandmarks(
@@ -222,15 +222,15 @@ describeWithBackend('tinyFaceDetector', () => {
222222
)
223223
})
224224

225-
it('detectSingleFace.withFaceExpressions().withFaceLandmarks().withFaceDescriptor()', async () => {
225+
it('detectSingleFace.withFaceLandmarks().withFaceExpressions().withFaceDescriptor()', async () => {
226226
const options = new TinyFaceDetectorOptions({
227227
inputSize: 416
228228
})
229229

230230
const result = await faceapi
231231
.detectSingleFace(imgEl, options)
232-
.withFaceExpressions()
233232
.withFaceLandmarks()
233+
.withFaceExpressions()
234234
.withFaceDescriptor()
235235

236236
expect(!!result).toBeTruthy()

0 commit comments

Comments
 (0)