mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-08 01:50:27 +08:00
[Other] Refactor js submodule (#415)
* Refactor js submodule * Remove change-log * Update ocr module * Update ocr-detection module * Update ocr-detection module * Remove change-log
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file mobilenet model
|
||||
*/
|
||||
|
||||
import { Runner, env } from '@paddlejs/paddlejs-core';
|
||||
import '@paddlejs/paddlejs-backend-webgl';
|
||||
|
||||
interface ModelConfig {
|
||||
path: string;
|
||||
mean?: number[];
|
||||
std?: number[];
|
||||
needPreheat?: boolean;
|
||||
}
|
||||
|
||||
interface MobilenetMap {
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
let mobilenetMap = null as any;
|
||||
let runner = null as Runner;
|
||||
|
||||
export async function load(config: ModelConfig, map: string[] | MobilenetMap) {
|
||||
mobilenetMap = map;
|
||||
|
||||
const {
|
||||
path,
|
||||
mean,
|
||||
std,
|
||||
needPreheat = true
|
||||
} = config;
|
||||
|
||||
runner = new Runner({
|
||||
modelPath: path,
|
||||
fill: '#fff',
|
||||
mean: mean || [],
|
||||
std: std || [],
|
||||
scale: 256,
|
||||
needPreheat
|
||||
});
|
||||
env.set('webgl_pack_channel', true);
|
||||
await runner.init();
|
||||
}
|
||||
|
||||
// 获取数组中的最大值索引
|
||||
function getMaxItem(datas: number[] = []) {
|
||||
const max: number = Math.max.apply(null, datas);
|
||||
const index: number = datas.indexOf(max);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
export async function classify(image) {
|
||||
const res = await runner.predict(image);
|
||||
const maxItem = getMaxItem(res);
|
||||
const result = mobilenetMap[`${maxItem}`];
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user