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