msluszniak commited on
Commit
72f021c
·
verified ·
1 Parent(s): 9044a46

Re-export under the get_model_schema contract; restructure to the MODEL_SPEC layout

Browse files
.gitattributes CHANGED
@@ -36,3 +36,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
36
  PP-OCRv6_coreml.pte filter=lfs diff=lfs merge=lfs -text
37
  PP-OCRv6_vulkan.pte filter=lfs diff=lfs merge=lfs -text
38
  PP-OCRv6_xnnpack.pte filter=lfs diff=lfs merge=lfs -text
 
 
 
 
36
  PP-OCRv6_coreml.pte filter=lfs diff=lfs merge=lfs -text
37
  PP-OCRv6_vulkan.pte filter=lfs diff=lfs merge=lfs -text
38
  PP-OCRv6_xnnpack.pte filter=lfs diff=lfs merge=lfs -text
39
+ coreml/pp_ocrv6_coreml_int8.pte filter=lfs diff=lfs merge=lfs -text
40
+ vulkan/pp_ocrv6_vulkan_fp16.pte filter=lfs diff=lfs merge=lfs -text
41
+ xnnpack/pp_ocrv6_xnnpack_fp32.pte filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -19,31 +19,44 @@ per-size method buckets). The `.pte` is a pure tensor→tensor function; all pre
19
  (resize, normalize, DBNet box decode, perspective crop, CTC decode) is the client's job and is
20
  driven by `config.json`. One model covers **all languages** (18 709-entry multilingual charset).
21
 
 
 
 
 
 
 
 
 
22
  ## Methods & I/O contract
23
 
24
  | method | input | output |
25
  |---|---|---|
26
  | `detect` (DBNet) | `[1,3,H,W]` f32 RGB, **ImageNet-normalized by the client**: `(x/255 − mean)/std`, `mean=[0.485,0.456,0.406]`, `std=[0.229,0.224,0.225]` | `[1,1,H,W]` probability map (sigmoid baked) |
27
- | `recognize` (SVTR) | `[1,3,48,W]` f32 RGB, client-normalized `(x/255 − 0.5)/0.5` | `[1,W/8,18709+1]` probs (softmax baked); `charset[i]` → logit `i+1`, blank = 0 |
28
 
29
  **Nothing is baked for input normalization** — the client normalizes before calling.
30
  Note the two methods use *different* norms (ImageNet for detect, `0.5/0.5` for recognize).
31
 
32
- ## Shape discovery (companion methods)
33
-
34
- Every method carries exactly **one** no-arg discovery companion:
35
 
36
- - `get_dynamic_dims_<method>` dynamic method. Returns one `int32 [rank, 3]` tensor per
37
- tensor input; each row is `[min, max, step]` (static dims are `[n, n, 1]`). Any conforming
38
- shape is valid.
39
- - `get_enum_shapes_<method>` enumerated method. Returns one `int32 [N, rank]` tensor per
40
- tensor input; each row is a complete legal shape (cross-dimension coupling is exact —
41
- a listed `1280×640` does **not** imply `640×1280`). Snap inputs to the nearest row.
 
 
 
42
 
43
- | backend | `detect` | `recognize` |
44
  |---|---|---|
45
- | `xnnpack`, `vulkan` | `get_dynamic_dims_detect` → H, W ∈ `[640, 1280]` step 32 | `get_dynamic_dims_recognize` → W ∈ `[160, 1280]` step 8 (H fixed 48) |
46
- | `coreml` | `get_enum_shapes_detect` `640²`, `960²`, `1280²`, `1280×640` | `get_enum_shapes_recognize` → widths `160, 320, 480, 640, 1280` |
 
 
 
 
47
 
48
  ## Backends
49
 
