baraa00109 commited on
Commit
772099e
·
verified ·
1 Parent(s): 0f23841

SLI Sentences Large v2 and Phone v1

Browse files
README.md ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-sa-4.0
3
+ language:
4
+ - ar
5
+ library_name: onnx
6
+ pipeline_tag: other
7
+ tags:
8
+ - sign-language
9
+ - saudi-sign-language
10
+ - continuous-sign-language-recognition
11
+ - ctc
12
+ - conformer
13
+ - mediapipe
14
+ - onnx
15
+ ---
16
+
17
+ # SLI Sentences
18
+
19
+ Continuous Saudi Sign Language recognition from body, face and hand landmarks. Each model reads
20
+ a whole signed sentence and outputs its glosses with CTC. They power Sentences mode in
21
+ **SLI**, the Arabic sign-language interpreter made by the Digital Fingers Team.
22
+
23
+ | File | Model | Params | Size | Dev WER | One hand hidden | 1.5× faster | No face |
24
+ | --- | --- | --- | --- | --- | --- | --- | --- |
25
+ | `sli-sentences-large-v2.onnx` | SLI Sentences Large v2 | 42M | 169 MB | **17.5%** | 18.0% | 16.8% | 19.2% |
26
+ | `sli-sentences-phone-v1.onnx` | SLI Sentences Phone v1 | 4.5M | 17.9 MB | **17.4%** | 18.0% | 16.7% | 19.4% |
27
+
28
+ Word error rate (WER) is measured on the signer-independent (SI) dev split of
29
+ [Isharah-1000](https://www.kaggle.com/datasets/tfmohamedyahia/isharah-1000-pose). The dev signer is
30
+ never seen in training. Scores come from the exported ONNX files. For reference, the best SI baseline
31
+ in the Isharah paper is Swin-MSTP (RGB video), with a dev WER of 17.9% (Alyami et al.,
32
+ arXiv:2506.03615, Table 4).
33
+
34
+ Stress tests: *one hand hidden* hides a hand for 0.5–1.5 s at a time (about 1/3 of frames);
35
+ *1.5× faster* speeds up the signing; *no face* drops the face landmarks entirely (signer far from
36
+ the camera).
37
+
38
+ ## Models
39
+
40
+ Both are Conformer encoders (self-attention, convolution kernel 15) with a linear CTC head over
41
+ 673 classes (blank = 0, plus 672 Isharah glosses).
42
+
43
+ - **Large v2**: d=384, 12 layers, 6 heads, FF 1536. It is pre-trained on KArSL (502 isolated signs),
44
+ trained on the Isharah SI train split (10 signers) with strong augmentation for 100 epochs, and
45
+ self-distilled from an earlier large model. Sentence accuracy on dev is 67.2%.
46
+ - **Phone v1**: d=192, 6 layers, 4 heads, FF 512. It is distilled from a large teacher with the same
47
+ augmentation. Small enough to run in a browser (onnxruntime-web). It scores slightly better than
48
+ its teacher.
49
+
50
+ In the SLI app the large model runs on a server, and the phone model runs in the browser as a fallback.
51
+
52
+ ## Input: SF1 features
53
+
54
+ - `feats`: float32 `[1, T, 356]` at **15 fps**. Each frame holds 176 points × (x, y) plus 4
55
+ presence flags:
56
+ pose 6 | face 128 | left hand 21 | right hand 21 | presence (pose, face, left hand, right hand).
57
+ - Hands are stored by the **signer's own** side. Each part is normalised to its own anchor and
58
+ scale. A missing part is all zeros with presence 0.
59
+ - `feats.py` (with `face_idx.json` and `conventions.json`) builds SF1 from MediaPipe landmarks:
60
+ - `from_holistic(xyz, conf, w, h)` takes MediaPipe Holistic frames (pose-format layout: 33 + 468 + 21 + 21).
61
+ - `from_app_raw(raw)` takes MediaPipe Tasks pose / face / hands results.
62
+ - `resample(frames, t_ms)` puts frames on the 15 fps grid.
63
+ - The models expect sentences of 8–450 frames (0.5–30 s).
64
+
65
+ ## Output
66
+
67
+ `logprobs`: `[1, T', 673]` CTC log-probabilities. Decode greedily: take the argmax per frame,
68
+ collapse repeats and drop blanks (0). Class `k` is the gloss `vocab.json["glosses"][k - 1]`.
69
+ `vocab.json["lookup"]` maps some gloss sequences to written Arabic sentences.
70
+
71
+ ```python
72
+ import json, numpy as np, onnxruntime as ort
73
+
74
+ sess = ort.InferenceSession("sli-sentences-large-v2.onnx")
75
+ vocab = json.load(open("vocab.json", encoding="utf-8"))
76
+
77
+ x = np.load("sentence_sf1.npy").astype(np.float32)[None] # [1, T, 356], 15 fps
78
+ lp = sess.run(None, {"feats": x})[0][0]
79
+
80
+ ids, prev = [], 0
81
+ for k in lp.argmax(-1):
82
+ if k != prev and k != 0:
83
+ ids.append(int(k))
84
+ prev = k
85
+ glosses = [vocab["glosses"][i - 1] for i in ids]
86
+ key = " ".join(glosses)
87
+ print(vocab["lookup"].get(key, key))
88
+ ```
89
+
90
+ ## Limitations
91
+
92
+ - The vocabulary is limited to the 672 Isharah glosses, in Saudi Sign Language. Other Arabic sign
93
+ languages and signs outside the vocabulary are not recognised.
94
+ - The models were trained on 10 signers filmed with room around them. Accuracy drops when a hand
95
+ leaves the frame, and falls by 1–2 points when no face is detected.
96
+ - They output glosses, not grammatical Arabic. Only the sentences in `lookup` get a written form.
97
+ - Research prototype: not for medical, legal or other high-stakes interpretation.
98
+
99
+ ## Licence and data
100
+
101
+ Released under **CC BY-NC-SA 4.0**, following the Isharah dataset licence. Training data:
102
+ Isharah-1000 (Alyami et al., arXiv:2506.03615) and KArSL (pre-training).
conventions.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "karsl_rh_slot_is_signer_right": true,
3
+ "karsl_fps": 20,
4
+ "app_left_label_is_signer_left": true,
5
+ "measured": true
6
+ }
face_idx.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"face": [0, 7, 10, 13, 14, 17, 21, 33, 37, 39, 40, 46, 52, 53, 54, 55, 58, 61, 63, 65, 66, 67, 70, 78, 80, 81, 82, 84, 87, 88, 91, 93, 95, 103, 105, 107, 109, 127, 132, 133, 136, 144, 145, 146, 148, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 162, 163, 172, 173, 176, 178, 181, 185, 191, 234, 246, 249, 251, 263, 267, 269, 270, 276, 282, 283, 284, 285, 288, 291, 293, 295, 296, 297, 300, 308, 310, 311, 312, 314, 317, 318, 321, 323, 324, 332, 334, 336, 338, 356, 361, 362, 365, 373, 374, 375, 377, 378, 379, 380, 381, 382, 384, 385, 386, 387, 388, 389, 390, 397, 398, 400, 402, 405, 409, 415, 454, 466, 469, 470, 471, 472, 474, 475, 476, 477]}
feats.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Sentence features v1 (SF1): 176 points x (x, y) + 4 presence flags per frame, 15 fps.
2
+
3
+ Layout: pose 6 | face 128 | left hand 21 | right hand 21 | presence (pose, face, lh, rh).
4
+ Hands are stored by the signer's own side. src/recognition/sentenceFeatures.ts is the browser
5
+ port; tests/unit/sentenceFeatures.test.ts checks parity against export_parity.py.
6
+ """
7
+
8
+ import json
9
+ import os
10
+
11
+ import numpy as np
12
+
13
+ HERE = os.path.dirname(os.path.abspath(__file__))
14
+ FACE_IDX = json.load(open(os.path.join(HERE, "face_idx.json")))["face"][:128] # no iris
15
+ CONV = json.load(open(os.path.join(HERE, "conventions.json")))
16
+
17
+ POSE_IDX = (11, 12, 13, 14, 15, 16)
18
+ N_POSE, N_FACE, N_HAND = 6, 128, 21
19
+ N_POINTS = N_POSE + N_FACE + 2 * N_HAND # 176
20
+ FEAT_DIM = N_POINTS * 2 + 4 # 356
21
+ FPS = 15
22
+ O_POSE, O_FACE, O_LH, O_RH, O_PRES = 0, 12, 268, 310, 352
23
+ FACE_ANCHOR = 1 # subset position 1 = mesh point 7, as the word model
24
+ FACE_SCALE = (33, 263) # outer eye corners (mesh indices)
25
+ HAND_SCALE = (2, 17)
26
+ SWAP = [1, 0, 3, 2, 5, 4] # pose subset left <-> right
27
+
28
+
29
+ def _d(a, b):
30
+ return max(float(np.hypot(a[0] - b[0], a[1] - b[1])), 1e-6)
31
+
32
+
33
+ def _pose(out, p): # p: (33, >=2) in image-normalised coords
34
+ sub = p[list(POSE_IDX), :2]
35
+ out[O_POSE:O_POSE + 12] = ((sub - sub[0]) / _d(p[11], p[12])).ravel()
36
+ out[O_PRES] = 1
37
+
38
+
39
+ def _face(out, f): # f: (>=468, >=2)
40
+ sub = f[FACE_IDX, :2]
41
+ out[O_FACE:O_FACE + 256] = ((sub - sub[FACE_ANCHOR]) / _d(f[FACE_SCALE[0]], f[FACE_SCALE[1]])).ravel()
42
+ out[O_PRES + 1] = 1
43
+
44
+
45
+ def _hand(out, h, left): # h: (21, >=2)
46
+ o = O_LH if left else O_RH
47
+ out[o:o + 42] = ((h[:, :2] - h[0, :2]) / _d(h[HAND_SCALE[0]], h[HAND_SCALE[1]])).ravel()
48
+ out[O_PRES + (2 if left else 3)] = 1
49
+
50
+
51
+ def from_holistic(xyz, conf, w, h):
52
+ """MediaPipe Holistic frame as stored by pose-format: 33 pose, 468 face, 21 left, 21 right."""
53
+ out = np.zeros(FEAT_DIM, np.float32)
54
+ p = np.asarray(xyz, np.float64)[:, :2] / [w, h]
55
+ c = np.asarray(conf)
56
+ if c[11] > 0 and c[12] > 0:
57
+ _pose(out, p[:33])
58
+ if c[33:501].any():
59
+ _face(out, p[33:501])
60
+ if c[501:522].any():
61
+ _hand(out, p[501:522], True)
62
+ if c[522:543].any():
63
+ _hand(out, p[522:543], False)
64
+ return out
65
+
66
+
67
+ def _assign(pose, hands):
68
+ """Signer side for each hand (True = left): nearest pose wrist (15 = left, 16 = right)."""
69
+ if pose is None:
70
+ flip = CONV["app_left_label_is_signer_left"]
71
+ return [(h["label"] == "Left") == flip for h in hands]
72
+ lw, rw = np.asarray(pose[15][:2]), np.asarray(pose[16][:2])
73
+ wr = [np.asarray(h["lms"][0][:2]) for h in hands]
74
+ if len(hands) == 2:
75
+ straight = np.linalg.norm(wr[0] - lw) + np.linalg.norm(wr[1] - rw)
76
+ crossed = np.linalg.norm(wr[0] - rw) + np.linalg.norm(wr[1] - lw)
77
+ return [True, False] if straight <= crossed else [False, True]
78
+ return [np.linalg.norm(w - lw) <= np.linalg.norm(w - rw) for w in wr]
79
+
80
+
81
+ def from_app_raw(raw):
82
+ """RawFrame as produced by the app / sli_kps.Extractor.raw."""
83
+ out = np.zeros(FEAT_DIM, np.float32)
84
+ if raw["pose"]:
85
+ _pose(out, np.asarray(raw["pose"], np.float64))
86
+ if raw["face"]:
87
+ _face(out, np.asarray(raw["face"], np.float64))
88
+ hands = raw["hands"][:2]
89
+ for hand, left in zip(hands, _assign(raw["pose"], hands)):
90
+ _hand(out, np.asarray(hand["lms"], np.float64), left)
91
+ return out
92
+
93
+
94
+ def from_karsl184(f):
95
+ """The word model's (184, 4) features (as published for KArSL) -> SF1."""
96
+ f = np.asarray(f, np.float64)
97
+ out = np.zeros(FEAT_DIM, np.float32)
98
+ pose, face, rh, lh = f[0:6, :2], f[6:134, :2], f[142:163, :2], f[163:184, :2]
99
+ if np.abs(pose).sum() > 0:
100
+ out[O_POSE:O_POSE + 12] = pose.ravel() # same anchor and scale as SF1
101
+ out[O_PRES] = 1
102
+ if np.abs(face).sum() > 0:
103
+ i33, i263 = FACE_IDX.index(33), FACE_IDX.index(263)
104
+ out[O_FACE:O_FACE + 256] = (face / _d(face[i33], face[i263])).ravel()
105
+ out[O_PRES + 1] = 1
106
+ right_is_right = CONV["karsl_rh_slot_is_signer_right"]
107
+ for slot, is_rh_slot in ((rh, True), (lh, False)):
108
+ if np.abs(slot).sum() == 0:
109
+ continue
110
+ left = (not is_rh_slot) if right_is_right else is_rh_slot
111
+ o = O_LH if left else O_RH
112
+ out[o:o + 42] = slot.ravel() # already wrist-relative and hand-scaled
113
+ out[O_PRES + (2 if left else 3)] = 1
114
+ return out
115
+
116
+
117
+ def resample(frames, t_ms, fps=FPS):
118
+ """Linear interpolation of frames taken at t_ms onto a uniform fps grid starting at t_ms[0]."""
119
+ frames = np.asarray(frames, np.float32)
120
+ if len(frames) == 1:
121
+ return frames.copy()
122
+ t = np.asarray(t_ms, np.float64) - t_ms[0]
123
+ step = 1000.0 / fps
124
+ grid = np.arange(int(t[-1] / step) + 1) * step
125
+ idx = np.clip(np.searchsorted(t, grid, side="right") - 1, 0, len(t) - 2)
126
+ t0, t1 = t[idx], t[idx + 1]
127
+ a = np.clip((grid - t0) / np.maximum(t1 - t0, 1e-9), 0, 1)[:, None]
128
+ return ((1 - a) * frames[idx] + a * frames[idx + 1]).astype(np.float32)
129
+
130
+
131
+ def mirror(frames):
132
+ """Left-right mirror of a signer: arms and hands mirrored and swapped; the face is kept."""
133
+ x = np.array(frames, np.float32, copy=True)
134
+ pose = x[:, O_POSE:O_POSE + 12].reshape(-1, 6, 2)
135
+ new = pose[:, SWAP].copy()
136
+ new -= new[:, :1] # re-anchor on the new left shoulder (the old right shoulder)
137
+ new[..., 0] *= -1
138
+ x[:, O_POSE:O_POSE + 12] = new.reshape(-1, 12) * x[:, [O_PRES]]
139
+ lh, rh = x[:, O_LH:O_LH + 42].copy(), x[:, O_RH:O_RH + 42].copy()
140
+ lh[:, 0::2] *= -1
141
+ rh[:, 0::2] *= -1
142
+ x[:, O_LH:O_LH + 42], x[:, O_RH:O_RH + 42] = rh, lh
143
+ x[:, [O_PRES + 2, O_PRES + 3]] = x[:, [O_PRES + 3, O_PRES + 2]]
144
+ return x
sli-sentences-large-v2.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73dd2deea3d32700c98a7a1388e5be5cc89cc9d6e5139b0aa8341534d52c742b
3
+ size 168700451
sli-sentences-phone-v1.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59f47f5dc7ffc02f00df6b0563bead2eca0de15b4bd96851b0c690ab8f58e805
3
+ size 17935987
vocab.json ADDED
The diff for this file is too large to render. See raw diff