@genai-fi/nanogpt 0.6.2 → 0.7.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/Generator.js +11 -11
- package/dist/NanoGPTModel.d.ts +2 -2
- package/dist/NanoGPTModel.js +104 -136
- package/dist/{RealDiv-BYViZwhN.js → RealDiv-C4hOvYOZ.js} +26 -25
- package/dist/{Reshape-t7Kcikjk.js → Reshape-BLijOA8h.js} +5 -5
- package/dist/TeachableLLM.d.ts +3 -0
- package/dist/TeachableLLM.js +50 -47
- package/dist/{TiedEmbedding-9WeDwvjO.js → TiedEmbedding-BLltddza.js} +4 -4
- package/dist/{axis_util-Bu4h7XWV.js → axis_util-DaAl5MER.js} +3 -3
- package/dist/backend.d.ts +1 -0
- package/dist/backend.js +7 -0
- package/dist/backend_util-DWiwsi2N.js +749 -0
- package/dist/{broadcast_to-DARN-DBD.js → broadcast_to-C4v-j9yA.js} +2 -2
- package/dist/{concat-5aPGqw3Z.js → concat-CsHeR4zV.js} +8 -8
- package/dist/{dataset-pgqp-YfL.js → dataset-JDyjG3QR.js} +3 -3
- package/dist/{dropout-Bciw46HT.js → dropout-hpDwECTe.js} +7 -7
- package/dist/{gather-DjyCjmOD.js → gather-D0_gPiBz.js} +4 -4
- package/dist/gelu-uyHP1x1f.js +26 -0
- package/dist/gpgpu_math-DJm3ZTAf.js +2371 -0
- package/dist/index-BPPzKVdR.js +12099 -0
- package/dist/{index-BAzbokzv.js → index-C0dhsYom.js} +405 -389
- package/dist/{kernel_funcs_utils-CUxJCg0g.js → kernel_funcs_utils-CwRTFqrc.js} +31 -30
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/MLP.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +4 -4
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +5 -5
- package/dist/{log_sum_exp-YEo2h3gb.js → log_sum_exp-D086OgZJ.js} +15 -15
- package/dist/main.d.ts +2 -0
- package/dist/main.js +9 -5
- package/dist/{mat_mul-7121rsJk.js → mat_mul-1nwdPkQ_.js} +4 -4
- package/dist/{max-DtlIuVeW.js → max-BQc2Aj-I.js} +4 -4
- package/dist/{mulmat_packed_gpu-D4nKF7Je.js → mulmat_packed_gpu-Gzf3I9UV.js} +1 -1
- package/dist/non_max_suppression_impl-CsEgBuMA.js +134 -0
- package/dist/{ones-BBlSRqn1.js → ones-D63HpSF_.js} +2 -2
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +8 -8
- package/dist/ops/cpu/attentionMask.js +9 -9
- package/dist/ops/cpu/fusedSoftmax.js +17 -11
- package/dist/ops/cpu/gatherSub.js +7 -7
- package/dist/ops/cpu/gelu.js +13 -13
- package/dist/ops/cpu/matMulGelu.js +36 -24
- package/dist/ops/cpu/matMulMul.js +14 -8
- package/dist/ops/cpu/mulDropout.js +9 -3
- package/dist/ops/cpu/normRMS.js +5 -5
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +11 -11
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +3 -24
- package/dist/ops/grads/matMulGelu.js +5 -5
- package/dist/ops/grads/normRMS.js +6 -6
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +3 -3
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/rope.js +4 -4
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +4 -4
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +5 -5
- package/dist/ops/webgl/matMulGelu.js +17 -17
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/ops/webgl/mulDropout.js +4 -4
- package/dist/ops/webgl/normRMS.js +2 -2
- 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/webgpu/appendCache.js +56 -0
- package/dist/ops/webgpu/attentionMask.d.ts +1 -0
- package/dist/ops/webgpu/attentionMask.js +64 -0
- package/dist/ops/webgpu/gatherSub.d.ts +1 -0
- package/dist/ops/webgpu/gatherSub.js +37 -0
- package/dist/ops/webgpu/gelu.d.ts +14 -0
- package/dist/ops/webgpu/gelu.js +86 -0
- package/dist/ops/webgpu/index.d.ts +0 -0
- package/dist/ops/webgpu/index.js +8 -0
- package/dist/ops/webgpu/normRMS.d.ts +1 -0
- package/dist/ops/webgpu/normRMS.js +115 -0
- package/dist/ops/webgpu/qkv.d.ts +1 -0
- package/dist/ops/webgpu/qkv.js +56 -0
- package/dist/ops/webgpu/rope.d.ts +1 -0
- package/dist/ops/webgpu/rope.js +68 -0
- package/dist/ops/webgpu/scatterSub.d.ts +1 -0
- package/dist/ops/webgpu/scatterSub.js +37 -0
- package/dist/{ops-C0sQEcPw.js → ops-CIQLNshk.js} +452 -503
- package/dist/{random_width-DWzaOgrn.js → random_width-DkYP8W8N.js} +143 -144
- package/dist/{range-DYsrnfiy.js → range-CYzpQY53.js} +1 -1
- package/dist/{reciprocal-CJQeasVa.js → reciprocal-_A9yv27J.js} +1 -1
- package/dist/{register_all_kernels-BfFCQAqs.js → register_all_kernels-guvSxp7M.js} +202 -200
- package/dist/{reshape-krWGKraP.js → reshape-BMUzc1UY.js} +3 -3
- package/dist/{scatter_nd_util-93ln7Hut.js → scatter_nd_util-IRBqKz_b.js} +3 -3
- package/dist/{selu_util-sntGesxr.js → selu_util-Dt_iuXaq.js} +6 -6
- package/dist/shared-BNa2q6jD.js +69 -0
- package/dist/{shared-Ca6iDobD.js → shared-CDu9S76h.js} +541 -606
- package/dist/{sin-D_h-qCSx.js → sin-Cocju-BY.js} +6 -6
- package/dist/{softmax-fsdtf6JC.js → softmax-GPNK3o-U.js} +3 -3
- package/dist/{split-eiktj-6L.js → split-CHzJjxDv.js} +4 -4
- package/dist/{stack-dfEEz2OY.js → stack-Dpgg_1W1.js} +2 -2
- package/dist/{sum-BE_Irnim.js → sum-B8wEpKsg.js} +5 -5
- package/dist/{tensor-Xyi595sG.js → tensor-RvZVNmg0.js} +1 -1
- package/dist/{tensor2d-CPEkynbH.js → tensor2d-B_kyod7_.js} +1 -1
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/Evaluator.js +1 -1
- package/dist/training/FullTrainer.js +20 -20
- package/dist/training/Trainer.d.ts +5 -6
- package/dist/training/Trainer.js +59 -60
- package/dist/training/sparseCrossEntropy.js +19 -26
- package/dist/utilities/dummy.js +19 -19
- package/dist/utilities/generate.js +15 -16
- package/dist/utilities/multinomialCPU.d.ts +2 -0
- package/dist/utilities/multinomialCPU.js +13 -0
- package/dist/utilities/performance.d.ts +2 -0
- package/dist/utilities/performance.js +16 -0
- package/dist/utilities/profile.d.ts +1 -0
- package/dist/utilities/profile.js +9 -6
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-wSS22xj5.js → variable-DXEUOwew.js} +1 -1
- package/dist/webgpu_util-g13LvDIv.js +625 -0
- package/dist/{zeros-YJDE7oRb.js → zeros-DCPCdFGq.js} +8 -8
- package/package.json +2 -1
- package/dist/gpgpu_math-CNslybmD.js +0 -3115
- package/dist/norm-CzltS9Fz.js +0 -86
- package/dist/ops/node/sparseCrossEntropy.js +0 -11
- /package/dist/ops/{node/sparseCrossEntropy.d.ts → webgpu/appendCache.d.ts} +0 -0
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { s as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { m as
|
|
13
|
-
import {
|
|
1
|
+
import { x as m, y as u, E as f, aN as gn, l, aO as $n, k as S, aP as kn, aQ as yn, aR as En, p as _n, aS as w, aT as rn, n as In, b as pn, aU as Nn, aV as An, L as Tn, ai as xn, F as v, aW as wn, aX as Sn, aY as Mn, aZ as zn, a_ as qn, a$ as Kn, b0 as Bn, Q as G, b1 as Gn, b2 as Rn, b3 as Dn, aE as vn, X as Vn, V as Pn, W as jn, b4 as Fn, t as Wn, b5 as C, b6 as On, b7 as Yn, b8 as Ln, b9 as Cn, ba as Xn, bb as Qn, bc as Jn, bd as Zn, a as $, a6 as U, aj as q, h as Hn, c as A, be as Un, K as X, d as ne } from "./index-C0dhsYom.js";
|
|
2
|
+
import { n as ee, a as se, b as te } from "./non_max_suppression_impl-CsEgBuMA.js";
|
|
3
|
+
import { r as k } from "./reshape-BMUzc1UY.js";
|
|
4
|
+
import { s as mn } from "./split-CHzJjxDv.js";
|
|
5
|
+
import { s as E } from "./sum-B8wEpKsg.js";
|
|
6
|
+
import { b as Q } from "./broadcast_to-C4v-j9yA.js";
|
|
7
|
+
import { r as W } from "./range-CYzpQY53.js";
|
|
8
|
+
import { t as re } from "./tensor-RvZVNmg0.js";
|
|
9
|
+
import { s as O } from "./stack-Dpgg_1W1.js";
|
|
10
|
+
import { c as ae, z as oe } from "./zeros-DCPCdFGq.js";
|
|
11
|
+
import { e as ie } from "./axis_util-DaAl5MER.js";
|
|
12
|
+
import { m as J } from "./max-BQc2Aj-I.js";
|
|
13
|
+
import { c as Z } from "./concat-CsHeR4zV.js";
|
|
14
|
+
import { m as N } from "./mat_mul-1nwdPkQ_.js";
|
|
15
|
+
import { t as H } from "./tensor2d-B_kyod7_.js";
|
|
14
16
|
/**
|
|
15
17
|
* @license
|
|
16
18
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -27,14 +29,14 @@ import { t as H } from "./tensor2d-CPEkynbH.js";
|
|
|
27
29
|
* limitations under the License.
|
|
28
30
|
* =============================================================================
|
|
29
31
|
*/
|
|
30
|
-
function
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
32
|
+
function ce(s, e, n) {
|
|
33
|
+
const r = u(s, "x", "slice", "string_or_numeric");
|
|
34
|
+
if (r.rank === 0)
|
|
33
35
|
throw new Error("Slicing scalar is not possible");
|
|
34
|
-
const
|
|
35
|
-
return f.runKernel(
|
|
36
|
+
const t = { x: r }, a = { begin: e, size: n };
|
|
37
|
+
return f.runKernel(gn, t, a);
|
|
36
38
|
}
|
|
37
|
-
const
|
|
39
|
+
const _ = /* @__PURE__ */ m({ slice_: ce });
|
|
38
40
|
/**
|
|
39
41
|
* @license
|
|
40
42
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -51,13 +53,13 @@ const M = /* @__PURE__ */ h({ slice_: Hn });
|
|
|
51
53
|
* limitations under the License.
|
|
52
54
|
* =============================================================================
|
|
53
55
|
*/
|
|
54
|
-
function
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const a = { x:
|
|
58
|
-
return f.runKernel(
|
|
56
|
+
function ue(s, e, n) {
|
|
57
|
+
const r = u(s, "x", "bincount"), t = u(e, "weights", "bincount");
|
|
58
|
+
l(r.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${r.dtype}`), l(n >= 0, () => `size must be non-negative, but got ${n}.`), l(t.size === r.size || t.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${r.shape}, weights shape: ${t.shape}.`);
|
|
59
|
+
const a = { x: r, weights: t }, o = { size: n };
|
|
60
|
+
return f.runKernel($n, a, o);
|
|
59
61
|
}
|
|
60
|
-
const
|
|
62
|
+
const le = /* @__PURE__ */ m({ bincount_: ue });
|
|
61
63
|
/**
|
|
62
64
|
* @license
|
|
63
65
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -74,15 +76,15 @@ const Un = /* @__PURE__ */ h({ bincount_: Zn });
|
|
|
74
76
|
* limitations under the License.
|
|
75
77
|
* =============================================================================
|
|
76
78
|
*/
|
|
77
|
-
function
|
|
78
|
-
const
|
|
79
|
+
function pe(s, e, n) {
|
|
80
|
+
const r = u(e, "a", "where"), t = u(n, "b", "where"), a = u(s, "condition", "where", "bool"), o = S(S(a.shape, r.shape), t.shape), i = Q(a, o), p = Q(r, o), c = Q(t, o), b = {
|
|
79
81
|
condition: i,
|
|
80
|
-
t:
|
|
82
|
+
t: p,
|
|
81
83
|
e: c
|
|
82
84
|
};
|
|
83
|
-
return f.runKernel(
|
|
85
|
+
return f.runKernel(kn, b);
|
|
84
86
|
}
|
|
85
|
-
const
|
|
87
|
+
const B = /* @__PURE__ */ m({ where_: pe });
|
|
86
88
|
/**
|
|
87
89
|
* @license
|
|
88
90
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -99,11 +101,88 @@ const G = /* @__PURE__ */ h({ where_: ne });
|
|
|
99
101
|
* limitations under the License.
|
|
100
102
|
* =============================================================================
|
|
101
103
|
*/
|
|
102
|
-
function
|
|
103
|
-
const n =
|
|
104
|
-
return f.runKernel(
|
|
104
|
+
function me(s, ...e) {
|
|
105
|
+
const n = e.map((t, a) => u(t, `tensors${a}`, "einsum")), r = { equation: s };
|
|
106
|
+
return f.runKernel(yn, n, r);
|
|
105
107
|
}
|
|
106
|
-
const
|
|
108
|
+
const D = /* @__PURE__ */ m({ einsum_: me });
|
|
109
|
+
/**
|
|
110
|
+
* @license
|
|
111
|
+
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
112
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
113
|
+
* you may not use this file except in compliance with the License.
|
|
114
|
+
* You may obtain a copy of the License at
|
|
115
|
+
*
|
|
116
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
117
|
+
*
|
|
118
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
119
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
120
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
121
|
+
* See the License for the specific language governing permissions and
|
|
122
|
+
* limitations under the License.
|
|
123
|
+
* =============================================================================
|
|
124
|
+
*/
|
|
125
|
+
function fe(s, e = null, n = !1) {
|
|
126
|
+
const t = { x: u(s, "x", "min") }, a = { axis: e, keepDims: n };
|
|
127
|
+
return f.runKernel(En, t, a);
|
|
128
|
+
}
|
|
129
|
+
const an = /* @__PURE__ */ m({ min_: fe });
|
|
130
|
+
/**
|
|
131
|
+
* @license
|
|
132
|
+
* Copyright 2018 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 he(s, e = "euclidean", n = null, r = !1) {
|
|
147
|
+
s = u(s, "x", "norm");
|
|
148
|
+
const t = fn(s, e, n);
|
|
149
|
+
let a = t.shape;
|
|
150
|
+
if (r) {
|
|
151
|
+
const o = _n(n, s.shape);
|
|
152
|
+
a = ie(t.shape, o);
|
|
153
|
+
}
|
|
154
|
+
return k(t, a);
|
|
155
|
+
}
|
|
156
|
+
function fn(s, e, n = null) {
|
|
157
|
+
if (s.rank === 0)
|
|
158
|
+
return w(s);
|
|
159
|
+
if (s.rank !== 1 && n === null)
|
|
160
|
+
return fn(k(s, [-1]), e, n);
|
|
161
|
+
if (s.rank === 1 || typeof n == "number" || Array.isArray(n) && n.length === 1) {
|
|
162
|
+
if (e === 1)
|
|
163
|
+
return E(w(s), n);
|
|
164
|
+
if (e === 1 / 0)
|
|
165
|
+
return J(w(s), n);
|
|
166
|
+
if (e === -1 / 0)
|
|
167
|
+
return an(w(s), n);
|
|
168
|
+
if (e === "euclidean" || e === 2)
|
|
169
|
+
return rn(E(In(w(s), pn(2, "int32")), n));
|
|
170
|
+
throw new Error(`Error in norm: invalid ord value: ${e}`);
|
|
171
|
+
}
|
|
172
|
+
if (Array.isArray(n) && n.length === 2) {
|
|
173
|
+
if (e === 1)
|
|
174
|
+
return J(E(w(s), n[0]), n[1] - 1);
|
|
175
|
+
if (e === 1 / 0)
|
|
176
|
+
return J(E(w(s), n[1]), n[0]);
|
|
177
|
+
if (e === -1 / 0)
|
|
178
|
+
return an(E(w(s), n[1]), n[0]);
|
|
179
|
+
if (e === "fro" || e === "euclidean")
|
|
180
|
+
return rn(E(Nn(s), n));
|
|
181
|
+
throw new Error(`Error in norm: invalid ord value: ${e}`);
|
|
182
|
+
}
|
|
183
|
+
throw new Error(`Error in norm: invalid axis: ${n}`);
|
|
184
|
+
}
|
|
185
|
+
const hn = /* @__PURE__ */ m({ norm_: he });
|
|
107
186
|
/**
|
|
108
187
|
* @license
|
|
109
188
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -120,13 +199,13 @@ const v = /* @__PURE__ */ h({ einsum_: ee });
|
|
|
120
199
|
* limitations under the License.
|
|
121
200
|
* =============================================================================
|
|
122
201
|
*/
|
|
123
|
-
function
|
|
124
|
-
const n =
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
return f.runKernel(
|
|
202
|
+
function be(s, e = 0) {
|
|
203
|
+
const n = u(s, "x", "expandDims", "string_or_numeric");
|
|
204
|
+
l(e <= n.rank, () => "Axis must be <= rank of the tensor");
|
|
205
|
+
const r = { input: n }, t = { dim: e };
|
|
206
|
+
return f.runKernel(An, r, t);
|
|
128
207
|
}
|
|
129
|
-
const
|
|
208
|
+
const z = /* @__PURE__ */ m({ expandDims_: be });
|
|
130
209
|
/**
|
|
131
210
|
* @license
|
|
132
211
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -143,13 +222,13 @@ const K = /* @__PURE__ */ h({ expandDims_: se });
|
|
|
143
222
|
* limitations under the License.
|
|
144
223
|
* =============================================================================
|
|
145
224
|
*/
|
|
146
|
-
function
|
|
147
|
-
const n =
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
return f.runKernel(
|
|
225
|
+
function de(s, e) {
|
|
226
|
+
const n = u(s, "x", "tile", "string_or_numeric");
|
|
227
|
+
l(n.rank === e.length, () => `Error in transpose: rank of input ${n.rank} must match length of reps ${e}.`);
|
|
228
|
+
const r = { x: n }, t = { reps: e };
|
|
229
|
+
return f.runKernel(Tn, r, t);
|
|
151
230
|
}
|
|
152
|
-
const
|
|
231
|
+
const F = /* @__PURE__ */ m({ tile_: de });
|
|
153
232
|
/**
|
|
154
233
|
* @license
|
|
155
234
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -166,20 +245,20 @@ const O = /* @__PURE__ */ h({ tile_: te });
|
|
|
166
245
|
* limitations under the License.
|
|
167
246
|
* =============================================================================
|
|
168
247
|
*/
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
const
|
|
248
|
+
function ge(s, e, n, r = "float32") {
|
|
249
|
+
e == null && (e = s);
|
|
250
|
+
const t = xn([s, e], r), a = s <= e ? s : e;
|
|
172
251
|
for (let i = 0; i < a; ++i)
|
|
173
|
-
|
|
174
|
-
const o =
|
|
252
|
+
t.set(1, i, i);
|
|
253
|
+
const o = k(t.toTensor(), [s, e]);
|
|
175
254
|
if (n == null)
|
|
176
255
|
return o;
|
|
177
256
|
if (n.length === 1)
|
|
178
|
-
return
|
|
257
|
+
return F(z(o, 0), [n[0], 1, 1]);
|
|
179
258
|
if (n.length === 2)
|
|
180
|
-
return
|
|
259
|
+
return F(z(z(o, 0), 0), [n[0], n[1], 1, 1]);
|
|
181
260
|
if (n.length === 3)
|
|
182
|
-
return
|
|
261
|
+
return F(z(z(z(o, 0), 0), 0), [
|
|
183
262
|
n[0],
|
|
184
263
|
n[1],
|
|
185
264
|
n[2],
|
|
@@ -188,7 +267,7 @@ function re(r, t, n, e = "float32") {
|
|
|
188
267
|
]);
|
|
189
268
|
throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${n.length}D.`);
|
|
190
269
|
}
|
|
191
|
-
const
|
|
270
|
+
const $e = /* @__PURE__ */ m({ eye_: ge });
|
|
192
271
|
/**
|
|
193
272
|
* @license
|
|
194
273
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -205,13 +284,13 @@ const ae = /* @__PURE__ */ h({ eye_: re });
|
|
|
205
284
|
* limitations under the License.
|
|
206
285
|
* =============================================================================
|
|
207
286
|
*/
|
|
208
|
-
function
|
|
209
|
-
let n =
|
|
210
|
-
[n,
|
|
211
|
-
const
|
|
212
|
-
return f.runKernel(
|
|
287
|
+
function ke(s, e) {
|
|
288
|
+
let n = u(s, "a", "greater", "string_or_numeric"), r = u(e, "b", "greater", "string_or_numeric");
|
|
289
|
+
[n, r] = v(n, r), S(n.shape, r.shape);
|
|
290
|
+
const t = { a: n, b: r };
|
|
291
|
+
return f.runKernel(wn, t);
|
|
213
292
|
}
|
|
214
|
-
const
|
|
293
|
+
const nn = /* @__PURE__ */ m({ greater_: ke });
|
|
215
294
|
/**
|
|
216
295
|
* @license
|
|
217
296
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -228,13 +307,13 @@ const U = /* @__PURE__ */ h({ greater_: oe });
|
|
|
228
307
|
* limitations under the License.
|
|
229
308
|
* =============================================================================
|
|
230
309
|
*/
|
|
231
|
-
function
|
|
232
|
-
let n =
|
|
233
|
-
[n,
|
|
234
|
-
const
|
|
235
|
-
return f.runKernel(
|
|
310
|
+
function ye(s, e) {
|
|
311
|
+
let n = u(s, "a", "greaterEqual", "string_or_numeric"), r = u(e, "b", "greaterEqual", "string_or_numeric");
|
|
312
|
+
[n, r] = v(n, r), S(n.shape, r.shape);
|
|
313
|
+
const t = { a: n, b: r };
|
|
314
|
+
return f.runKernel(Sn, t);
|
|
236
315
|
}
|
|
237
|
-
const
|
|
316
|
+
const Ee = /* @__PURE__ */ m({ greaterEqual_: ye });
|
|
238
317
|
/**
|
|
239
318
|
* @license
|
|
240
319
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -251,11 +330,11 @@ const ce = /* @__PURE__ */ h({ greaterEqual_: ie });
|
|
|
251
330
|
* limitations under the License.
|
|
252
331
|
* =============================================================================
|
|
253
332
|
*/
|
|
254
|
-
function
|
|
255
|
-
const n = { input:
|
|
256
|
-
return f.runKernel(
|
|
333
|
+
function _e(s) {
|
|
334
|
+
const n = { input: u(s, "input", "imag") };
|
|
335
|
+
return f.runKernel(Mn, n);
|
|
257
336
|
}
|
|
258
|
-
const
|
|
337
|
+
const Ie = /* @__PURE__ */ m({ imag_: _e });
|
|
259
338
|
/**
|
|
260
339
|
* @license
|
|
261
340
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -272,13 +351,13 @@ const le = /* @__PURE__ */ h({ imag_: ue });
|
|
|
272
351
|
* limitations under the License.
|
|
273
352
|
* =============================================================================
|
|
274
353
|
*/
|
|
275
|
-
function
|
|
276
|
-
let n =
|
|
277
|
-
[n,
|
|
278
|
-
const
|
|
279
|
-
return f.runKernel(
|
|
354
|
+
function Ne(s, e) {
|
|
355
|
+
let n = u(s, "a", "less", "string_or_numeric"), r = u(e, "b", "less", "string_or_numeric");
|
|
356
|
+
[n, r] = v(n, r), S(n.shape, r.shape);
|
|
357
|
+
const t = { a: n, b: r };
|
|
358
|
+
return f.runKernel(zn, t);
|
|
280
359
|
}
|
|
281
|
-
const
|
|
360
|
+
const on = /* @__PURE__ */ m({ less_: Ne });
|
|
282
361
|
/**
|
|
283
362
|
* @license
|
|
284
363
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -295,13 +374,13 @@ const tn = /* @__PURE__ */ h({ less_: pe });
|
|
|
295
374
|
* limitations under the License.
|
|
296
375
|
* =============================================================================
|
|
297
376
|
*/
|
|
298
|
-
function
|
|
299
|
-
let n =
|
|
300
|
-
[n,
|
|
301
|
-
const
|
|
302
|
-
return f.runKernel(
|
|
377
|
+
function Ae(s, e) {
|
|
378
|
+
let n = u(s, "a", "lessEqual", "string_or_numeric"), r = u(e, "b", "lessEqual", "string_or_numeric");
|
|
379
|
+
[n, r] = v(n, r), S(n.shape, r.shape);
|
|
380
|
+
const t = { a: n, b: r };
|
|
381
|
+
return f.runKernel(qn, t);
|
|
303
382
|
}
|
|
304
|
-
const
|
|
383
|
+
const bn = /* @__PURE__ */ m({ lessEqual_: Ae });
|
|
305
384
|
/**
|
|
306
385
|
* @license
|
|
307
386
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -318,11 +397,11 @@ const pn = /* @__PURE__ */ h({ lessEqual_: me });
|
|
|
318
397
|
* limitations under the License.
|
|
319
398
|
* =============================================================================
|
|
320
399
|
*/
|
|
321
|
-
function
|
|
322
|
-
const n = { x:
|
|
323
|
-
return f.runKernel(
|
|
400
|
+
function Te(s) {
|
|
401
|
+
const n = { x: u(s, "x", "neg") };
|
|
402
|
+
return f.runKernel(Kn, n);
|
|
324
403
|
}
|
|
325
|
-
const
|
|
404
|
+
const en = /* @__PURE__ */ m({ neg_: Te });
|
|
326
405
|
/**
|
|
327
406
|
* @license
|
|
328
407
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -339,13 +418,13 @@ const nn = /* @__PURE__ */ h({ neg_: he });
|
|
|
339
418
|
* limitations under the License.
|
|
340
419
|
* =============================================================================
|
|
341
420
|
*/
|
|
342
|
-
function
|
|
343
|
-
const n =
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
return f.runKernel(
|
|
421
|
+
function xe(s, e) {
|
|
422
|
+
const n = u(s, "a", "logicalAnd", "bool"), r = u(e, "b", "logicalAnd", "bool");
|
|
423
|
+
S(n.shape, r.shape);
|
|
424
|
+
const t = { a: n, b: r };
|
|
425
|
+
return f.runKernel(Bn, t);
|
|
347
426
|
}
|
|
348
|
-
const
|
|
427
|
+
const we = /* @__PURE__ */ m({ logicalAnd_: xe });
|
|
349
428
|
/**
|
|
350
429
|
* @license
|
|
351
430
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -362,13 +441,13 @@ const be = /* @__PURE__ */ h({ logicalAnd_: fe });
|
|
|
362
441
|
* limitations under the License.
|
|
363
442
|
* =============================================================================
|
|
364
443
|
*/
|
|
365
|
-
function
|
|
366
|
-
let n =
|
|
367
|
-
[n,
|
|
368
|
-
const
|
|
369
|
-
return f.runKernel(
|
|
444
|
+
function Se(s, e) {
|
|
445
|
+
let n = u(s, "a", "minimum"), r = u(e, "b", "minimum");
|
|
446
|
+
[n, r] = v(n, r), n.dtype === "bool" && (n = G(n, "int32"), r = G(r, "int32")), S(n.shape, r.shape);
|
|
447
|
+
const t = { a: n, b: r };
|
|
448
|
+
return f.runKernel(Gn, t);
|
|
370
449
|
}
|
|
371
|
-
const
|
|
450
|
+
const cn = /* @__PURE__ */ m({ minimum_: Se });
|
|
372
451
|
/**
|
|
373
452
|
* @license
|
|
374
453
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -385,11 +464,11 @@ const rn = /* @__PURE__ */ h({ minimum_: de });
|
|
|
385
464
|
* limitations under the License.
|
|
386
465
|
* =============================================================================
|
|
387
466
|
*/
|
|
388
|
-
function
|
|
389
|
-
const n = { input:
|
|
390
|
-
return f.runKernel(
|
|
467
|
+
function Me(s) {
|
|
468
|
+
const n = { input: u(s, "input", "real") };
|
|
469
|
+
return f.runKernel(Rn, n);
|
|
391
470
|
}
|
|
392
|
-
const
|
|
471
|
+
const ze = /* @__PURE__ */ m({ real_: Me });
|
|
393
472
|
/**
|
|
394
473
|
* @license
|
|
395
474
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -406,11 +485,11 @@ const $e = /* @__PURE__ */ h({ real_: ge });
|
|
|
406
485
|
* limitations under the License.
|
|
407
486
|
* =============================================================================
|
|
408
487
|
*/
|
|
409
|
-
function
|
|
410
|
-
const n = { x:
|
|
411
|
-
return f.runKernel(
|
|
488
|
+
function qe(s) {
|
|
489
|
+
const n = { x: u(s, "x", "round") };
|
|
490
|
+
return f.runKernel(Dn, n);
|
|
412
491
|
}
|
|
413
|
-
const
|
|
492
|
+
const Ke = /* @__PURE__ */ m({ round_: qe });
|
|
414
493
|
/**
|
|
415
494
|
* @license
|
|
416
495
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -427,11 +506,11 @@ const ke = /* @__PURE__ */ h({ round_: xe });
|
|
|
427
506
|
* limitations under the License.
|
|
428
507
|
* =============================================================================
|
|
429
508
|
*/
|
|
430
|
-
function
|
|
431
|
-
const n =
|
|
432
|
-
return
|
|
509
|
+
function Be(s, e) {
|
|
510
|
+
const n = u(s, "x", "squeeze", "string_or_numeric");
|
|
511
|
+
return k(n, vn(n.shape, e).newShape);
|
|
433
512
|
}
|
|
434
|
-
const
|
|
513
|
+
const Ge = /* @__PURE__ */ m({ squeeze_: Be });
|
|
435
514
|
/**
|
|
436
515
|
* @license
|
|
437
516
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -448,12 +527,12 @@ const Ie = /* @__PURE__ */ h({ squeeze_: ye });
|
|
|
448
527
|
* limitations under the License.
|
|
449
528
|
* =============================================================================
|
|
450
529
|
*/
|
|
451
|
-
function
|
|
452
|
-
|
|
453
|
-
const n =
|
|
530
|
+
function I(s, e) {
|
|
531
|
+
Vn(s);
|
|
532
|
+
const n = Pn(s, e);
|
|
454
533
|
if (n.length !== 1)
|
|
455
534
|
throw new Error("tensor1d() requires values to be a flat/TypedArray");
|
|
456
|
-
return
|
|
535
|
+
return jn(s, null, n, e);
|
|
457
536
|
}
|
|
458
537
|
/**
|
|
459
538
|
* @license
|
|
@@ -471,13 +550,13 @@ function N(r, t) {
|
|
|
471
550
|
* limitations under the License.
|
|
472
551
|
* =============================================================================
|
|
473
552
|
*/
|
|
474
|
-
function
|
|
475
|
-
const n =
|
|
476
|
-
|
|
477
|
-
const
|
|
478
|
-
return f.runKernel(
|
|
553
|
+
function Re(s, e = 0) {
|
|
554
|
+
const n = u(s, "x", "unstack", "string_or_numeric");
|
|
555
|
+
l(e >= -n.shape.length && e < n.shape.length, () => `Axis = ${e} is not in [-${n.shape.length}, ${n.shape.length})`);
|
|
556
|
+
const r = { value: n }, t = { axis: e };
|
|
557
|
+
return f.runKernel(Fn, r, t);
|
|
479
558
|
}
|
|
480
|
-
const
|
|
559
|
+
const dn = /* @__PURE__ */ m({ unstack_: Re });
|
|
481
560
|
/**
|
|
482
561
|
* @license
|
|
483
562
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -494,19 +573,19 @@ const mn = /* @__PURE__ */ h({ unstack_: _e });
|
|
|
494
573
|
* limitations under the License.
|
|
495
574
|
* =============================================================================
|
|
496
575
|
*/
|
|
497
|
-
function
|
|
498
|
-
const
|
|
499
|
-
if (
|
|
500
|
-
|
|
501
|
-
}),
|
|
502
|
-
return
|
|
503
|
-
const
|
|
504
|
-
return
|
|
505
|
-
let o =
|
|
506
|
-
return o = f.runKernel(
|
|
507
|
-
}) : f.runKernel(
|
|
576
|
+
function De(s, e, n) {
|
|
577
|
+
const r = u(s, "x", "transpose");
|
|
578
|
+
if (e == null && (e = r.shape.map((o, i) => i).reverse()), l(r.rank === e.length, () => `Error in transpose: rank of input ${r.rank} must match length of perm ${e}.`), e.forEach((o) => {
|
|
579
|
+
l(o >= 0 && o < r.rank, () => `All entries in 'perm' must be between 0 and ${r.rank - 1} but got ${e}`);
|
|
580
|
+
}), r.rank <= 1)
|
|
581
|
+
return r.clone();
|
|
582
|
+
const t = { x: r }, a = { perm: e };
|
|
583
|
+
return r.dtype === "complex64" ? Wn(() => {
|
|
584
|
+
let o = ze(r), i = Ie(r);
|
|
585
|
+
return o = f.runKernel(C, { x: o }, a), i = f.runKernel(C, { x: i }, a), n && (i = en(i)), ae(o, i);
|
|
586
|
+
}) : f.runKernel(C, t, a);
|
|
508
587
|
}
|
|
509
|
-
const
|
|
588
|
+
const un = /* @__PURE__ */ m({ transpose_: De });
|
|
510
589
|
/**
|
|
511
590
|
* @license
|
|
512
591
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -523,13 +602,13 @@ const an = /* @__PURE__ */ h({ transpose_: Ee });
|
|
|
523
602
|
* limitations under the License.
|
|
524
603
|
* =============================================================================
|
|
525
604
|
*/
|
|
526
|
-
function
|
|
527
|
-
const o =
|
|
528
|
-
|
|
529
|
-
const b = { image: o, boxes: i, boxInd:
|
|
530
|
-
return f.runKernel(
|
|
605
|
+
function ve(s, e, n, r, t = "bilinear", a = 0) {
|
|
606
|
+
const o = u(s, "image", "cropAndResize"), i = u(e, "boxes", "cropAndResize", "float32"), p = u(n, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
|
|
607
|
+
l(o.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${o.rank}.`), l(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${c},4] but had shape ${i.shape}.`), l(p.rank === 1 && p.shape[0] === c, () => `Error in cropAndResize: boxInd must be have size [${c}] but had shape ${i.shape}.`), l(r.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${r.length}.`), l(r[0] >= 1 && r[1] >= 1, () => `cropSize must be atleast [1,1], but was ${r}`), l(t === "bilinear" || t === "nearest", () => `method must be bilinear or nearest, but was ${t}`);
|
|
608
|
+
const b = { image: o, boxes: i, boxInd: p }, h = { method: t, extrapolationValue: a, cropSize: r };
|
|
609
|
+
return f.runKernel(On, b, h);
|
|
531
610
|
}
|
|
532
|
-
const
|
|
611
|
+
const Ve = /* @__PURE__ */ m({ cropAndResize_: ve });
|
|
533
612
|
/**
|
|
534
613
|
* @license
|
|
535
614
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -546,13 +625,13 @@ const Ne = /* @__PURE__ */ h({ cropAndResize_: Me });
|
|
|
546
625
|
* limitations under the License.
|
|
547
626
|
* =============================================================================
|
|
548
627
|
*/
|
|
549
|
-
function
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
const n = { image:
|
|
553
|
-
return f.runKernel(
|
|
628
|
+
function Pe(s) {
|
|
629
|
+
const e = u(s, "image", "flipLeftRight", "float32");
|
|
630
|
+
l(e.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${e.rank}.`);
|
|
631
|
+
const n = { image: e };
|
|
632
|
+
return f.runKernel(Yn, n, {});
|
|
554
633
|
}
|
|
555
|
-
const
|
|
634
|
+
const je = /* @__PURE__ */ m({ flipLeftRight_: Pe });
|
|
556
635
|
/**
|
|
557
636
|
* @license
|
|
558
637
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -569,13 +648,13 @@ const Te = /* @__PURE__ */ h({ flipLeftRight_: Ae });
|
|
|
569
648
|
* limitations under the License.
|
|
570
649
|
* =============================================================================
|
|
571
650
|
*/
|
|
572
|
-
function
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
const
|
|
576
|
-
return
|
|
651
|
+
function Fe(s) {
|
|
652
|
+
const e = u(s, "image", "grayscaleToRGB"), n = e.rank - 1, r = e.shape[n];
|
|
653
|
+
l(e.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${e.rank}.`), l(r === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${r}.`);
|
|
654
|
+
const t = new Array(e.rank);
|
|
655
|
+
return t.fill(1, 0, n), t[n] = 3, F(e, t);
|
|
577
656
|
}
|
|
578
|
-
const
|
|
657
|
+
const We = /* @__PURE__ */ m({ grayscaleToRGB_: Fe });
|
|
579
658
|
/**
|
|
580
659
|
* @license
|
|
581
660
|
* Copyright 2023 Google LLC.
|
|
@@ -592,33 +671,33 @@ const we = /* @__PURE__ */ h({ grayscaleToRGB_: Se });
|
|
|
592
671
|
* limitations under the License.
|
|
593
672
|
* =============================================================================
|
|
594
673
|
*/
|
|
595
|
-
function
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
const
|
|
674
|
+
function Oe(s) {
|
|
675
|
+
const e = u(s, "image", "RGBToGrayscale"), n = e.rank - 1, r = e.shape[n];
|
|
676
|
+
l(e.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${e.rank}.`), l(r === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${r}.`);
|
|
677
|
+
const t = e.dtype, a = G(e, "float32"), o = I([0.2989, 0.587, 0.114]);
|
|
599
678
|
let i;
|
|
600
|
-
switch (
|
|
679
|
+
switch (e.rank) {
|
|
601
680
|
case 2:
|
|
602
|
-
i =
|
|
681
|
+
i = D("ij,j->i", a, o);
|
|
603
682
|
break;
|
|
604
683
|
case 3:
|
|
605
|
-
i =
|
|
684
|
+
i = D("ijk,k->ij", a, o);
|
|
606
685
|
break;
|
|
607
686
|
case 4:
|
|
608
|
-
i =
|
|
687
|
+
i = D("ijkl,l->ijk", a, o);
|
|
609
688
|
break;
|
|
610
689
|
case 5:
|
|
611
|
-
i =
|
|
690
|
+
i = D("ijklm,m->ijkl", a, o);
|
|
612
691
|
break;
|
|
613
692
|
case 6:
|
|
614
|
-
i =
|
|
693
|
+
i = D("ijklmn,n->ijklm", a, o);
|
|
615
694
|
break;
|
|
616
695
|
default:
|
|
617
696
|
throw new Error("Not a valid tensor rank.");
|
|
618
697
|
}
|
|
619
|
-
return i =
|
|
698
|
+
return i = z(i, -1), G(i, t);
|
|
620
699
|
}
|
|
621
|
-
const
|
|
700
|
+
const Ye = /* @__PURE__ */ m({ rgbToGrayscale_: Oe });
|
|
622
701
|
/**
|
|
623
702
|
* @license
|
|
624
703
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -635,13 +714,13 @@ const Be = /* @__PURE__ */ h({ rgbToGrayscale_: ze });
|
|
|
635
714
|
* limitations under the License.
|
|
636
715
|
* =============================================================================
|
|
637
716
|
*/
|
|
638
|
-
function
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
const a = { image:
|
|
642
|
-
return f.runKernel(
|
|
717
|
+
function Le(s, e, n = 0, r = 0.5) {
|
|
718
|
+
const t = u(s, "image", "rotateWithOffset", "float32");
|
|
719
|
+
l(t.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${t.rank}.`);
|
|
720
|
+
const a = { image: t }, o = { radians: e, fillValue: n, center: r };
|
|
721
|
+
return f.runKernel(Ln, a, o);
|
|
643
722
|
}
|
|
644
|
-
const
|
|
723
|
+
const Ce = /* @__PURE__ */ m({ rotateWithOffset_: Le });
|
|
645
724
|
/**
|
|
646
725
|
* @license
|
|
647
726
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -658,10 +737,10 @@ const Ke = /* @__PURE__ */ h({ rotateWithOffset_: qe });
|
|
|
658
737
|
* limitations under the License.
|
|
659
738
|
* =============================================================================
|
|
660
739
|
*/
|
|
661
|
-
function
|
|
662
|
-
|
|
663
|
-
const o =
|
|
664
|
-
return n = Math.min(n, o),
|
|
740
|
+
function R(s, e, n, r, t, a) {
|
|
741
|
+
r == null && (r = 0.5), t == null && (t = Number.NEGATIVE_INFINITY), a == null && (a = 0);
|
|
742
|
+
const o = s.shape[0];
|
|
743
|
+
return n = Math.min(n, o), l(0 <= r && r <= 1, () => `iouThreshold must be in [0, 1], but was '${r}'`), l(s.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${s.rank}'`), l(s.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${s.shape[1]}`), l(e.rank === 1, () => "scores must be a 1D tensor"), l(e.shape[0] === o, () => `scores has incompatible shape with boxes. Expected ${o}, but was ${e.shape[0]}`), l(0 <= a && a <= 1, () => `softNmsSigma must be in [0, 1], but was '${a}'`), { maxOutputSize: n, iouThreshold: r, scoreThreshold: t, softNmsSigma: a };
|
|
665
744
|
}
|
|
666
745
|
/**
|
|
667
746
|
* @license
|
|
@@ -679,142 +758,13 @@ function D(r, t, n, e, s, a) {
|
|
|
679
758
|
* limitations under the License.
|
|
680
759
|
* =============================================================================
|
|
681
760
|
*/
|
|
682
|
-
function
|
|
683
|
-
const a =
|
|
684
|
-
n = i.maxOutputSize,
|
|
685
|
-
const
|
|
686
|
-
return f.runKernel(
|
|
687
|
-
}
|
|
688
|
-
const Ge = /* @__PURE__ */ h({ nonMaxSuppression_: Re });
|
|
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 Ve(r, t, n) {
|
|
706
|
-
const e = De(r, t, n), s = e < 0 ? -(e + 1) : e;
|
|
707
|
-
r.splice(s, 0, t);
|
|
708
|
-
}
|
|
709
|
-
function De(r, t, n) {
|
|
710
|
-
return ve(r, t, n || Pe);
|
|
711
|
-
}
|
|
712
|
-
function Pe(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 Oe(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 d = 0; d < t.length; d++)
|
|
780
|
-
t[d] > s && c.push({ score: t[d], boxIndex: d, suppressBeginIndex: 0 });
|
|
781
|
-
c.sort(on);
|
|
782
|
-
const b = a > 0 ? -0.5 / a : 0, m = [], $ = [];
|
|
783
|
-
for (; m.length < n && c.length > 0; ) {
|
|
784
|
-
const d = c.pop(), { score: E, boxIndex: I, suppressBeginIndex: A } = d;
|
|
785
|
-
if (E < s)
|
|
786
|
-
break;
|
|
787
|
-
let z = !1;
|
|
788
|
-
for (let B = m.length - 1; B >= A; --B) {
|
|
789
|
-
const P = We(r, I, m[B]);
|
|
790
|
-
if (P >= e) {
|
|
791
|
-
z = !0;
|
|
792
|
-
break;
|
|
793
|
-
}
|
|
794
|
-
if (d.score = d.score * Ye(e, b, P), d.score <= s)
|
|
795
|
-
break;
|
|
796
|
-
}
|
|
797
|
-
d.suppressBeginIndex = m.length, z || (d.score === E ? (m.push(I), $.push(d.score)) : d.score > s && Ve(c, d, 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 We(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]), b = 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) * ($ - b);
|
|
806
|
-
if (g <= 0 || x <= 0)
|
|
807
|
-
return 0;
|
|
808
|
-
const y = Math.max(a, c), d = Math.max(o, b), E = Math.min(i, m), I = Math.min(u, $), A = Math.max(E - y, 0) * Math.max(I - d, 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;
|
|
761
|
+
function Xe(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
|
|
762
|
+
const a = u(s, "boxes", "nonMaxSuppression", "float32"), o = u(e, "scores", "nonMaxSuppression", "float32"), i = R(a, o, n, r, t);
|
|
763
|
+
n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
|
|
764
|
+
const p = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t };
|
|
765
|
+
return f.runKernel(Cn, { boxes: a, scores: o }, p);
|
|
817
766
|
}
|
|
767
|
+
const Qe = /* @__PURE__ */ m({ nonMaxSuppression_: Xe });
|
|
818
768
|
/**
|
|
819
769
|
* @license
|
|
820
770
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -831,13 +781,13 @@ function on(r, t) {
|
|
|
831
781
|
* limitations under the License.
|
|
832
782
|
* =============================================================================
|
|
833
783
|
*/
|
|
834
|
-
async function
|
|
835
|
-
const a =
|
|
836
|
-
n = i.maxOutputSize,
|
|
837
|
-
const
|
|
838
|
-
return a !==
|
|
784
|
+
async function Je(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
|
|
785
|
+
const a = u(s, "boxes", "nonMaxSuppressionAsync"), o = u(e, "scores", "nonMaxSuppressionAsync"), i = R(a, o, n, r, t);
|
|
786
|
+
n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
|
|
787
|
+
const p = await Promise.all([a.data(), o.data()]), c = p[0], b = p[1], { selectedIndices: h } = ee(c, b, n, r, t);
|
|
788
|
+
return a !== s && a.dispose(), o !== e && o.dispose(), I(h, "int32");
|
|
839
789
|
}
|
|
840
|
-
const
|
|
790
|
+
const Ze = Je;
|
|
841
791
|
/**
|
|
842
792
|
* @license
|
|
843
793
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -854,13 +804,13 @@ const Je = Ce;
|
|
|
854
804
|
* limitations under the License.
|
|
855
805
|
* =============================================================================
|
|
856
806
|
*/
|
|
857
|
-
function
|
|
858
|
-
const o =
|
|
859
|
-
n =
|
|
860
|
-
const c = { boxes: o, scores: i }, b = { maxOutputSize: n, iouThreshold:
|
|
861
|
-
return { selectedIndices:
|
|
807
|
+
function He(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = 0) {
|
|
808
|
+
const o = u(s, "boxes", "nonMaxSuppression"), i = u(e, "scores", "nonMaxSuppression"), p = R(o, i, n, r, t, a);
|
|
809
|
+
n = p.maxOutputSize, r = p.iouThreshold, t = p.scoreThreshold, a = p.softNmsSigma;
|
|
810
|
+
const c = { boxes: o, scores: i }, b = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t, softNmsSigma: a }, h = f.runKernel(Xn, c, b);
|
|
811
|
+
return { selectedIndices: h[0], selectedScores: h[1] };
|
|
862
812
|
}
|
|
863
|
-
const
|
|
813
|
+
const Ue = /* @__PURE__ */ m({ nonMaxSuppressionWithScore_: He });
|
|
864
814
|
/**
|
|
865
815
|
* @license
|
|
866
816
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -877,16 +827,16 @@ const Xe = /* @__PURE__ */ h({ nonMaxSuppressionWithScore_: Le });
|
|
|
877
827
|
* limitations under the License.
|
|
878
828
|
* =============================================================================
|
|
879
829
|
*/
|
|
880
|
-
async function
|
|
881
|
-
const o =
|
|
882
|
-
n =
|
|
883
|
-
const c = await Promise.all([o.data(), i.data()]), b = c[0],
|
|
884
|
-
return o !==
|
|
885
|
-
selectedIndices:
|
|
886
|
-
selectedScores:
|
|
830
|
+
async function ns(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = 0) {
|
|
831
|
+
const o = u(s, "boxes", "nonMaxSuppressionAsync"), i = u(e, "scores", "nonMaxSuppressionAsync"), p = R(o, i, n, r, t, a);
|
|
832
|
+
n = p.maxOutputSize, r = p.iouThreshold, t = p.scoreThreshold, a = p.softNmsSigma;
|
|
833
|
+
const c = await Promise.all([o.data(), i.data()]), b = c[0], h = c[1], { selectedIndices: g, selectedScores: d } = se(b, h, n, r, t, a);
|
|
834
|
+
return o !== s && o.dispose(), i !== e && i.dispose(), {
|
|
835
|
+
selectedIndices: I(g, "int32"),
|
|
836
|
+
selectedScores: I(d)
|
|
887
837
|
};
|
|
888
838
|
}
|
|
889
|
-
const
|
|
839
|
+
const es = ns;
|
|
890
840
|
/**
|
|
891
841
|
* @license
|
|
892
842
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -903,24 +853,24 @@ const He = Qe;
|
|
|
903
853
|
* limitations under the License.
|
|
904
854
|
* =============================================================================
|
|
905
855
|
*/
|
|
906
|
-
function
|
|
907
|
-
const o =
|
|
856
|
+
function ss(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = !1) {
|
|
857
|
+
const o = u(s, "boxes", "nonMaxSuppression"), i = u(e, "scores", "nonMaxSuppression"), p = R(
|
|
908
858
|
o,
|
|
909
859
|
i,
|
|
910
860
|
n,
|
|
911
|
-
|
|
912
|
-
|
|
861
|
+
r,
|
|
862
|
+
t,
|
|
913
863
|
null
|
|
914
864
|
/* softNmsSigma */
|
|
915
|
-
), c =
|
|
865
|
+
), c = p.maxOutputSize, b = p.iouThreshold, h = p.scoreThreshold, g = { boxes: o, scores: i }, d = {
|
|
916
866
|
maxOutputSize: c,
|
|
917
867
|
iouThreshold: b,
|
|
918
|
-
scoreThreshold:
|
|
868
|
+
scoreThreshold: h,
|
|
919
869
|
padToMaxOutputSize: a
|
|
920
|
-
},
|
|
921
|
-
return { selectedIndices:
|
|
870
|
+
}, y = f.runKernel(Qn, g, d);
|
|
871
|
+
return { selectedIndices: y[0], validOutputs: y[1] };
|
|
922
872
|
}
|
|
923
|
-
const
|
|
873
|
+
const ts = /* @__PURE__ */ m({ nonMaxSuppressionPadded_: ss });
|
|
924
874
|
/**
|
|
925
875
|
* @license
|
|
926
876
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -937,22 +887,22 @@ const Ue = /* @__PURE__ */ h({ nonMaxSuppressionPadded_: Ze });
|
|
|
937
887
|
* limitations under the License.
|
|
938
888
|
* =============================================================================
|
|
939
889
|
*/
|
|
940
|
-
async function
|
|
941
|
-
const o =
|
|
890
|
+
async function rs(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = !1) {
|
|
891
|
+
const o = u(s, "boxes", "nonMaxSuppressionAsync"), i = u(e, "scores", "nonMaxSuppressionAsync"), p = R(
|
|
942
892
|
o,
|
|
943
893
|
i,
|
|
944
894
|
n,
|
|
945
|
-
|
|
946
|
-
|
|
895
|
+
r,
|
|
896
|
+
t,
|
|
947
897
|
null
|
|
948
898
|
/* softNmsSigma */
|
|
949
|
-
), c =
|
|
950
|
-
return o !==
|
|
951
|
-
selectedIndices:
|
|
952
|
-
validOutputs:
|
|
899
|
+
), c = p.maxOutputSize, b = p.iouThreshold, h = p.scoreThreshold, [g, d] = await Promise.all([o.data(), i.data()]), { selectedIndices: y, validOutputs: M } = te(g, d, c, b, h, a);
|
|
900
|
+
return o !== s && o.dispose(), i !== e && i.dispose(), {
|
|
901
|
+
selectedIndices: I(y, "int32"),
|
|
902
|
+
validOutputs: pn(M, "int32")
|
|
953
903
|
};
|
|
954
904
|
}
|
|
955
|
-
const
|
|
905
|
+
const as = rs;
|
|
956
906
|
/**
|
|
957
907
|
* @license
|
|
958
908
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -969,15 +919,15 @@ const es = ns;
|
|
|
969
919
|
* limitations under the License.
|
|
970
920
|
* =============================================================================
|
|
971
921
|
*/
|
|
972
|
-
function
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
let a =
|
|
976
|
-
|
|
977
|
-
const i = { images: a },
|
|
978
|
-
return o ?
|
|
922
|
+
function os(s, e, n = !1, r = !1) {
|
|
923
|
+
const t = u(s, "images", "resizeBilinear");
|
|
924
|
+
l(t.rank === 3 || t.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${t.rank}.`), l(e.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${e}.`), l(r === !1 || n === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.");
|
|
925
|
+
let a = t, o = !1;
|
|
926
|
+
t.rank === 3 && (o = !0, a = k(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
|
|
927
|
+
const i = { images: a }, p = { alignCorners: n, halfPixelCenters: r, size: e }, c = f.runKernel(Jn, i, p);
|
|
928
|
+
return o ? k(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
|
|
979
929
|
}
|
|
980
|
-
const
|
|
930
|
+
const is = /* @__PURE__ */ m({ resizeBilinear_: os });
|
|
981
931
|
/**
|
|
982
932
|
* @license
|
|
983
933
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -994,15 +944,15 @@ const ts = /* @__PURE__ */ h({ resizeBilinear_: ss });
|
|
|
994
944
|
* limitations under the License.
|
|
995
945
|
* =============================================================================
|
|
996
946
|
*/
|
|
997
|
-
function
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
let a =
|
|
1001
|
-
|
|
1002
|
-
const i = { images: a },
|
|
1003
|
-
return o ?
|
|
947
|
+
function cs(s, e, n = !1, r = !1) {
|
|
948
|
+
const t = u(s, "images", "resizeNearestNeighbor");
|
|
949
|
+
l(t.rank === 3 || t.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${t.rank}.`), l(e.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${e}.`), l(t.dtype === "float32" || t.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), l(r === !1 || n === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.");
|
|
950
|
+
let a = t, o = !1;
|
|
951
|
+
t.rank === 3 && (o = !0, a = k(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
|
|
952
|
+
const i = { images: a }, p = { alignCorners: n, halfPixelCenters: r, size: e }, c = f.runKernel(Zn, i, p);
|
|
953
|
+
return o ? k(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
|
|
1004
954
|
}
|
|
1005
|
-
const
|
|
955
|
+
const us = /* @__PURE__ */ m({ resizeNearestNeighbor_: cs });
|
|
1006
956
|
/**
|
|
1007
957
|
* @license
|
|
1008
958
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -1019,38 +969,38 @@ const as = /* @__PURE__ */ h({ resizeNearestNeighbor_: rs });
|
|
|
1019
969
|
* limitations under the License.
|
|
1020
970
|
* =============================================================================
|
|
1021
971
|
*/
|
|
1022
|
-
function
|
|
1023
|
-
const
|
|
1024
|
-
let c =
|
|
1025
|
-
if (
|
|
1026
|
-
[b,
|
|
1027
|
-
const
|
|
1028
|
-
|
|
972
|
+
function ls(s, e = "binary", n = !1, r = 0.5) {
|
|
973
|
+
const t = u(s, "image", "threshold"), a = 0.2989, o = 0.587, i = 0.114, p = t.shape[0] * t.shape[1];
|
|
974
|
+
let c = $(I([r]), 255), b, h, g, d;
|
|
975
|
+
if (l(t.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${t.rank}.`), l(t.shape[2] === 3 || t.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${t.shape[2]}.`), l(t.dtype === "int32" || t.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${t.dtype}.`), l(e === "otsu" || e === "binary", () => `Method must be binary or otsu, but was ${e}`), t.shape[2] === 3) {
|
|
976
|
+
[b, h, g] = mn(t, [1, 1, 1], -1);
|
|
977
|
+
const T = $(b, a), K = $(h, o), x = $(g, i);
|
|
978
|
+
d = U(U(T, K), x);
|
|
1029
979
|
} else
|
|
1030
|
-
|
|
1031
|
-
if (
|
|
1032
|
-
const
|
|
1033
|
-
c =
|
|
980
|
+
d = s;
|
|
981
|
+
if (e === "otsu") {
|
|
982
|
+
const T = le(G(Ke(d), "int32"), re([]), 256);
|
|
983
|
+
c = ps(T, p);
|
|
1034
984
|
}
|
|
1035
|
-
const
|
|
1036
|
-
return
|
|
985
|
+
const y = n ? bn(d, c) : nn(d, c);
|
|
986
|
+
return G($(y, 255), "int32");
|
|
1037
987
|
}
|
|
1038
|
-
function
|
|
1039
|
-
let n =
|
|
1040
|
-
for (let
|
|
1041
|
-
a =
|
|
1042
|
-
const
|
|
1043
|
-
i =
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1048
|
-
const
|
|
1049
|
-
|
|
988
|
+
function ps(s, e) {
|
|
989
|
+
let n = I([-1]), r = I([0]), t = I([0]), a, o, i, p, c, b;
|
|
990
|
+
for (let h = 0; h < s.size - 1; h++) {
|
|
991
|
+
a = _(s, 0, h + 1), o = _(s, h + 1), c = q(E(a), e), b = q(E(o), e);
|
|
992
|
+
const g = E($(a, W(0, a.size)));
|
|
993
|
+
i = q(g, E(a));
|
|
994
|
+
const d = Hn(o.shape, a.size), y = U(W(0, o.size), d), M = $(o, y);
|
|
995
|
+
p = q(E(M), E(o));
|
|
996
|
+
const T = A(i, p), K = A(i, p), x = $(c, b);
|
|
997
|
+
t = $($(x, T), K);
|
|
998
|
+
const V = nn(t, r);
|
|
999
|
+
r = B(V, t, r), n = B(V, I([h]), n);
|
|
1050
1000
|
}
|
|
1051
1001
|
return n;
|
|
1052
1002
|
}
|
|
1053
|
-
const
|
|
1003
|
+
const ms = /* @__PURE__ */ m({ threshold_: ls });
|
|
1054
1004
|
/**
|
|
1055
1005
|
* @license
|
|
1056
1006
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -1067,13 +1017,13 @@ const cs = /* @__PURE__ */ h({ threshold_: os });
|
|
|
1067
1017
|
* limitations under the License.
|
|
1068
1018
|
* =============================================================================
|
|
1069
1019
|
*/
|
|
1070
|
-
function
|
|
1071
|
-
const o =
|
|
1072
|
-
|
|
1073
|
-
const
|
|
1074
|
-
return f.runKernel(
|
|
1020
|
+
function fs(s, e, n = "nearest", r = "constant", t = 0, a) {
|
|
1021
|
+
const o = u(s, "image", "transform", "float32"), i = u(e, "transforms", "transform", "float32");
|
|
1022
|
+
l(o.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${o.rank}.`), l(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"), l(a == null || a.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${a}.`);
|
|
1023
|
+
const p = { image: o, transforms: i }, c = { interpolation: n, fillMode: r, fillValue: t, outputShape: a };
|
|
1024
|
+
return f.runKernel(Un, p, c);
|
|
1075
1025
|
}
|
|
1076
|
-
const
|
|
1026
|
+
const hs = /* @__PURE__ */ m({ transform_: fs });
|
|
1077
1027
|
/**
|
|
1078
1028
|
* @license
|
|
1079
1029
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1090,16 +1040,16 @@ const ls = /* @__PURE__ */ h({ transform_: us });
|
|
|
1090
1040
|
* limitations under the License.
|
|
1091
1041
|
* =============================================================================
|
|
1092
1042
|
*/
|
|
1093
|
-
function
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
const
|
|
1097
|
-
let i,
|
|
1098
|
-
typeof
|
|
1099
|
-
const c =
|
|
1100
|
-
return
|
|
1043
|
+
function bs(s, e, n) {
|
|
1044
|
+
const r = u(s, "a", "bandPart");
|
|
1045
|
+
l(r.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${r.rank}.`);
|
|
1046
|
+
const t = r.shape, [a, o] = r.shape.slice(-2);
|
|
1047
|
+
let i, p;
|
|
1048
|
+
typeof e == "number" ? (l(e % 1 === 0, () => `bandPart(): numLower must be an integer, got ${e}.`), l(e <= a, () => `bandPart(): numLower (${e}) must not be greater than the number of rows (${a}).`), i = u(e < 0 ? a : e, "numLower", "bandPart")) : (l(e.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = B(on(e, 0), a, cn(e, a))), typeof n == "number" ? (l(n % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${n}.`), l(n <= o, () => `bandPart(): numUpper (${n}) must not be greater than the number of columns (${o}).`), p = u(n < 0 ? o : n, "numUpper", "bandPart")) : (l(n.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), p = B(on(n, 0), o, cn(n, o)));
|
|
1049
|
+
const c = k(W(0, a, 1, "int32"), [-1, 1]), b = W(0, o, 1, "int32"), h = A(c, b), g = we(bn(h, i), Ee(h, en(p))), d = oe([a, o], r.dtype);
|
|
1050
|
+
return k(O(dn(k(r, [-1, a, o])).map((y) => B(g, y, d))), t);
|
|
1101
1051
|
}
|
|
1102
|
-
const
|
|
1052
|
+
const ds = /* @__PURE__ */ m({ bandPart_: bs });
|
|
1103
1053
|
/**
|
|
1104
1054
|
* @license
|
|
1105
1055
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1116,30 +1066,30 @@ const ms = /* @__PURE__ */ h({ bandPart_: ps });
|
|
|
1116
1066
|
* limitations under the License.
|
|
1117
1067
|
* =============================================================================
|
|
1118
1068
|
*/
|
|
1119
|
-
function
|
|
1120
|
-
let
|
|
1121
|
-
if (Array.isArray(
|
|
1122
|
-
|
|
1123
|
-
const
|
|
1124
|
-
for (let a = 1; a <
|
|
1125
|
-
|
|
1069
|
+
function gs(s) {
|
|
1070
|
+
let e;
|
|
1071
|
+
if (Array.isArray(s)) {
|
|
1072
|
+
e = !1, l(s != null && s.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
|
|
1073
|
+
const t = s[0].shape[0];
|
|
1074
|
+
for (let a = 1; a < s.length; ++a)
|
|
1075
|
+
l(s[a].shape[0] === t, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${s[a].shape[0]} vs. ${t})`);
|
|
1126
1076
|
} else
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
const n = [],
|
|
1130
|
-
for (let
|
|
1077
|
+
e = !0, s = mn(s, s.shape[0], 0).map((t) => Ge(t, [0]));
|
|
1078
|
+
l(s.length <= s[0].shape[0], () => `Gram-Schmidt: Number of vectors (${s.length}) exceeds number of dimensions (${s[0].shape[0]}).`);
|
|
1079
|
+
const n = [], r = s;
|
|
1080
|
+
for (let t = 0; t < s.length; ++t)
|
|
1131
1081
|
n.push(f.tidy(() => {
|
|
1132
|
-
let a =
|
|
1133
|
-
if (
|
|
1134
|
-
for (let o = 0; o <
|
|
1135
|
-
const i =
|
|
1136
|
-
a =
|
|
1082
|
+
let a = r[t];
|
|
1083
|
+
if (t > 0)
|
|
1084
|
+
for (let o = 0; o < t; ++o) {
|
|
1085
|
+
const i = $(E($(n[o], a)), n[o]);
|
|
1086
|
+
a = A(a, i);
|
|
1137
1087
|
}
|
|
1138
|
-
return
|
|
1088
|
+
return q(a, hn(a, "euclidean"));
|
|
1139
1089
|
}));
|
|
1140
|
-
return
|
|
1090
|
+
return e ? O(n, 0) : n;
|
|
1141
1091
|
}
|
|
1142
|
-
const
|
|
1092
|
+
const $s = /* @__PURE__ */ m({ gramSchmidt_: gs });
|
|
1143
1093
|
/**
|
|
1144
1094
|
* @license
|
|
1145
1095
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1156,60 +1106,60 @@ const fs = /* @__PURE__ */ h({ gramSchmidt_: hs });
|
|
|
1156
1106
|
* limitations under the License.
|
|
1157
1107
|
* =============================================================================
|
|
1158
1108
|
*/
|
|
1159
|
-
function
|
|
1160
|
-
if (
|
|
1161
|
-
return
|
|
1109
|
+
function ks(s, e = !1) {
|
|
1110
|
+
if (l(s.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${s.rank}`), s.rank === 2)
|
|
1111
|
+
return ln(s, e);
|
|
1162
1112
|
{
|
|
1163
|
-
const n =
|
|
1113
|
+
const n = s.shape.slice(0, s.shape.length - 2).reduce((p, c) => p * c), r = dn(k(s, [
|
|
1164
1114
|
n,
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
]), 0),
|
|
1168
|
-
|
|
1169
|
-
const [c, b] =
|
|
1170
|
-
|
|
1115
|
+
s.shape[s.shape.length - 2],
|
|
1116
|
+
s.shape[s.shape.length - 1]
|
|
1117
|
+
]), 0), t = [], a = [];
|
|
1118
|
+
r.forEach((p) => {
|
|
1119
|
+
const [c, b] = ln(p, e);
|
|
1120
|
+
t.push(c), a.push(b);
|
|
1171
1121
|
});
|
|
1172
|
-
const o =
|
|
1122
|
+
const o = k(O(t, 0), s.shape), i = k(O(a, 0), s.shape);
|
|
1173
1123
|
return [o, i];
|
|
1174
1124
|
}
|
|
1175
1125
|
}
|
|
1176
|
-
function
|
|
1126
|
+
function ln(s, e = !1) {
|
|
1177
1127
|
return f.tidy(() => {
|
|
1178
|
-
|
|
1179
|
-
const n =
|
|
1180
|
-
let
|
|
1128
|
+
l(s.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${s.shape.length}D Tensor.`);
|
|
1129
|
+
const n = s.shape[0], r = s.shape[1];
|
|
1130
|
+
let t = $e(n), a = X(s);
|
|
1181
1131
|
const o = H([[1]], [1, 1]);
|
|
1182
|
-
let i =
|
|
1183
|
-
const
|
|
1184
|
-
for (let c = 0; c <
|
|
1185
|
-
const b = a,
|
|
1186
|
-
[i, a,
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1132
|
+
let i = X(o);
|
|
1133
|
+
const p = n >= r ? r : n;
|
|
1134
|
+
for (let c = 0; c < p; ++c) {
|
|
1135
|
+
const b = a, h = i, g = t;
|
|
1136
|
+
[i, a, t] = f.tidy(() => {
|
|
1137
|
+
const d = _(a, [c, c], [n - c, 1]), y = hn(d), M = _(a, [c, c], [1, 1]), T = B(nn(M, 0), H([[-1]]), H([[1]])), K = A(M, $(T, y)), x = q(d, K);
|
|
1138
|
+
x.shape[0] === 1 ? i = X(o) : i = Z([
|
|
1189
1139
|
o,
|
|
1190
|
-
|
|
1140
|
+
_(x, [1, 0], [x.shape[0] - 1, x.shape[1]])
|
|
1191
1141
|
], 0);
|
|
1192
|
-
const
|
|
1142
|
+
const V = en(q(N(T, K), y)), P = _(a, [c, 0], [n - c, r]), Y = $(V, i), sn = un(i);
|
|
1193
1143
|
if (c === 0)
|
|
1194
|
-
a =
|
|
1144
|
+
a = A(P, N(Y, N(sn, P)));
|
|
1195
1145
|
else {
|
|
1196
|
-
const
|
|
1197
|
-
a =
|
|
1146
|
+
const L = A(P, N(Y, N(sn, P)));
|
|
1147
|
+
a = Z([_(a, [0, 0], [c, r]), L], 0);
|
|
1198
1148
|
}
|
|
1199
|
-
const
|
|
1149
|
+
const tn = un(Y), j = _(t, [0, c], [n, t.shape[1] - c]);
|
|
1200
1150
|
if (c === 0)
|
|
1201
|
-
|
|
1151
|
+
t = A(j, N(N(j, i), tn));
|
|
1202
1152
|
else {
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1153
|
+
const L = A(j, N(N(j, i), tn));
|
|
1154
|
+
t = Z([_(t, [0, 0], [n, c]), L], 1);
|
|
1205
1155
|
}
|
|
1206
|
-
return [i, a,
|
|
1207
|
-
}),
|
|
1156
|
+
return [i, a, t];
|
|
1157
|
+
}), ne([b, h, g]);
|
|
1208
1158
|
}
|
|
1209
|
-
return !
|
|
1159
|
+
return !e && n > r && (t = _(t, [0, 0], [n, r]), a = _(a, [0, 0], [r, r])), [t, a];
|
|
1210
1160
|
});
|
|
1211
1161
|
}
|
|
1212
|
-
const
|
|
1162
|
+
const ys = /* @__PURE__ */ m({ qr_: ks });
|
|
1213
1163
|
/**
|
|
1214
1164
|
* @license
|
|
1215
1165
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1226,52 +1176,51 @@ const ds = /* @__PURE__ */ h({ qr_: bs });
|
|
|
1226
1176
|
* limitations under the License.
|
|
1227
1177
|
* =============================================================================
|
|
1228
1178
|
*/
|
|
1229
|
-
const
|
|
1230
|
-
flipLeftRight:
|
|
1231
|
-
grayscaleToRGB:
|
|
1232
|
-
resizeNearestNeighbor:
|
|
1233
|
-
resizeBilinear:
|
|
1234
|
-
rgbToGrayscale:
|
|
1235
|
-
rotateWithOffset:
|
|
1236
|
-
cropAndResize:
|
|
1237
|
-
nonMaxSuppression:
|
|
1238
|
-
nonMaxSuppressionAsync:
|
|
1239
|
-
nonMaxSuppressionWithScore:
|
|
1240
|
-
nonMaxSuppressionWithScoreAsync:
|
|
1241
|
-
nonMaxSuppressionPadded:
|
|
1242
|
-
nonMaxSuppressionPaddedAsync:
|
|
1243
|
-
threshold:
|
|
1244
|
-
transform:
|
|
1245
|
-
},
|
|
1246
|
-
bandPart:
|
|
1247
|
-
gramSchmidt:
|
|
1248
|
-
qr:
|
|
1179
|
+
const Rs = {
|
|
1180
|
+
flipLeftRight: je,
|
|
1181
|
+
grayscaleToRGB: We,
|
|
1182
|
+
resizeNearestNeighbor: us,
|
|
1183
|
+
resizeBilinear: is,
|
|
1184
|
+
rgbToGrayscale: Ye,
|
|
1185
|
+
rotateWithOffset: Ce,
|
|
1186
|
+
cropAndResize: Ve,
|
|
1187
|
+
nonMaxSuppression: Qe,
|
|
1188
|
+
nonMaxSuppressionAsync: Ze,
|
|
1189
|
+
nonMaxSuppressionWithScore: Ue,
|
|
1190
|
+
nonMaxSuppressionWithScoreAsync: es,
|
|
1191
|
+
nonMaxSuppressionPadded: ts,
|
|
1192
|
+
nonMaxSuppressionPaddedAsync: as,
|
|
1193
|
+
threshold: ms,
|
|
1194
|
+
transform: hs
|
|
1195
|
+
}, Ds = {
|
|
1196
|
+
bandPart: ds,
|
|
1197
|
+
gramSchmidt: $s,
|
|
1198
|
+
qr: ys
|
|
1249
1199
|
};
|
|
1250
1200
|
export {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
Oe as z
|
|
1201
|
+
we as a,
|
|
1202
|
+
bn as b,
|
|
1203
|
+
F as c,
|
|
1204
|
+
nn as d,
|
|
1205
|
+
on as e,
|
|
1206
|
+
z as f,
|
|
1207
|
+
Ee as g,
|
|
1208
|
+
I as h,
|
|
1209
|
+
$e as i,
|
|
1210
|
+
Ge as j,
|
|
1211
|
+
Rs as k,
|
|
1212
|
+
Ds as l,
|
|
1213
|
+
cn as m,
|
|
1214
|
+
en as n,
|
|
1215
|
+
an as o,
|
|
1216
|
+
hn as p,
|
|
1217
|
+
Ie as q,
|
|
1218
|
+
ze as r,
|
|
1219
|
+
_ as s,
|
|
1220
|
+
un as t,
|
|
1221
|
+
dn as u,
|
|
1222
|
+
is as v,
|
|
1223
|
+
B as w,
|
|
1224
|
+
us as x,
|
|
1225
|
+
Ke as y
|
|
1277
1226
|
};
|