@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.
- package/dist/BaseLayer-BhrMN8JO.js +135 -0
- package/dist/Generator.js +44 -41
- package/dist/NanoGPTModel.d.ts +12 -16
- package/dist/NanoGPTModel.js +128 -138
- package/dist/{Reshape-CiAY8ltP.js → Reshape-BE5rA4rT.js} +8 -8
- package/dist/TeachableLLM.js +8 -5
- package/dist/{TiedEmbedding-DznFwzcB.js → TiedEmbedding-DsDRvLB0.js} +751 -768
- package/dist/{axis_util-QP0LdI1v.js → axis_util-97KkkyRQ.js} +1 -1
- package/dist/broadcast_to-CMlkG8NS.js +44 -0
- package/dist/{concat-DvWM7HGZ.js → concat-Cxbo2sOz.js} +3 -3
- package/dist/{dropout-DFEXTPV0.js → dropout-kbDY39Ci.js} +1 -1
- package/dist/{gather-C5D8PxwA.js → gather-Bxe1Qip8.js} +4 -4
- package/dist/{gpgpu_math-CUzjlO9A.js → gpgpu_math-C0zyxKFi.js} +1 -1
- package/dist/{index--6vO-cOz.js → index-iNhkcAEQ.js} +82 -82
- package/dist/{kernel_funcs_utils-C6YBCuOt.js → kernel_funcs_utils-C4eIk4fE.js} +20 -20
- package/dist/layers/BaseLayer.d.ts +28 -4
- package/dist/layers/BaseLayer.js +3 -16
- package/dist/layers/CausalSelfAttention.d.ts +22 -24
- package/dist/layers/CausalSelfAttention.js +73 -127
- package/dist/layers/MLP.d.ts +8 -15
- package/dist/layers/MLP.js +43 -81
- package/dist/layers/RMSNorm.d.ts +5 -11
- package/dist/layers/RMSNorm.js +13 -29
- package/dist/layers/RoPECache.js +14 -12
- package/dist/layers/TiedEmbedding.d.ts +6 -16
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.d.ts +12 -16
- package/dist/layers/TransformerBlock.js +20 -41
- package/dist/{log_sum_exp-CiEy1aUe.js → log_sum_exp-CkumwesB.js} +11 -11
- package/dist/main.js +22 -19
- package/dist/{mat_mul-BEHRPMh0.js → mat_mul-D0SifYfJ.js} +3 -3
- package/dist/{max-BUShNgfh.js → max-CYaAjEEp.js} +3 -3
- package/dist/{moments-DYOHXoRV.js → moments-B06NlR_V.js} +6 -6
- package/dist/{norm-DSva3hI3.js → norm-D3676xIo.js} +7 -7
- package/dist/{ones-D6kB8bdY.js → ones-BIeFnPHR.js} +2 -2
- package/dist/ops/appendCache.js +4 -4
- package/dist/ops/attentionMask.d.ts +1 -1
- package/dist/ops/attentionMask.js +4 -4
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +14 -15
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +5 -5
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.js +1 -1
- package/dist/ops/cpu/matMulMul.d.ts +1 -0
- package/dist/ops/cpu/matMulMul.js +17 -0
- package/dist/ops/cpu/mulDropout.js +1 -1
- package/dist/ops/cpu/normRMS.d.ts +1 -0
- package/dist/ops/cpu/normRMS.js +39 -0
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +8 -8
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +1 -1
- package/dist/ops/grads/attentionMask.js +13 -9
- package/dist/ops/grads/fusedSoftmax.js +12 -9
- package/dist/ops/grads/gelu.js +1 -1
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/normRMS.d.ts +2 -0
- package/dist/ops/grads/normRMS.js +20 -0
- package/dist/ops/grads/qkv.js +19 -9
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.d.ts +2 -0
- package/dist/ops/matMulMul.js +9 -0
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/normRMS.d.ts +2 -0
- package/dist/ops/normRMS.js +10 -0
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +13 -12
- package/dist/ops/webgl/fusedSoftmax.js +43 -40
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/matMulGelu.d.ts +3 -2
- package/dist/ops/webgl/matMulGelu.js +77 -75
- package/dist/ops/webgl/matMulMul.d.ts +14 -0
- package/dist/ops/webgl/matMulMul.js +28 -0
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.d.ts +1 -0
- package/dist/ops/webgl/normRMS.js +86 -0
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/ops-ObfXLHYQ.js +1269 -0
- package/dist/{range-C_vpUjBu.js → range-BsFU-SNG.js} +1 -1
- package/dist/{reshape-z51Eu-re.js → reshape-DxTPgnwL.js} +3 -3
- package/dist/{sin-H567uayl.js → sin-BOX-JVAj.js} +5 -5
- package/dist/slice_util-D-kaD4ZV.js +49 -0
- package/dist/{softmax-Dsxflvdl.js → softmax-BjsptB07.js} +2 -2
- package/dist/{split-B_k_jwud.js → split-BCbrzthj.js} +4 -4
- package/dist/{stack-CmqSdsfs.js → stack--cqr9Dgc.js} +2 -2
- package/dist/{sum-DdkDf2MG.js → sum-B_92TaHD.js} +5 -5
- package/dist/{tensor-BGYi41cj.js → tensor-CfiPXsW4.js} +1 -1
- package/dist/{tensor2d-DUr_htjt.js → tensor2d-tSxWdFMH.js} +1 -1
- package/dist/tfjs_backend-NucKez4s.js +1010 -0
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +44 -44
- package/dist/training/Evaluator.js +6 -6
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +7 -7
- package/dist/training/sparseCrossEntropy.js +4 -4
- package/dist/utilities/dummy.js +10 -10
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/save.js +10 -8
- package/dist/utilities/weights.js +2 -2
- package/dist/{zeros-8xl-W2DC.js → zeros-NMYTayy7.js} +3 -3
- package/package.json +1 -1
- package/dist/slice_util-BdhYwFY_.js +0 -90
- package/dist/tfjs_backend-DuKis_xG.js +0 -2271
- package/dist/variable-BJTZ3jOy.js +0 -23
|
@@ -0,0 +1,1269 @@
|
|
|
1
|
+
import { o as h, i as l, E as f, aA as hn, k as p, aB as fn, N as w, aC as dn, aD as bn, aE as gn, T as $n, ah as xn, q as j, aF as kn, aG as yn, aH as In, aI as _n, aJ as En, aK as Nn, aL as Mn, y as D, aM as An, aN as Tn, aO as Sn, aP as wn, H as zn, I as Bn, J as qn, aQ as Gn, t as Kn, aR as J, aS as Rn, aT as Dn, aU as Pn, aV as Vn, aW as vn, aX as jn, f as Fn, aY as Wn, aZ as On, b as k, a9 as Z, ai as K, g as Yn, s as S, a_ as Cn, x as L, a as Jn } from "./index-iNhkcAEQ.js";
|
|
2
|
+
import { r as _ } from "./reshape-DxTPgnwL.js";
|
|
3
|
+
import { s as un } from "./split-BCbrzthj.js";
|
|
4
|
+
import { s as q } from "./sum-B_92TaHD.js";
|
|
5
|
+
import { b as X } from "./broadcast_to-CMlkG8NS.js";
|
|
6
|
+
import { r as O } from "./range-BsFU-SNG.js";
|
|
7
|
+
import { t as Ln } from "./tensor-CfiPXsW4.js";
|
|
8
|
+
import { s as Y } from "./stack--cqr9Dgc.js";
|
|
9
|
+
import { c as Xn, z as Hn } from "./zeros-NMYTayy7.js";
|
|
10
|
+
import { n as ln } from "./norm-D3676xIo.js";
|
|
11
|
+
import { c as H } from "./concat-Cxbo2sOz.js";
|
|
12
|
+
import { m as T } from "./mat_mul-D0SifYfJ.js";
|
|
13
|
+
import { t as Q } from "./tensor2d-tSxWdFMH.js";
|
|
14
|
+
/**
|
|
15
|
+
* @license
|
|
16
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
17
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
* you may not use this file except in compliance with the License.
|
|
19
|
+
* You may obtain a copy of the License at
|
|
20
|
+
*
|
|
21
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
25
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
|
+
* See the License for the specific language governing permissions and
|
|
27
|
+
* limitations under the License.
|
|
28
|
+
* =============================================================================
|
|
29
|
+
*/
|
|
30
|
+
function Qn(r, t, n) {
|
|
31
|
+
const e = l(r, "x", "slice", "string_or_numeric");
|
|
32
|
+
if (e.rank === 0)
|
|
33
|
+
throw new Error("Slicing scalar is not possible");
|
|
34
|
+
const s = { x: e }, a = { begin: t, size: n };
|
|
35
|
+
return f.runKernel(hn, s, a);
|
|
36
|
+
}
|
|
37
|
+
const N = /* @__PURE__ */ h({ slice_: Qn });
|
|
38
|
+
/**
|
|
39
|
+
* @license
|
|
40
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
41
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42
|
+
* you may not use this file except in compliance with the License.
|
|
43
|
+
* You may obtain a copy of the License at
|
|
44
|
+
*
|
|
45
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
46
|
+
*
|
|
47
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
48
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
49
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
50
|
+
* See the License for the specific language governing permissions and
|
|
51
|
+
* limitations under the License.
|
|
52
|
+
* =============================================================================
|
|
53
|
+
*/
|
|
54
|
+
function Zn(r, t, n) {
|
|
55
|
+
const e = l(r, "x", "bincount"), s = l(t, "weights", "bincount");
|
|
56
|
+
p(e.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${e.dtype}`), p(n >= 0, () => `size must be non-negative, but got ${n}.`), p(s.size === e.size || s.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${e.shape}, weights shape: ${s.shape}.`);
|
|
57
|
+
const a = { x: e, weights: s }, o = { size: n };
|
|
58
|
+
return f.runKernel(fn, a, o);
|
|
59
|
+
}
|
|
60
|
+
const Un = /* @__PURE__ */ h({ bincount_: Zn });
|
|
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 ne(r, t, n) {
|
|
78
|
+
const e = l(t, "a", "where"), s = l(n, "b", "where"), a = l(r, "condition", "where", "bool"), o = w(w(a.shape, e.shape), s.shape), i = X(a, o), u = X(e, o), c = X(s, o), d = {
|
|
79
|
+
condition: i,
|
|
80
|
+
t: u,
|
|
81
|
+
e: c
|
|
82
|
+
};
|
|
83
|
+
return f.runKernel(dn, d);
|
|
84
|
+
}
|
|
85
|
+
const R = /* @__PURE__ */ h({ where_: ne });
|
|
86
|
+
/**
|
|
87
|
+
* @license
|
|
88
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
89
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
90
|
+
* you may not use this file except in compliance with the License.
|
|
91
|
+
* You may obtain a copy of the License at
|
|
92
|
+
*
|
|
93
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
94
|
+
*
|
|
95
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
96
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
97
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
98
|
+
* See the License for the specific language governing permissions and
|
|
99
|
+
* limitations under the License.
|
|
100
|
+
* =============================================================================
|
|
101
|
+
*/
|
|
102
|
+
function ee(r, ...t) {
|
|
103
|
+
const n = t.map((s, a) => l(s, `tensors${a}`, "einsum")), e = { equation: r };
|
|
104
|
+
return f.runKernel(bn, n, e);
|
|
105
|
+
}
|
|
106
|
+
const v = /* @__PURE__ */ h({ einsum_: ee });
|
|
107
|
+
/**
|
|
108
|
+
* @license
|
|
109
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
110
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
111
|
+
* you may not use this file except in compliance with the License.
|
|
112
|
+
* You may obtain a copy of the License at
|
|
113
|
+
*
|
|
114
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
115
|
+
*
|
|
116
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
117
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
118
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
119
|
+
* See the License for the specific language governing permissions and
|
|
120
|
+
* limitations under the License.
|
|
121
|
+
* =============================================================================
|
|
122
|
+
*/
|
|
123
|
+
function se(r, t = 0) {
|
|
124
|
+
const n = l(r, "x", "expandDims", "string_or_numeric");
|
|
125
|
+
p(t <= n.rank, () => "Axis must be <= rank of the tensor");
|
|
126
|
+
const e = { input: n }, s = { dim: t };
|
|
127
|
+
return f.runKernel(gn, e, s);
|
|
128
|
+
}
|
|
129
|
+
const G = /* @__PURE__ */ h({ expandDims_: se });
|
|
130
|
+
/**
|
|
131
|
+
* @license
|
|
132
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
133
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
134
|
+
* you may not use this file except in compliance with the License.
|
|
135
|
+
* You may obtain a copy of the License at
|
|
136
|
+
*
|
|
137
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
138
|
+
*
|
|
139
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
140
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
141
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
142
|
+
* See the License for the specific language governing permissions and
|
|
143
|
+
* limitations under the License.
|
|
144
|
+
* =============================================================================
|
|
145
|
+
*/
|
|
146
|
+
function te(r, t) {
|
|
147
|
+
const n = l(r, "x", "tile", "string_or_numeric");
|
|
148
|
+
p(n.rank === t.length, () => `Error in transpose: rank of input ${n.rank} must match length of reps ${t}.`);
|
|
149
|
+
const e = { x: n }, s = { reps: t };
|
|
150
|
+
return f.runKernel($n, e, s);
|
|
151
|
+
}
|
|
152
|
+
const W = /* @__PURE__ */ h({ tile_: te });
|
|
153
|
+
/**
|
|
154
|
+
* @license
|
|
155
|
+
* Copyright 2020 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 re(r, t, n, e = "float32") {
|
|
170
|
+
t == null && (t = r);
|
|
171
|
+
const s = xn([r, t], e), a = r <= t ? r : t;
|
|
172
|
+
for (let i = 0; i < a; ++i)
|
|
173
|
+
s.set(1, i, i);
|
|
174
|
+
const o = _(s.toTensor(), [r, t]);
|
|
175
|
+
if (n == null)
|
|
176
|
+
return o;
|
|
177
|
+
if (n.length === 1)
|
|
178
|
+
return W(G(o, 0), [n[0], 1, 1]);
|
|
179
|
+
if (n.length === 2)
|
|
180
|
+
return W(G(G(o, 0), 0), [n[0], n[1], 1, 1]);
|
|
181
|
+
if (n.length === 3)
|
|
182
|
+
return W(G(G(G(o, 0), 0), 0), [
|
|
183
|
+
n[0],
|
|
184
|
+
n[1],
|
|
185
|
+
n[2],
|
|
186
|
+
1,
|
|
187
|
+
1
|
|
188
|
+
]);
|
|
189
|
+
throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${n.length}D.`);
|
|
190
|
+
}
|
|
191
|
+
const ae = /* @__PURE__ */ h({ eye_: re });
|
|
192
|
+
/**
|
|
193
|
+
* @license
|
|
194
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
195
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
196
|
+
* you may not use this file except in compliance with the License.
|
|
197
|
+
* You may obtain a copy of the License at
|
|
198
|
+
*
|
|
199
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
200
|
+
*
|
|
201
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
202
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
203
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
204
|
+
* See the License for the specific language governing permissions and
|
|
205
|
+
* limitations under the License.
|
|
206
|
+
* =============================================================================
|
|
207
|
+
*/
|
|
208
|
+
function oe(r, t) {
|
|
209
|
+
let n = l(r, "a", "greater", "string_or_numeric"), e = l(t, "b", "greater", "string_or_numeric");
|
|
210
|
+
[n, e] = j(n, e), w(n.shape, e.shape);
|
|
211
|
+
const s = { a: n, b: e };
|
|
212
|
+
return f.runKernel(kn, s);
|
|
213
|
+
}
|
|
214
|
+
const U = /* @__PURE__ */ h({ greater_: oe });
|
|
215
|
+
/**
|
|
216
|
+
* @license
|
|
217
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
218
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
219
|
+
* you may not use this file except in compliance with the License.
|
|
220
|
+
* You may obtain a copy of the License at
|
|
221
|
+
*
|
|
222
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
223
|
+
*
|
|
224
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
225
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
226
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
227
|
+
* See the License for the specific language governing permissions and
|
|
228
|
+
* limitations under the License.
|
|
229
|
+
* =============================================================================
|
|
230
|
+
*/
|
|
231
|
+
function ie(r, t) {
|
|
232
|
+
let n = l(r, "a", "greaterEqual", "string_or_numeric"), e = l(t, "b", "greaterEqual", "string_or_numeric");
|
|
233
|
+
[n, e] = j(n, e), w(n.shape, e.shape);
|
|
234
|
+
const s = { a: n, b: e };
|
|
235
|
+
return f.runKernel(yn, s);
|
|
236
|
+
}
|
|
237
|
+
const ce = /* @__PURE__ */ h({ greaterEqual_: ie });
|
|
238
|
+
/**
|
|
239
|
+
* @license
|
|
240
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
241
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
242
|
+
* you may not use this file except in compliance with the License.
|
|
243
|
+
* You may obtain a copy of the License at
|
|
244
|
+
*
|
|
245
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
246
|
+
*
|
|
247
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
248
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
249
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
250
|
+
* See the License for the specific language governing permissions and
|
|
251
|
+
* limitations under the License.
|
|
252
|
+
* =============================================================================
|
|
253
|
+
*/
|
|
254
|
+
function ue(r) {
|
|
255
|
+
const n = { input: l(r, "input", "imag") };
|
|
256
|
+
return f.runKernel(In, n);
|
|
257
|
+
}
|
|
258
|
+
const le = /* @__PURE__ */ h({ imag_: ue });
|
|
259
|
+
/**
|
|
260
|
+
* @license
|
|
261
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
262
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
263
|
+
* you may not use this file except in compliance with the License.
|
|
264
|
+
* You may obtain a copy of the License at
|
|
265
|
+
*
|
|
266
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
267
|
+
*
|
|
268
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
269
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
270
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
271
|
+
* See the License for the specific language governing permissions and
|
|
272
|
+
* limitations under the License.
|
|
273
|
+
* =============================================================================
|
|
274
|
+
*/
|
|
275
|
+
function pe(r, t) {
|
|
276
|
+
let n = l(r, "a", "less", "string_or_numeric"), e = l(t, "b", "less", "string_or_numeric");
|
|
277
|
+
[n, e] = j(n, e), w(n.shape, e.shape);
|
|
278
|
+
const s = { a: n, b: e };
|
|
279
|
+
return f.runKernel(_n, s);
|
|
280
|
+
}
|
|
281
|
+
const tn = /* @__PURE__ */ h({ less_: pe });
|
|
282
|
+
/**
|
|
283
|
+
* @license
|
|
284
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
285
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
286
|
+
* you may not use this file except in compliance with the License.
|
|
287
|
+
* You may obtain a copy of the License at
|
|
288
|
+
*
|
|
289
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
290
|
+
*
|
|
291
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
292
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
293
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
294
|
+
* See the License for the specific language governing permissions and
|
|
295
|
+
* limitations under the License.
|
|
296
|
+
* =============================================================================
|
|
297
|
+
*/
|
|
298
|
+
function me(r, t) {
|
|
299
|
+
let n = l(r, "a", "lessEqual", "string_or_numeric"), e = l(t, "b", "lessEqual", "string_or_numeric");
|
|
300
|
+
[n, e] = j(n, e), w(n.shape, e.shape);
|
|
301
|
+
const s = { a: n, b: e };
|
|
302
|
+
return f.runKernel(En, s);
|
|
303
|
+
}
|
|
304
|
+
const pn = /* @__PURE__ */ h({ lessEqual_: me });
|
|
305
|
+
/**
|
|
306
|
+
* @license
|
|
307
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
308
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
309
|
+
* you may not use this file except in compliance with the License.
|
|
310
|
+
* You may obtain a copy of the License at
|
|
311
|
+
*
|
|
312
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
313
|
+
*
|
|
314
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
315
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
316
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
317
|
+
* See the License for the specific language governing permissions and
|
|
318
|
+
* limitations under the License.
|
|
319
|
+
* =============================================================================
|
|
320
|
+
*/
|
|
321
|
+
function he(r) {
|
|
322
|
+
const n = { x: l(r, "x", "neg") };
|
|
323
|
+
return f.runKernel(Nn, n);
|
|
324
|
+
}
|
|
325
|
+
const nn = /* @__PURE__ */ h({ neg_: he });
|
|
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 fe(r, t) {
|
|
343
|
+
const n = l(r, "a", "logicalAnd", "bool"), e = l(t, "b", "logicalAnd", "bool");
|
|
344
|
+
w(n.shape, e.shape);
|
|
345
|
+
const s = { a: n, b: e };
|
|
346
|
+
return f.runKernel(Mn, s);
|
|
347
|
+
}
|
|
348
|
+
const de = /* @__PURE__ */ h({ logicalAnd_: fe });
|
|
349
|
+
/**
|
|
350
|
+
* @license
|
|
351
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
352
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
353
|
+
* you may not use this file except in compliance with the License.
|
|
354
|
+
* You may obtain a copy of the License at
|
|
355
|
+
*
|
|
356
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
357
|
+
*
|
|
358
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
359
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
360
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
361
|
+
* See the License for the specific language governing permissions and
|
|
362
|
+
* limitations under the License.
|
|
363
|
+
* =============================================================================
|
|
364
|
+
*/
|
|
365
|
+
function be(r, t) {
|
|
366
|
+
let n = l(r, "a", "minimum"), e = l(t, "b", "minimum");
|
|
367
|
+
[n, e] = j(n, e), n.dtype === "bool" && (n = D(n, "int32"), e = D(e, "int32")), w(n.shape, e.shape);
|
|
368
|
+
const s = { a: n, b: e };
|
|
369
|
+
return f.runKernel(An, s);
|
|
370
|
+
}
|
|
371
|
+
const rn = /* @__PURE__ */ h({ minimum_: be });
|
|
372
|
+
/**
|
|
373
|
+
* @license
|
|
374
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
375
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
376
|
+
* you may not use this file except in compliance with the License.
|
|
377
|
+
* You may obtain a copy of the License at
|
|
378
|
+
*
|
|
379
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
380
|
+
*
|
|
381
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
382
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
383
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
384
|
+
* See the License for the specific language governing permissions and
|
|
385
|
+
* limitations under the License.
|
|
386
|
+
* =============================================================================
|
|
387
|
+
*/
|
|
388
|
+
function ge(r) {
|
|
389
|
+
const n = { input: l(r, "input", "real") };
|
|
390
|
+
return f.runKernel(Tn, n);
|
|
391
|
+
}
|
|
392
|
+
const $e = /* @__PURE__ */ h({ real_: ge });
|
|
393
|
+
/**
|
|
394
|
+
* @license
|
|
395
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
396
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
397
|
+
* you may not use this file except in compliance with the License.
|
|
398
|
+
* You may obtain a copy of the License at
|
|
399
|
+
*
|
|
400
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
401
|
+
*
|
|
402
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
403
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
404
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
405
|
+
* See the License for the specific language governing permissions and
|
|
406
|
+
* limitations under the License.
|
|
407
|
+
* =============================================================================
|
|
408
|
+
*/
|
|
409
|
+
function xe(r) {
|
|
410
|
+
const n = { x: l(r, "x", "round") };
|
|
411
|
+
return f.runKernel(Sn, n);
|
|
412
|
+
}
|
|
413
|
+
const ke = /* @__PURE__ */ h({ round_: xe });
|
|
414
|
+
/**
|
|
415
|
+
* @license
|
|
416
|
+
* Copyright 2020 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 ye(r, t) {
|
|
431
|
+
const n = l(r, "x", "squeeze", "string_or_numeric");
|
|
432
|
+
return _(n, wn(n.shape, t).newShape);
|
|
433
|
+
}
|
|
434
|
+
const Ie = /* @__PURE__ */ h({ squeeze_: ye });
|
|
435
|
+
/**
|
|
436
|
+
* @license
|
|
437
|
+
* Copyright 2018 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 M(r, t) {
|
|
452
|
+
zn(r);
|
|
453
|
+
const n = Bn(r, t);
|
|
454
|
+
if (n.length !== 1)
|
|
455
|
+
throw new Error("tensor1d() requires values to be a flat/TypedArray");
|
|
456
|
+
return qn(r, null, n, t);
|
|
457
|
+
}
|
|
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 _e(r, t = 0) {
|
|
475
|
+
const n = l(r, "x", "unstack", "string_or_numeric");
|
|
476
|
+
p(t >= -n.shape.length && t < n.shape.length, () => `Axis = ${t} is not in [-${n.shape.length}, ${n.shape.length})`);
|
|
477
|
+
const e = { value: n }, s = { axis: t };
|
|
478
|
+
return f.runKernel(Gn, e, s);
|
|
479
|
+
}
|
|
480
|
+
const mn = /* @__PURE__ */ h({ unstack_: _e });
|
|
481
|
+
/**
|
|
482
|
+
* @license
|
|
483
|
+
* Copyright 2018 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 Ee(r, t, n) {
|
|
498
|
+
const e = l(r, "x", "transpose");
|
|
499
|
+
if (t == null && (t = e.shape.map((o, i) => i).reverse()), p(e.rank === t.length, () => `Error in transpose: rank of input ${e.rank} must match length of perm ${t}.`), t.forEach((o) => {
|
|
500
|
+
p(o >= 0 && o < e.rank, () => `All entries in 'perm' must be between 0 and ${e.rank - 1} but got ${t}`);
|
|
501
|
+
}), e.rank <= 1)
|
|
502
|
+
return e.clone();
|
|
503
|
+
const s = { x: e }, a = { perm: t };
|
|
504
|
+
return e.dtype === "complex64" ? Kn(() => {
|
|
505
|
+
let o = $e(e), i = le(e);
|
|
506
|
+
return o = f.runKernel(J, { x: o }, a), i = f.runKernel(J, { x: i }, a), n && (i = nn(i)), Xn(o, i);
|
|
507
|
+
}) : f.runKernel(J, s, a);
|
|
508
|
+
}
|
|
509
|
+
const an = /* @__PURE__ */ h({ transpose_: Ee });
|
|
510
|
+
/**
|
|
511
|
+
* @license
|
|
512
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
513
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
514
|
+
* you may not use this file except in compliance with the License.
|
|
515
|
+
* You may obtain a copy of the License at
|
|
516
|
+
*
|
|
517
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
518
|
+
*
|
|
519
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
520
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
521
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
522
|
+
* See the License for the specific language governing permissions and
|
|
523
|
+
* limitations under the License.
|
|
524
|
+
* =============================================================================
|
|
525
|
+
*/
|
|
526
|
+
function Ne(r, t, n, e, s = "bilinear", a = 0) {
|
|
527
|
+
const o = l(r, "image", "cropAndResize"), i = l(t, "boxes", "cropAndResize", "float32"), u = l(n, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
|
|
528
|
+
p(o.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${o.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(e.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${e.length}.`), p(e[0] >= 1 && e[1] >= 1, () => `cropSize must be atleast [1,1], but was ${e}`), p(s === "bilinear" || s === "nearest", () => `method must be bilinear or nearest, but was ${s}`);
|
|
529
|
+
const d = { image: o, boxes: i, boxInd: u }, m = { method: s, extrapolationValue: a, cropSize: e };
|
|
530
|
+
return f.runKernel(Rn, d, m);
|
|
531
|
+
}
|
|
532
|
+
const Me = /* @__PURE__ */ h({ cropAndResize_: Ne });
|
|
533
|
+
/**
|
|
534
|
+
* @license
|
|
535
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
536
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
537
|
+
* you may not use this file except in compliance with the License.
|
|
538
|
+
* You may obtain a copy of the License at
|
|
539
|
+
*
|
|
540
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
541
|
+
*
|
|
542
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
543
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
544
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
545
|
+
* See the License for the specific language governing permissions and
|
|
546
|
+
* limitations under the License.
|
|
547
|
+
* =============================================================================
|
|
548
|
+
*/
|
|
549
|
+
function Ae(r) {
|
|
550
|
+
const t = l(r, "image", "flipLeftRight", "float32");
|
|
551
|
+
p(t.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${t.rank}.`);
|
|
552
|
+
const n = { image: t };
|
|
553
|
+
return f.runKernel(Dn, n, {});
|
|
554
|
+
}
|
|
555
|
+
const Te = /* @__PURE__ */ h({ flipLeftRight_: Ae });
|
|
556
|
+
/**
|
|
557
|
+
* @license
|
|
558
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
559
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
560
|
+
* you may not use this file except in compliance with the License.
|
|
561
|
+
* You may obtain a copy of the License at
|
|
562
|
+
*
|
|
563
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
564
|
+
*
|
|
565
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
566
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
567
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
568
|
+
* See the License for the specific language governing permissions and
|
|
569
|
+
* limitations under the License.
|
|
570
|
+
* =============================================================================
|
|
571
|
+
*/
|
|
572
|
+
function Se(r) {
|
|
573
|
+
const t = l(r, "image", "grayscaleToRGB"), n = t.rank - 1, e = t.shape[n];
|
|
574
|
+
p(t.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${t.rank}.`), p(e === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${e}.`);
|
|
575
|
+
const s = new Array(t.rank);
|
|
576
|
+
return s.fill(1, 0, n), s[n] = 3, W(t, s);
|
|
577
|
+
}
|
|
578
|
+
const we = /* @__PURE__ */ h({ grayscaleToRGB_: Se });
|
|
579
|
+
/**
|
|
580
|
+
* @license
|
|
581
|
+
* Copyright 2023 Google LLC.
|
|
582
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
583
|
+
* you may not use this file except in compliance with the License.
|
|
584
|
+
* You may obtain a copy of the License at
|
|
585
|
+
*
|
|
586
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
587
|
+
*
|
|
588
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
589
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
590
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
591
|
+
* See the License for the specific language governing permissions and
|
|
592
|
+
* limitations under the License.
|
|
593
|
+
* =============================================================================
|
|
594
|
+
*/
|
|
595
|
+
function ze(r) {
|
|
596
|
+
const t = l(r, "image", "RGBToGrayscale"), n = t.rank - 1, e = t.shape[n];
|
|
597
|
+
p(t.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${t.rank}.`), p(e === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${e}.`);
|
|
598
|
+
const s = t.dtype, a = D(t, "float32"), o = M([0.2989, 0.587, 0.114]);
|
|
599
|
+
let i;
|
|
600
|
+
switch (t.rank) {
|
|
601
|
+
case 2:
|
|
602
|
+
i = v("ij,j->i", a, o);
|
|
603
|
+
break;
|
|
604
|
+
case 3:
|
|
605
|
+
i = v("ijk,k->ij", a, o);
|
|
606
|
+
break;
|
|
607
|
+
case 4:
|
|
608
|
+
i = v("ijkl,l->ijk", a, o);
|
|
609
|
+
break;
|
|
610
|
+
case 5:
|
|
611
|
+
i = v("ijklm,m->ijkl", a, o);
|
|
612
|
+
break;
|
|
613
|
+
case 6:
|
|
614
|
+
i = v("ijklmn,n->ijklm", a, o);
|
|
615
|
+
break;
|
|
616
|
+
default:
|
|
617
|
+
throw new Error("Not a valid tensor rank.");
|
|
618
|
+
}
|
|
619
|
+
return i = G(i, -1), D(i, s);
|
|
620
|
+
}
|
|
621
|
+
const Be = /* @__PURE__ */ h({ rgbToGrayscale_: ze });
|
|
622
|
+
/**
|
|
623
|
+
* @license
|
|
624
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
625
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
626
|
+
* you may not use this file except in compliance with the License.
|
|
627
|
+
* You may obtain a copy of the License at
|
|
628
|
+
*
|
|
629
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
630
|
+
*
|
|
631
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
632
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
633
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
634
|
+
* See the License for the specific language governing permissions and
|
|
635
|
+
* limitations under the License.
|
|
636
|
+
* =============================================================================
|
|
637
|
+
*/
|
|
638
|
+
function qe(r, t, n = 0, e = 0.5) {
|
|
639
|
+
const s = l(r, "image", "rotateWithOffset", "float32");
|
|
640
|
+
p(s.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${s.rank}.`);
|
|
641
|
+
const a = { image: s }, o = { radians: t, fillValue: n, center: e };
|
|
642
|
+
return f.runKernel(Pn, a, o);
|
|
643
|
+
}
|
|
644
|
+
const Ge = /* @__PURE__ */ h({ rotateWithOffset_: qe });
|
|
645
|
+
/**
|
|
646
|
+
* @license
|
|
647
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
648
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
649
|
+
* you may not use this file except in compliance with the License.
|
|
650
|
+
* You may obtain a copy of the License at
|
|
651
|
+
*
|
|
652
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
653
|
+
*
|
|
654
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
655
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
656
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
657
|
+
* See the License for the specific language governing permissions and
|
|
658
|
+
* limitations under the License.
|
|
659
|
+
* =============================================================================
|
|
660
|
+
*/
|
|
661
|
+
function P(r, t, n, e, s, a) {
|
|
662
|
+
e == null && (e = 0.5), s == null && (s = Number.NEGATIVE_INFINITY), a == null && (a = 0);
|
|
663
|
+
const o = r.shape[0];
|
|
664
|
+
return n = Math.min(n, o), p(0 <= e && e <= 1, () => `iouThreshold must be in [0, 1], but was '${e}'`), p(r.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${r.rank}'`), p(r.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${r.shape[1]}`), p(t.rank === 1, () => "scores must be a 1D tensor"), p(t.shape[0] === o, () => `scores has incompatible shape with boxes. Expected ${o}, but was ${t.shape[0]}`), p(0 <= a && a <= 1, () => `softNmsSigma must be in [0, 1], but was '${a}'`), { maxOutputSize: n, iouThreshold: e, scoreThreshold: s, softNmsSigma: a };
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* @license
|
|
668
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
669
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
670
|
+
* you may not use this file except in compliance with the License.
|
|
671
|
+
* You may obtain a copy of the License at
|
|
672
|
+
*
|
|
673
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
674
|
+
*
|
|
675
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
676
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
677
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
678
|
+
* See the License for the specific language governing permissions and
|
|
679
|
+
* limitations under the License.
|
|
680
|
+
* =============================================================================
|
|
681
|
+
*/
|
|
682
|
+
function Ke(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY) {
|
|
683
|
+
const a = l(r, "boxes", "nonMaxSuppression", "float32"), o = l(t, "scores", "nonMaxSuppression", "float32"), i = P(a, o, n, e, s);
|
|
684
|
+
n = i.maxOutputSize, e = i.iouThreshold, s = i.scoreThreshold;
|
|
685
|
+
const u = { maxOutputSize: n, iouThreshold: e, scoreThreshold: s };
|
|
686
|
+
return f.runKernel(Vn, { boxes: a, scores: o }, u);
|
|
687
|
+
}
|
|
688
|
+
const Re = /* @__PURE__ */ h({ nonMaxSuppression_: Ke });
|
|
689
|
+
/**
|
|
690
|
+
* @license
|
|
691
|
+
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
692
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
693
|
+
* you may not use this file except in compliance with the License.
|
|
694
|
+
* You may obtain a copy of the License at
|
|
695
|
+
*
|
|
696
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
697
|
+
*
|
|
698
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
699
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
700
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
701
|
+
* See the License for the specific language governing permissions and
|
|
702
|
+
* limitations under the License.
|
|
703
|
+
* =============================================================================
|
|
704
|
+
*/
|
|
705
|
+
function De(r, t, n) {
|
|
706
|
+
const e = Pe(r, t, n), s = e < 0 ? -(e + 1) : e;
|
|
707
|
+
r.splice(s, 0, t);
|
|
708
|
+
}
|
|
709
|
+
function Pe(r, t, n) {
|
|
710
|
+
return ve(r, t, n || Ve);
|
|
711
|
+
}
|
|
712
|
+
function Ve(r, t) {
|
|
713
|
+
return r > t ? 1 : r < t ? -1 : 0;
|
|
714
|
+
}
|
|
715
|
+
function ve(r, t, n) {
|
|
716
|
+
let e = 0, s = r.length, a = 0, o = !1;
|
|
717
|
+
for (; e < s; ) {
|
|
718
|
+
a = e + (s - e >>> 1);
|
|
719
|
+
const i = n(t, r[a]);
|
|
720
|
+
i > 0 ? e = a + 1 : (s = a, o = !i);
|
|
721
|
+
}
|
|
722
|
+
return o ? e : -e - 1;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* @license
|
|
726
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
727
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
728
|
+
* you may not use this file except in compliance with the License.
|
|
729
|
+
* You may obtain a copy of the License at
|
|
730
|
+
*
|
|
731
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
732
|
+
*
|
|
733
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
734
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
735
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
736
|
+
* See the License for the specific language governing permissions and
|
|
737
|
+
* limitations under the License.
|
|
738
|
+
* =============================================================================
|
|
739
|
+
*/
|
|
740
|
+
function je(r, t, n, e, s) {
|
|
741
|
+
return en(
|
|
742
|
+
r,
|
|
743
|
+
t,
|
|
744
|
+
n,
|
|
745
|
+
e,
|
|
746
|
+
s,
|
|
747
|
+
0
|
|
748
|
+
/* softNmsSigma */
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
function Fe(r, t, n, e, s, a) {
|
|
752
|
+
return en(
|
|
753
|
+
r,
|
|
754
|
+
t,
|
|
755
|
+
n,
|
|
756
|
+
e,
|
|
757
|
+
s,
|
|
758
|
+
0,
|
|
759
|
+
!1,
|
|
760
|
+
a,
|
|
761
|
+
!0
|
|
762
|
+
/* returnValidOutputs */
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
function We(r, t, n, e, s, a) {
|
|
766
|
+
return en(
|
|
767
|
+
r,
|
|
768
|
+
t,
|
|
769
|
+
n,
|
|
770
|
+
e,
|
|
771
|
+
s,
|
|
772
|
+
a,
|
|
773
|
+
!0
|
|
774
|
+
/* returnScoresTensor */
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
function en(r, t, n, e, s, a, o = !1, i = !1, u = !1) {
|
|
778
|
+
const c = [];
|
|
779
|
+
for (let b = 0; b < t.length; b++)
|
|
780
|
+
t[b] > s && c.push({ score: t[b], boxIndex: b, suppressBeginIndex: 0 });
|
|
781
|
+
c.sort(on);
|
|
782
|
+
const d = a > 0 ? -0.5 / a : 0, m = [], $ = [];
|
|
783
|
+
for (; m.length < n && c.length > 0; ) {
|
|
784
|
+
const b = c.pop(), { score: E, boxIndex: I, suppressBeginIndex: A } = b;
|
|
785
|
+
if (E < s)
|
|
786
|
+
break;
|
|
787
|
+
let z = !1;
|
|
788
|
+
for (let B = m.length - 1; B >= A; --B) {
|
|
789
|
+
const V = Oe(r, I, m[B]);
|
|
790
|
+
if (V >= e) {
|
|
791
|
+
z = !0;
|
|
792
|
+
break;
|
|
793
|
+
}
|
|
794
|
+
if (b.score = b.score * Ye(e, d, V), b.score <= s)
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
b.suppressBeginIndex = m.length, z || (b.score === E ? (m.push(I), $.push(b.score)) : b.score > s && De(c, b, on));
|
|
798
|
+
}
|
|
799
|
+
const g = m.length, x = n - g;
|
|
800
|
+
i && x > 0 && (m.push(...new Array(x).fill(0)), $.push(...new Array(x).fill(0)));
|
|
801
|
+
const y = { selectedIndices: m };
|
|
802
|
+
return o && (y.selectedScores = $), u && (y.validOutputs = g), y;
|
|
803
|
+
}
|
|
804
|
+
function Oe(r, t, n) {
|
|
805
|
+
const e = r.subarray(t * 4, t * 4 + 4), s = r.subarray(n * 4, n * 4 + 4), a = Math.min(e[0], e[2]), o = Math.min(e[1], e[3]), i = Math.max(e[0], e[2]), u = Math.max(e[1], e[3]), c = Math.min(s[0], s[2]), d = Math.min(s[1], s[3]), m = Math.max(s[0], s[2]), $ = Math.max(s[1], s[3]), g = (i - a) * (u - o), x = (m - c) * ($ - d);
|
|
806
|
+
if (g <= 0 || x <= 0)
|
|
807
|
+
return 0;
|
|
808
|
+
const y = Math.max(a, c), b = Math.max(o, d), E = Math.min(i, m), I = Math.min(u, $), A = Math.max(E - y, 0) * Math.max(I - b, 0);
|
|
809
|
+
return A / (g + x - A);
|
|
810
|
+
}
|
|
811
|
+
function Ye(r, t, n) {
|
|
812
|
+
const e = Math.exp(t * n * n);
|
|
813
|
+
return n <= r ? e : 0;
|
|
814
|
+
}
|
|
815
|
+
function on(r, t) {
|
|
816
|
+
return r.score - t.score || r.score === t.score && t.boxIndex - r.boxIndex;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* @license
|
|
820
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
821
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
822
|
+
* you may not use this file except in compliance with the License.
|
|
823
|
+
* You may obtain a copy of the License at
|
|
824
|
+
*
|
|
825
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
826
|
+
*
|
|
827
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
828
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
829
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
830
|
+
* See the License for the specific language governing permissions and
|
|
831
|
+
* limitations under the License.
|
|
832
|
+
* =============================================================================
|
|
833
|
+
*/
|
|
834
|
+
async function Ce(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY) {
|
|
835
|
+
const a = l(r, "boxes", "nonMaxSuppressionAsync"), o = l(t, "scores", "nonMaxSuppressionAsync"), i = P(a, o, n, e, s);
|
|
836
|
+
n = i.maxOutputSize, e = i.iouThreshold, s = i.scoreThreshold;
|
|
837
|
+
const u = await Promise.all([a.data(), o.data()]), c = u[0], d = u[1], { selectedIndices: m } = je(c, d, n, e, s);
|
|
838
|
+
return a !== r && a.dispose(), o !== t && o.dispose(), M(m, "int32");
|
|
839
|
+
}
|
|
840
|
+
const Je = Ce;
|
|
841
|
+
/**
|
|
842
|
+
* @license
|
|
843
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
844
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
845
|
+
* you may not use this file except in compliance with the License.
|
|
846
|
+
* You may obtain a copy of the License at
|
|
847
|
+
*
|
|
848
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
849
|
+
*
|
|
850
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
851
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
852
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
853
|
+
* See the License for the specific language governing permissions and
|
|
854
|
+
* limitations under the License.
|
|
855
|
+
* =============================================================================
|
|
856
|
+
*/
|
|
857
|
+
function Le(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = 0) {
|
|
858
|
+
const o = l(r, "boxes", "nonMaxSuppression"), i = l(t, "scores", "nonMaxSuppression"), u = P(o, i, n, e, s, a);
|
|
859
|
+
n = u.maxOutputSize, e = u.iouThreshold, s = u.scoreThreshold, a = u.softNmsSigma;
|
|
860
|
+
const c = { boxes: o, scores: i }, d = { maxOutputSize: n, iouThreshold: e, scoreThreshold: s, softNmsSigma: a }, m = f.runKernel(vn, c, d);
|
|
861
|
+
return { selectedIndices: m[0], selectedScores: m[1] };
|
|
862
|
+
}
|
|
863
|
+
const Xe = /* @__PURE__ */ h({ nonMaxSuppressionWithScore_: Le });
|
|
864
|
+
/**
|
|
865
|
+
* @license
|
|
866
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
867
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
868
|
+
* you may not use this file except in compliance with the License.
|
|
869
|
+
* You may obtain a copy of the License at
|
|
870
|
+
*
|
|
871
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
872
|
+
*
|
|
873
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
874
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
875
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
876
|
+
* See the License for the specific language governing permissions and
|
|
877
|
+
* limitations under the License.
|
|
878
|
+
* =============================================================================
|
|
879
|
+
*/
|
|
880
|
+
async function He(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = 0) {
|
|
881
|
+
const o = l(r, "boxes", "nonMaxSuppressionAsync"), i = l(t, "scores", "nonMaxSuppressionAsync"), u = P(o, i, n, e, s, a);
|
|
882
|
+
n = u.maxOutputSize, e = u.iouThreshold, s = u.scoreThreshold, a = u.softNmsSigma;
|
|
883
|
+
const c = await Promise.all([o.data(), i.data()]), d = c[0], m = c[1], { selectedIndices: $, selectedScores: g } = We(d, m, n, e, s, a);
|
|
884
|
+
return o !== r && o.dispose(), i !== t && i.dispose(), {
|
|
885
|
+
selectedIndices: M($, "int32"),
|
|
886
|
+
selectedScores: M(g)
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
const Qe = He;
|
|
890
|
+
/**
|
|
891
|
+
* @license
|
|
892
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
893
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
894
|
+
* you may not use this file except in compliance with the License.
|
|
895
|
+
* You may obtain a copy of the License at
|
|
896
|
+
*
|
|
897
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
898
|
+
*
|
|
899
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
900
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
901
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
902
|
+
* See the License for the specific language governing permissions and
|
|
903
|
+
* limitations under the License.
|
|
904
|
+
* =============================================================================
|
|
905
|
+
*/
|
|
906
|
+
function Ze(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = !1) {
|
|
907
|
+
const o = l(r, "boxes", "nonMaxSuppression"), i = l(t, "scores", "nonMaxSuppression"), u = P(
|
|
908
|
+
o,
|
|
909
|
+
i,
|
|
910
|
+
n,
|
|
911
|
+
e,
|
|
912
|
+
s,
|
|
913
|
+
null
|
|
914
|
+
/* softNmsSigma */
|
|
915
|
+
), c = u.maxOutputSize, d = u.iouThreshold, m = u.scoreThreshold, $ = { boxes: o, scores: i }, g = {
|
|
916
|
+
maxOutputSize: c,
|
|
917
|
+
iouThreshold: d,
|
|
918
|
+
scoreThreshold: m,
|
|
919
|
+
padToMaxOutputSize: a
|
|
920
|
+
}, x = f.runKernel(jn, $, g);
|
|
921
|
+
return { selectedIndices: x[0], validOutputs: x[1] };
|
|
922
|
+
}
|
|
923
|
+
const Ue = /* @__PURE__ */ h({ nonMaxSuppressionPadded_: Ze });
|
|
924
|
+
/**
|
|
925
|
+
* @license
|
|
926
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
927
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
928
|
+
* you may not use this file except in compliance with the License.
|
|
929
|
+
* You may obtain a copy of the License at
|
|
930
|
+
*
|
|
931
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
932
|
+
*
|
|
933
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
934
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
935
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
936
|
+
* See the License for the specific language governing permissions and
|
|
937
|
+
* limitations under the License.
|
|
938
|
+
* =============================================================================
|
|
939
|
+
*/
|
|
940
|
+
async function ns(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = !1) {
|
|
941
|
+
const o = l(r, "boxes", "nonMaxSuppressionAsync"), i = l(t, "scores", "nonMaxSuppressionAsync"), u = P(
|
|
942
|
+
o,
|
|
943
|
+
i,
|
|
944
|
+
n,
|
|
945
|
+
e,
|
|
946
|
+
s,
|
|
947
|
+
null
|
|
948
|
+
/* softNmsSigma */
|
|
949
|
+
), c = u.maxOutputSize, d = u.iouThreshold, m = u.scoreThreshold, [$, g] = await Promise.all([o.data(), i.data()]), { selectedIndices: x, validOutputs: y } = Fe($, g, c, d, m, a);
|
|
950
|
+
return o !== r && o.dispose(), i !== t && i.dispose(), {
|
|
951
|
+
selectedIndices: M(x, "int32"),
|
|
952
|
+
validOutputs: Fn(y, "int32")
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
const es = ns;
|
|
956
|
+
/**
|
|
957
|
+
* @license
|
|
958
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
959
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
960
|
+
* you may not use this file except in compliance with the License.
|
|
961
|
+
* You may obtain a copy of the License at
|
|
962
|
+
*
|
|
963
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
964
|
+
*
|
|
965
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
966
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
967
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
968
|
+
* See the License for the specific language governing permissions and
|
|
969
|
+
* limitations under the License.
|
|
970
|
+
* =============================================================================
|
|
971
|
+
*/
|
|
972
|
+
function ss(r, t, n = !1, e = !1) {
|
|
973
|
+
const s = l(r, "images", "resizeBilinear");
|
|
974
|
+
p(s.rank === 3 || s.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${s.rank}.`), p(t.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${t}.`), p(e === !1 || n === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.");
|
|
975
|
+
let a = s, o = !1;
|
|
976
|
+
s.rank === 3 && (o = !0, a = _(s, [1, s.shape[0], s.shape[1], s.shape[2]]));
|
|
977
|
+
const i = { images: a }, u = { alignCorners: n, halfPixelCenters: e, size: t }, c = f.runKernel(Wn, i, u);
|
|
978
|
+
return o ? _(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
|
|
979
|
+
}
|
|
980
|
+
const ts = /* @__PURE__ */ h({ resizeBilinear_: ss });
|
|
981
|
+
/**
|
|
982
|
+
* @license
|
|
983
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
984
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
985
|
+
* you may not use this file except in compliance with the License.
|
|
986
|
+
* You may obtain a copy of the License at
|
|
987
|
+
*
|
|
988
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
989
|
+
*
|
|
990
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
991
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
992
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
993
|
+
* See the License for the specific language governing permissions and
|
|
994
|
+
* limitations under the License.
|
|
995
|
+
* =============================================================================
|
|
996
|
+
*/
|
|
997
|
+
function rs(r, t, n = !1, e = !1) {
|
|
998
|
+
const s = l(r, "images", "resizeNearestNeighbor");
|
|
999
|
+
p(s.rank === 3 || s.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${s.rank}.`), p(t.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${t}.`), p(s.dtype === "float32" || s.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), p(e === !1 || n === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.");
|
|
1000
|
+
let a = s, o = !1;
|
|
1001
|
+
s.rank === 3 && (o = !0, a = _(s, [1, s.shape[0], s.shape[1], s.shape[2]]));
|
|
1002
|
+
const i = { images: a }, u = { alignCorners: n, halfPixelCenters: e, size: t }, c = f.runKernel(On, i, u);
|
|
1003
|
+
return o ? _(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
|
|
1004
|
+
}
|
|
1005
|
+
const as = /* @__PURE__ */ h({ resizeNearestNeighbor_: rs });
|
|
1006
|
+
/**
|
|
1007
|
+
* @license
|
|
1008
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
1009
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1010
|
+
* you may not use this file except in compliance with the License.
|
|
1011
|
+
* You may obtain a copy of the License at
|
|
1012
|
+
*
|
|
1013
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
1014
|
+
*
|
|
1015
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1016
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1017
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1018
|
+
* See the License for the specific language governing permissions and
|
|
1019
|
+
* limitations under the License.
|
|
1020
|
+
* =============================================================================
|
|
1021
|
+
*/
|
|
1022
|
+
function os(r, t = "binary", n = !1, e = 0.5) {
|
|
1023
|
+
const s = l(r, "image", "threshold"), a = 0.2989, o = 0.587, i = 0.114, u = s.shape[0] * s.shape[1];
|
|
1024
|
+
let c = k(M([e]), 255), d, m, $, g;
|
|
1025
|
+
if (p(s.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${s.rank}.`), p(s.shape[2] === 3 || s.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${s.shape[2]}.`), p(s.dtype === "int32" || s.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${s.dtype}.`), p(t === "otsu" || t === "binary", () => `Method must be binary or otsu, but was ${t}`), s.shape[2] === 3) {
|
|
1026
|
+
[d, m, $] = un(s, [1, 1, 1], -1);
|
|
1027
|
+
const b = k(d, a), E = k(m, o), I = k($, i);
|
|
1028
|
+
g = Z(Z(b, E), I);
|
|
1029
|
+
} else
|
|
1030
|
+
g = r;
|
|
1031
|
+
if (t === "otsu") {
|
|
1032
|
+
const b = Un(D(ke(g), "int32"), Ln([]), 256);
|
|
1033
|
+
c = is(b, u);
|
|
1034
|
+
}
|
|
1035
|
+
const x = n ? pn(g, c) : U(g, c);
|
|
1036
|
+
return D(k(x, 255), "int32");
|
|
1037
|
+
}
|
|
1038
|
+
function is(r, t) {
|
|
1039
|
+
let n = M([-1]), e = M([0]), s = M([0]), a, o, i, u, c, d;
|
|
1040
|
+
for (let m = 0; m < r.size - 1; m++) {
|
|
1041
|
+
a = N(r, 0, m + 1), o = N(r, m + 1), c = K(q(a), t), d = K(q(o), t);
|
|
1042
|
+
const $ = q(k(a, O(0, a.size)));
|
|
1043
|
+
i = K($, q(a));
|
|
1044
|
+
const g = Yn(o.shape, a.size), x = Z(O(0, o.size), g), y = k(o, x);
|
|
1045
|
+
u = K(q(y), q(o));
|
|
1046
|
+
const b = S(i, u), E = S(i, u), I = k(c, d);
|
|
1047
|
+
s = k(k(I, b), E);
|
|
1048
|
+
const A = U(s, e);
|
|
1049
|
+
e = R(A, s, e), n = R(A, M([m]), n);
|
|
1050
|
+
}
|
|
1051
|
+
return n;
|
|
1052
|
+
}
|
|
1053
|
+
const cs = /* @__PURE__ */ h({ threshold_: os });
|
|
1054
|
+
/**
|
|
1055
|
+
* @license
|
|
1056
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
1057
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1058
|
+
* you may not use this file except in compliance with the License.
|
|
1059
|
+
* You may obtain a copy of the License at
|
|
1060
|
+
*
|
|
1061
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1062
|
+
*
|
|
1063
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1064
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1065
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1066
|
+
* See the License for the specific language governing permissions and
|
|
1067
|
+
* limitations under the License.
|
|
1068
|
+
* =============================================================================
|
|
1069
|
+
*/
|
|
1070
|
+
function us(r, t, n = "nearest", e = "constant", s = 0, a) {
|
|
1071
|
+
const o = l(r, "image", "transform", "float32"), i = l(t, "transforms", "transform", "float32");
|
|
1072
|
+
p(o.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${o.rank}.`), p(i.rank === 2 && (i.shape[0] === o.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(a == null || a.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${a}.`);
|
|
1073
|
+
const u = { image: o, transforms: i }, c = { interpolation: n, fillMode: e, fillValue: s, outputShape: a };
|
|
1074
|
+
return f.runKernel(Cn, u, c);
|
|
1075
|
+
}
|
|
1076
|
+
const ls = /* @__PURE__ */ h({ transform_: us });
|
|
1077
|
+
/**
|
|
1078
|
+
* @license
|
|
1079
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1080
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1081
|
+
* you may not use this file except in compliance with the License.
|
|
1082
|
+
* You may obtain a copy of the License at
|
|
1083
|
+
*
|
|
1084
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1085
|
+
*
|
|
1086
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1087
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1088
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1089
|
+
* See the License for the specific language governing permissions and
|
|
1090
|
+
* limitations under the License.
|
|
1091
|
+
* =============================================================================
|
|
1092
|
+
*/
|
|
1093
|
+
function ps(r, t, n) {
|
|
1094
|
+
const e = l(r, "a", "bandPart");
|
|
1095
|
+
p(e.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${e.rank}.`);
|
|
1096
|
+
const s = e.shape, [a, o] = e.shape.slice(-2);
|
|
1097
|
+
let i, u;
|
|
1098
|
+
typeof t == "number" ? (p(t % 1 === 0, () => `bandPart(): numLower must be an integer, got ${t}.`), p(t <= a, () => `bandPart(): numLower (${t}) must not be greater than the number of rows (${a}).`), i = l(t < 0 ? a : t, "numLower", "bandPart")) : (p(t.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = R(tn(t, 0), a, rn(t, a))), typeof n == "number" ? (p(n % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${n}.`), p(n <= o, () => `bandPart(): numUpper (${n}) must not be greater than the number of columns (${o}).`), u = l(n < 0 ? o : n, "numUpper", "bandPart")) : (p(n.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), u = R(tn(n, 0), o, rn(n, o)));
|
|
1099
|
+
const c = _(O(0, a, 1, "int32"), [-1, 1]), d = O(0, o, 1, "int32"), m = S(c, d), $ = de(pn(m, i), ce(m, nn(u))), g = Hn([a, o], e.dtype);
|
|
1100
|
+
return _(Y(mn(_(e, [-1, a, o])).map((x) => R($, x, g))), s);
|
|
1101
|
+
}
|
|
1102
|
+
const ms = /* @__PURE__ */ h({ bandPart_: ps });
|
|
1103
|
+
/**
|
|
1104
|
+
* @license
|
|
1105
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1106
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1107
|
+
* you may not use this file except in compliance with the License.
|
|
1108
|
+
* You may obtain a copy of the License at
|
|
1109
|
+
*
|
|
1110
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1111
|
+
*
|
|
1112
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1113
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1114
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1115
|
+
* See the License for the specific language governing permissions and
|
|
1116
|
+
* limitations under the License.
|
|
1117
|
+
* =============================================================================
|
|
1118
|
+
*/
|
|
1119
|
+
function hs(r) {
|
|
1120
|
+
let t;
|
|
1121
|
+
if (Array.isArray(r)) {
|
|
1122
|
+
t = !1, p(r != null && r.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
|
|
1123
|
+
const s = r[0].shape[0];
|
|
1124
|
+
for (let a = 1; a < r.length; ++a)
|
|
1125
|
+
p(r[a].shape[0] === s, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${r[a].shape[0]} vs. ${s})`);
|
|
1126
|
+
} else
|
|
1127
|
+
t = !0, r = un(r, r.shape[0], 0).map((s) => Ie(s, [0]));
|
|
1128
|
+
p(r.length <= r[0].shape[0], () => `Gram-Schmidt: Number of vectors (${r.length}) exceeds number of dimensions (${r[0].shape[0]}).`);
|
|
1129
|
+
const n = [], e = r;
|
|
1130
|
+
for (let s = 0; s < r.length; ++s)
|
|
1131
|
+
n.push(f.tidy(() => {
|
|
1132
|
+
let a = e[s];
|
|
1133
|
+
if (s > 0)
|
|
1134
|
+
for (let o = 0; o < s; ++o) {
|
|
1135
|
+
const i = k(q(k(n[o], a)), n[o]);
|
|
1136
|
+
a = S(a, i);
|
|
1137
|
+
}
|
|
1138
|
+
return K(a, ln(a, "euclidean"));
|
|
1139
|
+
}));
|
|
1140
|
+
return t ? Y(n, 0) : n;
|
|
1141
|
+
}
|
|
1142
|
+
const fs = /* @__PURE__ */ h({ gramSchmidt_: hs });
|
|
1143
|
+
/**
|
|
1144
|
+
* @license
|
|
1145
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1146
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1147
|
+
* you may not use this file except in compliance with the License.
|
|
1148
|
+
* You may obtain a copy of the License at
|
|
1149
|
+
*
|
|
1150
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1151
|
+
*
|
|
1152
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1153
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1154
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1155
|
+
* See the License for the specific language governing permissions and
|
|
1156
|
+
* limitations under the License.
|
|
1157
|
+
* =============================================================================
|
|
1158
|
+
*/
|
|
1159
|
+
function ds(r, t = !1) {
|
|
1160
|
+
if (p(r.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${r.rank}`), r.rank === 2)
|
|
1161
|
+
return cn(r, t);
|
|
1162
|
+
{
|
|
1163
|
+
const n = r.shape.slice(0, r.shape.length - 2).reduce((u, c) => u * c), e = mn(_(r, [
|
|
1164
|
+
n,
|
|
1165
|
+
r.shape[r.shape.length - 2],
|
|
1166
|
+
r.shape[r.shape.length - 1]
|
|
1167
|
+
]), 0), s = [], a = [];
|
|
1168
|
+
e.forEach((u) => {
|
|
1169
|
+
const [c, d] = cn(u, t);
|
|
1170
|
+
s.push(c), a.push(d);
|
|
1171
|
+
});
|
|
1172
|
+
const o = _(Y(s, 0), r.shape), i = _(Y(a, 0), r.shape);
|
|
1173
|
+
return [o, i];
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
function cn(r, t = !1) {
|
|
1177
|
+
return f.tidy(() => {
|
|
1178
|
+
p(r.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${r.shape.length}D Tensor.`);
|
|
1179
|
+
const n = r.shape[0], e = r.shape[1];
|
|
1180
|
+
let s = ae(n), a = L(r);
|
|
1181
|
+
const o = Q([[1]], [1, 1]);
|
|
1182
|
+
let i = L(o);
|
|
1183
|
+
const u = n >= e ? e : n;
|
|
1184
|
+
for (let c = 0; c < u; ++c) {
|
|
1185
|
+
const d = a, m = i, $ = s;
|
|
1186
|
+
[i, a, s] = f.tidy(() => {
|
|
1187
|
+
const g = N(a, [c, c], [n - c, 1]), x = ln(g), y = N(a, [c, c], [1, 1]), b = R(U(y, 0), Q([[-1]]), Q([[1]])), E = S(y, k(b, x)), I = K(g, E);
|
|
1188
|
+
I.shape[0] === 1 ? i = L(o) : i = H([
|
|
1189
|
+
o,
|
|
1190
|
+
N(I, [1, 0], [I.shape[0] - 1, I.shape[1]])
|
|
1191
|
+
], 0);
|
|
1192
|
+
const A = nn(K(T(b, E), x)), z = N(a, [c, 0], [n - c, e]), B = k(A, i), V = an(i);
|
|
1193
|
+
if (c === 0)
|
|
1194
|
+
a = S(z, T(B, T(V, z)));
|
|
1195
|
+
else {
|
|
1196
|
+
const C = S(z, T(B, T(V, z)));
|
|
1197
|
+
a = H([N(a, [0, 0], [c, e]), C], 0);
|
|
1198
|
+
}
|
|
1199
|
+
const sn = an(B), F = N(s, [0, c], [n, s.shape[1] - c]);
|
|
1200
|
+
if (c === 0)
|
|
1201
|
+
s = S(F, T(T(F, i), sn));
|
|
1202
|
+
else {
|
|
1203
|
+
const C = S(F, T(T(F, i), sn));
|
|
1204
|
+
s = H([N(s, [0, 0], [n, c]), C], 1);
|
|
1205
|
+
}
|
|
1206
|
+
return [i, a, s];
|
|
1207
|
+
}), Jn([d, m, $]);
|
|
1208
|
+
}
|
|
1209
|
+
return !t && n > e && (s = N(s, [0, 0], [n, e]), a = N(a, [0, 0], [e, e])), [s, a];
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
const bs = /* @__PURE__ */ h({ qr_: ds });
|
|
1213
|
+
/**
|
|
1214
|
+
* @license
|
|
1215
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1216
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1217
|
+
* you may not use this file except in compliance with the License.
|
|
1218
|
+
* You may obtain a copy of the License at
|
|
1219
|
+
*
|
|
1220
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1221
|
+
*
|
|
1222
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1223
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1224
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1225
|
+
* See the License for the specific language governing permissions and
|
|
1226
|
+
* limitations under the License.
|
|
1227
|
+
* =============================================================================
|
|
1228
|
+
*/
|
|
1229
|
+
const ws = {
|
|
1230
|
+
flipLeftRight: Te,
|
|
1231
|
+
grayscaleToRGB: we,
|
|
1232
|
+
resizeNearestNeighbor: as,
|
|
1233
|
+
resizeBilinear: ts,
|
|
1234
|
+
rgbToGrayscale: Be,
|
|
1235
|
+
rotateWithOffset: Ge,
|
|
1236
|
+
cropAndResize: Me,
|
|
1237
|
+
nonMaxSuppression: Re,
|
|
1238
|
+
nonMaxSuppressionAsync: Je,
|
|
1239
|
+
nonMaxSuppressionWithScore: Xe,
|
|
1240
|
+
nonMaxSuppressionWithScoreAsync: Qe,
|
|
1241
|
+
nonMaxSuppressionPadded: Ue,
|
|
1242
|
+
nonMaxSuppressionPaddedAsync: es,
|
|
1243
|
+
threshold: cs,
|
|
1244
|
+
transform: ls
|
|
1245
|
+
}, zs = {
|
|
1246
|
+
bandPart: ms,
|
|
1247
|
+
gramSchmidt: fs,
|
|
1248
|
+
qr: bs
|
|
1249
|
+
};
|
|
1250
|
+
export {
|
|
1251
|
+
W as a,
|
|
1252
|
+
an as b,
|
|
1253
|
+
de as c,
|
|
1254
|
+
pn as d,
|
|
1255
|
+
ae as e,
|
|
1256
|
+
U as f,
|
|
1257
|
+
ce as g,
|
|
1258
|
+
tn as h,
|
|
1259
|
+
G as i,
|
|
1260
|
+
Ie as j,
|
|
1261
|
+
ws as k,
|
|
1262
|
+
zs as l,
|
|
1263
|
+
rn as m,
|
|
1264
|
+
nn as n,
|
|
1265
|
+
N as s,
|
|
1266
|
+
M as t,
|
|
1267
|
+
mn as u,
|
|
1268
|
+
R as w
|
|
1269
|
+
};
|