初次提交

This commit is contained in:
2025-03-06 14:38:32 +08:00
commit b0e71d0ebb
46 changed files with 1926 additions and 0 deletions

View 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 { }