Commit 58e1e11b by vincent

fix tests + let typescript automatically figure out return values of composable tasks

parent 52858047
...@@ -45,12 +45,12 @@ export class ComputeAllFaceDescriptorsTask< ...@@ -45,12 +45,12 @@ export class ComputeAllFaceDescriptorsTask<
return descriptors.map((descriptor, i) => extendWithFaceDescriptor<TSource>(parentResults[i], descriptor)) return descriptors.map((descriptor, i) => extendWithFaceDescriptor<TSource>(parentResults[i], descriptor))
} }
withFaceExpressions(): PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withFaceExpressions() {
return new PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input)
} }
withAgeAndGender(): PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withAgeAndGender() {
return new PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input)
} }
} }
...@@ -75,11 +75,11 @@ export class ComputeSingleFaceDescriptorTask< ...@@ -75,11 +75,11 @@ export class ComputeSingleFaceDescriptorTask<
return extendWithFaceDescriptor(parentResult, descriptor) return extendWithFaceDescriptor(parentResult, descriptor)
} }
withFaceExpressions(): PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withFaceExpressions() {
return new PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input)
} }
withAgeAndGender(): PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withAgeAndGender() {
return new PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input)
} }
} }
\ No newline at end of file
...@@ -59,16 +59,16 @@ export class DetectAllFaceLandmarksTask< ...@@ -59,16 +59,16 @@ export class DetectAllFaceLandmarksTask<
) )
} }
withFaceExpressions(): PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withFaceExpressions() {
return new PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input)
} }
withAgeAndGender(): PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withAgeAndGender() {
return new PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input)
} }
withFaceDescriptors(): ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>> { withFaceDescriptors() {
return new ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>>(this, this.input) return new ComputeAllFaceDescriptorsTask(this, this.input)
} }
} }
...@@ -95,15 +95,15 @@ export class DetectSingleFaceLandmarksTask< ...@@ -95,15 +95,15 @@ export class DetectSingleFaceLandmarksTask<
return extendWithFaceLandmarks<TSource>(parentResult, landmarks) return extendWithFaceLandmarks<TSource>(parentResult, landmarks)
} }
withFaceExpressions(): PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withFaceExpressions() {
return new PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input)
} }
withAgeAndGender(): PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withAgeAndGender() {
return new PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input)
} }
withFaceDescriptor(): ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>> { withFaceDescriptor() {
return new ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>>(this, this.input) return new ComputeSingleFaceDescriptorTask(this, this.input)
} }
} }
\ No newline at end of file
...@@ -57,16 +57,16 @@ export class DetectAllFacesTask extends DetectFacesTaskBase<FaceDetection[]> { ...@@ -57,16 +57,16 @@ export class DetectAllFacesTask extends DetectFacesTaskBase<FaceDetection[]> {
}) })
} }
withFaceLandmarks(useTinyLandmarkNet: boolean = false): DetectAllFaceLandmarksTask<WithFaceDetection<{}>> { withFaceLandmarks(useTinyLandmarkNet: boolean = false) {
return new DetectAllFaceLandmarksTask<WithFaceDetection<{}>>( return new DetectAllFaceLandmarksTask(
this.runAndExtendWithFaceDetections(), this.runAndExtendWithFaceDetections(),
this.input, this.input,
useTinyLandmarkNet useTinyLandmarkNet
) )
} }
withFaceExpressions(): PredictAllFaceExpressionsTask<WithFaceDetection<{}>> { withFaceExpressions() {
return new PredictAllFaceExpressionsTask<WithFaceDetection<{}>>( return new PredictAllFaceExpressionsTask (
this.runAndExtendWithFaceDetections(), this.runAndExtendWithFaceDetections(),
this.input this.input
) )
...@@ -93,16 +93,16 @@ export class DetectSingleFaceTask extends DetectFacesTaskBase<FaceDetection | un ...@@ -93,16 +93,16 @@ export class DetectSingleFaceTask extends DetectFacesTaskBase<FaceDetection | un
}) })
} }
withFaceLandmarks(useTinyLandmarkNet: boolean = false): DetectSingleFaceLandmarksTask<WithFaceDetection<{}>> { withFaceLandmarks(useTinyLandmarkNet: boolean = false) {
return new DetectSingleFaceLandmarksTask<WithFaceDetection<{}>>( return new DetectSingleFaceLandmarksTask(
this.runAndExtendWithFaceDetection(), this.runAndExtendWithFaceDetection(),
this.input, this.input,
useTinyLandmarkNet useTinyLandmarkNet
) )
} }
withFaceExpressions(): PredictSingleFaceExpressionsTask<WithFaceDetection<{}>> { withFaceExpressions() {
return new PredictSingleFaceExpressionsTask<WithFaceDetection<{}>>( return new PredictSingleFaceExpressionsTask(
this.runAndExtendWithFaceDetection(), this.runAndExtendWithFaceDetection(),
this.input this.input
) )
......
...@@ -75,12 +75,12 @@ export class PredictAllAgeAndGenderWithFaceAlignmentTask< ...@@ -75,12 +75,12 @@ export class PredictAllAgeAndGenderWithFaceAlignmentTask<
TSource extends WithFaceLandmarks<WithFaceDetection<{}>> TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
> extends PredictAllAgeAndGenderTask<TSource> { > extends PredictAllAgeAndGenderTask<TSource> {
withFaceExpressions(): PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withFaceExpressions() {
return new PredictAllFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input)
} }
withFaceDescriptors(): ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>> { withFaceDescriptors() {
return new ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>>(this, this.input) return new ComputeAllFaceDescriptorsTask(this, this.input)
} }
} }
...@@ -88,11 +88,11 @@ export class PredictSingleAgeAndGenderWithFaceAlignmentTask< ...@@ -88,11 +88,11 @@ export class PredictSingleAgeAndGenderWithFaceAlignmentTask<
TSource extends WithFaceLandmarks<WithFaceDetection<{}>> TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
> extends PredictSingleAgeAndGenderTask<TSource> { > extends PredictSingleAgeAndGenderTask<TSource> {
withFaceExpressions(): PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withFaceExpressions() {
return new PredictSingleFaceExpressionsWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input)
} }
withFaceDescriptor(): ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>> { withFaceDescriptor() {
return new ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>>(this, this.input) return new ComputeSingleFaceDescriptorTask(this, this.input)
} }
} }
\ No newline at end of file
...@@ -73,12 +73,12 @@ export class PredictAllFaceExpressionsWithFaceAlignmentTask< ...@@ -73,12 +73,12 @@ export class PredictAllFaceExpressionsWithFaceAlignmentTask<
TSource extends WithFaceLandmarks<WithFaceDetection<{}>> TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
> extends PredictAllFaceExpressionsTask<TSource> { > extends PredictAllFaceExpressionsTask<TSource> {
withAgeAndGender(): PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withAgeAndGender() {
return new PredictAllAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input)
} }
withFaceDescriptors(): ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>> { withFaceDescriptors() {
return new ComputeAllFaceDescriptorsTask<WithFaceLandmarks<TSource>>(this, this.input) return new ComputeAllFaceDescriptorsTask(this, this.input)
} }
} }
...@@ -86,11 +86,11 @@ export class PredictSingleFaceExpressionsWithFaceAlignmentTask< ...@@ -86,11 +86,11 @@ export class PredictSingleFaceExpressionsWithFaceAlignmentTask<
TSource extends WithFaceLandmarks<WithFaceDetection<{}>> TSource extends WithFaceLandmarks<WithFaceDetection<{}>>
> extends PredictSingleFaceExpressionsTask<TSource> { > extends PredictSingleFaceExpressionsTask<TSource> {
withAgeAndGender(): PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>> { withAgeAndGender() {
return new PredictSingleAgeAndGenderWithFaceAlignmentTask<WithFaceLandmarks<TSource>>(this, this.input) return new PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input)
} }
withFaceDescriptor(): ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>> { withFaceDescriptor() {
return new ComputeSingleFaceDescriptorTask<WithFaceLandmarks<TSource>>(this, this.input) return new ComputeSingleFaceDescriptorTask(this, this.input)
} }
} }
\ No newline at end of file
...@@ -55,9 +55,8 @@ export class TinyXception extends NeuralNetwork<TinyXceptionParams> { ...@@ -55,9 +55,8 @@ export class TinyXception extends NeuralNetwork<TinyXceptionParams> {
return tf.tidy(() => { return tf.tidy(() => {
const batchTensor = input.toBatchTensor(112, true) const batchTensor = input.toBatchTensor(112, true)
const batchTensorRgb = bgrToRgbTensor(batchTensor)
const meanRgb = [122.782, 117.001, 104.298] const meanRgb = [122.782, 117.001, 104.298]
const normalized = normalize(batchTensorRgb, meanRgb).div(tf.scalar(256)) as tf.Tensor4D const normalized = normalize(batchTensor, meanRgb).div(tf.scalar(256)) as tf.Tensor4D
let out = tf.relu(conv(normalized, params.entry_flow.conv_in, [2, 2])) let out = tf.relu(conv(normalized, params.entry_flow.conv_in, [2, 2]))
out = reductionBlock(out, params.entry_flow.reduction_block_0, false) out = reductionBlock(out, params.entry_flow.reduction_block_0, false)
......
...@@ -78,15 +78,15 @@ describeWithBackend('tinyFaceDetector', () => { ...@@ -78,15 +78,15 @@ describeWithBackend('tinyFaceDetector', () => {
expectFaceExpressions(results) expectFaceExpressions(results)
}) })
it('detectAllFaces.withFaceExpressions().withFaceLandmarks()', async () => { it('detectAllFaces.withFaceLandmarks().withFaceExpressions()', async () => {
const options = new TinyFaceDetectorOptions({ const options = new TinyFaceDetectorOptions({
inputSize: 416 inputSize: 416
}) })
const results = await faceapi const results = await faceapi
.detectAllFaces(imgEl, options) .detectAllFaces(imgEl, options)
.withFaceExpressions()
.withFaceLandmarks() .withFaceLandmarks()
.withFaceExpressions()
expect(results.length).toEqual(6) expect(results.length).toEqual(6)
expectFaceExpressions(results) expectFaceExpressions(results)
...@@ -114,8 +114,8 @@ describeWithBackend('tinyFaceDetector', () => { ...@@ -114,8 +114,8 @@ describeWithBackend('tinyFaceDetector', () => {
const results = await faceapi const results = await faceapi
.detectAllFaces(imgEl, options) .detectAllFaces(imgEl, options)
.withFaceExpressions()
.withFaceLandmarks() .withFaceLandmarks()
.withFaceExpressions()
.withFaceDescriptors() .withFaceDescriptors()
expect(results.length).toEqual(6) expect(results.length).toEqual(6)
...@@ -183,15 +183,15 @@ describeWithBackend('tinyFaceDetector', () => { ...@@ -183,15 +183,15 @@ describeWithBackend('tinyFaceDetector', () => {
result && expect(result.expressions.happy).toBeGreaterThanOrEqual(0.95) result && expect(result.expressions.happy).toBeGreaterThanOrEqual(0.95)
}) })
it('detectSingleFace.withFaceExpressions().withFaceLandmarks()', async () => { it('detectSingleFace.withFaceLandmarks().withFaceExpressions()', async () => {
const options = new TinyFaceDetectorOptions({ const options = new TinyFaceDetectorOptions({
inputSize: 416 inputSize: 416
}) })
const result = await faceapi const result = await faceapi
.detectSingleFace(imgEl, options) .detectSingleFace(imgEl, options)
.withFaceExpressions()
.withFaceLandmarks() .withFaceLandmarks()
.withFaceExpressions()
expect(!!result).toBeTruthy() expect(!!result).toBeTruthy()
expectFaceDetectionsWithLandmarks( expectFaceDetectionsWithLandmarks(
...@@ -222,15 +222,15 @@ describeWithBackend('tinyFaceDetector', () => { ...@@ -222,15 +222,15 @@ describeWithBackend('tinyFaceDetector', () => {
) )
}) })
it('detectSingleFace.withFaceExpressions().withFaceLandmarks().withFaceDescriptor()', async () => { it('detectSingleFace.withFaceLandmarks().withFaceExpressions().withFaceDescriptor()', async () => {
const options = new TinyFaceDetectorOptions({ const options = new TinyFaceDetectorOptions({
inputSize: 416 inputSize: 416
}) })
const result = await faceapi const result = await faceapi
.detectSingleFace(imgEl, options) .detectSingleFace(imgEl, options)
.withFaceExpressions()
.withFaceLandmarks() .withFaceLandmarks()
.withFaceExpressions()
.withFaceDescriptor() .withFaceDescriptor()
expect(!!result).toBeTruthy() expect(!!result).toBeTruthy()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment