@genai-fi/nanogpt 0.4.4 → 0.5.0

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.
Files changed (116) hide show
  1. package/dist/BaseLayer-BhrMN8JO.js +135 -0
  2. package/dist/Generator.js +44 -41
  3. package/dist/NanoGPTModel.d.ts +12 -16
  4. package/dist/NanoGPTModel.js +128 -138
  5. package/dist/{Reshape-CiAY8ltP.js → Reshape-BE5rA4rT.js} +8 -8
  6. package/dist/TeachableLLM.js +8 -5
  7. package/dist/{TiedEmbedding-DznFwzcB.js → TiedEmbedding-DsDRvLB0.js} +751 -768
  8. package/dist/{axis_util-QP0LdI1v.js → axis_util-97KkkyRQ.js} +1 -1
  9. package/dist/broadcast_to-CMlkG8NS.js +44 -0
  10. package/dist/{concat-DvWM7HGZ.js → concat-Cxbo2sOz.js} +3 -3
  11. package/dist/{dropout-DFEXTPV0.js → dropout-kbDY39Ci.js} +1 -1
  12. package/dist/{gather-C5D8PxwA.js → gather-Bxe1Qip8.js} +4 -4
  13. package/dist/{gpgpu_math-CUzjlO9A.js → gpgpu_math-C0zyxKFi.js} +1 -1
  14. package/dist/{index--6vO-cOz.js → index-iNhkcAEQ.js} +82 -82
  15. package/dist/{kernel_funcs_utils-C6YBCuOt.js → kernel_funcs_utils-C4eIk4fE.js} +20 -20
  16. package/dist/layers/BaseLayer.d.ts +28 -4
  17. package/dist/layers/BaseLayer.js +3 -16
  18. package/dist/layers/CausalSelfAttention.d.ts +22 -24
  19. package/dist/layers/CausalSelfAttention.js +73 -127
  20. package/dist/layers/MLP.d.ts +8 -15
  21. package/dist/layers/MLP.js +43 -81
  22. package/dist/layers/RMSNorm.d.ts +5 -11
  23. package/dist/layers/RMSNorm.js +13 -29
  24. package/dist/layers/RoPECache.js +14 -12
  25. package/dist/layers/TiedEmbedding.d.ts +6 -16
  26. package/dist/layers/TiedEmbedding.js +5 -5
  27. package/dist/layers/TransformerBlock.d.ts +12 -16
  28. package/dist/layers/TransformerBlock.js +20 -41
  29. package/dist/{log_sum_exp-CiEy1aUe.js → log_sum_exp-CkumwesB.js} +11 -11
  30. package/dist/main.js +22 -19
  31. package/dist/{mat_mul-BEHRPMh0.js → mat_mul-D0SifYfJ.js} +3 -3
  32. package/dist/{max-BUShNgfh.js → max-CYaAjEEp.js} +3 -3
  33. package/dist/{moments-DYOHXoRV.js → moments-B06NlR_V.js} +6 -6
  34. package/dist/{norm-DSva3hI3.js → norm-D3676xIo.js} +7 -7
  35. package/dist/{ones-D6kB8bdY.js → ones-BIeFnPHR.js} +2 -2
  36. package/dist/ops/appendCache.js +4 -4
  37. package/dist/ops/attentionMask.d.ts +1 -1
  38. package/dist/ops/attentionMask.js +4 -4
  39. package/dist/ops/cpu/appendCache.js +2 -2
  40. package/dist/ops/cpu/attentionMask.js +14 -15
  41. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  42. package/dist/ops/cpu/gatherSub.js +5 -5
  43. package/dist/ops/cpu/gelu.js +1 -1
  44. package/dist/ops/cpu/matMulGelu.js +1 -1
  45. package/dist/ops/cpu/matMulMul.d.ts +1 -0
  46. package/dist/ops/cpu/matMulMul.js +17 -0
  47. package/dist/ops/cpu/mulDropout.js +1 -1
  48. package/dist/ops/cpu/normRMS.d.ts +1 -0
  49. package/dist/ops/cpu/normRMS.js +39 -0
  50. package/dist/ops/cpu/qkv.js +3 -3
  51. package/dist/ops/cpu/rope.js +5 -5
  52. package/dist/ops/cpu/scatterSub.js +8 -8
  53. package/dist/ops/fusedSoftmax.js +1 -1
  54. package/dist/ops/gatherSub.js +1 -1
  55. package/dist/ops/gelu.js +1 -1
  56. package/dist/ops/grads/attentionMask.js +13 -9
  57. package/dist/ops/grads/fusedSoftmax.js +12 -9
  58. package/dist/ops/grads/gelu.js +1 -1
  59. package/dist/ops/grads/matMulGelu.js +1 -1
  60. package/dist/ops/grads/normRMS.d.ts +2 -0
  61. package/dist/ops/grads/normRMS.js +20 -0
  62. package/dist/ops/grads/qkv.js +19 -9
  63. package/dist/ops/grads/rope.js +1 -1
  64. package/dist/ops/matMulGelu.js +1 -1
  65. package/dist/ops/matMulMul.d.ts +2 -0
  66. package/dist/ops/matMulMul.js +9 -0
  67. package/dist/ops/mulDrop.js +1 -1
  68. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  69. package/dist/ops/normRMS.d.ts +2 -0
  70. package/dist/ops/normRMS.js +10 -0
  71. package/dist/ops/qkv.js +1 -1
  72. package/dist/ops/scatterSub.js +1 -1
  73. package/dist/ops/webgl/appendCache.js +1 -1
  74. package/dist/ops/webgl/attentionMask.js +13 -12
  75. package/dist/ops/webgl/fusedSoftmax.js +43 -40
  76. package/dist/ops/webgl/gatherSub.js +1 -1
  77. package/dist/ops/webgl/gelu.js +2 -2
  78. package/dist/ops/webgl/matMulGelu.d.ts +3 -2
  79. package/dist/ops/webgl/matMulGelu.js +77 -75
  80. package/dist/ops/webgl/matMulMul.d.ts +14 -0
  81. package/dist/ops/webgl/matMulMul.js +28 -0
  82. package/dist/ops/webgl/mulDropout.js +1 -1
  83. package/dist/ops/webgl/normRMS.d.ts +1 -0
  84. package/dist/ops/webgl/normRMS.js +86 -0
  85. package/dist/ops/webgl/qkv.js +1 -1
  86. package/dist/ops/webgl/rope.js +1 -1
  87. package/dist/ops/webgl/scatterSub.js +1 -1
  88. package/dist/ops-ObfXLHYQ.js +1269 -0
  89. package/dist/{range-C_vpUjBu.js → range-BsFU-SNG.js} +1 -1
  90. package/dist/{reshape-z51Eu-re.js → reshape-DxTPgnwL.js} +3 -3
  91. package/dist/{sin-H567uayl.js → sin-BOX-JVAj.js} +5 -5
  92. package/dist/slice_util-D-kaD4ZV.js +49 -0
  93. package/dist/{softmax-Dsxflvdl.js → softmax-BjsptB07.js} +2 -2
  94. package/dist/{split-B_k_jwud.js → split-BCbrzthj.js} +4 -4
  95. package/dist/{stack-CmqSdsfs.js → stack--cqr9Dgc.js} +2 -2
  96. package/dist/{sum-DdkDf2MG.js → sum-B_92TaHD.js} +5 -5
  97. package/dist/{tensor-BGYi41cj.js → tensor-CfiPXsW4.js} +1 -1
  98. package/dist/{tensor2d-DUr_htjt.js → tensor2d-tSxWdFMH.js} +1 -1
  99. package/dist/tfjs_backend-NucKez4s.js +1010 -0
  100. package/dist/training/AdamExt.js +1 -1
  101. package/dist/training/DatasetBuilder.js +44 -44
  102. package/dist/training/Evaluator.js +6 -6
  103. package/dist/training/FullTrainer.js +1 -1
  104. package/dist/training/Trainer.js +7 -7
  105. package/dist/training/sparseCrossEntropy.js +4 -4
  106. package/dist/utilities/dummy.js +10 -10
  107. package/dist/utilities/generate.js +3 -3
  108. package/dist/utilities/load.js +1 -1
  109. package/dist/utilities/profile.js +1 -1
  110. package/dist/utilities/save.js +10 -8
  111. package/dist/utilities/weights.js +2 -2
  112. package/dist/{zeros-8xl-W2DC.js → zeros-NMYTayy7.js} +3 -3
  113. package/package.json +1 -1
  114. package/dist/slice_util-BdhYwFY_.js +0 -90
  115. package/dist/tfjs_backend-DuKis_xG.js +0 -2271
  116. package/dist/variable-BJTZ3jOy.js +0 -23
