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