You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/paddlejs-core/README.md
+89Lines changed: 89 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,42 @@ As the core part of the Paddle.js ecosystem, this package hosts `@paddlejs/paddl
5
5
which is responsible for the operation of the inference process of the entire engine,
6
6
and provides interfaces for backend registration and environment variable registration.
7
7
8
+
9
+
## RunnerConfig
10
+
11
+
When registering the engine you need to configure the engine, you must configure the items `modelPath`, `feedShape`, all items are configured as follows.
12
+
13
+
```typescript
14
+
15
+
// model struture
16
+
enumGraphType {
17
+
SingleOutput='single',
18
+
MultipleOutput='multiple',
19
+
MultipleInput='multipleInput'
20
+
}
21
+
22
+
interfaceRunnerConfig {
23
+
modelPath:string; // model path (local or web address)
24
+
modelName?:string; // model name
25
+
feedShape: { // input feed shape
26
+
fc?:number; // feed channel, default is 3.
27
+
fw:number; // feed width
28
+
fh:number; // feed height
29
+
};
30
+
fill?:Color; // the color used to padding
31
+
mean?:number[]; // mean value
32
+
std?:number[]; // standard deviation
33
+
bgr?:boolean; // whether the image channel alignment is BGR, default is false (RGB)
34
+
type?:GraphType; // model structure, default is singleInput and singleOutput
35
+
needPreheat?:boolean; // whether to warm up the engine during initialization, default is true
36
+
plugins?: { // register model topology transform plugin
37
+
preTransforms?:Transformer[]; // transform before creating network topology
38
+
transforms?:Transformer[]; // transform when traversing model layers
39
+
postTransforms?:Transformer[]; // transform the model topology diagram after it has been created
40
+
};
41
+
}
42
+
43
+
```
8
44
## Importing
9
45
You can install this package via npm., `@paddlejs/paddlejs-core`
10
46
@@ -32,3 +68,56 @@ const res = await runner.predict(mediadata, callback?);
32
68
**Note**: If you are importing the Core package, you also need to import a backend (e.g.,
1. `@paddlejs/paddlejs-core` provides the interface `registerOp`, through which developers can register custom operators.
75
+
76
+
2. `@paddlejs/paddlejs-core` provides the global variable `env` module, through which developers can register environment variables, using the following method:
77
+
78
+
```js
79
+
// set env key/flag and value
80
+
env.set(key, value);
81
+
82
+
// get value by key/flag
83
+
env.get(key);
84
+
```
85
+
86
+
3. transform model stucture
87
+
88
+
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.
89
+
90
+
91
+
4. Turn on performance flag for acceleration
92
+
93
+
Paddle.js currently provides five performance `flags`, which can be set to `true` if you want to enable inference acceleration.
94
+
95
+
96
+
```js
97
+
env.set('webgl_pack_channel', true);
98
+
```
99
+
Turn on `webgl_pack_channel` and the eligible conv2d will use packing shader to perform packing transformations to improve performance through vectorization calculations.
Turn on `webgl_feed_process` to convert all pre-processing parts of the model to shader processing, and keep the original image texture.
112
+
113
+
114
+
```js
115
+
env.set('webgl_gpu_pipeline', true);
116
+
```
117
+
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.
118
+
119
+
120
+
```js
121
+
env.set('webgl_pack_output', true);
122
+
```
123
+
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
0 commit comments