[中文](./README_cn.md)
# Paddle.js Core
As the core part of the Paddle.js ecosystem, this package hosts `@paddlejs/paddlejs-core`,
which is responsible for the operation of the inference process of the entire engine,
and provides interfaces for backend registration and environment variable registration.
<img src="https://img.shields.io/npm/v/@paddlejs/paddlejs-core?color=success" alt="version"> <img src="https://img.shields.io/bundlephobia/min/@paddlejs/paddlejs-core" alt="size"> <img src="https://img.shields.io/npm/dm/@paddlejs/paddlejs-core?color=orange" alt="downloads"> <img src="https://img.shields.io/npm/dt/@paddlejs/paddlejs-core" alt="downloads">
## RunnerConfig
When registering the engine you need to configure the engine, you must configure the items `modelPath`, `feedShape`, all items are configured as follows.
```typescript
// model struture
enum GraphType {
SingleOutput = 'single',
MultipleOutput = 'multiple',
MultipleInput = 'multipleInput'
}
interface RunnerConfig {
modelPath: string; // model path (local or web address)
modelName?: string; // model name
feedShape: { // input feed shape
fc?: number; // feed channel, default is 3.
fw: number; // feed width
fh: number; // feed height
};
fill?: Color; // the color used to padding
mean?: number[]; // mean value
std?: number[]; // standard deviation
bgr?: boolean; // whether the image channel alignment is BGR, default is false (RGB)
type?: GraphType; // model structure, default is singleInput and singleOutput
needPreheat?: boolean; // whether to warm up the engine during initialization, default is true
plugins?: { // register model topology transform plugin
preTransforms?: Transformer[]; // transform before creating network topology
transforms?: Transformer[]; // transform when traversing model layers
postTransforms?: Transformer[]; // transform the model topology diagram after it has been created
};
}
```
## Importing
You can install this package via npm., `@paddlejs/paddlejs-core`
```js
// Import @paddlejs/paddlejs-core
import { Runner } from '@paddlejs/paddlejs-core';
// Import the registered WebGL backend.
import '@paddlejs/paddlejs-backend-webgl';
const runner = new Runner({
modelPath: '/model/mobilenetv2', // model path, e.g. http://xx.cc/path, http://xx.cc/path/model.json, /localModelDir/model.json, /localModelDir
feedShape: { // input shape
fw: 256,
fh: 256
},
fill?: '#fff', // fill color when resize image, default value is #fff
webglFeedProcess?: true // Turn on `webglFeedProcess` to convert all pre-processing parts of the model to shader processing, and keep the original image texture.
});
// init runner
await runner.init();
// predict and get result
const res = await runner.predict(mediadata, callback?);
```
**Note**: If you are importing the Core package, you also need to import a backend (e.g.,
[paddlejs-backend-webgl](/packages/paddlejs-backend-webgl), [paddlejs-backend-webgpu](/packages/paddlejs-backend-webgpu)).
## High-level use
1. `@paddlejs/paddlejs-core` provides the interface `registerOp`, through which developers can register custom operators.
2. `@paddlejs/paddlejs-core` provides the global variable `env` module, through which developers can register environment variables, using the following method:
```js
// set env key/flag and value
env.set(key, value);
// get value by key/flag
env.get(key);
```
3. transform model stucture
By registering the model transformers through `runnerConfig.plugins`, developers can make changes (add, delete, change) to the model structure, such as pruning to remove unnecessary layers to speed up inference, or adding custom layers to the end of the model and turning post-processing into layers in the model to speed up post-processing.
4. Turn on performance flag for acceleration
Paddle.js currently provides five performance `flags`, which can be set to `true` if you want to enable inference acceleration.
```js
env.set('webgl_pack_channel', true);
```
Turn on `webgl_pack_channel` and the eligible conv2d will use packing shader to perform packing transformations to improve performance through vectorization calculations.
```js
env.set('webgl_force_half_float_texture', true);
```
Enable `webgl_force_half_float_texture`, feature map uses half float `HALF_FLOAT`.
```js
env.set('webgl_gpu_pipeline', true);
```
Turn on `webgl_gpu_pipeline` to convert all model pre-processing parts to shader processing, and render the model results to `WebGL2RenderingContext` of webgl backend on screen. Developers can perform model post-processing on the output texture and the original image texture to achieve the `GPU_PIPELINE`: pre-processing + inference + post-processing (rendering processing) to get high performance. Take humanseg model case for reference.
```js
env.set('webgl_pack_output', true);
```
Enable `webgl_pack_output` to migrate the `NHWC` to `NCHW` layout transformation of the model output to the GPU, and `pack` to a four-channel layout to reduce loop processing when reading the results from the GPU
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Paddle.js 是百度 PaddlePaddle 的 web 方向子项目,是一个运行在浏览器中的开源深度学习框架。Paddle.js 可以加载提前训练好的 paddle 模型,或者将 paddle hub 中的模型通过 Paddle.js 的模型转换工具 paddlejs-converter 变成浏览器友好的模型进行在线推理预测使用。
资源推荐
资源详情
资源评论
收起资源包目录
Paddle.js-release-v2.2.3.zip (658个子文件)
opencv_js.wasm.br 254KB
.eslintignore 90B
demo1.gif 11.58MB
.gitignore 104B
index.html 4KB
index.html 3KB
index.html 3KB
index.html 3KB
index.html 3KB
index.html 3KB
index.html 3KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1007B
index.html 278B
index.html 273B
MANIFEST.in 43B
detect.jpeg 819KB
multi_small_face.jpeg 133KB
banana.jpeg 30KB
banana.jpeg 30KB
banana.jpeg 30KB
single_big_face.jpeg 14KB
cat.jpeg 6KB
ok.jpeg 4KB
car.jpg 756KB
3.jpg 683KB
6.jpg 481KB
4.jpg 469KB
5.jpg 467KB
1.jpg 443KB
7.jpg 439KB
2.jpg 419KB
001.jpg 417KB
boy.jpg 409KB
ocr.jpg 281KB
mayon-volcano-erupt.jpg 230KB
bg.jpg 89KB
bg.jpg 89KB
bg.jpg 25KB
2.jpg 25KB
human.jpg 12KB
white.jpg 7KB
opencv.js 7.34MB
opencv_ocr.js 1.32MB
opencv_blur.js 1.03MB
numjs.js 840KB
opencv.js 357KB
numjs.min.js 172KB
kernelWasm.js 40KB
webgl-image-filter.js 21KB
index.js 10KB
config.js 6KB
play.js 5KB
jest.config.js 5KB
jest.config.js 4KB
start-animation.js 3KB
webpack.config.js 3KB
util.js 3KB
webpack.config.js 3KB
index.js 2KB
webpack.prod.js 2KB
Timer.js 2KB
finder-ui.js 2KB
timer.js 2KB
app.js 2KB
final.js 2KB
index.js 2KB
webpack.config.js 1KB
webpack.dev.js 1KB
webpack.config.js 1KB
webpack.config.js 1KB
webpack.dev.js 1KB
webpack.prod.js 1KB
webpack.dev.js 1KB
webpack.config.js 1KB
webpack.dev.js 1KB
webpack.dev.js 1KB
webpack.config.js 1KB
webpack.dev.js 1008B
webpack.prod.js 1003B
img-preloader.js 1000B
webpack.config.js 980B
webpack.prod.js 943B
webpack.prod.js 940B
webpack.prod.js 915B
webpack.dev.js 901B
共 658 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
m0_72731342
- 粉丝: 2
- 资源: 1832
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功