@@ -77,3 +90,6 @@ the compatibility note in the
77
  [ExecuTorch GitHub repository](https://github.com/pytorch/executorch/blob/main/runtime/COMPATIBILITY.md).
78
  If you work with React Native ExecuTorch, the library constants guarantee compatibility with the
79
  runtime used behind the scenes.
 
 
 
 
19
  (resize, normalize, DBNet box decode, perspective crop, CTC decode) is the client's job and is
20
  driven by `config.json`. One model covers **all languages** (18 709-entry multilingual charset).
21
 
22
+ ## Repository layout
23
+
24
+ ```
25
+ <backend>/config.json # per-backend spec (see the schema link inside)
26
+ <backend>/pp_ocrv6_<backend>_<precision>.pte
27
+ charset.txt # 18 709 entries; charset[i] -> logit i+1, blank = 0
28
+ ```
29
+
30
  ## Methods & I/O contract
31
 
32
  | method | input | output |
33
  |---|---|---|
34
  | `detect` (DBNet) | `[1,3,H,W]` f32 RGB, **ImageNet-normalized by the client**: `(x/255 − mean)/std`, `mean=[0.485,0.456,0.406]`, `std=[0.229,0.224,0.225]` | `[1,1,H,W]` probability map (sigmoid baked) |
35
+ | `recognize` (SVTR) | `[1,3,48,W]` f32 RGB, client-normalized `(x/255 − 0.5)/0.5` | `[1,W/8,18710]` probs (softmax baked); `charset[i]` → logit `i+1`, blank = 0 |
36
 
37
  **Nothing is baked for input normalization** — the client normalizes before calling.
38
  Note the two methods use *different* norms (ImageNet for detect, `0.5/0.5` for recognize).
39
 
40
+ ## Shape discovery (`get_model_schema`)
 
 
41
 
42
+ Every `.pte` exports one no-arg constant method, **`get_model_schema`**, returning a JSON
43
+ `ModelSpec` string: per method, the input and output parameter specs (dtype plus a domain per
44
+ dimension `constant`, `range` with `{min, max, step}`, or `enum` with explicit `choices`) and
45
+ the runtime constraints the method declares over its dimensions. Methods absent from the JSON
46
+ are fully static and described by ExecuTorch's own `MethodMeta`. The schema is validated
47
+ against
48
+ [`config.schema.json`'s `ModelSpec`](https://huggingface.co/software-mansion/react-native-executorch-spec)
49
+ counterpart in the library at load time. The older `get_dynamic_dims_<m>` / `get_enum_shapes_<m>`
50
+ companion methods are **gone** — everything they carried now lives in this one document.
51
 
52
+ | backend | `detect` H, W | `recognize` W (H fixed 48) |
53
  |---|---|---|
54
+ | `xnnpack`, `vulkan` | `range` `[640, 1280]` step 32 | `range` `[160, 1280]` step 8 |
55
+ | `coreml` | `enum` `640, 960, 1280` per dimension | `enum` `160, 320, 480, 640, 1280` |
56
+
57
+ `recognize` additionally declares a **linear runtime constraint** tying its input width to its
58
+ CTC timestep count — `width = 8 × timesteps + 0` — so a client can size the probs output for
59
+ whatever width it picks instead of inferring a ratio.
60
 
61
  ## Backends
62
 
 
90
  [ExecuTorch GitHub repository](https://github.com/pytorch/executorch/blob/main/runtime/COMPATIBILITY.md).
91
  If you work with React Native ExecuTorch, the library constants guarantee compatibility with the
92
  runtime used behind the scenes.
93
+
94
+ These models were exported with ExecuTorch 1.3.1 and **no forward compatibility** is
95
+ guaranteed; older runtimes may not load them.
config.json CHANGED
@@ -1,20 +1,3 @@
1
  {
2
- "schemaVersion": 1,
3
- "detectorKind": "dbnet",
4
- "buckets": {
5
- "detect": [
6
- 640,
7
- 960,
8
- 1280
9
- ],
10
- "recognize": [
11
- 160,
12
- 320,
13
- 480,
14
- 640,
15
- 1280
16
- ]
17
- },
18
- "charsetUrl": "charset.txt",
19
- "dropScore": 0.5
20
- }
 
1
  {
2
+ "modelName": "pp-ocrv6"
3
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
coreml/config.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://huggingface.co/software-mansion/react-native-executorch-spec/resolve/main/config.schema.json",
3
+ "model": "pp_ocrv6",
4
+ "family": "paddleocr",
5
+ "capabilities": [
6
+ "text-detection",
7
+ "text-recognition"
8
+ ],
9
+ "backend": "coreml",
10
+ "license": "apache-2.0",
11
+ "variants": [
12
+ {
13
+ "file": "pp_ocrv6_coreml_int8.pte",
14
+ "precision": "int8",
15
+ "quantized": true,
16
+ "default": true,
17
+ "size_bytes": 8269910,
18
+ "methods": {
19
+ "detect": {
20
+ "inputs": [
21
+ {
22
+ "shape": [
23
+ 1,
24
+ 3,
25
+ -1,
26
+ -1
27
+ ],
28
+ "dtype": "float32"
29
+ }
30
+ ],
31
+ "outputs": [
32
+ {
33
+ "shape": [
34
+ 1,
35
+ 1,
36
+ -1,
37
+ -1
38
+ ],
39
+ "dtype": "float32"
40
+ }
41
+ ]
42
+ },
43
+ "recognize": {
44
+ "inputs": [
45
+ {
46
+ "shape": [
47
+ 1,
48
+ 3,
49
+ 48,
50
+ -1
51
+ ],
52
+ "dtype": "float32"
53
+ }
54
+ ],
55
+ "outputs": [
56
+ {
57
+ "shape": [
58
+ 1,
59
+ -1,
60
+ 18710
61
+ ],
62
+ "dtype": "float32"
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ ]
69
+ }
coreml/pp_ocrv6_coreml_int8.pte ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:170309543ff4f519b304aa40be96be36224ed92b24760fade21af9909df771d3
3
+ size 8269910
vulkan/config.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://huggingface.co/software-mansion/react-native-executorch-spec/resolve/main/config.schema.json",
3
+ "model": "pp_ocrv6",
4
+ "family": "paddleocr",
5
+ "capabilities": [
6
+ "text-detection",
7
+ "text-recognition"
8
+ ],
9
+ "backend": "vulkan",
10
+ "license": "apache-2.0",
11
+ "variants": [
12
+ {
13
+ "file": "pp_ocrv6_vulkan_fp16.pte",
14
+ "precision": "fp16",
15
+ "quantized": false,
16
+ "default": true,
17
+ "size_bytes": 26176856,
18
+ "methods": {
19
+ "detect": {
20
+ "inputs": [
21
+ {
22
+ "shape": [
23
+ 1,
24
+ 3,
25
+ -1,
26
+ -1
27
+ ],
28
+ "dtype": "float32"
29
+ }
30
+ ],
31
+ "outputs": [
32
+ {
33
+ "shape": [
34
+ 1,
35
+ 1,
36
+ -1,
37
+ -1
38
+ ],
39
+ "dtype": "float32"
40
+ }
41
+ ]
42
+ },
43
+ "recognize": {
44
+ "inputs": [
45
+ {
46
+ "shape": [
47
+ 1,
48
+ 3,
49
+ 48,
50
+ -1
51
+ ],
52
+ "dtype": "float32"
53
+ }
54
+ ],
55
+ "outputs": [
56
+ {
57
+ "shape": [
58
+ 1,
59
+ -1,
60
+ 18710
61
+ ],
62
+ "dtype": "float32"
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ ]
69
+ }
vulkan/pp_ocrv6_vulkan_fp16.pte ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71a26547bb71bbc66d829648183ea112d4d5c1ec71295cea847e6c4d6ffad818
3
+ size 26176856
xnnpack/config.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://huggingface.co/software-mansion/react-native-executorch-spec/resolve/main/config.schema.json",
3
+ "model": "pp_ocrv6",
4
+ "family": "paddleocr",
5
+ "capabilities": [
6
+ "text-detection",
7
+ "text-recognition"
8
+ ],
9
+ "backend": "xnnpack",
10
+ "license": "apache-2.0",
11
+ "variants": [
12
+ {
13
+ "file": "pp_ocrv6_xnnpack_fp32.pte",
14
+ "precision": "fp32",
15
+ "quantized": false,
16
+ "default": true,
17
+ "size_bytes": 31066200,
18
+ "methods": {
19
+ "detect": {
20
+ "inputs": [
21
+ {
22
+ "shape": [
23
+ 1,
24
+ 3,
25
+ -1,
26
+ -1
27
+ ],
28
+ "dtype": "float32"
29
+ }
30
+ ],
31
+ "outputs": [
32
+ {
33
+ "shape": [
34
+ 1,
35
+ 1,
36
+ -1,
37
+ -1
38
+ ],
39
+ "dtype": "float32"
40
+ }
41
+ ]
42
+ },
43
+ "recognize": {
44
+ "inputs": [
45
+ {
46
+ "shape": [
47
+ 1,
48
+ 3,
49
+ 48,
50
+ -1
51
+ ],
52
+ "dtype": "float32"
53
+ }
54
+ ],
55
+ "outputs": [
56
+ {
57
+ "shape": [
58
+ 1,
59
+ -1,
60
+ 18710
61
+ ],
62
+ "dtype": "float32"
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ ]
69
+ }
xnnpack/pp_ocrv6_xnnpack_fp32.pte ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fad0b9ed668021ac5c4afc4501ec59c0eb9cc1dccf8b5ed627ab0a51a34d30df
3
+ size 31066200