@@ -1,2271 +0,0 @@
1
- import { o as f, h as l, E as d, ap as nn, aq as tn, j as p, ar as sn, D as Ve, as as rn, O as P, at as on, au as an, av as cn, aw as un, a4 as ln, ag as pn, p as Y, ax as fn, ay as hn, az as dn, aA as mn, aB as gn, aC as $n, aD as bn, aE as kn, x as C, aF as xn, aG as wn, aH as An, aI as yn, aJ as _n, aK as In, aL as En, aM as Sn, I as Tn, J as Nn, K as Dn, aN as Mn, t as K, aO as he, b as I, aP as On, a8 as U, n as Me, c as Oe, aQ as Be, aR as Bn, aS as Pn, aT as Kn, aU as Rn, aV as qn, aW as jn, f as Fn, aX as Gn, aY as Ln, ai as L, s as q, aZ as Vn, w as de, a as Cn, am as Pe, a_ as vn, a2 as zn } from "./index--6vO-cOz.js";
2
- import { r as $ } from "./reshape-z51Eu-re.js";
3
- import { s as Ce } from "./split-B_k_jwud.js";
4
- import { s as G } from "./sum-DdkDf2MG.js";
5
- import { b as me } from "./slice_util-BdhYwFY_.js";
6
- import { r as ue } from "./range-C_vpUjBu.js";
7
- import { t as Wn } from "./tensor-BGYi41cj.js";
8
- import { s as le } from "./stack-CmqSdsfs.js";
9
- import { c as Jn, z as Yn } from "./zeros-8xl-W2DC.js";
10
- import { n as ve } from "./norm-DSva3hI3.js";
11
- import { c as V } from "./concat-DvWM7HGZ.js";
12
- import { m as y } from "./mat_mul-BEHRPMh0.js";
13
- import { t as ge } from "./tensor2d-DUr_htjt.js";
14
- import { r as Un, d as Zn } from "./dropout-DFEXTPV0.js";
15
- import { g as Xn } from "./gather-C5D8PxwA.js";
16
- /**
17
- * @license
18
- * Copyright 2018 Google LLC. All Rights Reserved.
19
- * Licensed under the Apache License, Version 2.0 (the "License");
20
- * you may not use this file except in compliance with the License.
21
- * You may obtain a copy of the License at
22
- *
23
- * http://www.apache.org/licenses/LICENSE-2.0
24
- *
25
- * Unless required by applicable law or agreed to in writing, software
26
- * distributed under the License is distributed on an "AS IS" BASIS,
27
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
- * See the License for the specific language governing permissions and
29
- * limitations under the License.
30
- * =============================================================================
31
- */
32
- function Hn(e) {
33
- const t = { x: l(e, "x", "sigmoid", "float32") };
34
- return d.runKernel(nn, t);
35
- }
36
- const Qn = /* @__PURE__ */ f({ sigmoid_: Hn });
37
- /**
38
- * @license
39
- * Copyright 2018 Google LLC. All Rights Reserved.
40
- * Licensed under the Apache License, Version 2.0 (the "License");
41
- * you may not use this file except in compliance with the License.
42
- * You may obtain a copy of the License at
43
- *
44
- * http://www.apache.org/licenses/LICENSE-2.0
45
- *
46
- * Unless required by applicable law or agreed to in writing, software
47
- * distributed under the License is distributed on an "AS IS" BASIS,
48
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
- * See the License for the specific language governing permissions and
50
- * limitations under the License.
51
- * =============================================================================
52
- */
53
- function et(e, n, t) {
54
- const s = l(e, "x", "slice", "string_or_numeric");
55
- if (s.rank === 0)
56
- throw new Error("Slicing scalar is not possible");
57
- const r = { x: s }, o = { begin: n, size: t };
58
- return d.runKernel(tn, r, o);
59
- }
60
- const _ = /* @__PURE__ */ f({ slice_: et });
61
- /**
62
- * @license
63
- * Copyright 2020 Google LLC. All Rights Reserved.
64
- * Licensed under the Apache License, Version 2.0 (the "License");
65
- * you may not use this file except in compliance with the License.
66
- * You may obtain a copy of the License at
67
- *
68
- * http://www.apache.org/licenses/LICENSE-2.0
69
- *
70
- * Unless required by applicable law or agreed to in writing, software
71
- * distributed under the License is distributed on an "AS IS" BASIS,
72
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73
- * See the License for the specific language governing permissions and
74
- * limitations under the License.
75
- * =============================================================================
76
- */
77
- function nt(e, n, t) {
78
- const s = l(e, "x", "bincount"), r = l(n, "weights", "bincount");
79
- p(s.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${s.dtype}`), p(t >= 0, () => `size must be non-negative, but got ${t}.`), p(r.size === s.size || r.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${s.shape}, weights shape: ${r.shape}.`);
80
- const o = { x: s, weights: r }, a = { size: t };
81
- return d.runKernel(sn, o, a);
82
- }
83
- const tt = /* @__PURE__ */ f({ bincount_: nt });
84
- /**
85
- * @license
86
- * Copyright 2018 Google LLC. All Rights Reserved.
87
- * Licensed under the Apache License, Version 2.0 (the "License");
88
- * you may not use this file except in compliance with the License.
89
- * You may obtain a copy of the License at
90
- *
91
- * http://www.apache.org/licenses/LICENSE-2.0
92
- *
93
- * Unless required by applicable law or agreed to in writing, software
94
- * distributed under the License is distributed on an "AS IS" BASIS,
95
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96
- * See the License for the specific language governing permissions and
97
- * limitations under the License.
98
- * =============================================================================
99
- */
100
- function st(e, n, t) {
101
- const s = l(e, "x", "clipByValue");
102
- if (p(n <= t, () => `Error in clip: min (${n}) must be less than or equal to max (${t}).`), n === t)
103
- return Ve(s.shape, n, s.dtype);
104
- const r = { x: s }, o = { clipValueMin: n, clipValueMax: t };
105
- return d.runKernel(rn, r, o);
106
- }
107
- const rt = /* @__PURE__ */ f({ clipByValue_: st });
108
- function ot(e) {
109
- return V(
110
- e,
111
- 0
112
- /* axis */
113
- );
114
- }
115
- const at = /* @__PURE__ */ f({ concat1d_: ot });
116
- function it(e, n) {
117
- return V(e, n);
118
- }
119
- const ct = /* @__PURE__ */ f({ concat2d_: it });
120
- function ut(e, n) {
121
- return V(e, n);
122
- }
123
- const lt = /* @__PURE__ */ f({ concat3d_: ut });
124
- function pt(e, n) {
125
- return V(e, n);
126
- }
127
- const ft = /* @__PURE__ */ f({ concat4d_: pt });
128
- /**
129
- * @license
130
- * Copyright 2020 Google LLC. All Rights Reserved.
131
- * Licensed under the Apache License, Version 2.0 (the "License");
132
- * you may not use this file except in compliance with the License.
133
- * You may obtain a copy of the License at
134
- *
135
- * http://www.apache.org/licenses/LICENSE-2.0
136
- *
137
- * Unless required by applicable law or agreed to in writing, software
138
- * distributed under the License is distributed on an "AS IS" BASIS,
139
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140
- * See the License for the specific language governing permissions and
141
- * limitations under the License.
142
- * =============================================================================
143
- */
144
- function ht(e, n, t) {
145
- const s = l(n, "a", "where"), r = l(t, "b", "where"), o = l(e, "condition", "where", "bool"), a = P(P(o.shape, s.shape), r.shape), i = me(o, a), u = me(s, a), c = me(r, a), m = {
146
- condition: i,
147
- t: u,
148
- e: c
149
- };
150
- return d.runKernel(on, m);
151
- }
152
- const ee = /* @__PURE__ */ f({ where_: ht });
153
- /**
154
- * @license
155
- * Copyright 2021 Google LLC. All Rights Reserved.
156
- * Licensed under the Apache License, Version 2.0 (the "License");
157
- * you may not use this file except in compliance with the License.
158
- * You may obtain a copy of the License at
159
- *
160
- * http://www.apache.org/licenses/LICENSE-2.0
161
- *
162
- * Unless required by applicable law or agreed to in writing, software
163
- * distributed under the License is distributed on an "AS IS" BASIS,
164
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
165
- * See the License for the specific language governing permissions and
166
- * limitations under the License.
167
- * =============================================================================
168
- */
169
- function dt(e, ...n) {
170
- const t = n.map((r, o) => l(r, `tensors${o}`, "einsum")), s = { equation: e };
171
- return d.runKernel(an, t, s);
172
- }
173
- const re = /* @__PURE__ */ f({ einsum_: dt });
174
- /**
175
- * @license
176
- * Copyright 2020 Google LLC. All Rights Reserved.
177
- * Licensed under the Apache License, Version 2.0 (the "License");
178
- * you may not use this file except in compliance with the License.
179
- * You may obtain a copy of the License at
180
- *
181
- * http://www.apache.org/licenses/LICENSE-2.0
182
- *
183
- * Unless required by applicable law or agreed to in writing, software
184
- * distributed under the License is distributed on an "AS IS" BASIS,
185
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
186
- * See the License for the specific language governing permissions and
187
- * limitations under the License.
188
- * =============================================================================
189
- */
190
- function mt(e) {
191
- const t = { x: l(e, "x", "elu", "float32") };
192
- return d.runKernel(cn, t);
193
- }
194
- const ze = /* @__PURE__ */ f({ elu_: mt });
195
- /**
196
- * @license
197
- * Copyright 2020 Google LLC. All Rights Reserved.
198
- * Licensed under the Apache License, Version 2.0 (the "License");
199
- * you may not use this file except in compliance with the License.
200
- * You may obtain a copy of the License at
201
- *
202
- * http://www.apache.org/licenses/LICENSE-2.0
203
- *
204
- * Unless required by applicable law or agreed to in writing, software
205
- * distributed under the License is distributed on an "AS IS" BASIS,
206
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207
- * See the License for the specific language governing permissions and
208
- * limitations under the License.
209
- * =============================================================================
210
- */
211
- function gt(e, n = 0) {
212
- const t = l(e, "x", "expandDims", "string_or_numeric");
213
- p(n <= t.rank, () => "Axis must be <= rank of the tensor");
214
- const s = { input: t }, r = { dim: n };
215
- return d.runKernel(un, s, r);
216
- }
217
- const J = /* @__PURE__ */ f({ expandDims_: gt });
218
- /**
219
- * @license
220
- * Copyright 2020 Google LLC. All Rights Reserved.
221
- * Licensed under the Apache License, Version 2.0 (the "License");
222
- * you may not use this file except in compliance with the License.
223
- * You may obtain a copy of the License at
224
- *
225
- * http://www.apache.org/licenses/LICENSE-2.0
226
- *
227
- * Unless required by applicable law or agreed to in writing, software
228
- * distributed under the License is distributed on an "AS IS" BASIS,
229
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
230
- * See the License for the specific language governing permissions and
231
- * limitations under the License.
232
- * =============================================================================
233
- */
234
- function $t(e, n) {
235
- const t = l(e, "x", "tile", "string_or_numeric");
236
- p(t.rank === n.length, () => `Error in transpose: rank of input ${t.rank} must match length of reps ${n}.`);
237
- const s = { x: t }, r = { reps: n };
238
- return d.runKernel(ln, s, r);
239
- }
240
- const oe = /* @__PURE__ */ f({ tile_: $t });
241
- /**
242
- * @license
243
- * Copyright 2020 Google LLC. All Rights Reserved.
244
- * Licensed under the Apache License, Version 2.0 (the "License");
245
- * you may not use this file except in compliance with the License.
246
- * You may obtain a copy of the License at
247
- *
248
- * http://www.apache.org/licenses/LICENSE-2.0
249
- *
250
- * Unless required by applicable law or agreed to in writing, software
251
- * distributed under the License is distributed on an "AS IS" BASIS,
252
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
253
- * See the License for the specific language governing permissions and
254
- * limitations under the License.
255
- * =============================================================================
256
- */
257
- function bt(e, n, t, s = "float32") {
258
- n == null && (n = e);
259
- const r = pn([e, n], s), o = e <= n ? e : n;
260
- for (let i = 0; i < o; ++i)
261
- r.set(1, i, i);
262
- const a = $(r.toTensor(), [e, n]);
263
- if (t == null)
264
- return a;
265
- if (t.length === 1)
266
- return oe(J(a, 0), [t[0], 1, 1]);
267
- if (t.length === 2)
268
- return oe(J(J(a, 0), 0), [t[0], t[1], 1, 1]);
269
- if (t.length === 3)
270
- return oe(J(J(J(a, 0), 0), 0), [
271
- t[0],
272
- t[1],
273
- t[2],
274
- 1,
275
- 1
276
- ]);
277
- throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${t.length}D.`);
278
- }
279
- const kt = /* @__PURE__ */ f({ eye_: bt });
280
- /**
281
- * @license
282
- * Copyright 2020 Google LLC. All Rights Reserved.
283
- * Licensed under the Apache License, Version 2.0 (the "License");
284
- * you may not use this file except in compliance with the License.
285
- * You may obtain a copy of the License at
286
- *
287
- * http://www.apache.org/licenses/LICENSE-2.0
288
- *
289
- * Unless required by applicable law or agreed to in writing, software
290
- * distributed under the License is distributed on an "AS IS" BASIS,
291
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
292
- * See the License for the specific language governing permissions and
293
- * limitations under the License.
294
- * =============================================================================
295
- */
296
- function xt(e, n) {
297
- let t = l(e, "a", "greater", "string_or_numeric"), s = l(n, "b", "greater", "string_or_numeric");
298
- [t, s] = Y(t, s), P(t.shape, s.shape);
299
- const r = { a: t, b: s };
300
- return d.runKernel(fn, r);
301
- }
302
- const _e = /* @__PURE__ */ f({ greater_: xt });
303
- /**
304
- * @license
305
- * Copyright 2020 Google LLC. All Rights Reserved.
306
- * Licensed under the Apache License, Version 2.0 (the "License");
307
- * you may not use this file except in compliance with the License.
308
- * You may obtain a copy of the License at
309
- *
310
- * http://www.apache.org/licenses/LICENSE-2.0
311
- *
312
- * Unless required by applicable law or agreed to in writing, software
313
- * distributed under the License is distributed on an "AS IS" BASIS,
314
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
315
- * See the License for the specific language governing permissions and
316
- * limitations under the License.
317
- * =============================================================================
318
- */
319
- function wt(e, n) {
320
- let t = l(e, "a", "greaterEqual", "string_or_numeric"), s = l(n, "b", "greaterEqual", "string_or_numeric");
321
- [t, s] = Y(t, s), P(t.shape, s.shape);
322
- const r = { a: t, b: s };
323
- return d.runKernel(hn, r);
324
- }
325
- const At = /* @__PURE__ */ f({ greaterEqual_: wt });
326
- /**
327
- * @license
328
- * Copyright 2020 Google LLC. All Rights Reserved.
329
- * Licensed under the Apache License, Version 2.0 (the "License");
330
- * you may not use this file except in compliance with the License.
331
- * You may obtain a copy of the License at
332
- *
333
- * http://www.apache.org/licenses/LICENSE-2.0
334
- *
335
- * Unless required by applicable law or agreed to in writing, software
336
- * distributed under the License is distributed on an "AS IS" BASIS,
337
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
338
- * See the License for the specific language governing permissions and
339
- * limitations under the License.
340
- * =============================================================================
341
- */
342
- function yt(e) {
343
- const t = { input: l(e, "input", "imag") };
344
- return d.runKernel(dn, t);
345
- }
346
- const _t = /* @__PURE__ */ f({ imag_: yt });
347
- /**
348
- * @license
349
- * Copyright 2020 Google LLC. All Rights Reserved.
350
- * Licensed under the Apache License, Version 2.0 (the "License");
351
- * you may not use this file except in compliance with the License.
352
- * You may obtain a copy of the License at
353
- *
354
- * http://www.apache.org/licenses/LICENSE-2.0
355
- *
356
- * Unless required by applicable law or agreed to in writing, software
357
- * distributed under the License is distributed on an "AS IS" BASIS,
358
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
359
- * See the License for the specific language governing permissions and
360
- * limitations under the License.
361
- * =============================================================================
362
- */
363
- function It(e, n = 0.2) {
364
- const s = { x: l(e, "x", "leakyRelu") }, r = { alpha: n };
365
- return d.runKernel(mn, s, r);
366
- }
367
- const Et = /* @__PURE__ */ f({ leakyRelu_: It });
368
- /**
369
- * @license
370
- * Copyright 2020 Google LLC. All Rights Reserved.
371
- * Licensed under the Apache License, Version 2.0 (the "License");
372
- * you may not use this file except in compliance with the License.
373
- * You may obtain a copy of the License at
374
- *
375
- * http://www.apache.org/licenses/LICENSE-2.0
376
- *
377
- * Unless required by applicable law or agreed to in writing, software
378
- * distributed under the License is distributed on an "AS IS" BASIS,
379
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
380
- * See the License for the specific language governing permissions and
381
- * limitations under the License.
382
- * =============================================================================
383
- */
384
- function St(e, n) {
385
- let t = l(e, "a", "less", "string_or_numeric"), s = l(n, "b", "less", "string_or_numeric");
386
- [t, s] = Y(t, s), P(t.shape, s.shape);
387
- const r = { a: t, b: s };
388
- return d.runKernel(gn, r);
389
- }
390
- const Ke = /* @__PURE__ */ f({ less_: St });
391
- /**
392
- * @license
393
- * Copyright 2020 Google LLC. All Rights Reserved.
394
- * Licensed under the Apache License, Version 2.0 (the "License");
395
- * you may not use this file except in compliance with the License.
396
- * You may obtain a copy of the License at
397
- *
398
- * http://www.apache.org/licenses/LICENSE-2.0
399
- *
400
- * Unless required by applicable law or agreed to in writing, software
401
- * distributed under the License is distributed on an "AS IS" BASIS,
402
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
403
- * See the License for the specific language governing permissions and
404
- * limitations under the License.
405
- * =============================================================================
406
- */
407
- function Tt(e, n) {
408
- let t = l(e, "a", "lessEqual", "string_or_numeric"), s = l(n, "b", "lessEqual", "string_or_numeric");
409
- [t, s] = Y(t, s), P(t.shape, s.shape);
410
- const r = { a: t, b: s };
411
- return d.runKernel($n, r);
412
- }
413
- const We = /* @__PURE__ */ f({ lessEqual_: Tt });
414
- /**
415
- * @license
416
- * Copyright 2018 Google LLC. All Rights Reserved.
417
- * Licensed under the Apache License, Version 2.0 (the "License");
418
- * you may not use this file except in compliance with the License.
419
- * You may obtain a copy of the License at
420
- *
421
- * http://www.apache.org/licenses/LICENSE-2.0
422
- *
423
- * Unless required by applicable law or agreed to in writing, software
424
- * distributed under the License is distributed on an "AS IS" BASIS,
425
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
426
- * See the License for the specific language governing permissions and
427
- * limitations under the License.
428
- * =============================================================================
429
- */
430
- function Nt(e) {
431
- const t = { x: l(e, "x", "neg") };
432
- return d.runKernel(bn, t);
433
- }
434
- const Ie = /* @__PURE__ */ f({ neg_: Nt });
435
- /**
436
- * @license
437
- * Copyright 2020 Google LLC. All Rights Reserved.
438
- * Licensed under the Apache License, Version 2.0 (the "License");
439
- * you may not use this file except in compliance with the License.
440
- * You may obtain a copy of the License at
441
- *
442
- * http://www.apache.org/licenses/LICENSE-2.0
443
- *
444
- * Unless required by applicable law or agreed to in writing, software
445
- * distributed under the License is distributed on an "AS IS" BASIS,
446
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
447
- * See the License for the specific language governing permissions and
448
- * limitations under the License.
449
- * =============================================================================
450
- */
451
- function Dt(e, n) {
452
- const t = l(e, "a", "logicalAnd", "bool"), s = l(n, "b", "logicalAnd", "bool");
453
- P(t.shape, s.shape);
454
- const r = { a: t, b: s };
455
- return d.runKernel(kn, r);
456
- }
457
- const Mt = /* @__PURE__ */ f({ logicalAnd_: Dt });
458
- /**
459
- * @license
460
- * Copyright 2020 Google LLC. All Rights Reserved.
461
- * Licensed under the Apache License, Version 2.0 (the "License");
462
- * you may not use this file except in compliance with the License.
463
- * You may obtain a copy of the License at
464
- *
465
- * http://www.apache.org/licenses/LICENSE-2.0
466
- *
467
- * Unless required by applicable law or agreed to in writing, software
468
- * distributed under the License is distributed on an "AS IS" BASIS,
469
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
470
- * See the License for the specific language governing permissions and
471
- * limitations under the License.
472
- * =============================================================================
473
- */
474
- function Ot(e, n) {
475
- let t = l(e, "a", "minimum"), s = l(n, "b", "minimum");
476
- [t, s] = Y(t, s), t.dtype === "bool" && (t = C(t, "int32"), s = C(s, "int32")), P(t.shape, s.shape);
477
- const r = { a: t, b: s };
478
- return d.runKernel(xn, r);
479
- }
480
- const Re = /* @__PURE__ */ f({ minimum_: Ot });
481
- /**
482
- * @license
483
- * Copyright 2020 Google LLC. All Rights Reserved.
484
- * Licensed under the Apache License, Version 2.0 (the "License");
485
- * you may not use this file except in compliance with the License.
486
- * You may obtain a copy of the License at
487
- *
488
- * http://www.apache.org/licenses/LICENSE-2.0
489
- *
490
- * Unless required by applicable law or agreed to in writing, software
491
- * distributed under the License is distributed on an "AS IS" BASIS,
492
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
493
- * See the License for the specific language governing permissions and
494
- * limitations under the License.
495
- * =============================================================================
496
- */
497
- function Bt(e, n) {
498
- const t = l(e, "x", "prelu"), s = l(n, "alpha", "prelu"), r = { x: t, alpha: s };
499
- return d.runKernel(wn, r);
500
- }
501
- const Pt = /* @__PURE__ */ f({ prelu_: Bt });
502
- /**
503
- * @license
504
- * Copyright 2020 Google LLC. All Rights Reserved.
505
- * Licensed under the Apache License, Version 2.0 (the "License");
506
- * you may not use this file except in compliance with the License.
507
- * You may obtain a copy of the License at
508
- *
509
- * http://www.apache.org/licenses/LICENSE-2.0
510
- *
511
- * Unless required by applicable law or agreed to in writing, software
512
- * distributed under the License is distributed on an "AS IS" BASIS,
513
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
514
- * See the License for the specific language governing permissions and
515
- * limitations under the License.
516
- * =============================================================================
517
- */
518
- function Kt(e) {
519
- const t = { input: l(e, "input", "real") };
520
- return d.runKernel(An, t);
521
- }
522
- const Rt = /* @__PURE__ */ f({ real_: Kt });
523
- /**
524
- * @license
525
- * Copyright 2020 Google LLC. All Rights Reserved.
526
- * Licensed under the Apache License, Version 2.0 (the "License");
527
- * you may not use this file except in compliance with the License.
528
- * You may obtain a copy of the License at
529
- *
530
- * http://www.apache.org/licenses/LICENSE-2.0
531
- *
532
- * Unless required by applicable law or agreed to in writing, software
533
- * distributed under the License is distributed on an "AS IS" BASIS,
534
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
535
- * See the License for the specific language governing permissions and
536
- * limitations under the License.
537
- * =============================================================================
538
- */
539
- function qt(e) {
540
- const t = { x: l(e, "x", "relu") };
541
- return d.runKernel(yn, t);
542
- }
543
- const jt = /* @__PURE__ */ f({ relu_: qt });
544
- /**
545
- * @license
546
- * Copyright 2020 Google LLC. All Rights Reserved.
547
- * Licensed under the Apache License, Version 2.0 (the "License");
548
- * you may not use this file except in compliance with the License.
549
- * You may obtain a copy of the License at
550
- *
551
- * http://www.apache.org/licenses/LICENSE-2.0
552
- *
553
- * Unless required by applicable law or agreed to in writing, software
554
- * distributed under the License is distributed on an "AS IS" BASIS,
555
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
556
- * See the License for the specific language governing permissions and
557
- * limitations under the License.
558
- * =============================================================================
559
- */
560
- function Ft(e) {
561
- const t = { x: l(e, "x", "relu6") };
562
- return d.runKernel(_n, t);
563
- }
564
- const Gt = /* @__PURE__ */ f({ relu6_: Ft });
565
- /**
566
- * @license
567
- * Copyright 2018 Google LLC. All Rights Reserved.
568
- * Licensed under the Apache License, Version 2.0 (the "License");
569
- * you may not use this file except in compliance with the License.
570
- * You may obtain a copy of the License at
571
- *
572
- * http://www.apache.org/licenses/LICENSE-2.0
573
- *
574
- * Unless required by applicable law or agreed to in writing, software
575
- * distributed under the License is distributed on an "AS IS" BASIS,
576
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
577
- * See the License for the specific language governing permissions and
578
- * limitations under the License.
579
- * =============================================================================
580
- */
581
- function Lt(e) {
582
- const t = { x: l(e, "x", "round") };
583
- return d.runKernel(In, t);
584
- }
585
- const Vt = /* @__PURE__ */ f({ round_: Lt });
586
- /**
587
- * @license
588
- * Copyright 2018 Google LLC. All Rights Reserved.
589
- * Licensed under the Apache License, Version 2.0 (the "License");
590
- * you may not use this file except in compliance with the License.
591
- * You may obtain a copy of the License at
592
- *
593
- * http://www.apache.org/licenses/LICENSE-2.0
594
- *
595
- * Unless required by applicable law or agreed to in writing, software
596
- * distributed under the License is distributed on an "AS IS" BASIS,
597
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
598
- * See the License for the specific language governing permissions and
599
- * limitations under the License.
600
- * =============================================================================
601
- */
602
- function Ct(e, n, t) {
603
- const s = l(e, "x", "slice1d");
604
- return p(s.rank === 1, () => `slice1d expects a rank-1 tensor, but got a rank-${s.rank} tensor`), _(s, [n], [t]);
605
- }
606
- const Ee = /* @__PURE__ */ f({ slice1d_: Ct });
607
- /**
608
- * @license
609
- * Copyright 2018 Google LLC. All Rights Reserved.
610
- * Licensed under the Apache License, Version 2.0 (the "License");
611
- * you may not use this file except in compliance with the License.
612
- * You may obtain a copy of the License at
613
- *
614
- * http://www.apache.org/licenses/LICENSE-2.0
615
- *
616
- * Unless required by applicable law or agreed to in writing, software
617
- * distributed under the License is distributed on an "AS IS" BASIS,
618
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
619
- * See the License for the specific language governing permissions and
620
- * limitations under the License.
621
- * =============================================================================
622
- */
623
- function vt(e, n, t) {
624
- const s = l(e, "x", "slice2d");
625
- return p(s.rank === 2, () => `slice2d expects a rank-2 tensor, but got a rank-${s.rank} tensor`), _(s, n, t);
626
- }
627
- const Je = /* @__PURE__ */ f({ slice2d_: vt });
628
- /**
629
- * @license
630
- * Copyright 2018 Google LLC. All Rights Reserved.
631
- * Licensed under the Apache License, Version 2.0 (the "License");
632
- * you may not use this file except in compliance with the License.
633
- * You may obtain a copy of the License at
634
- *
635
- * http://www.apache.org/licenses/LICENSE-2.0
636
- *
637
- * Unless required by applicable law or agreed to in writing, software
638
- * distributed under the License is distributed on an "AS IS" BASIS,
639
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
640
- * See the License for the specific language governing permissions and
641
- * limitations under the License.
642
- * =============================================================================
643
- */
644
- function zt(e, n, t) {
645
- const s = l(e, "x", "slice3d");
646
- return p(s.rank === 3, () => `slice3d expects a rank-3 tensor, but got a rank-${s.rank} tensor`), _(s, n, t);
647
- }
648
- const Se = /* @__PURE__ */ f({ slice3d_: zt });
649
- /**
650
- * @license
651
- * Copyright 2018 Google LLC. All Rights Reserved.
652
- * Licensed under the Apache License, Version 2.0 (the "License");
653
- * you may not use this file except in compliance with the License.
654
- * You may obtain a copy of the License at
655
- *
656
- * http://www.apache.org/licenses/LICENSE-2.0
657
- *
658
- * Unless required by applicable law or agreed to in writing, software
659
- * distributed under the License is distributed on an "AS IS" BASIS,
660
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
661
- * See the License for the specific language governing permissions and
662
- * limitations under the License.
663
- * =============================================================================
664
- */
665
- function Wt(e, n, t) {
666
- const s = l(e, "x", "slice4d");
667
- return p(s.rank === 4, () => `slice4d expects a rank-4 tensor, but got a rank-${s.rank} tensor`), _(s, n, t);
668
- }
669
- const pe = /* @__PURE__ */ f({ slice4d_: Wt });
670
- /**
671
- * @license
672
- * Copyright 2020 Google LLC. All Rights Reserved.
673
- * Licensed under the Apache License, Version 2.0 (the "License");
674
- * you may not use this file except in compliance with the License.
675
- * You may obtain a copy of the License at
676
- *
677
- * http://www.apache.org/licenses/LICENSE-2.0
678
- *
679
- * Unless required by applicable law or agreed to in writing, software
680
- * distributed under the License is distributed on an "AS IS" BASIS,
681
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
682
- * See the License for the specific language governing permissions and
683
- * limitations under the License.
684
- * =============================================================================
685
- */
686
- function Jt(e, n) {
687
- const t = l(e, "x", "squeeze", "string_or_numeric");
688
- return $(t, En(t.shape, n).newShape);
689
- }
690
- const Yt = /* @__PURE__ */ f({ squeeze_: Jt });
691
- /**
692
- * @license
693
- * Copyright 2018 Google LLC. All Rights Reserved.
694
- * Licensed under the Apache License, Version 2.0 (the "License");
695
- * you may not use this file except in compliance with the License.
696
- * You may obtain a copy of the License at
697
- *
698
- * http://www.apache.org/licenses/LICENSE-2.0
699
- *
700
- * Unless required by applicable law or agreed to in writing, software
701
- * distributed under the License is distributed on an "AS IS" BASIS,
702
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
703
- * See the License for the specific language governing permissions and
704
- * limitations under the License.
705
- * =============================================================================
706
- */
707
- function Ut(e, n = 0) {
708
- const s = { x: l(e, "x", "step") }, r = { alpha: n };
709
- return d.runKernel(Sn, s, r);
710
- }
711
- const Zt = /* @__PURE__ */ f({ step_: Ut });
712
- /**
713
- * @license
714
- * Copyright 2018 Google LLC. All Rights Reserved.
715
- * Licensed under the Apache License, Version 2.0 (the "License");
716
- * you may not use this file except in compliance with the License.
717
- * You may obtain a copy of the License at
718
- *
719
- * http://www.apache.org/licenses/LICENSE-2.0
720
- *
721
- * Unless required by applicable law or agreed to in writing, software
722
- * distributed under the License is distributed on an "AS IS" BASIS,
723
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
724
- * See the License for the specific language governing permissions and
725
- * limitations under the License.
726
- * =============================================================================
727
- */
728
- function B(e, n) {
729
- Tn(e);
730
- const t = Nn(e, n);
731
- if (t.length !== 1)
732
- throw new Error("tensor1d() requires values to be a flat/TypedArray");
733
- return Dn(e, null, t, n);
734
- }
735
- /**
736
- * @license
737
- * Copyright 2020 Google LLC. All Rights Reserved.
738
- * Licensed under the Apache License, Version 2.0 (the "License");
739
- * you may not use this file except in compliance with the License.
740
- * You may obtain a copy of the License at
741
- *
742
- * http://www.apache.org/licenses/LICENSE-2.0
743
- *
744
- * Unless required by applicable law or agreed to in writing, software
745
- * distributed under the License is distributed on an "AS IS" BASIS,
746
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
747
- * See the License for the specific language governing permissions and
748
- * limitations under the License.
749
- * =============================================================================
750
- */
751
- function Xt(e, n = 0) {
752
- const t = l(e, "x", "unstack", "string_or_numeric");
753
- p(n >= -t.shape.length && n < t.shape.length, () => `Axis = ${n} is not in [-${t.shape.length}, ${t.shape.length})`);
754
- const s = { value: t }, r = { axis: n };
755
- return d.runKernel(Mn, s, r);
756
- }
757
- const Ye = /* @__PURE__ */ f({ unstack_: Xt });
758
- /**
759
- * @license
760
- * Copyright 2018 Google LLC. All Rights Reserved.
761
- * Licensed under the Apache License, Version 2.0 (the "License");
762
- * you may not use this file except in compliance with the License.
763
- * You may obtain a copy of the License at
764
- *
765
- * http://www.apache.org/licenses/LICENSE-2.0
766
- *
767
- * Unless required by applicable law or agreed to in writing, software
768
- * distributed under the License is distributed on an "AS IS" BASIS,
769
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
770
- * See the License for the specific language governing permissions and
771
- * limitations under the License.
772
- * =============================================================================
773
- */
774
- function Ht(e, n, t) {
775
- const s = l(e, "x", "transpose");
776
- if (n == null && (n = s.shape.map((a, i) => i).reverse()), p(s.rank === n.length, () => `Error in transpose: rank of input ${s.rank} must match length of perm ${n}.`), n.forEach((a) => {
777
- p(a >= 0 && a < s.rank, () => `All entries in 'perm' must be between 0 and ${s.rank - 1} but got ${n}`);
778
- }), s.rank <= 1)
779
- return s.clone();
780
- const r = { x: s }, o = { perm: n };
781
- return s.dtype === "complex64" ? K(() => {
782
- let a = Rt(s), i = _t(s);
783
- return a = d.runKernel(he, { x: a }, o), i = d.runKernel(he, { x: i }, o), t && (i = Ie(i)), Jn(a, i);
784
- }) : d.runKernel(he, r, o);
785
- }
786
- const xe = /* @__PURE__ */ f({ transpose_: Ht });
787
- /**
788
- * @license
789
- * Copyright 2019 Google LLC. All Rights Reserved.
790
- * Licensed under the Apache License, Version 2.0 (the "License");
791
- * you may not use this file except in compliance with the License.
792
- * You may obtain a copy of the License at
793
- *
794
- * http://www.apache.org/licenses/LICENSE-2.0
795
- *
796
- * Unless required by applicable law or agreed to in writing, software
797
- * distributed under the License is distributed on an "AS IS" BASIS,
798
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
799
- * See the License for the specific language governing permissions and
800
- * limitations under the License.
801
- * =============================================================================
802
- */
803
- function Qt(e, n, t) {
804
- if (t == null || t === "linear")
805
- return e;
806
- if (t === "relu")
807
- return I(e, Zt(n));
808
- throw new Error(`Cannot compute gradient for fused activation ${t}.`);
809
- }
810
- function es(e, n) {
811
- let t = n;
812
- const s = On(e.shape, n.shape);
813
- return s.length > 0 && (t = G(t, s)), $(t, e.shape);
814
- }
815
- function ns(e, n, t, s) {
816
- if (n === "linear")
817
- return e;
818
- if (n === "relu")
819
- return jt(e);
820
- if (n === "elu")
821
- return ze(e);
822
- if (n === "relu6")
823
- return Gt(e);
824
- if (n === "prelu")
825
- return Pt(e, t);
826
- if (n === "leakyrelu")
827
- return Et(e, s);
828
- if (n === "sigmoid")
829
- return Qn(e);
830
- throw new Error(`Unknown fused activation ${n}.`);
831
- }
832
- const ts = (e, n) => !(e > 0) || n === "linear";
833
- /**
834
- * @license
835
- * Copyright 2019 Google LLC. All Rights Reserved.
836
- * Licensed under the Apache License, Version 2.0 (the "License");
837
- * you may not use this file except in compliance with the License.
838
- * You may obtain a copy of the License at
839
- *
840
- * http://www.apache.org/licenses/LICENSE-2.0
841
- *
842
- * Unless required by applicable law or agreed to in writing, software
843
- * distributed under the License is distributed on an "AS IS" BASIS,
844
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
845
- * See the License for the specific language governing permissions and
846
- * limitations under the License.
847
- * =============================================================================
848
- */
849
- function ss({ a: e, b: n, transposeA: t = !1, transposeB: s = !1, bias: r, activation: o = "linear", preluActivationWeights: a, leakyreluAlpha: i = 0.2 }) {
850
- if (ts(d.state.gradientDepth, o) === !1) {
851
- let z = y(e, n, t, s);
852
- return r != null && (z = U(z, r)), ns(z, o, a, i);
853
- }
854
- let u = l(e, "a", "fused matMul"), c = l(n, "b", "fused matMul");
855
- [u, c] = Y(u, c);
856
- const m = t ? u.shape[u.rank - 2] : u.shape[u.rank - 1], h = s ? c.shape[c.rank - 1] : c.shape[c.rank - 2], b = t ? u.shape[u.rank - 1] : u.shape[u.rank - 2], g = s ? c.shape[c.rank - 2] : c.shape[c.rank - 1], x = u.shape.slice(0, -2), w = c.shape.slice(0, -2), k = Me(x), E = Me(w);
857
- p(m === h, () => `Error in fused matMul: inner shapes (${m}) and (${h}) of Tensors with shapes ${u.shape} and ${c.shape} and transposeA=${t} and transposeB=${s} must match.`);
858
- const T = P(u.shape.slice(0, -2), c.shape.slice(0, -2)).concat([b, g]), M = t ? $(u, [k, m, b]) : $(u, [k, b, m]), O = s ? $(c, [E, g, h]) : $(c, [E, h, g]);
859
- let N;
860
- r != null && (N = l(r, "bias", "fused matMul"), [N] = Y(N, u), P(T, N.shape));
861
- let te;
862
- a != null && (te = l(a, "prelu weights", "fused matMul"));
863
- const v = (z, se) => {
864
- const [j, F, W, ce] = se, R = Qt($(z, W.shape), W, o);
865
- let X, H;
866
- if (!t && !s ? (X = y(R, F, !1, !0), H = y(j, R, !0, !1)) : !t && s ? (X = y(R, F, !1, !1), H = y(R, j, !0, !1)) : t && !s ? (X = y(F, R, !1, !0), H = y(j, R, !1, !1)) : (X = y(F, R, !0, !0), H = y(R, j, !0, !0)), r != null) {
867
- const en = es(ce, R);
868
- return [X, H, en];
869
- } else
870
- return [X, H];
871
- }, Z = {
872
- a: M,
873
- b: O,
874
- bias: N,
875
- preluActivationWeights: te
876
- }, De = { transposeA: t, transposeB: s, activation: o, leakyreluAlpha: i };
877
- return r == null ? Oe((se, j, F) => {
878
- const W = (
879
- // tslint:disable-next-line: no-unnecessary-type-assertion
880
- d.runKernel(Be, Z, De)
881
- );
882
- return F([se, j, W]), { value: $(W, T), gradFunc: v };
883
- })(M, O) : Oe((se, j, F, W) => {
884
- const ce = (
885
- // tslint:disable-next-line: no-unnecessary-type-assertion
886
- d.runKernel(Be, Z, De)
887
- );
888
- return W([se, j, ce, F]), { value: $(ce, T), gradFunc: v };
889
- })(M, O, N);
890
- }
891
- const qe = /* @__PURE__ */ f({ fusedMatMul_: ss });
892
- /**
893
- * @license
894
- * Copyright 2020 Google LLC. All Rights Reserved.
895
- * Licensed under the Apache License, Version 2.0 (the "License");
896
- * you may not use this file except in compliance with the License.
897
- * You may obtain a copy of the License at
898
- *
899
- * http://www.apache.org/licenses/LICENSE-2.0
900
- *
901
- * Unless required by applicable law or agreed to in writing, software
902
- * distributed under the License is distributed on an "AS IS" BASIS,
903
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
904
- * See the License for the specific language governing permissions and
905
- * limitations under the License.
906
- * =============================================================================
907
- */
908
- function rs(e, n, t, s, r = "bilinear", o = 0) {
909
- const a = l(e, "image", "cropAndResize"), i = l(n, "boxes", "cropAndResize", "float32"), u = l(t, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
910
- p(a.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${a.rank}.`), p(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${c},4] but had shape ${i.shape}.`), p(u.rank === 1 && u.shape[0] === c, () => `Error in cropAndResize: boxInd must be have size [${c}] but had shape ${i.shape}.`), p(s.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${s.length}.`), p(s[0] >= 1 && s[1] >= 1, () => `cropSize must be atleast [1,1], but was ${s}`), p(r === "bilinear" || r === "nearest", () => `method must be bilinear or nearest, but was ${r}`);
911
- const m = { image: a, boxes: i, boxInd: u }, h = { method: r, extrapolationValue: o, cropSize: s };
912
- return d.runKernel(Bn, m, h);
913
- }
914
- const os = /* @__PURE__ */ f({ cropAndResize_: rs });
915
- /**
916
- * @license
917
- * Copyright 2020 Google LLC. All Rights Reserved.
918
- * Licensed under the Apache License, Version 2.0 (the "License");
919
- * you may not use this file except in compliance with the License.
920
- * You may obtain a copy of the License at
921
- *
922
- * http://www.apache.org/licenses/LICENSE-2.0
923
- *
924
- * Unless required by applicable law or agreed to in writing, software
925
- * distributed under the License is distributed on an "AS IS" BASIS,
926
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
927
- * See the License for the specific language governing permissions and
928
- * limitations under the License.
929
- * =============================================================================
930
- */
931
- function as(e) {
932
- const n = l(e, "image", "flipLeftRight", "float32");
933
- p(n.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${n.rank}.`);
934
- const t = { image: n };
935
- return d.runKernel(Pn, t, {});
936
- }
937
- const is = /* @__PURE__ */ f({ flipLeftRight_: as });
938
- /**
939
- * @license
940
- * Copyright 2021 Google LLC. All Rights Reserved.
941
- * Licensed under the Apache License, Version 2.0 (the "License");
942
- * you may not use this file except in compliance with the License.
943
- * You may obtain a copy of the License at
944
- *
945
- * http://www.apache.org/licenses/LICENSE-2.0
946
- *
947
- * Unless required by applicable law or agreed to in writing, software
948
- * distributed under the License is distributed on an "AS IS" BASIS,
949
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
950
- * See the License for the specific language governing permissions and
951
- * limitations under the License.
952
- * =============================================================================
953
- */
954
- function cs(e) {
955
- const n = l(e, "image", "grayscaleToRGB"), t = n.rank - 1, s = n.shape[t];
956
- p(n.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${n.rank}.`), p(s === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${s}.`);
957
- const r = new Array(n.rank);
958
- return r.fill(1, 0, t), r[t] = 3, oe(n, r);
959
- }
960
- const us = /* @__PURE__ */ f({ grayscaleToRGB_: cs });
961
- /**
962
- * @license
963
- * Copyright 2023 Google LLC.
964
- * Licensed under the Apache License, Version 2.0 (the "License");
965
- * you may not use this file except in compliance with the License.
966
- * You may obtain a copy of the License at
967
- *
968
- * http://www.apache.org/licenses/LICENSE-2.0
969
- *
970
- * Unless required by applicable law or agreed to in writing, software
971
- * distributed under the License is distributed on an "AS IS" BASIS,
972
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
973
- * See the License for the specific language governing permissions and
974
- * limitations under the License.
975
- * =============================================================================
976
- */
977
- function ls(e) {
978
- const n = l(e, "image", "RGBToGrayscale"), t = n.rank - 1, s = n.shape[t];
979
- p(n.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${n.rank}.`), p(s === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${s}.`);
980
- const r = n.dtype, o = C(n, "float32"), a = B([0.2989, 0.587, 0.114]);
981
- let i;
982
- switch (n.rank) {
983
- case 2:
984
- i = re("ij,j->i", o, a);
985
- break;
986
- case 3:
987
- i = re("ijk,k->ij", o, a);
988
- break;
989
- case 4:
990
- i = re("ijkl,l->ijk", o, a);
991
- break;
992
- case 5:
993
- i = re("ijklm,m->ijkl", o, a);
994
- break;
995
- case 6:
996
- i = re("ijklmn,n->ijklm", o, a);
997
- break;
998
- default:
999
- throw new Error("Not a valid tensor rank.");
1000
- }
1001
- return i = J(i, -1), C(i, r);
1002
- }
1003
- const ps = /* @__PURE__ */ f({ rgbToGrayscale_: ls });
1004
- /**
1005
- * @license
1006
- * Copyright 2020 Google LLC. All Rights Reserved.
1007
- * Licensed under the Apache License, Version 2.0 (the "License");
1008
- * you may not use this file except in compliance with the License.
1009
- * You may obtain a copy of the License at
1010
- *
1011
- * http://www.apache.org/licenses/LICENSE-2.0
1012
- *
1013
- * Unless required by applicable law or agreed to in writing, software
1014
- * distributed under the License is distributed on an "AS IS" BASIS,
1015
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1016
- * See the License for the specific language governing permissions and
1017
- * limitations under the License.
1018
- * =============================================================================
1019
- */
1020
- function fs(e, n, t = 0, s = 0.5) {
1021
- const r = l(e, "image", "rotateWithOffset", "float32");
1022
- p(r.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${r.rank}.`);
1023
- const o = { image: r }, a = { radians: n, fillValue: t, center: s };
1024
- return d.runKernel(Kn, o, a);
1025
- }
1026
- const hs = /* @__PURE__ */ f({ rotateWithOffset_: fs });
1027
- /**
1028
- * @license
1029
- * Copyright 2020 Google LLC. All Rights Reserved.
1030
- * Licensed under the Apache License, Version 2.0 (the "License");
1031
- * you may not use this file except in compliance with the License.
1032
- * You may obtain a copy of the License at
1033
- *
1034
- * http://www.apache.org/licenses/LICENSE-2.0
1035
- *
1036
- * Unless required by applicable law or agreed to in writing, software
1037
- * distributed under the License is distributed on an "AS IS" BASIS,
1038
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1039
- * See the License for the specific language governing permissions and
1040
- * limitations under the License.
1041
- * =============================================================================
1042
- */
1043
- function ne(e, n, t, s, r, o) {
1044
- s == null && (s = 0.5), r == null && (r = Number.NEGATIVE_INFINITY), o == null && (o = 0);
1045
- const a = e.shape[0];
1046
- return t = Math.min(t, a), p(0 <= s && s <= 1, () => `iouThreshold must be in [0, 1], but was '${s}'`), p(e.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${e.rank}'`), p(e.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${e.shape[1]}`), p(n.rank === 1, () => "scores must be a 1D tensor"), p(n.shape[0] === a, () => `scores has incompatible shape with boxes. Expected ${a}, but was ${n.shape[0]}`), p(0 <= o && o <= 1, () => `softNmsSigma must be in [0, 1], but was '${o}'`), { maxOutputSize: t, iouThreshold: s, scoreThreshold: r, softNmsSigma: o };
1047
- }
1048
- /**
1049
- * @license
1050
- * Copyright 2020 Google LLC. All Rights Reserved.
1051
- * Licensed under the Apache License, Version 2.0 (the "License");
1052
- * you may not use this file except in compliance with the License.
1053
- * You may obtain a copy of the License at
1054
- *
1055
- * http://www.apache.org/licenses/LICENSE-2.0
1056
- *
1057
- * Unless required by applicable law or agreed to in writing, software
1058
- * distributed under the License is distributed on an "AS IS" BASIS,
1059
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1060
- * See the License for the specific language governing permissions and
1061
- * limitations under the License.
1062
- * =============================================================================
1063
- */
1064
- function ds(e, n, t, s = 0.5, r = Number.NEGATIVE_INFINITY) {
1065
- const o = l(e, "boxes", "nonMaxSuppression", "float32"), a = l(n, "scores", "nonMaxSuppression", "float32"), i = ne(o, a, t, s, r);
1066
- t = i.maxOutputSize, s = i.iouThreshold, r = i.scoreThreshold;
1067
- const u = { maxOutputSize: t, iouThreshold: s, scoreThreshold: r };
1068
- return d.runKernel(Rn, { boxes: o, scores: a }, u);
1069
- }
1070
- const ms = /* @__PURE__ */ f({ nonMaxSuppression_: ds });
1071
- /**
1072
- * @license
1073
- * Copyright 2019 Google LLC. All Rights Reserved.
1074
- * Licensed under the Apache License, Version 2.0 (the "License");
1075
- * you may not use this file except in compliance with the License.
1076
- * You may obtain a copy of the License at
1077
- *
1078
- * http://www.apache.org/licenses/LICENSE-2.0
1079
- *
1080
- * Unless required by applicable law or agreed to in writing, software
1081
- * distributed under the License is distributed on an "AS IS" BASIS,
1082
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1083
- * See the License for the specific language governing permissions and
1084
- * limitations under the License.
1085
- * =============================================================================
1086
- */
1087
- function gs(e, n, t) {
1088
- const s = $s(e, n, t), r = s < 0 ? -(s + 1) : s;
1089
- e.splice(r, 0, n);
1090
- }
1091
- function $s(e, n, t) {
1092
- return ks(e, n, t || bs);
1093
- }
1094
- function bs(e, n) {
1095
- return e > n ? 1 : e < n ? -1 : 0;
1096
- }
1097
- function ks(e, n, t) {
1098
- let s = 0, r = e.length, o = 0, a = !1;
1099
- for (; s < r; ) {
1100
- o = s + (r - s >>> 1);
1101
- const i = t(n, e[o]);
1102
- i > 0 ? s = o + 1 : (r = o, a = !i);
1103
- }
1104
- return a ? s : -s - 1;
1105
- }
1106
- /**
1107
- * @license
1108
- * Copyright 2020 Google LLC. All Rights Reserved.
1109
- * Licensed under the Apache License, Version 2.0 (the "License");
1110
- * you may not use this file except in compliance with the License.
1111
- * You may obtain a copy of the License at
1112
- *
1113
- * http://www.apache.org/licenses/LICENSE-2.0
1114
- *
1115
- * Unless required by applicable law or agreed to in writing, software
1116
- * distributed under the License is distributed on an "AS IS" BASIS,
1117
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1118
- * See the License for the specific language governing permissions and
1119
- * limitations under the License.
1120
- * =============================================================================
1121
- */
1122
- function xs(e, n, t, s, r) {
1123
- return Te(
1124
- e,
1125
- n,
1126
- t,
1127
- s,
1128
- r,
1129
- 0
1130
- /* softNmsSigma */
1131
- );
1132
- }
1133
- function ws(e, n, t, s, r, o) {
1134
- return Te(
1135
- e,
1136
- n,
1137
- t,
1138
- s,
1139
- r,
1140
- 0,
1141
- !1,
1142
- o,
1143
- !0
1144
- /* returnValidOutputs */
1145
- );
1146
- }
1147
- function As(e, n, t, s, r, o) {
1148
- return Te(
1149
- e,
1150
- n,
1151
- t,
1152
- s,
1153
- r,
1154
- o,
1155
- !0
1156
- /* returnScoresTensor */
1157
- );
1158
- }
1159
- function Te(e, n, t, s, r, o, a = !1, i = !1, u = !1) {
1160
- const c = [];
1161
- for (let k = 0; k < n.length; k++)
1162
- n[k] > r && c.push({ score: n[k], boxIndex: k, suppressBeginIndex: 0 });
1163
- c.sort(je);
1164
- const m = o > 0 ? -0.5 / o : 0, h = [], b = [];
1165
- for (; h.length < t && c.length > 0; ) {
1166
- const k = c.pop(), { score: E, boxIndex: S, suppressBeginIndex: T } = k;
1167
- if (E < r)
1168
- break;
1169
- let M = !1;
1170
- for (let O = h.length - 1; O >= T; --O) {
1171
- const N = ys(e, S, h[O]);
1172
- if (N >= s) {
1173
- M = !0;
1174
- break;
1175
- }
1176
- if (k.score = k.score * _s(s, m, N), k.score <= r)
1177
- break;
1178
- }
1179
- k.suppressBeginIndex = h.length, M || (k.score === E ? (h.push(S), b.push(k.score)) : k.score > r && gs(c, k, je));
1180
- }
1181
- const g = h.length, x = t - g;
1182
- i && x > 0 && (h.push(...new Array(x).fill(0)), b.push(...new Array(x).fill(0)));
1183
- const w = { selectedIndices: h };
1184
- return a && (w.selectedScores = b), u && (w.validOutputs = g), w;
1185
- }
1186
- function ys(e, n, t) {
1187
- const s = e.subarray(n * 4, n * 4 + 4), r = e.subarray(t * 4, t * 4 + 4), o = Math.min(s[0], s[2]), a = Math.min(s[1], s[3]), i = Math.max(s[0], s[2]), u = Math.max(s[1], s[3]), c = Math.min(r[0], r[2]), m = Math.min(r[1], r[3]), h = Math.max(r[0], r[2]), b = Math.max(r[1], r[3]), g = (i - o) * (u - a), x = (h - c) * (b - m);
1188
- if (g <= 0 || x <= 0)
1189
- return 0;
1190
- const w = Math.max(o, c), k = Math.max(a, m), E = Math.min(i, h), S = Math.min(u, b), T = Math.max(E - w, 0) * Math.max(S - k, 0);
1191
- return T / (g + x - T);
1192
- }
1193
- function _s(e, n, t) {
1194
- const s = Math.exp(n * t * t);
1195
- return t <= e ? s : 0;
1196
- }
1197
- function je(e, n) {
1198
- return e.score - n.score || e.score === n.score && n.boxIndex - e.boxIndex;
1199
- }
1200
- /**
1201
- * @license
1202
- * Copyright 2020 Google LLC. All Rights Reserved.
1203
- * Licensed under the Apache License, Version 2.0 (the "License");
1204
- * you may not use this file except in compliance with the License.
1205
- * You may obtain a copy of the License at
1206
- *
1207
- * http://www.apache.org/licenses/LICENSE-2.0
1208
- *
1209
- * Unless required by applicable law or agreed to in writing, software
1210
- * distributed under the License is distributed on an "AS IS" BASIS,
1211
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
- * See the License for the specific language governing permissions and
1213
- * limitations under the License.
1214
- * =============================================================================
1215
- */
1216
- async function Is(e, n, t, s = 0.5, r = Number.NEGATIVE_INFINITY) {
1217
- const o = l(e, "boxes", "nonMaxSuppressionAsync"), a = l(n, "scores", "nonMaxSuppressionAsync"), i = ne(o, a, t, s, r);
1218
- t = i.maxOutputSize, s = i.iouThreshold, r = i.scoreThreshold;
1219
- const u = await Promise.all([o.data(), a.data()]), c = u[0], m = u[1], { selectedIndices: h } = xs(c, m, t, s, r);
1220
- return o !== e && o.dispose(), a !== n && a.dispose(), B(h, "int32");
1221
- }
1222
- const Es = Is;
1223
- /**
1224
- * @license
1225
- * Copyright 2020 Google LLC. All Rights Reserved.
1226
- * Licensed under the Apache License, Version 2.0 (the "License");
1227
- * you may not use this file except in compliance with the License.
1228
- * You may obtain a copy of the License at
1229
- *
1230
- * http://www.apache.org/licenses/LICENSE-2.0
1231
- *
1232
- * Unless required by applicable law or agreed to in writing, software
1233
- * distributed under the License is distributed on an "AS IS" BASIS,
1234
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1235
- * See the License for the specific language governing permissions and
1236
- * limitations under the License.
1237
- * =============================================================================
1238
- */
1239
- function Ss(e, n, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = 0) {
1240
- const a = l(e, "boxes", "nonMaxSuppression"), i = l(n, "scores", "nonMaxSuppression"), u = ne(a, i, t, s, r, o);
1241
- t = u.maxOutputSize, s = u.iouThreshold, r = u.scoreThreshold, o = u.softNmsSigma;
1242
- const c = { boxes: a, scores: i }, m = { maxOutputSize: t, iouThreshold: s, scoreThreshold: r, softNmsSigma: o }, h = d.runKernel(qn, c, m);
1243
- return { selectedIndices: h[0], selectedScores: h[1] };
1244
- }
1245
- const Ts = /* @__PURE__ */ f({ nonMaxSuppressionWithScore_: Ss });
1246
- /**
1247
- * @license
1248
- * Copyright 2020 Google LLC. All Rights Reserved.
1249
- * Licensed under the Apache License, Version 2.0 (the "License");
1250
- * you may not use this file except in compliance with the License.
1251
- * You may obtain a copy of the License at
1252
- *
1253
- * http://www.apache.org/licenses/LICENSE-2.0
1254
- *
1255
- * Unless required by applicable law or agreed to in writing, software
1256
- * distributed under the License is distributed on an "AS IS" BASIS,
1257
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1258
- * See the License for the specific language governing permissions and
1259
- * limitations under the License.
1260
- * =============================================================================
1261
- */
1262
- async function Ns(e, n, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = 0) {
1263
- const a = l(e, "boxes", "nonMaxSuppressionAsync"), i = l(n, "scores", "nonMaxSuppressionAsync"), u = ne(a, i, t, s, r, o);
1264
- t = u.maxOutputSize, s = u.iouThreshold, r = u.scoreThreshold, o = u.softNmsSigma;
1265
- const c = await Promise.all([a.data(), i.data()]), m = c[0], h = c[1], { selectedIndices: b, selectedScores: g } = As(m, h, t, s, r, o);
1266
- return a !== e && a.dispose(), i !== n && i.dispose(), {
1267
- selectedIndices: B(b, "int32"),
1268
- selectedScores: B(g)
1269
- };
1270
- }
1271
- const Ds = Ns;
1272
- /**
1273
- * @license
1274
- * Copyright 2020 Google LLC. All Rights Reserved.
1275
- * Licensed under the Apache License, Version 2.0 (the "License");
1276
- * you may not use this file except in compliance with the License.
1277
- * You may obtain a copy of the License at
1278
- *
1279
- * http://www.apache.org/licenses/LICENSE-2.0
1280
- *
1281
- * Unless required by applicable law or agreed to in writing, software
1282
- * distributed under the License is distributed on an "AS IS" BASIS,
1283
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1284
- * See the License for the specific language governing permissions and
1285
- * limitations under the License.
1286
- * =============================================================================
1287
- */
1288
- function Ms(e, n, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = !1) {
1289
- const a = l(e, "boxes", "nonMaxSuppression"), i = l(n, "scores", "nonMaxSuppression"), u = ne(
1290
- a,
1291
- i,
1292
- t,
1293
- s,
1294
- r,
1295
- null
1296
- /* softNmsSigma */
1297
- ), c = u.maxOutputSize, m = u.iouThreshold, h = u.scoreThreshold, b = { boxes: a, scores: i }, g = {
1298
- maxOutputSize: c,
1299
- iouThreshold: m,
1300
- scoreThreshold: h,
1301
- padToMaxOutputSize: o
1302
- }, x = d.runKernel(jn, b, g);
1303
- return { selectedIndices: x[0], validOutputs: x[1] };
1304
- }
1305
- const Os = /* @__PURE__ */ f({ nonMaxSuppressionPadded_: Ms });
1306
- /**
1307
- * @license
1308
- * Copyright 2020 Google LLC. All Rights Reserved.
1309
- * Licensed under the Apache License, Version 2.0 (the "License");
1310
- * you may not use this file except in compliance with the License.
1311
- * You may obtain a copy of the License at
1312
- *
1313
- * http://www.apache.org/licenses/LICENSE-2.0
1314
- *
1315
- * Unless required by applicable law or agreed to in writing, software
1316
- * distributed under the License is distributed on an "AS IS" BASIS,
1317
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1318
- * See the License for the specific language governing permissions and
1319
- * limitations under the License.
1320
- * =============================================================================
1321
- */
1322
- async function Bs(e, n, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = !1) {
1323
- const a = l(e, "boxes", "nonMaxSuppressionAsync"), i = l(n, "scores", "nonMaxSuppressionAsync"), u = ne(
1324
- a,
1325
- i,
1326
- t,
1327
- s,
1328
- r,
1329
- null
1330
- /* softNmsSigma */
1331
- ), c = u.maxOutputSize, m = u.iouThreshold, h = u.scoreThreshold, [b, g] = await Promise.all([a.data(), i.data()]), { selectedIndices: x, validOutputs: w } = ws(b, g, c, m, h, o);
1332
- return a !== e && a.dispose(), i !== n && i.dispose(), {
1333
- selectedIndices: B(x, "int32"),
1334
- validOutputs: Fn(w, "int32")
1335
- };
1336
- }
1337
- const Ps = Bs;
1338
- /**
1339
- * @license
1340
- * Copyright 2020 Google LLC. All Rights Reserved.
1341
- * Licensed under the Apache License, Version 2.0 (the "License");
1342
- * you may not use this file except in compliance with the License.
1343
- * You may obtain a copy of the License at
1344
- *
1345
- * http://www.apache.org/licenses/LICENSE-2.0
1346
- *
1347
- * Unless required by applicable law or agreed to in writing, software
1348
- * distributed under the License is distributed on an "AS IS" BASIS,
1349
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1350
- * See the License for the specific language governing permissions and
1351
- * limitations under the License.
1352
- * =============================================================================
1353
- */
1354
- function Ks(e, n, t = !1, s = !1) {
1355
- const r = l(e, "images", "resizeBilinear");
1356
- p(r.rank === 3 || r.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${r.rank}.`), p(n.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${n}.`), p(s === !1 || t === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.");
1357
- let o = r, a = !1;
1358
- r.rank === 3 && (a = !0, o = $(r, [1, r.shape[0], r.shape[1], r.shape[2]]));
1359
- const i = { images: o }, u = { alignCorners: t, halfPixelCenters: s, size: n }, c = d.runKernel(Gn, i, u);
1360
- return a ? $(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
1361
- }
1362
- const Rs = /* @__PURE__ */ f({ resizeBilinear_: Ks });
1363
- /**
1364
- * @license
1365
- * Copyright 2020 Google LLC. All Rights Reserved.
1366
- * Licensed under the Apache License, Version 2.0 (the "License");
1367
- * you may not use this file except in compliance with the License.
1368
- * You may obtain a copy of the License at
1369
- *
1370
- * http://www.apache.org/licenses/LICENSE-2.0
1371
- *
1372
- * Unless required by applicable law or agreed to in writing, software
1373
- * distributed under the License is distributed on an "AS IS" BASIS,
1374
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1375
- * See the License for the specific language governing permissions and
1376
- * limitations under the License.
1377
- * =============================================================================
1378
- */
1379
- function qs(e, n, t = !1, s = !1) {
1380
- const r = l(e, "images", "resizeNearestNeighbor");
1381
- p(r.rank === 3 || r.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${r.rank}.`), p(n.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${n}.`), p(r.dtype === "float32" || r.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), p(s === !1 || t === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.");
1382
- let o = r, a = !1;
1383
- r.rank === 3 && (a = !0, o = $(r, [1, r.shape[0], r.shape[1], r.shape[2]]));
1384
- const i = { images: o }, u = { alignCorners: t, halfPixelCenters: s, size: n }, c = d.runKernel(Ln, i, u);
1385
- return a ? $(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
1386
- }
1387
- const js = /* @__PURE__ */ f({ resizeNearestNeighbor_: qs });
1388
- /**
1389
- * @license
1390
- * Copyright 2021 Google LLC. All Rights Reserved.
1391
- * Licensed under the Apache License, Version 2.0 (the "License");
1392
- * you may not use this file except in compliance with the License.
1393
- * You may obtain a copy of the License at
1394
- *
1395
- * https://www.apache.org/licenses/LICENSE-2.0
1396
- *
1397
- * Unless required by applicable law or agreed to in writing, software
1398
- * distributed under the License is distributed on an "AS IS" BASIS,
1399
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1400
- * See the License for the specific language governing permissions and
1401
- * limitations under the License.
1402
- * =============================================================================
1403
- */
1404
- function Fs(e, n = "binary", t = !1, s = 0.5) {
1405
- const r = l(e, "image", "threshold"), o = 0.2989, a = 0.587, i = 0.114, u = r.shape[0] * r.shape[1];
1406
- let c = I(B([s]), 255), m, h, b, g;
1407
- if (p(r.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${r.rank}.`), p(r.shape[2] === 3 || r.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${r.shape[2]}.`), p(r.dtype === "int32" || r.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${r.dtype}.`), p(n === "otsu" || n === "binary", () => `Method must be binary or otsu, but was ${n}`), r.shape[2] === 3) {
1408
- [m, h, b] = Ce(r, [1, 1, 1], -1);
1409
- const k = I(m, o), E = I(h, a), S = I(b, i);
1410
- g = U(U(k, E), S);
1411
- } else
1412
- g = e;
1413
- if (n === "otsu") {
1414
- const k = tt(C(Vt(g), "int32"), Wn([]), 256);
1415
- c = Gs(k, u);
1416
- }
1417
- const x = t ? We(g, c) : _e(g, c);
1418
- return C(I(x, 255), "int32");
1419
- }
1420
- function Gs(e, n) {
1421
- let t = B([-1]), s = B([0]), r = B([0]), o, a, i, u, c, m;
1422
- for (let h = 0; h < e.size - 1; h++) {
1423
- o = _(e, 0, h + 1), a = _(e, h + 1), c = L(G(o), n), m = L(G(a), n);
1424
- const b = G(I(o, ue(0, o.size)));
1425
- i = L(b, G(o));
1426
- const g = Ve(a.shape, o.size), x = U(ue(0, a.size), g), w = I(a, x);
1427
- u = L(G(w), G(a));
1428
- const k = q(i, u), E = q(i, u), S = I(c, m);
1429
- r = I(I(S, k), E);
1430
- const T = _e(r, s);
1431
- s = ee(T, r, s), t = ee(T, B([h]), t);
1432
- }
1433
- return t;
1434
- }
1435
- const Ls = /* @__PURE__ */ f({ threshold_: Fs });
1436
- /**
1437
- * @license
1438
- * Copyright 2021 Google LLC. All Rights Reserved.
1439
- * Licensed under the Apache License, Version 2.0 (the "License");
1440
- * you may not use this file except in compliance with the License.
1441
- * You may obtain a copy of the License at
1442
- *
1443
- * http://www.apache.org/licenses/LICENSE-2.0
1444
- *
1445
- * Unless required by applicable law or agreed to in writing, software
1446
- * distributed under the License is distributed on an "AS IS" BASIS,
1447
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1448
- * See the License for the specific language governing permissions and
1449
- * limitations under the License.
1450
- * =============================================================================
1451
- */
1452
- function Vs(e, n, t = "nearest", s = "constant", r = 0, o) {
1453
- const a = l(e, "image", "transform", "float32"), i = l(n, "transforms", "transform", "float32");
1454
- p(a.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${a.rank}.`), p(i.rank === 2 && (i.shape[0] === a.shape[0] || i.shape[0] === 1) && i.shape[1] === 8, () => "Error in transform: Input transform should be batch x 8 or 1 x 8"), p(o == null || o.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${o}.`);
1455
- const u = { image: a, transforms: i }, c = { interpolation: t, fillMode: s, fillValue: r, outputShape: o };
1456
- return d.runKernel(Vn, u, c);
1457
- }
1458
- const Cs = /* @__PURE__ */ f({ transform_: Vs });
1459
- /**
1460
- * @license
1461
- * Copyright 2020 Google LLC. All Rights Reserved.
1462
- * Licensed under the Apache License, Version 2.0 (the "License");
1463
- * you may not use this file except in compliance with the License.
1464
- * You may obtain a copy of the License at
1465
- *
1466
- * http://www.apache.org/licenses/LICENSE-2.0
1467
- *
1468
- * Unless required by applicable law or agreed to in writing, software
1469
- * distributed under the License is distributed on an "AS IS" BASIS,
1470
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1471
- * See the License for the specific language governing permissions and
1472
- * limitations under the License.
1473
- * =============================================================================
1474
- */
1475
- function vs(e, n, t) {
1476
- const s = l(e, "a", "bandPart");
1477
- p(s.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${s.rank}.`);
1478
- const r = s.shape, [o, a] = s.shape.slice(-2);
1479
- let i, u;
1480
- typeof n == "number" ? (p(n % 1 === 0, () => `bandPart(): numLower must be an integer, got ${n}.`), p(n <= o, () => `bandPart(): numLower (${n}) must not be greater than the number of rows (${o}).`), i = l(n < 0 ? o : n, "numLower", "bandPart")) : (p(n.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = ee(Ke(n, 0), o, Re(n, o))), typeof t == "number" ? (p(t % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${t}.`), p(t <= a, () => `bandPart(): numUpper (${t}) must not be greater than the number of columns (${a}).`), u = l(t < 0 ? a : t, "numUpper", "bandPart")) : (p(t.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), u = ee(Ke(t, 0), a, Re(t, a)));
1481
- const c = $(ue(0, o, 1, "int32"), [-1, 1]), m = ue(0, a, 1, "int32"), h = q(c, m), b = Mt(We(h, i), At(h, Ie(u))), g = Yn([o, a], s.dtype);
1482
- return $(le(Ye($(s, [-1, o, a])).map((x) => ee(b, x, g))), r);
1483
- }
1484
- const zs = /* @__PURE__ */ f({ bandPart_: vs });
1485
- /**
1486
- * @license
1487
- * Copyright 2020 Google LLC. All Rights Reserved.
1488
- * Licensed under the Apache License, Version 2.0 (the "License");
1489
- * you may not use this file except in compliance with the License.
1490
- * You may obtain a copy of the License at
1491
- *
1492
- * http://www.apache.org/licenses/LICENSE-2.0
1493
- *
1494
- * Unless required by applicable law or agreed to in writing, software
1495
- * distributed under the License is distributed on an "AS IS" BASIS,
1496
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1497
- * See the License for the specific language governing permissions and
1498
- * limitations under the License.
1499
- * =============================================================================
1500
- */
1501
- function Ws(e) {
1502
- let n;
1503
- if (Array.isArray(e)) {
1504
- n = !1, p(e != null && e.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
1505
- const r = e[0].shape[0];
1506
- for (let o = 1; o < e.length; ++o)
1507
- p(e[o].shape[0] === r, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${e[o].shape[0]} vs. ${r})`);
1508
- } else
1509
- n = !0, e = Ce(e, e.shape[0], 0).map((r) => Yt(r, [0]));
1510
- p(e.length <= e[0].shape[0], () => `Gram-Schmidt: Number of vectors (${e.length}) exceeds number of dimensions (${e[0].shape[0]}).`);
1511
- const t = [], s = e;
1512
- for (let r = 0; r < e.length; ++r)
1513
- t.push(d.tidy(() => {
1514
- let o = s[r];
1515
- if (r > 0)
1516
- for (let a = 0; a < r; ++a) {
1517
- const i = I(G(I(t[a], o)), t[a]);
1518
- o = q(o, i);
1519
- }
1520
- return L(o, ve(o, "euclidean"));
1521
- }));
1522
- return n ? le(t, 0) : t;
1523
- }
1524
- const Js = /* @__PURE__ */ f({ gramSchmidt_: Ws });
1525
- /**
1526
- * @license
1527
- * Copyright 2020 Google LLC. All Rights Reserved.
1528
- * Licensed under the Apache License, Version 2.0 (the "License");
1529
- * you may not use this file except in compliance with the License.
1530
- * You may obtain a copy of the License at
1531
- *
1532
- * http://www.apache.org/licenses/LICENSE-2.0
1533
- *
1534
- * Unless required by applicable law or agreed to in writing, software
1535
- * distributed under the License is distributed on an "AS IS" BASIS,
1536
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1537
- * See the License for the specific language governing permissions and
1538
- * limitations under the License.
1539
- * =============================================================================
1540
- */
1541
- function Ys(e, n = !1) {
1542
- if (p(e.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${e.rank}`), e.rank === 2)
1543
- return Fe(e, n);
1544
- {
1545
- const t = e.shape.slice(0, e.shape.length - 2).reduce((u, c) => u * c), s = Ye($(e, [
1546
- t,
1547
- e.shape[e.shape.length - 2],
1548
- e.shape[e.shape.length - 1]
1549
- ]), 0), r = [], o = [];
1550
- s.forEach((u) => {
1551
- const [c, m] = Fe(u, n);
1552
- r.push(c), o.push(m);
1553
- });
1554
- const a = $(le(r, 0), e.shape), i = $(le(o, 0), e.shape);
1555
- return [a, i];
1556
- }
1557
- }
1558
- function Fe(e, n = !1) {
1559
- return d.tidy(() => {
1560
- p(e.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${e.shape.length}D Tensor.`);
1561
- const t = e.shape[0], s = e.shape[1];
1562
- let r = kt(t), o = de(e);
1563
- const a = ge([[1]], [1, 1]);
1564
- let i = de(a);
1565
- const u = t >= s ? s : t;
1566
- for (let c = 0; c < u; ++c) {
1567
- const m = o, h = i, b = r;
1568
- [i, o, r] = d.tidy(() => {
1569
- const g = _(o, [c, c], [t - c, 1]), x = ve(g), w = _(o, [c, c], [1, 1]), k = ee(_e(w, 0), ge([[-1]]), ge([[1]])), E = q(w, I(k, x)), S = L(g, E);
1570
- S.shape[0] === 1 ? i = de(a) : i = V([
1571
- a,
1572
- _(S, [1, 0], [S.shape[0] - 1, S.shape[1]])
1573
- ], 0);
1574
- const T = Ie(L(y(k, E), x)), M = _(o, [c, 0], [t - c, s]), O = I(T, i), N = xe(i);
1575
- if (c === 0)
1576
- o = q(M, y(O, y(N, M)));
1577
- else {
1578
- const Z = q(M, y(O, y(N, M)));
1579
- o = V([_(o, [0, 0], [c, s]), Z], 0);
1580
- }
1581
- const te = xe(O), v = _(r, [0, c], [t, r.shape[1] - c]);
1582
- if (c === 0)
1583
- r = q(v, y(y(v, i), te));
1584
- else {
1585
- const Z = q(v, y(y(v, i), te));
1586
- r = V([_(r, [0, 0], [t, c]), Z], 1);
1587
- }
1588
- return [i, o, r];
1589
- }), Cn([m, h, b]);
1590
- }
1591
- return !n && t > s && (r = _(r, [0, 0], [t, s]), o = _(o, [0, 0], [s, s])), [r, o];
1592
- });
1593
- }
1594
- const Us = /* @__PURE__ */ f({ qr_: Ys });
1595
- /**
1596
- * @license
1597
- * Copyright 2020 Google LLC. All Rights Reserved.
1598
- * Licensed under the Apache License, Version 2.0 (the "License");
1599
- * you may not use this file except in compliance with the License.
1600
- * You may obtain a copy of the License at
1601
- *
1602
- * http://www.apache.org/licenses/LICENSE-2.0
1603
- *
1604
- * Unless required by applicable law or agreed to in writing, software
1605
- * distributed under the License is distributed on an "AS IS" BASIS,
1606
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1607
- * See the License for the specific language governing permissions and
1608
- * limitations under the License.
1609
- * =============================================================================
1610
- */
1611
- const Ar = {
1612
- flipLeftRight: is,
1613
- grayscaleToRGB: us,
1614
- resizeNearestNeighbor: js,
1615
- resizeBilinear: Rs,
1616
- rgbToGrayscale: ps,
1617
- rotateWithOffset: hs,
1618
- cropAndResize: os,
1619
- nonMaxSuppression: ms,
1620
- nonMaxSuppressionAsync: Es,
1621
- nonMaxSuppressionWithScore: Ts,
1622
- nonMaxSuppressionWithScoreAsync: Ds,
1623
- nonMaxSuppressionPadded: Os,
1624
- nonMaxSuppressionPaddedAsync: Ps,
1625
- threshold: Ls,
1626
- transform: Cs
1627
- }, yr = {
1628
- bandPart: zs,
1629
- gramSchmidt: Js,
1630
- qr: Us
1631
- };
1632
- /**
1633
- * @license
1634
- * Copyright 2018 Google LLC
1635
- *
1636
- * Use of this source code is governed by an MIT-style
1637
- * license that can be found in the LICENSE file or at
1638
- * https://opensource.org/licenses/MIT.
1639
- * =============================================================================
1640
- */
1641
- const Zs = ["channelsFirst", "channelsLast"], Xs = ["nearest", "bilinear"], Hs = ["valid", "same", "causal"], Qs = ["max", "avg"], _r = ["sum", "mul", "concat", "ave"];
1642
- /**
1643
- * @license
1644
- * Copyright 2018 Google LLC
1645
- *
1646
- * Use of this source code is governed by an MIT-style
1647
- * license that can be found in the LICENSE file or at
1648
- * https://opensource.org/licenses/MIT.
1649
- * =============================================================================
1650
- */
1651
- class Ue extends Error {
1652
- constructor(n) {
1653
- super(n), Object.setPrototypeOf(this, Ue.prototype);
1654
- }
1655
- }
1656
- class Ze extends Error {
1657
- constructor(n) {
1658
- super(n), Object.setPrototypeOf(this, Ze.prototype);
1659
- }
1660
- }
1661
- class A extends Error {
1662
- constructor(n) {
1663
- super(n), Object.setPrototypeOf(this, A.prototype);
1664
- }
1665
- }
1666
- class ie extends Error {
1667
- constructor(n) {
1668
- super(n), Object.setPrototypeOf(this, ie.prototype);
1669
- }
1670
- }
1671
- class Ne extends Error {
1672
- constructor(n) {
1673
- super(n), Object.setPrototypeOf(this, Ne.prototype);
1674
- }
1675
- }
1676
- /**
1677
- * @license
1678
- * Copyright 2018 Google LLC
1679
- *
1680
- * Use of this source code is governed by an MIT-style
1681
- * license that can be found in the LICENSE file or at
1682
- * https://opensource.org/licenses/MIT.
1683
- * =============================================================================
1684
- */
1685
- function Ir(e, n) {
1686
- if (Array.isArray(e)) {
1687
- let t = [];
1688
- for (let s = 0; s < n; s++)
1689
- t = t.concat(e);
1690
- return t;
1691
- } else {
1692
- const t = new Array(n);
1693
- return t.fill(e), t;
1694
- }
1695
- }
1696
- function Ge(e, n) {
1697
- if (!e)
1698
- throw new Ne(n);
1699
- }
1700
- function Er(e, n) {
1701
- let t = 0;
1702
- for (const s of e)
1703
- s === n && t++;
1704
- return t;
1705
- }
1706
- function Sr(e) {
1707
- return e.length === 1 ? e[0] : e;
1708
- }
1709
- function Tr(e) {
1710
- return Array.isArray(e) ? e : [e];
1711
- }
1712
- function Nr(e) {
1713
- const t = e.replace(/(.)([A-Z][a-z0-9]+)/g, "$1_$2").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
1714
- return t[0] !== "_" ? t : "private" + t;
1715
- }
1716
- function Dr(e) {
1717
- return e.length <= 1 || e.indexOf("_") === -1 ? e : e.replace(/[_]+(\w|$)/g, (n, t) => t.toUpperCase());
1718
- }
1719
- let D = {};
1720
- function Mr(e) {
1721
- if (e == null)
1722
- return null;
1723
- const n = {};
1724
- return n.className = e.getClassName(), n.config = e.getConfig(), n;
1725
- }
1726
- function we(e) {
1727
- if (!(e == null || typeof e != "object"))
1728
- if (Array.isArray(e))
1729
- e.forEach((n) => we(n));
1730
- else {
1731
- const n = Object.keys(e);
1732
- for (const t of n) {
1733
- const s = e[t];
1734
- s != null && typeof s == "object" && (!Array.isArray(s) && s.type === "ndarray" && typeof s.value == "number" ? e[t] = s.value : we(s));
1735
- }
1736
- }
1737
- }
1738
- function Or(e, n = {}, t = {}, s = "object", r = !1) {
1739
- if (typeof e == "string") {
1740
- const o = e;
1741
- let a;
1742
- if (o in t)
1743
- a = t[o];
1744
- else if (o in D)
1745
- a = D[o];
1746
- else if (a = n[o], a == null)
1747
- throw new A(`Unknown ${s}: ${e}. This may be due to one of the following reasons:
1748
- 1. The ${s} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
1749
- 2. The custom ${s} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`);
1750
- return a;
1751
- } else {
1752
- const o = e;
1753
- if (o.className == null || o.config == null)
1754
- throw new A(`${s}: Improper config format: ${JSON.stringify(o)}.
1755
- 'className' and 'config' must set.`);
1756
- const a = o.className;
1757
- let i, u;
1758
- if (a in t ? [i, u] = t[a] : a in D ? [i, u] = D.className : a in n && ([i, u] = n[a]), i == null)
1759
- throw new A(`Unknown ${s}: ${a}. This may be due to one of the following reasons:
1760
- 1. The ${s} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
1761
- 2. The custom ${s} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`);
1762
- if (u != null) {
1763
- const c = {};
1764
- for (const g of Object.keys(D))
1765
- c[g] = D[g];
1766
- for (const g of Object.keys(t))
1767
- c[g] = t[g];
1768
- const m = o.config;
1769
- m.customObjects = c;
1770
- const h = Object.assign({}, D);
1771
- for (const g of Object.keys(t))
1772
- D[g] = t[g];
1773
- we(o.config);
1774
- const b = u(i, o.config, t, r);
1775
- return D = Object.assign({}, h), b;
1776
- } else {
1777
- const c = Object.assign({}, D);
1778
- for (const h of Object.keys(t))
1779
- D[h] = t[h];
1780
- const m = new i(o.config);
1781
- return D = Object.assign({}, c), m;
1782
- }
1783
- }
1784
- }
1785
- function er(e, n) {
1786
- return e < n ? -1 : e > n ? 1 : 0;
1787
- }
1788
- function Br(e, n) {
1789
- return -1 * er(e, n);
1790
- }
1791
- function Pr(e) {
1792
- if (e == null)
1793
- return e;
1794
- const n = [];
1795
- for (const t of e)
1796
- n.indexOf(t) === -1 && n.push(t);
1797
- return n;
1798
- }
1799
- function Kr(e) {
1800
- if (e == null)
1801
- throw new A(`Invalid value in obj: ${JSON.stringify(e)}`);
1802
- for (const n in e)
1803
- if (e.hasOwnProperty(n))
1804
- return !1;
1805
- return !0;
1806
- }
1807
- function fe(e, n, t) {
1808
- if (t != null && e.indexOf(t) < 0)
1809
- throw new A(`${t} is not a valid ${n}. Valid values are ${e} or null/undefined.`);
1810
- }
1811
- function Rr(e, n, t = 0, s = 1 / 0) {
1812
- return Ge(t >= 0), Ge(s >= t), Array.isArray(e) && e.length >= t && e.length <= s && e.every((r) => typeof r === n);
1813
- }
1814
- function nr(e, n) {
1815
- Array.isArray(e) ? (p(e.length > 0, () => `${n} is unexpectedly an empty array.`), e.forEach((t, s) => nr(t, `element ${s + 1} of ${n}`))) : p(Number.isInteger(e) && e > 0, () => `Expected ${n} to be a positive integer, but got ${Xe(e)}.`);
1816
- }
1817
- function Xe(e) {
1818
- return e === null ? "null" : Array.isArray(e) ? "[" + e.map((n) => Xe(n)).join(",") + "]" : typeof e == "string" ? `"${e}"` : `${e}`;
1819
- }
1820
- function qr(e, n, t) {
1821
- let s = t != null ? t() : Pe(), r;
1822
- return (...a) => {
1823
- const i = t != null ? t() : Pe();
1824
- return i - s < n || (s = i, r = e(...a)), r;
1825
- };
1826
- }
1827
- function jr(e) {
1828
- return e === "relu" ? "relu" : e === "linear" ? "linear" : e === "elu" ? "elu" : null;
1829
- }
1830
- /**
1831
- * @license
1832
- * Copyright 2018 Google LLC
1833
- *
1834
- * Use of this source code is governed by an MIT-style
1835
- * license that can be found in the LICENSE file or at
1836
- * https://opensource.org/licenses/MIT.
1837
- * =============================================================================
1838
- */
1839
- const Q = /* @__PURE__ */ new Map();
1840
- function tr(e) {
1841
- fe(Zs, "DataFormat", e);
1842
- }
1843
- function Fr(e) {
1844
- fe(Xs, "InterpolationFormat", e);
1845
- }
1846
- function Gr(e) {
1847
- fe(Hs, "PaddingMode", e);
1848
- }
1849
- function Lr(e) {
1850
- fe(Qs, "PoolMode", e);
1851
- }
1852
- const ae = [], Le = "/";
1853
- function Vr(e, n) {
1854
- ae.push(e);
1855
- try {
1856
- const t = n();
1857
- return ae.pop(), t;
1858
- } catch (t) {
1859
- throw ae.pop(), t;
1860
- }
1861
- }
1862
- function sr() {
1863
- return ae.length === 0 ? "" : ae.join(Le) + Le;
1864
- }
1865
- function Cr(e) {
1866
- if (!He(e))
1867
- throw new Error("Not a valid tensor name: '" + e + "'");
1868
- return sr() + e;
1869
- }
1870
- function vr(e) {
1871
- if (!He(e))
1872
- throw new Error("Not a valid tensor name: '" + e + "'");
1873
- Q.has(e) || Q.set(e, 0);
1874
- const n = Q.get(e);
1875
- if (Q.set(e, Q.get(e) + 1), n > 0) {
1876
- const t = `${e}_${n}`;
1877
- return Q.set(t, 1), t;
1878
- } else
1879
- return e;
1880
- }
1881
- const rr = new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);
1882
- function He(e) {
1883
- return !!e.match(rr);
1884
- }
1885
- /**
1886
- * @license
1887
- * Copyright 2018 Google LLC
1888
- *
1889
- * Use of this source code is governed by an MIT-style
1890
- * license that can be found in the LICENSE file or at
1891
- * https://opensource.org/licenses/MIT.
1892
- * =============================================================================
1893
- */
1894
- function zr(e) {
1895
- return e === parseInt(e.toString(), 10);
1896
- }
1897
- function Qe(e, n, t) {
1898
- n == null && (n = 0), t == null && (t = e.length);
1899
- let s = 1;
1900
- for (let r = n; r < t; ++r)
1901
- s *= e[r];
1902
- return s;
1903
- }
1904
- function Wr(e) {
1905
- if (e.length === 0)
1906
- return Number.NaN;
1907
- let n = Number.POSITIVE_INFINITY;
1908
- for (let t = 0; t < e.length; t++) {
1909
- const s = e[t];
1910
- s < n && (n = s);
1911
- }
1912
- return n;
1913
- }
1914
- function Jr(e) {
1915
- if (e.length === 0)
1916
- return Number.NaN;
1917
- let n = Number.NEGATIVE_INFINITY;
1918
- for (let t = 0; t < e.length; t++) {
1919
- const s = e[t];
1920
- s > n && (n = s);
1921
- }
1922
- return n;
1923
- }
1924
- function Yr(e, n) {
1925
- if (n < e)
1926
- throw new A(`end (${n}) < begin (${e}) is forbidden.`);
1927
- const t = [];
1928
- for (let s = e; s < n; ++s)
1929
- t.push(s);
1930
- return t;
1931
- }
1932
- /**
1933
- * @license
1934
- * Copyright 2018 Google LLC
1935
- *
1936
- * Use of this source code is governed by an MIT-style
1937
- * license that can be found in the LICENSE file or at
1938
- * https://opensource.org/licenses/MIT.
1939
- * =============================================================================
1940
- */
1941
- let $e;
1942
- function Ur() {
1943
- return $e == null && ($e = vn().epsilon()), $e;
1944
- }
1945
- function Ae() {
1946
- return "channelsLast";
1947
- }
1948
- /**
1949
- * @license
1950
- * Copyright 2018 Google LLC
1951
- *
1952
- * Use of this source code is governed by an MIT-style
1953
- * license that can be found in the LICENSE file or at
1954
- * https://opensource.org/licenses/MIT.
1955
- * =============================================================================
1956
- */
1957
- function Zr(e, n) {
1958
- return C(e, n);
1959
- }
1960
- function or(e, n = -1) {
1961
- const t = e.shape.slice();
1962
- return n < 0 && (n = t.length + n + 1), t.splice(n, 0, 1), $(e, t);
1963
- }
1964
- function Xr(e, n) {
1965
- return K(() => {
1966
- if (e.shape.length !== 2)
1967
- throw new A(`repeat() expects a rank-2 tensor, but received a rank-${e.shape.length} tensor.`);
1968
- const t = or(e, 1);
1969
- return ar(t, [1, n, 1]);
1970
- });
1971
- }
1972
- function Hr(e) {
1973
- const n = [Qe(e.shape)];
1974
- return $(e, n);
1975
- }
1976
- function Qr(e) {
1977
- if (e.rank <= 1)
1978
- throw new A(`batchFlatten requires a minimum rank of 2. Got rank: ${e.rank}.`);
1979
- const n = [e.shape[0], Qe(e.shape, 1)];
1980
- return $(e, n);
1981
- }
1982
- function be(e, n, t) {
1983
- return K(() => {
1984
- switch (e.rank) {
1985
- case 1:
1986
- return Ee(e, n, t);
1987
- case 2:
1988
- return Je(e, [n, 0], [t, e.shape[1]]);
1989
- case 3:
1990
- return Se(e, [n, 0, 0], [t, e.shape[1], e.shape[2]]);
1991
- case 4:
1992
- return pe(e, [n, 0, 0, 0], [t, e.shape[1], e.shape[2], e.shape[3]]);
1993
- case 5:
1994
- return _(e, [n, 0, 0, 0, 0], [
1995
- t,
1996
- e.shape[1],
1997
- e.shape[2],
1998
- e.shape[3],
1999
- e.shape[4]
2000
- ]);
2001
- case 6:
2002
- return _(e, [n, 0, 0, 0, 0, 0], [
2003
- t,
2004
- e.shape[1],
2005
- e.shape[2],
2006
- e.shape[3],
2007
- e.shape[4],
2008
- e.shape[5]
2009
- ]);
2010
- default:
2011
- throw new A(`sliceAlongFirstAxis() received an unsupported tensor rank: ${e.rank}`);
2012
- }
2013
- });
2014
- }
2015
- function ke(e, n, t) {
2016
- return K(() => {
2017
- switch (e.rank) {
2018
- case 1:
2019
- return Ee(e, n, t);
2020
- case 2:
2021
- return Je(e, [0, n], [e.shape[0], t]);
2022
- case 3:
2023
- return Se(e, [0, 0, n], [e.shape[0], e.shape[1], t]);
2024
- case 4:
2025
- return pe(e, [0, 0, 0, n], [e.shape[0], e.shape[1], e.shape[2], t]);
2026
- default:
2027
- throw new A(`sliceAlongLastAxis() received an unsupported tensor rank: ${e.rank}`);
2028
- }
2029
- });
2030
- }
2031
- function eo(e, n, t, s) {
2032
- return K(() => {
2033
- switch (e.rank) {
2034
- case 1:
2035
- return Ee(e, n, t);
2036
- case 2:
2037
- switch (s) {
2038
- case 1:
2039
- return be(e, n, t);
2040
- case 2:
2041
- return ke(e, n, t);
2042
- default:
2043
- throw new A(`The axis is not within the rank of the tensor ${s}`);
2044
- }
2045
- case 3:
2046
- switch (s) {
2047
- case 1:
2048
- return be(e, n, t);
2049
- case 2:
2050
- return Se(e, [0, n, 0], [e.shape[0], t, e.shape[2]]);
2051
- case 3:
2052
- return ke(e, n, t);
2053
- default:
2054
- throw new A(`The axis is not within the rank of the tensor ${s}`);
2055
- }
2056
- case 4:
2057
- switch (s) {
2058
- case 1:
2059
- return be(e, n, t);
2060
- case 2:
2061
- return pe(e, [0, n, 0, 0], [e.shape[0], t, e.shape[2], e.shape[3]]);
2062
- case 3:
2063
- return pe(e, [0, 0, n, 0], [e.shape[0], e.shape[1], t, e.shape[3]]);
2064
- case 4:
2065
- return ke(e, n, t);
2066
- default:
2067
- throw new A(`The axis is not within the rank of the tensor ${s}`);
2068
- }
2069
- default:
2070
- throw new A(`sliceAlongLastAxis() received an unsupported tensor rank: ${e.rank}`);
2071
- }
2072
- });
2073
- }
2074
- function no(e, n = -1) {
2075
- let t;
2076
- return n < 0 && (t = e[0].rank, t !== 0 ? n = t : n = 0), n === e[0].rank && (n = -1), V(e, n);
2077
- }
2078
- function to(e, n) {
2079
- switch (e.rank) {
2080
- case 1:
2081
- return at([e, n]);
2082
- case 2:
2083
- return ct([e, n], 0);
2084
- case 3:
2085
- return lt([e, n], 0);
2086
- case 4:
2087
- return ft([e, n], 0);
2088
- default:
2089
- throw new A(`concatAlongFirstAxis() received an unsupported tensor rank: ${e.rank}`);
2090
- }
2091
- }
2092
- function ar(e, n) {
2093
- if (Array.isArray(n) || (n = [n]), e.rank !== n.length)
2094
- throw new A(`The length of input n (${n.length}) does not match the number of dimensions in input x (${e.rank})`);
2095
- return oe(e, n);
2096
- }
2097
- function so(e, n = 0, t = 1, s, r) {
2098
- return Un(e, n, t, s, r);
2099
- }
2100
- function ro(e, n, t, s) {
2101
- if (e.rank < 2 || n.rank < 2)
2102
- throw new ie(`dot requires both inputs to be rank >= 2 but got x shape = ${e.shape} and y shape = ${n.shape}`);
2103
- if (n.rank >= 3) {
2104
- const r = e.shape.slice(-1)[0], o = n.shape.slice(-2)[0];
2105
- if (r !== o)
2106
- throw new ie(`If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = ${e.shape} and y shape = ${n.shape}`);
2107
- }
2108
- if (e.rank === 2 && n.rank === 2)
2109
- return qe({
2110
- a: e,
2111
- b: n,
2112
- transposeA: !1,
2113
- transposeB: !1,
2114
- bias: s ? ye(e.rank, s, Ae()) : null,
2115
- activation: t
2116
- });
2117
- {
2118
- const r = e.shape.slice(), o = r.pop();
2119
- e = $(e, [-1, o]);
2120
- const a = n.shape.slice(), i = a.pop(), u = a.pop(), c = [...a, i], m = Array.from({ length: n.rank }, (x, w) => w === 0 ? n.rank - 2 : w <= n.rank - 2 ? w - 1 : w);
2121
- n = $(xe(n, m), [u, -1]);
2122
- const h = [...r, ...c];
2123
- return $(qe({
2124
- a: e,
2125
- b: n,
2126
- transposeA: !1,
2127
- transposeB: !1,
2128
- bias: s ? ye(e.rank, s, Ae()) : null,
2129
- activation: t
2130
- }), h);
2131
- }
2132
- }
2133
- function oo(e, n, t) {
2134
- return K(() => (Array.isArray(n) ? n = B(n, "int32") : n = C(n, "int32"), Xn(e, n, t)));
2135
- }
2136
- function ao(e) {
2137
- return I(e, e);
2138
- }
2139
- function ye(e, n, t) {
2140
- const s = n.shape;
2141
- if (n.rank !== 1 && n.rank !== e)
2142
- throw new A(`Unexpected bias dimensions: ${n.rank}; expected it to be 1 or ${e}`);
2143
- if (e === 5) {
2144
- if (t === "channelsFirst")
2145
- return s.length === 1 ? $(n, [1, s[0], 1, 1, 1]) : $(n, [1, s[3], s[0], s[1], s[2]]);
2146
- if (t === "channelsLast")
2147
- return s.length === 1 ? $(n, [1, 1, 1, 1, s[0]]) : $(n, [1].concat(s));
2148
- } else if (e === 4) {
2149
- if (t === "channelsFirst")
2150
- return s.length === 1 ? $(n, [1, s[0], 1, 1]) : $(n, [1, s[2], s[0], s[1]]);
2151
- if (t === "channelsLast")
2152
- return s.length === 1 ? $(n, [1, 1, 1, s[0]]) : $(n, [1].concat(s));
2153
- } else if (e === 3) {
2154
- if (t === "channelsFirst")
2155
- return s.length === 1 ? $(n, [1, s[0], 1]) : $(n, [1, s[1], s[0]]);
2156
- if (t === "channelsLast")
2157
- return s.length === 1 ? $(n, [1, 1, s[0]]) : $(n, [1].concat(s));
2158
- } else if (e < 3)
2159
- return n;
2160
- throw new A(`Unsupported input rank by biasAdd: ${n.rank}`);
2161
- }
2162
- function io(e, n, t) {
2163
- return K(() => (t == null && (t = Ae()), tr(t), U(e, ye(e.rank, n, t))));
2164
- }
2165
- function co(e, n = 1) {
2166
- if (n !== 1)
2167
- throw new ie(`Support for alpha values other than 1 (${n}) is not implemented yet.`);
2168
- return ze(e);
2169
- }
2170
- function uo(e) {
2171
- return K(() => L(e, U(zn(e), 1)));
2172
- }
2173
- function lo(e, n, t, s) {
2174
- return K(() => Zn(e, n, t, s));
2175
- }
2176
- function po(e) {
2177
- return K(() => {
2178
- const n = U(0.5, I(0.2, e));
2179
- return rt(n, 0, 1);
2180
- });
2181
- }
2182
- function fo(e, n, t = !1) {
2183
- return t ? e() : n();
2184
- }
2185
- export {
2186
- or as $,
2187
- Ue as A,
2188
- oe as B,
2189
- _e as C,
2190
- Ke as D,
2191
- _ as E,
2192
- Ye as F,
2193
- Qn as G,
2194
- J as H,
2195
- rt as I,
2196
- Ur as J,
2197
- jt as K,
2198
- qr as L,
2199
- Hr as M,
2200
- ie as N,
2201
- ao as O,
2202
- Ge as P,
2203
- Zr as Q,
2204
- Ze as R,
2205
- Yt as S,
2206
- Dr as T,
2207
- Pr as U,
2208
- A as V,
2209
- Br as W,
2210
- Ir as X,
2211
- Kr as Y,
2212
- B as Z,
2213
- be as _,
2214
- ns as a,
2215
- oo as a0,
2216
- Yr as a1,
2217
- Er as a2,
2218
- co as a3,
2219
- Re as a4,
2220
- po as a5,
2221
- uo as a6,
2222
- Et as a7,
2223
- Pt as a8,
2224
- ze as a9,
2225
- Jr as aa,
2226
- zr as ab,
2227
- Rr as ac,
2228
- io as ad,
2229
- eo as ae,
2230
- Fr as af,
2231
- Ar as ag,
2232
- nr as ah,
2233
- jr as ai,
2234
- Gr as aj,
2235
- Ae as ak,
2236
- ar as al,
2237
- Wr as am,
2238
- to as an,
2239
- fo as ao,
2240
- lo as ap,
2241
- no as aq,
2242
- Qr as ar,
2243
- Xr as as,
2244
- Lr as at,
2245
- _r as au,
2246
- es as b,
2247
- fe as c,
2248
- ro as d,
2249
- kt as e,
2250
- tr as f,
2251
- Qt as g,
2252
- Qe as h,
2253
- Or as i,
2254
- Mr as j,
2255
- Cr as k,
2256
- yr as l,
2257
- vr as m,
2258
- Sr as n,
2259
- Tr as o,
2260
- Vr as p,
2261
- Zt as q,
2262
- so as r,
2263
- ts as s,
2264
- Nr as t,
2265
- Ie as u,
2266
- Mt as v,
2267
- ee as w,
2268
- At as x,
2269
- We as y,
2270
- xe as z
2271
- };