2020-12-23 18:58:47 +01:00
|
|
|
import * as tf from '../../dist/tfjs.esm';
|
2020-08-18 13:54:53 +02:00
|
|
|
|
2020-12-19 17:46:41 +01:00
|
|
|
import { FaceDetection, Point } from '../classes/index';
|
|
|
|
import { ParamMapping } from '../common/index';
|
|
|
|
import { TNetInput } from '../dom/index';
|
|
|
|
import { ITinyYolov2Options } from '../tinyYolov2/index';
|
2020-08-18 13:54:53 +02:00
|
|
|
import { TinyYolov2Base } from '../tinyYolov2/TinyYolov2Base';
|
|
|
|
import { TinyYolov2NetParams } from '../tinyYolov2/types';
|
|
|
|
import { BOX_ANCHORS, IOU_THRESHOLD, MEAN_RGB } from './const';
|
|
|
|
|
|
|
|
export class TinyFaceDetector extends TinyYolov2Base {
|
|
|
|
constructor() {
|
|
|
|
const config = {
|
|
|
|
withSeparableConvs: true,
|
|
|
|
iouThreshold: IOU_THRESHOLD,
|
|
|
|
classes: ['face'],
|
|
|
|
anchors: BOX_ANCHORS,
|
|
|
|
meanRgb: MEAN_RGB,
|
|
|
|
isFirstLayerConv2d: true,
|
2020-12-23 17:26:55 +01:00
|
|
|
filterSizes: [3, 16, 32, 64, 128, 256, 512],
|
|
|
|
};
|
2020-08-18 13:54:53 +02:00
|
|
|
|
2020-12-23 17:26:55 +01:00
|
|
|
super(config);
|
2020-08-18 13:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get anchors(): Point[] {
|
2020-12-23 17:26:55 +01:00
|
|
|
return this.config.anchors;
|
2020-08-18 13:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async locateFaces(input: TNetInput, forwardParams: ITinyYolov2Options): Promise<FaceDetection[]> {
|
2020-12-23 17:26:55 +01:00
|
|
|
const objectDetections = await this.detect(input, forwardParams);
|
|
|
|
return objectDetections.map((det) => new FaceDetection(det.score, det.relativeBox, { width: det.imageWidth, height: det.imageHeight }));
|
2020-08-18 13:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected getDefaultModelName(): string {
|
2020-12-23 17:26:55 +01:00
|
|
|
return 'tiny_face_detector_model';
|
2020-08-18 13:54:53 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 16:14:33 +01:00
|
|
|
protected extractParamsFromWeightMap(weightMap: tf.NamedTensorMap): { params: TinyYolov2NetParams, paramMappings: ParamMapping[] } {
|
|
|
|
return super.extractParamsFromWeightMap(weightMap);
|
2020-08-18 13:54:53 +02:00
|
|
|
}
|
2020-12-23 17:26:55 +01:00
|
|
|
}
|