【增加模型快捷加载方法】
This commit is contained in:
@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user