【增加模型快捷加载方法】

This commit is contained in:
2025-03-07 10:19:26 +08:00
parent dc94573862
commit 8af5846490
9 changed files with 187 additions and 22 deletions

View File

@ -10,8 +10,17 @@ export interface GenderAgePredictResult {
age: number
}
const MODEL_URL_CONFIG = {
INSIGHT_GENDER_AGE_ONNX: `https://www.modelscope.cn/models/luyizhi/basic_cv/resolve/master/faceattr/insight_gender_age.onnx`,
};
export class GenderAge extends Model {
public static async load(type?: keyof typeof MODEL_URL_CONFIG) {
return this.cacheModel(MODEL_URL_CONFIG[type ?? "INSIGHT_GENDER_AGE_ONNX"], { createModel: true }).then(r => r.model);
}
public predict(image: ImageSource, option?: GenderAgePredictOption) { return Model.resolveImage(image, im => this.doPredict(im, option)); }
private async doPredict(image: cv.Mat, option?: GenderAgePredictOption): Promise<GenderAgePredictResult> {
const input = this.input;
const output = this.output;
@ -33,8 +42,4 @@ export class GenderAge extends Model {
age: parseInt(result[2] * 100 as any),
}
}
public predict(image: ImageSource, option?: GenderAgePredictOption) {
return Model.resolveImage(image, im => this.doPredict(im, option));
}
}