初次提交
This commit is contained in:
32
src/deploy/faceid/insightface.ts
Normal file
32
src/deploy/faceid/insightface.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Mat } from "../../cv/mat";
|
||||
import { convertImage } from "../common/processors";
|
||||
import { FaceRecognition, FaceRecognitionPredictOption } from "./common";
|
||||
|
||||
export class Insightface extends FaceRecognition {
|
||||
|
||||
public async doPredict(image: Mat, option?: FaceRecognitionPredictOption): Promise<number[]> {
|
||||
const input = this.input;
|
||||
const output = this.output;
|
||||
if (option?.crop) image = image.crop(option.crop.sx, option.crop.sy, option.crop.sw, option.crop.sh);
|
||||
image = image.resize(input.shape[3], input.shape[2]);
|
||||
const nchwImageData = convertImage(image.data, { sourceImageFormat: "bgr", targetColorFormat: "bgr", targetShapeFormat: "nchw", targetNormalize: { mean: [127.5], std: [127.5] } });
|
||||
|
||||
const embedding = await this.session.run({
|
||||
[input.name]: {
|
||||
type: "float32",
|
||||
data: nchwImageData,
|
||||
shape: [1, 3, input.shape[2], input.shape[3]],
|
||||
}
|
||||
}).then(res => res[output.name]);
|
||||
|
||||
return new Array(...embedding);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class ArcFace extends Insightface { }
|
||||
|
||||
export class CosFace extends Insightface { }
|
||||
|
||||
export class PartialFC extends Insightface { }
|
||||
|
Reference in New Issue
Block a user