web-sdk-pp-detection 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/browser-global.js +54 -13
- package/dist/browser-global.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
基于 ONNX Runtime Web 的浏览器端 PP-Detection 目标检测 SDK,支持 PC、移动端与各类 H5 页面。
|
|
6
6
|
|
|
7
|
-
当前 SDK 版本为 **0.3.
|
|
7
|
+
当前 SDK 版本为 **0.3.1**,完整变更见[发布说明](https://github.com/chenmohan123/web-sdk-PP-Detection/blob/main/docs/zh-CN/release-0.3.1.md)。
|
|
8
8
|
|
|
9
9
|
## 安装
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
pnpm add web-sdk-pp-detection@0.3.
|
|
12
|
+
pnpm add web-sdk-pp-detection@0.3.1
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
也可以使用 `npm install web-sdk-pp-detection@0.3.
|
|
15
|
+
也可以使用 `npm install web-sdk-pp-detection@0.3.1`。
|
|
16
16
|
|
|
17
17
|
## 快速开始
|
|
18
18
|
|
|
@@ -82,15 +82,15 @@ const detector = await createPPDetection({
|
|
|
82
82
|
|
|
83
83
|
A browser-first PP-Detection object detection SDK powered by ONNX Runtime Web for desktop, mobile, and H5 pages.
|
|
84
84
|
|
|
85
|
-
The current SDK version is **0.3.
|
|
85
|
+
The current SDK version is **0.3.1**. See the [release notes](https://github.com/chenmohan123/web-sdk-PP-Detection/blob/main/docs/en/release-0.3.1.md) for the complete changes.
|
|
86
86
|
|
|
87
87
|
### Installation
|
|
88
88
|
|
|
89
89
|
```bash
|
|
90
|
-
pnpm add web-sdk-pp-detection@0.3.
|
|
90
|
+
pnpm add web-sdk-pp-detection@0.3.1
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
`npm install web-sdk-pp-detection@0.3.
|
|
93
|
+
`npm install web-sdk-pp-detection@0.3.1` is also supported.
|
|
94
94
|
|
|
95
95
|
### Quick start
|
|
96
96
|
|
package/dist/browser-global.js
CHANGED
|
@@ -14007,34 +14007,58 @@ ${u}`, c = n.createShaderModule({ code: d, label: e.name });
|
|
|
14007
14007
|
const rounded = value >> BICUBIC_PRECISION_BITS;
|
|
14008
14008
|
return Math.max(0, Math.min(255, rounded));
|
|
14009
14009
|
}
|
|
14010
|
-
function
|
|
14010
|
+
function writeBicubicChannels(raster, resizedWidth, resizedHeight, target) {
|
|
14011
14011
|
const horizontal = createBicubicAxis(raster.width, resizedWidth);
|
|
14012
14012
|
const vertical = createBicubicAxis(raster.height, resizedHeight);
|
|
14013
|
-
const
|
|
14013
|
+
const rowStride = resizedWidth * 3;
|
|
14014
|
+
const intermediate = new Uint8Array(raster.height * rowStride);
|
|
14014
14015
|
for (let y = 0; y < raster.height; y += 1) {
|
|
14016
|
+
const sourceRow = y * raster.width * 4;
|
|
14017
|
+
const targetRow = y * rowStride;
|
|
14015
14018
|
for (let x = 0; x < resizedWidth; x += 1) {
|
|
14016
14019
|
const [start, count] = horizontal.bounds[x];
|
|
14017
14020
|
const coefficients = horizontal.coefficients[x];
|
|
14018
|
-
let
|
|
14021
|
+
let red = BICUBIC_ROUNDING;
|
|
14022
|
+
let green = BICUBIC_ROUNDING;
|
|
14023
|
+
let blue = BICUBIC_ROUNDING;
|
|
14024
|
+
let source2 = sourceRow + start * 4;
|
|
14019
14025
|
for (let index = 0; index < count; index += 1) {
|
|
14020
|
-
|
|
14026
|
+
const coefficient = coefficients[index];
|
|
14027
|
+
red += raster.rgba[source2] * coefficient;
|
|
14028
|
+
green += raster.rgba[source2 + 1] * coefficient;
|
|
14029
|
+
blue += raster.rgba[source2 + 2] * coefficient;
|
|
14030
|
+
source2 += 4;
|
|
14021
14031
|
}
|
|
14022
|
-
|
|
14032
|
+
const offset = targetRow + x * 3;
|
|
14033
|
+
intermediate[offset] = clipBicubic(red);
|
|
14034
|
+
intermediate[offset + 1] = clipBicubic(green);
|
|
14035
|
+
intermediate[offset + 2] = clipBicubic(blue);
|
|
14023
14036
|
}
|
|
14024
14037
|
}
|
|
14025
|
-
const
|
|
14038
|
+
const plane = target.inputWidth * target.inputHeight;
|
|
14026
14039
|
for (let y = 0; y < resizedHeight; y += 1) {
|
|
14027
14040
|
const [start, count] = vertical.bounds[y];
|
|
14028
14041
|
const coefficients = vertical.coefficients[y];
|
|
14042
|
+
const sourceRow = start * rowStride;
|
|
14043
|
+
const targetRow = (y + target.padTop) * target.inputWidth + target.padLeft;
|
|
14029
14044
|
for (let x = 0; x < resizedWidth; x += 1) {
|
|
14030
|
-
let
|
|
14045
|
+
let red = BICUBIC_ROUNDING;
|
|
14046
|
+
let green = BICUBIC_ROUNDING;
|
|
14047
|
+
let blue = BICUBIC_ROUNDING;
|
|
14048
|
+
let source2 = sourceRow + x * 3;
|
|
14031
14049
|
for (let index = 0; index < count; index += 1) {
|
|
14032
|
-
|
|
14050
|
+
const coefficient = coefficients[index];
|
|
14051
|
+
red += intermediate[source2] * coefficient;
|
|
14052
|
+
green += intermediate[source2 + 1] * coefficient;
|
|
14053
|
+
blue += intermediate[source2 + 2] * coefficient;
|
|
14054
|
+
source2 += rowStride;
|
|
14033
14055
|
}
|
|
14034
|
-
|
|
14056
|
+
const offset = targetRow + x;
|
|
14057
|
+
target.data[offset] = target.values[clipBicubic(red)];
|
|
14058
|
+
target.data[plane + offset] = target.values[256 + clipBicubic(green)];
|
|
14059
|
+
target.data[plane * 2 + offset] = target.values[512 + clipBicubic(blue)];
|
|
14035
14060
|
}
|
|
14036
14061
|
}
|
|
14037
|
-
return output;
|
|
14038
14062
|
}
|
|
14039
14063
|
function preprocessImage(raster, preprocessing) {
|
|
14040
14064
|
const inputWidth = preprocessing.size.width;
|
|
@@ -14061,18 +14085,35 @@ ${u}`, c = n.createShaderModule({ code: d, label: e.name });
|
|
|
14061
14085
|
const mean = normalize ? preprocessing.mean ?? [0, 0, 0] : [0, 0, 0];
|
|
14062
14086
|
const std = normalize ? preprocessing.std ?? [1, 1, 1] : [1, 1, 1];
|
|
14063
14087
|
const interpolation2 = preprocessing.interpolation ?? "bilinear";
|
|
14088
|
+
const bicubicValues = doResize && interpolation2 === "bicubic" ? new Float32Array(256 * 3) : void 0;
|
|
14064
14089
|
for (let channel = 0; channel < 3; channel += 1) {
|
|
14065
14090
|
const padding = normalize && mean[channel] !== 0 ? -mean[channel] / std[channel] : 0;
|
|
14066
14091
|
data.fill(padding, channel * plane, (channel + 1) * plane);
|
|
14067
|
-
|
|
14092
|
+
if (bicubicValues) {
|
|
14093
|
+
for (let pixel = 0; pixel < 256; pixel += 1) {
|
|
14094
|
+
const scaled = rescale ? pixel * preprocessing.rescaleFactor : pixel;
|
|
14095
|
+
bicubicValues[channel * 256 + pixel] = normalize ? (scaled - mean[channel]) / std[channel] : scaled;
|
|
14096
|
+
}
|
|
14097
|
+
continue;
|
|
14098
|
+
}
|
|
14068
14099
|
for (let y = 0; y < resizedHeight; y += 1) {
|
|
14069
14100
|
for (let x = 0; x < resizedWidth; x += 1) {
|
|
14070
|
-
const pixel =
|
|
14101
|
+
const pixel = doResize ? bilinearChannel(raster, x, y, resizedWidth, resizedHeight, channel) : sampleChannel(raster, x, y, channel);
|
|
14071
14102
|
const scaled = rescale ? pixel * preprocessing.rescaleFactor : pixel;
|
|
14072
14103
|
data[channel * plane + (y + padTop) * inputWidth + x + padLeft] = normalize ? (scaled - mean[channel]) / std[channel] : scaled;
|
|
14073
14104
|
}
|
|
14074
14105
|
}
|
|
14075
14106
|
}
|
|
14107
|
+
if (bicubicValues) {
|
|
14108
|
+
writeBicubicChannels(raster, resizedWidth, resizedHeight, {
|
|
14109
|
+
data,
|
|
14110
|
+
inputWidth,
|
|
14111
|
+
inputHeight,
|
|
14112
|
+
padLeft,
|
|
14113
|
+
padTop,
|
|
14114
|
+
values: bicubicValues
|
|
14115
|
+
});
|
|
14116
|
+
}
|
|
14076
14117
|
return {
|
|
14077
14118
|
data,
|
|
14078
14119
|
dims: [1, 3, inputHeight, inputWidth],
|
|
@@ -15855,7 +15896,7 @@ ${u}`, c = n.createShaderModule({ code: d, label: e.name });
|
|
|
15855
15896
|
};
|
|
15856
15897
|
|
|
15857
15898
|
// src/index.ts
|
|
15858
|
-
var CURRENT_SDK_VERSION = "0.3.
|
|
15899
|
+
var CURRENT_SDK_VERSION = "0.3.1";
|
|
15859
15900
|
function probePPDetectionCapabilities(options = {}) {
|
|
15860
15901
|
return probeCapabilities(options);
|
|
15861
15902
|
}
|