paddleocr-js
Version:
JavaScript wrapper for PaddleOCR, providing OCR capabilities in browser and Node.js
2 lines • 1.72 MB
JavaScript
/*! For license information please see index.js.LICENSE.txt */
(()=>{var e={112:(e,t,n)=>{"use strict";n.d(t,{V:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({relu_:function(e){const t={x:(0,s.YT)(e,"x","relu")};return a.T2.runKernel(r.fUj,t)}})},125:(e,t,n)=>{"use strict";n.d(t,{o:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({clone_:function(e){const t={x:(0,s.YT)(e,"x","clone","string_or_numeric")};return a.T2.runKernel(r.lzr,t)}})},152:(e,t,n)=>{"use strict";n.d(t,{z:()=>o});var a=n(1585),r=n(5441),s=n(565),i=n(8189);const o=(0,n(929).op)({mod_:function(e,t){let n=(0,i.YT)(e,"a","mod"),o=(0,i.YT)(t,"b","mod");[n,o]=(0,s.makeTypesMatch)(n,o);const p={a:n,b:o};return a.T2.runKernel(r.BLA,p)}})},178:(e,t,n)=>{"use strict";n.d(t,{P:()=>l});var a=n(1585),r=n(5441),s=n(565),i=n(8189),o=n(2198),p=n(9809);const l=(0,n(929).op)({maximum_:function(e,t){let n=(0,i.YT)(e,"a","maximum"),l=(0,i.YT)(t,"b","maximum");[n,l]=(0,s.makeTypesMatch)(n,l),"bool"===n.dtype&&(n=(0,p.w)(n,"int32"),l=(0,p.w)(l,"int32")),(0,o.assertAndGetBroadcastShape)(n.shape,l.shape);const d={a:n,b:l};return a.T2.runKernel(r.LDN,d)}})},252:(e,t,n)=>{"use strict";n.d(t,{v:()=>l});var a=n(1585),r=n(5441),s=n(5119),i=n(7195),o=n(929),p=n(2302);const l=(0,o.op)({conv2DBackpropInput_:function(e,t,n,o,l,d="NHWC",u){s.vA(e.length===t.rank,(()=>`Length of inShape (${e.length}) and rank of dy (${t.rank}) must match`));let c=e,h=t,m=!1;3===t.rank&&(m=!0,h=(0,p.t)(t,[1,t.shape[0],t.shape[1],t.shape[2]]),c=[1,e[0],e[1],e[2]]),s.vA(4===c.length,(()=>`Error in conv2dDerInput: inShape must be length 4, but got length ${c.length}.`)),s.vA(4===h.rank,(()=>`Error in conv2dDerInput: dy must be rank 4, but got rank ${h.rank}`)),s.vA(4===n.rank,(()=>`Error in conv2dDerInput: filter must be rank 4, but got rank ${n.rank}`));const f="NHWC"===d?c[3]:c[1],g="NHWC"===d?h.shape[3]:h.shape[1];s.vA(f===n.shape[2],(()=>`Error in conv2dDerInput: depth of input (${f}) must match input depth for filter ${n.shape[2]}.`)),s.vA(g===n.shape[3],(()=>`Error in conv2dDerInput: depth of output (${g}) must match output depth for filter ${n.shape[3]}.`)),i.s_("conv2dDerInput",l,u);const y={dy:h,filter:n},b={strides:o,pad:l,dataFormat:d,dimRoundingMode:u,inputShape:c},v=a.T2.runKernel(r.jfg,y,b);return m?(0,p.t)(v,[v.shape[1],v.shape[2],v.shape[3]]):v}})},259:(e,t,n)=>{"use strict";n.d(t,{qY:()=>b,yl:()=>u,rT:()=>w,tp:()=>v,B4:()=>y,Q5:()=>g,qP:()=>f});var a=n(1743),r=n(5119);function s(e,t,n,a){const s=(0,r.Ur)(t),o=function(e,t,n,a){const s=(0,r.Ze)(t),o=a[a.length-1],p=new Array(o).fill(0),d=t.length,u="complex64"===n?l(e):e;if(d>1)for(let e=0;e<s/o;e++){const t=e*o;for(let e=0;e<o;e++)p[e]=Math.max(p[e],i(u[t+e],0,n).length)}return p}(e,t,n,s),d=t.length,u=p(e,t,n,s,o),c=["Tensor"];return a&&(c.push(` dtype: ${n}`),c.push(` rank: ${d}`),c.push(` shape: [${t}]`),c.push(" values:")),c.push(u.map((e=>" "+e)).join("\n")),c.join("\n")}function i(e,t,n){let a;return a=Array.isArray(e)?`${parseFloat(e[0].toFixed(7))} + ${parseFloat(e[1].toFixed(7))}j`:(0,r.Kg)(e)?`'${e}'`:"bool"===n?o(e):parseFloat(e.toFixed(7)).toString(),(0,r.av)(a,t)}function o(e){return 0===e?"false":"true"}function p(e,t,n,a,r,s=!0){const d="complex64"===n?2:1,u=t[0],c=t.length;if(0===c){if("complex64"===n){return[i(l(e)[0],0,n)]}return"bool"===n?[o(e[0])]:[e[0].toString()]}if(1===c){if(u>20){const t=3*d;let a=Array.from(e.slice(0,t)),s=Array.from(e.slice((u-3)*d,u*d));return"complex64"===n&&(a=l(a),s=l(s)),["["+a.map(((e,t)=>i(e,r[t],n))).join(", ")+", ..., "+s.map(((e,t)=>i(e,r[u-3+t],n))).join(", ")+"]"]}return["["+("complex64"===n?l(e):Array.from(e)).map(((e,t)=>i(e,r[t],n))).join(", ")+"]"]}const h=t.slice(1),m=a.slice(1),f=a[0]*d,g=[];if(u>20){for(let t=0;t<3;t++){const a=t*f,s=a+f;g.push(...p(e.slice(a,s),h,n,m,r,!1))}g.push("...");for(let t=u-3;t<u;t++){const a=t*f,s=a+f;g.push(...p(e.slice(a,s),h,n,m,r,t===u-1))}}else for(let t=0;t<u;t++){const a=t*f,s=a+f;g.push(...p(e.slice(a,s),h,n,m,r,t===u-1))}const y=2===c?",":"";g[0]="["+(u>0?g[0]+y:"");for(let e=1;e<g.length-1;e++)g[e]=" "+g[e]+y;let b=",\n";for(let e=2;e<c;e++)b+="\n";return g[g.length-1]=" "+g[g.length-1]+"]"+(s?"":b),g}function l(e){const t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var d=n(3879);class u{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=r.Ze(e),null!=n){const e=n.length;r.vA(e===this.size,(()=>`Length of values '${e}' does not match the size inferred by the shape '${this.size}'.`))}if("complex64"===t)throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||r.Ab(t,this.size),this.strides=(0,r.Ur)(e)}set(e,...t){0===t.length&&(t=[0]),r.vA(t.length===this.rank,(()=>`The number of provided coordinates (${t.length}) must match the rank (${this.rank})`));const n=this.locToIndex(t);this.values[n]=e}get(...e){0===e.length&&(e=[0]);let t=0;for(const n of e){if(n<0||n>=this.shape[t]){const t=`Requested out of range element at ${e}. Buffer shape=${this.shape}`;throw new Error(t)}t++}let n=e[e.length-1];for(let t=0;t<e.length-1;++t)n+=this.strides[t]*e[t];return this.values[n]}locToIndex(e){if(0===this.rank)return 0;if(1===this.rank)return e[0];let t=e[e.length-1];for(let n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t}indexToLoc(e){if(0===this.rank)return[];if(1===this.rank)return[e];const t=new Array(this.shape.length);for(let n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return c().makeTensor(this.values,this.shape,this.dtype)}}let c=null,h=null,m=null;function f(e){c=e}function g(e){h=e}function y(e){m=e}class b{constructor(e,t,n,a){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=r.Ze(e),this.strides=(0,r.Ur)(e),this.dataId=n,this.id=a,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const e=await this.data();return h.buffer(this.shape,this.dtype,e)}bufferSync(){return h.buffer(this.shape,this.dtype,this.dataSync())}async array(){const e=await this.data();return(0,r.yw)(this.shape,e,"complex64"===this.dtype)}arraySync(){return(0,r.yw)(this.shape,this.dataSync(),"complex64"===this.dtype)}async data(){this.throwIfDisposed();const e=c().read(this.dataId);if("string"===this.dtype){const t=await e;try{return t.map((e=>d.decodeString(e)))}catch(e){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return e}dataToGPU(e){return this.throwIfDisposed(),c().readToGPU(this.dataId,e)}dataSync(){this.throwIfDisposed();const e=c().readSync(this.dataId);if("string"===this.dtype)try{return e.map((e=>d.decodeString(e)))}catch(e){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e}async bytes(){this.throwIfDisposed();const e=await c().read(this.dataId);return"string"===this.dtype?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(this.kerasMask&&this.kerasMask.dispose(),c().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return h.print(this,e)}clone(){return this.throwIfDisposed(),h.clone(this)}toString(e=!1){return s(this.dataSync(),this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),h.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),c().makeVariable(this,e,t,n)}}function v(){return(0,a.m)("Tensor",(()=>b))}Object.defineProperty(b,Symbol.hasInstance,{value:e=>!!e&&null!=e.data&&null!=e.dataSync&&null!=e.throwIfDisposed}),v();class w extends b{constructor(e,t,n,a){super(e.shape,e.dtype,e.dataId,a),this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtype of the new value (${e.dtype}) and previous value (${this.dtype}) must match`);if(!r.r1(e.shape,this.shape))throw new Error(`shape of the new value (${e.shape}) and previous value (${this.shape}) must match`);c().disposeTensor(this),this.dataId=e.dataId,c().incRef(this,null)}dispose(){c().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty(w,Symbol.hasInstance,{value:e=>e instanceof b&&null!=e.assign&&e.assign instanceof Function})},269:(e,t,n)=>{"use strict";n.d(t,{y:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({asinh_:function(e){const t={x:(0,s.YT)(e,"x","asinh")};return a.T2.runKernel(r.epO,t)}})},302:(e,t,n)=>{"use strict";n.d(t,{L:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({cumprod_:function(e,t=0,n=!1,i=!1){const o={x:(0,s.YT)(e,"x","cumprod")},p={axis:t,exclusive:n,reverse:i};return a.T2.runKernel(r.jj_,o,p)}})},361:function(e,t,n){"use strict";var a=this&&this.__createBinding||(Object.create?function(e,t,n,a){void 0===a&&(a=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,a,r)}:function(e,t,n,a){void 0===a&&(a=n),e[a]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||a(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(6521),t),r(n(7118),t),r(n(2335),t),r(n(6536),t),r(n(7373),t),r(n(4483),t),r(n(7356),t),r(n(7190),t),r(n(554),t)},448:(e,t,n)=>{"use strict";n.d(t,{r:()=>s});var a=n(259),r=n(5119);function s(e,t="float32",n){return t=t||"float32",r.SA(e),new a.yl(e,t,n)}},517:(e,t,n)=>{"use strict";n.d(t,{I:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({expm1_:function(e){const t={x:(0,s.YT)(e,"x","expm1")};return a.T2.runKernel(r.ybj,t)}})},554:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},565:(e,t,n)=>{"use strict";n.r(t),n.d(t,{assertTypesMatch:()=>o,getTensorsInContainer:()=>l,isTensorInList:()=>p,makeTypesMatch:()=>i});var a=n(259),r=n(2046),s=n(5119);function i(e,t){if(e.dtype===t.dtype)return[e,t];const n=(0,r.Tu)(e.dtype,t.dtype);return[e.cast(n),t.cast(n)]}function o(e,t){(0,s.vA)(e.dtype===t.dtype,(()=>`The dtypes of the first(${e.dtype}) and second(${t.dtype}) input must match`))}function p(e,t){return t.some((t=>t.id===e.id))}function l(e){const t=[];return d(e,t,new Set),t}function d(e,t,n){if(null==e)return;if(e instanceof a.qY)return void t.push(e);if(r=e,!Array.isArray(r)&&"object"!==typeof r)return;var r;const s=e;for(const e in s){const a=s[e];n.has(a)||(n.add(a),d(a,t,n))}}},676:(e,t,n)=>{"use strict";n.d(t,{G:()=>d});var a=n(1585),r=n(5441),s=n(8189),i=n(5119),o=n(7195),p=n(929),l=n(2302);const d=(0,p.op)({depthwiseConv2d_:function(e,t,n,p,d="NHWC",u=[1,1],c){const h=(0,s.YT)(e,"x","depthwiseConv2d","float32"),m=(0,s.YT)(t,"filter","depthwiseConv2d","float32");let f=h,g=!1;3===h.rank&&(g=!0,f=(0,l.t)(h,[1,h.shape[0],h.shape[1],h.shape[2]])),i.vA(4===f.rank,(()=>`Error in depthwiseConv2d: input must be rank 4, but got rank ${f.rank}.`)),i.vA(4===m.rank,(()=>`Error in depthwiseConv2d: filter must be rank 4, but got rank ${m.rank}.`));const y="NHWC"===d?f.shape[3]:f.shape[1];i.vA(y===m.shape[2],(()=>`Error in depthwiseConv2d: number of input channels (${y}) must match the inChannels dimension in filter ${m.shape[2]}.`)),o.s_("depthwiseConv2d",p,c);const b={x:f,filter:m},v={strides:n,pad:p,dataFormat:d,dilations:u,dimRoundingMode:c},w=a.T2.runKernel(r.tGH,b,v);return g?(0,l.t)(w,[w.shape[1],w.shape[2],w.shape[3]]):w}})},700:(e,t,n)=>{"use strict";n.d(t,{P:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({step_:function(e,t=0){const n={x:(0,s.YT)(e,"x","step")},i={alpha:t};return a.T2.runKernel(r.pnw,n,i)}})},722:e=>{"use strict";e.exports=require("@tensorflow/tfjs-node")},776:(e,t,n)=>{"use strict";n.d(t,{e:()=>o});var a=n(1585),r=n(5441),s=n(8189),i=n(5119);const o=(0,n(929).op)({spaceToBatchND_:function(e,t,n){const o=(0,s.YT)(e,"x","spaceToBatchND");i.vA(o.rank>=1+t.length,(()=>`input rank ${o.rank} should be > than [blockShape] ${t.length}`)),i.vA(n.length===t.length,(()=>`paddings.shape[0] ${n.length} must be equal to [blockShape] ${t.length}`)),i.vA(o.shape.reduce(((e,a,r)=>r>0&&r<=t.length?e&&(a+n[r-1][0]+n[r-1][1])%t[r-1]===0:e),!0),(()=>`input spatial dimensions ${o.shape.slice(1)} with paddings ${n.toString()} must be divisible by blockShapes ${t.toString()}`));const p={x:o},l={blockShape:t,paddings:n};return a.T2.runKernel(r.A8B,p,l)}})},850:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.InferenceSession=void 0;const a=n(8176),r=n(6536),s=n(7356);class i{constructor(e){this.handler=e}async run(e,t,n){(0,s.TRACE_FUNC_BEGIN)();const a={};let i={};if("object"!==typeof e||null===e||e instanceof r.Tensor||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let o=!0;if("object"===typeof t){if(null===t)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof r.Tensor)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(0===t.length)throw new TypeError("'fetches' cannot be an empty array.");o=!1;for(const e of t){if("string"!==typeof e)throw new TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(e))throw new RangeError(`'fetches' contains invalid output name: ${e}.`);a[e]=null}if("object"===typeof n&&null!==n)i=n;else if("undefined"!==typeof n)throw new TypeError("'options' must be an object.")}else{let e=!1;const s=Object.getOwnPropertyNames(t);for(const n of this.outputNames)if(-1!==s.indexOf(n)){const s=t[n];(null===s||s instanceof r.Tensor)&&(e=!0,o=!1,a[n]=s)}if(e){if("object"===typeof n&&null!==n)i=n;else if("undefined"!==typeof n)throw new TypeError("'options' must be an object.")}else i=t}}else if("undefined"!==typeof t)throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const t of this.inputNames)if("undefined"===typeof e[t])throw new Error(`input '${t}' is missing in 'feeds'.`);if(o)for(const e of this.outputNames)a[e]=null;const p=await this.handler.run(e,a,i),l={};for(const e in p)if(Object.hasOwnProperty.call(p,e)){const t=p[e];t instanceof r.Tensor?l[e]=t:l[e]=new r.Tensor(t.type,t.data,t.dims)}return(0,s.TRACE_FUNC_END)(),l}async release(){return this.handler.dispose()}static async create(e,t,n,r){let o;(0,s.TRACE_FUNC_BEGIN)();let p={};if("string"===typeof e){if(o=e,"object"===typeof t&&null!==t)p=t;else if("undefined"!==typeof t)throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(o=e,"object"===typeof t&&null!==t)p=t;else if("undefined"!==typeof t)throw new TypeError("'options' must be an object.")}else{if(!(e instanceof ArrayBuffer||"undefined"!==typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{const a=e;let s=0,i=e.byteLength;if("object"===typeof t&&null!==t)p=t;else if("number"===typeof t){if(s=t,!Number.isSafeInteger(s))throw new RangeError("'byteOffset' must be an integer.");if(s<0||s>=a.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${a.byteLength}).`);if(i=e.byteLength-s,"number"===typeof n){if(i=n,!Number.isSafeInteger(i))throw new RangeError("'byteLength' must be an integer.");if(i<=0||s+i>a.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${a.byteLength-s}].`);if("object"===typeof r&&null!==r)p=r;else if("undefined"!==typeof r)throw new TypeError("'options' must be an object.")}else if("undefined"!==typeof n)throw new TypeError("'byteLength' must be a number.")}else if("undefined"!==typeof t)throw new TypeError("'options' must be an object.");o=new Uint8Array(a,s,i)}}const[l,d]=await(0,a.resolveBackendAndExecutionProviders)(p),u=await l.createInferenceSessionHandler(o,d);return(0,s.TRACE_FUNC_END)(),new i(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}t.InferenceSession=i},855:(e,t,n)=>{"use strict";n.d(t,{m:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({ceil_:function(e){const t={x:(0,s.YT)(e,"x","ceil","float32")};return a.T2.runKernel(r.QDP,t)}})},857:e=>{"use strict";e.exports=require("os")},897:(e,t,n)=>{"use strict";n.d(t,{F:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({argMax_:function(e,t=0){const n={x:(0,s.YT)(e,"x","argMax")},i={axis:t};return a.T2.runKernel(r.Jp_,n,i)}})},919:(e,t,n)=>{"use strict";n.d(t,{e:()=>d});var a=n(565),r=n(8189),s=n(9359),i=n(3020),o=n(929),p=n(2151),l=n(5537);const d=(0,o.op)({divNoNan_:function(e,t){let n=(0,r.YT)(e,"a","div"),o=(0,r.YT)(t,"b","div");[n,o]=(0,a.makeTypesMatch)(n,o);const d=(0,s.y)(n,o),u=(0,l.P)(d),c=(0,i.L)(o,u);return(0,p._)(c,u,d)}})},929:(e,t,n)=>{"use strict";n.d(t,{B:()=>s,op:()=>i});var a=n(1585),r=n(5119);const s="__op";function i(e){const t=Object.keys(e);if(1!==t.length)throw new Error(`Please provide an object with a single key (operation name) mapping to a function. Got an object with ${t.length} keys.`);let n=t[0];const i=e[n];n.endsWith("_")&&(n=n.substring(0,n.length-1)),n+=s;const o=(...e)=>{a.T2.startScope(n);try{const t=i(...e);return(0,r.yL)(t),a.T2.endScope(t),t}catch(e){throw a.T2.endScope(null),e}};return Object.defineProperty(o,"name",{value:n,configurable:!0}),o}},1078:(e,t,n)=>{"use strict";n.d(t,{Em:()=>l,SM:()=>o,WC:()=>p,WH:()=>r,aF:()=>s,fK:()=>u,gx:()=>d,lb:()=>i});var a=n(5119);function r(e,t){for(let n=0;n<e.length;++n)if(e[e.length-n-1]!==t-1-n)return!1;return!0}function s(e,t,n){const a=e.length+t.length,r=[];let s=0,i=0;for(let o=0;o<a;o++)-1===n.indexOf(o)?r.push(e[s++]):r.push(t[i++]);return r}function i(e,t){const n=[],a=e.length;for(let r=0;r<a;r++)-1===t.indexOf(r)&&n.push(e[r]);return[n,t.map((t=>e[t]))]}function o(e,t){return s(e,t.map((e=>1)),t)}function p(e,t,n){a.vA(r(t,n),(()=>`${e} supports only inner-most axes for now. Got axes ${t} and rank-${n} input.`))}function l(e,t){if(r(e,t))return null;const n=[];for(let a=0;a<t;++a)-1===e.indexOf(a)&&n.push(a);return e.forEach((e=>n.push(e))),n}function d(e){return e.map(((e,t)=>[t,e])).sort(((e,t)=>e[1]-t[1])).map((e=>e[0]))}function u(e,t){const n=[];for(let a=t-e;a<t;++a)n.push(a);return n}},1106:(e,t,n)=>{"use strict";n.d(t,{w:()=>s});var a=n(8189),r=n(252);const s=(0,n(929).op)({conv2dTranspose_:function(e,t,n,s,i,o){const p=(0,a.YT)(e,"x","conv2dTranspose"),l=(0,a.YT)(t,"filter","conv2dTranspose");return(0,r.v)(n,p,l,s,i,"NHWC",o)}})},1115:(e,t,n)=>{"use strict";n.d(t,{_:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({sign_:function(e){const t={x:(0,s.YT)(e,"x","sign")};return a.T2.runKernel(r.YVe,t)}})},1190:(e,t,n)=>{"use strict";n.d(t,{r:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({topk_:function(e,t=1,n=!0){const i=(0,s.YT)(e,"x","topk");if(0===i.rank)throw new Error("topk() expects the input to be of rank 1 or higher");const o=i.shape[i.shape.length-1];if(t<0)throw new Error(`'k' passed to topk() must be >= 0 but got ${t}`);if(t>o)throw new Error(`'k' passed to topk() must be <= the last dimension (${o}) but got ${t}`);const p={x:i},l={k:t,sorted:n},[d,u]=a.T2.runKernel(r.TBb,p,l);return{values:d,indices:u}}})},1216:(e,t,n)=>{"use strict";n.d(t,{R:()=>o});var a=n(1585),r=n(5441),s=n(8189),i=n(5119);const o=(0,n(929).op)({depthToSpace_:function(e,t,n="NHWC"){const o=(0,s.YT)(e,"x","depthToSpace","float32"),p="NHWC"===n?o.shape[1]:o.shape[2],l="NHWC"===n?o.shape[2]:o.shape[3],d="NHWC"===n?o.shape[3]:o.shape[1];i.vA(t>1,(()=>`blockSize should be > 1 for depthToSpace, but was: ${t}`)),i.vA(p*t>=0,(()=>`Negative dimension size caused by overflow when multiplying\n ${p} and ${t} for depthToSpace with input shape\n ${o.shape}`)),i.vA(l*t>=0,(()=>`Negative dimension size caused by overflow when multiplying\n ${l} and ${t} for depthToSpace with input shape\n ${o.shape}`)),i.vA(d%(t*t)===0,(()=>`Dimension size must be evenly divisible by ${t*t} but is ${d} for depthToSpace with input shape ${o.shape}`));const u={x:o},c={blockSize:t,dataFormat:n};return a.T2.runKernel(r.TMz,u,c)}})},1303:(e,t,n)=>{"use strict";n.d(t,{M:()=>p});var a=n(1585),r=n(5441),s=n(565),i=n(8189),o=n(2198);const p=(0,n(929).op)({less_:function(e,t){let n=(0,i.YT)(e,"a","less","string_or_numeric"),p=(0,i.YT)(t,"b","less","string_or_numeric");[n,p]=(0,s.makeTypesMatch)(n,p),(0,o.assertAndGetBroadcastShape)(n.shape,p.shape);const l={a:n,b:p};return a.T2.runKernel(r.mIA,l)}})},1361:(e,t,n)=>{"use strict";n.d(t,{h:()=>i});var a=n(1585),r=n(5441),s=n(5119);const i=(0,n(929).op)({fft_:function(e){(0,s.vA)("complex64"===e.dtype,(()=>`The dtype for tf.spectral.fft() must be complex64 but got ${e.dtype}.`));const t={input:e};return a.T2.runKernel(r.rGP,t)}})},1404:(e,t,n)=>{"use strict";n.d(t,{F:()=>o});var a=n(1585),r=n(5441),s=n(565),i=n(8189);const o=(0,n(929).op)({atan2_:function(e,t){let n=(0,i.YT)(e,"a","atan2"),o=(0,i.YT)(t,"b","atan2");[n,o]=(0,s.makeTypesMatch)(n,o);const p={a:n,b:o};return a.T2.runKernel(r.lxb,p)}})},1411:(e,t,n)=>{"use strict";n.d(t,{S:()=>o});var a=n(1585),r=n(5119),s=n(7148),i=n(2855);function o(e,t="float32"){if((0,r.SA)(e),"complex64"===t){const t=o(e,"float32"),n=(0,i.U)(e,"float32");return(0,s.f)(t,n)}const n=(0,r.FZ)((0,r.Ze)(e),t);return a.T2.makeTensor(n,e,t)}},1455:e=>{"use strict";e.exports=require("node:fs/promises")},1585:(e,t,n)=>{"use strict";n.d(t,{T2:()=>w,Ye:()=>v});var a=n(5149),r=n(6574),s=n(1743),i=n(5441),o=n(7074),p=n(3673),l=n(3879),d=n(5119);class u{constructor(e,t){this.backendTimer=e,this.logger=t,null==t&&(this.logger=new h)}profileKernel(e,t,n){let a;const s=()=>{a=n()};let i;const o=l.now();if(this.backendTimer.timerAvailable())i=this.backendTimer.time(s);else{s();for(const e of a)e.dataSync();i=Promise.resolve({kernelMs:l.now()-o})}if((0,r._K)().getBool("CHECK_COMPUTATION_FOR_ERRORS"))for(let t=0;t<a.length;t++){const n=a[t];n.data().then((t=>{c(t,n.dtype,e)}))}return{kernelName:e,outputs:a,inputs:t,timeMs:i.then((e=>e.kernelMs)),extraInfo:i.then((e=>null!=e.getExtraProfileInfo?e.getExtraProfileInfo():""))}}logKernelProfile(e){const{kernelName:t,outputs:n,timeMs:a,inputs:r,extraInfo:s}=e;n.forEach((e=>{Promise.all([e.data(),a,s]).then((n=>{this.logger.logKernelProfile(t,e,n[0],n[1],r,n[2])}))}))}}function c(e,t,n){if("float32"!==t)return!1;for(let t=0;t<e.length;t++){const n=e[t];if(isNaN(n)||!isFinite(n))return!0}return!1}class h{logKernelProfile(e,t,n,a,r,s){"number"===typeof a?d.av(`${a}ms`,9):a.error,d.av(e,25),t.rank,t.size,d.av(t.shape.toString(),14);let i="";for(const e in r){const n=r[e];if(null!=n){const a=n.shape||t.shape,r=a.length;i+=`${e}: ${r}D ${r>0?a:""} `}}}}var m=n(259),f=n(565);function g(e){return null!=e.kernelName}class y{constructor(){this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.gradientDepth=0,this.kernelDepth=0,this.scopeStack=[],this.numDataMovesStack=[],this.nextScopeId=0,this.tensorInfo=new WeakMap,this.profiling=!1,this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null,get kernelNames(){return Array.from(new Set(this.kernels.map((e=>e.name))))}}}dispose(){for(const e in this.registeredVariables)this.registeredVariables[e].dispose()}}class b{constructor(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new y}async ready(){if(null!=this.pendingBackendInit)return this.pendingBackendInit.then((()=>{}));if(null!=this.backendInstance)return;const e=this.getSortedBackends();for(let t=0;t<e.length;t++){const n=e[t];if(await this.initializeBackend(n).success)return void await this.setBackend(n)}throw new Error("Could not initialize any backends, all backend initializations failed.")}get backend(){if(null!=this.pendingBackendInit)throw new Error(`Backend '${this.backendName}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);if(null==this.backendInstance){const{name:e,asyncInit:t}=this.initializeBackendsAndReturnBest();if(t)throw new Error(`The highest priority backend '${e}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);this.setBackend(e)}return this.backendInstance}backendNames(){return Object.keys(this.registryFactory)}findBackend(e){if(!(e in this.registry)){if(!(e in this.registryFactory))return null;{const{asyncInit:t}=this.initializeBackend(e);if(t)return null}}return this.registry[e]}findBackendFactory(e){return e in this.registryFactory?this.registryFactory[e].factory:null}registerBackend(e,t,n=1){return e in this.registryFactory?(p.i(`${e} backend was already registered. Reusing existing backend factory.`),!1):(this.registryFactory[e]={factory:t,priority:n},!0)}async setBackend(e){if(null==this.registryFactory[e])throw new Error(`Backend name '${e}' not found in registry`);if(this.backendName=e,null==this.registry[e]){this.backendInstance=null;const{success:t,asyncInit:n}=this.initializeBackend(e);if(!(n?await t:t))return!1}return this.backendInstance=this.registry[e],this.setupRegisteredKernels(),this.profiler=new u(this.backendInstance),!0}setupRegisteredKernels(){(0,o.Op)(this.backendName).forEach((e=>{null!=e.setupFunc&&e.setupFunc(this.backendInstance)}))}disposeRegisteredKernels(e){(0,o.Op)(e).forEach((t=>{null!=t.disposeFunc&&t.disposeFunc(this.registry[e])}))}initializeBackend(e){const t=this.registryFactory[e];if(null==t)throw new Error(`Cannot initialize backend ${e}, no registration found.`);try{const n=t.factory();if(!n||n instanceof a.uI||"function"!==typeof n.then)return this.registry[e]=n,{success:!0,asyncInit:!1};{const t=++this.pendingBackendInitId,a=n.then((n=>!(t<this.pendingBackendInitId)&&(this.registry[e]=n,this.pendingBackendInit=null,!0))).catch((n=>(t<this.pendingBackendInitId||(this.pendingBackendInit=null,p.i(`Initialization of backend ${e} failed`),p.i(n.stack||n.message)),!1)));return this.pendingBackendInit=a,{success:a,asyncInit:!0}}}catch(t){return p.i(`Initialization of backend ${e} failed`),p.i(t.stack||t.message),{success:!1,asyncInit:!1}}}removeBackend(e){if(!(e in this.registryFactory))throw new Error(`${e} backend not found in registry`);this.backendName===e&&null!=this.pendingBackendInit&&this.pendingBackendInitId++,e in this.registry&&(this.disposeRegisteredKernels(e),this.registry[e].dispose(),delete this.registry[e]),delete this.registryFactory[e],this.backendName===e&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null)}getSortedBackends(){if(0===Object.keys(this.registryFactory).length)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort(((e,t)=>this.registryFactory[t].priority-this.registryFactory[e].priority))}initializeBackendsAndReturnBest(){const e=this.getSortedBackends();for(let t=0;t<e.length;t++){const n=e[t],{success:a,asyncInit:r}=this.initializeBackend(n);if(r||a)return{name:n,asyncInit:r}}throw new Error("Could not initialize any backends, all backend initializations failed.")}moveData(e,t){const n=this.state.tensorInfo.get(t),a=n.backend,r=this.readSync(t),s=a.refCount(t);a.disposeData(t,!0),n.backend=e,e.move(t,r,n.shape,n.dtype,s),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++}tidy(e,t){let n,a=null;if(null==t){if("function"!==typeof e)throw new Error("Please provide a function to tidy()");t=e}else{if("string"!==typeof e&&!(e instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if("function"!==typeof t)throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");a=e}return this.scopedRun((()=>this.startScope(a)),(()=>this.endScope(n)),(()=>(n=t(),n)))}scopedRun(e,t,n){e();try{const e=n();return t(),e}catch(e){throw t(),e}}nextTensorId(){return b.nextTensorId++}nextVariableId(){return b.nextVariableId++}clone(e){const t=w.runKernel(i.lzr,{x:e}),n={x:e};return this.addTapeNode(this.state.activeScope.name,n,[t],(e=>({x:()=>{const t={x:e},n={dtype:"float32"};return w.runKernel(i.KXH,t,n)}})),[],{}),t}runKernel(e,t,n){null==this.backendName&&this.backend;if(!(null!=(0,o._5)(e,this.backendName)))throw new Error(`Kernel '${e}' not registered for backend '${this.backendName}'`);return this.runKernelFunc({kernelName:e,inputs:t,attrs:n})}shouldCheckForMemLeaks(){return this.ENV.getBool("IS_TEST")}checkKernelForMemLeak(e,t,n){const a=this.backend.numDataIds();let r=0;n.forEach((e=>{r+="complex64"===e.dtype?3:1}));const s=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],i=a-t-r-s;if(i>0)throw new Error(`Backend '${this.backendName}' has an internal memory leak (${i} data ids) after running '${e}'`)}runKernelFunc(e){let t,n=[];const a=this.isTapeOn(),r=this.state.numBytes,s=this.state.numTensors;let i,p;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0),null==this.backendName&&this.backend;const l=g(e)?e.kernelName:null!=this.state.activeScope?this.state.activeScope.name:"";if(g(e)){const{kernelName:t,inputs:r,attrs:s}=e;null==this.backendName&&this.backend;const l=(0,o._5)(t,this.backendName);d.vA(null!=l,(()=>`Cannot find registered kernel '${t}' for backend '${this.backendName}'`)),i=()=>{const e=this.backend.numDataIds();p=l.kernelFunc({inputs:r,attrs:s,backend:this.backend});const i=Array.isArray(p)?p:[p];this.shouldCheckForMemLeaks()&&this.checkKernelForMemLeak(t,e,i);const o=i.map((e=>null!=e.rank?e:this.makeTensorFromTensorInfo(e)));if(a){const e=this.getTensorsForGradient(t,r,o);n=this.saveTensorsForBackwardMode(e)}return o}}else{const{forwardFunc:t}=e,r=e=>{a&&(n=e.map((e=>this.keep(this.clone(e)))))};i=()=>{const e=this.backend.numDataIds();p=this.tidy((()=>t(this.backend,r)));const n=Array.isArray(p)?p:[p];return this.shouldCheckForMemLeaks()&&this.checkKernelForMemLeak(l,e,n),n}}const{inputs:u,attrs:c}=e,h=g(e)?null:e.backwardsFunc;let m;return this.scopedRun((()=>this.state.kernelDepth++),(()=>this.state.kernelDepth--),(()=>{this.ENV.getBool("DEBUG")||this.state.profiling?(m=this.profiler.profileKernel(l,u,(()=>i())),this.ENV.getBool("DEBUG")&&this.profiler.logKernelProfile(m),t=m.outputs):t=i()})),a&&this.addTapeNode(l,u,t,h,n,c),this.state.profiling&&this.state.activeProfile.kernels.push({name:l,bytesAdded:this.state.numBytes-r,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-s,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(u).map((e=>null!=u[e]?u[e].shape:null)),outputShapes:t.map((e=>e.shape)),kernelTimeMs:m.timeMs,extraInfo:m.extraInfo}),Array.isArray(p)?t:t[0]}saveTensorsForBackwardMode(e){const t=e.map((e=>this.keep(this.clone(e))));return t}getTensorsForGradient(e,t,n){const a=(0,o.vQ)(e);if(null!=a){const e=a.inputsToSave||[],r=a.outputsToSave||[];let s;a.saveAllInputs?(d.vA(Array.isArray(t),(()=>"saveAllInputs is true, expected inputs to be an array.")),s=Object.keys(t).map((e=>t[e]))):s=e.map((e=>t[e]));const i=n.filter(((e,t)=>r[t]));return s.concat(i)}return[]}makeTensor(e,t,n,a){if(null==e)throw new Error("Values passed to engine.makeTensor() are null");n=n||"float32",a=a||this.backend;let r=e;"string"===n&&d.Kg(e[0])&&(r=e.map((e=>l.encodeString(e))));const s=a.write(r,t,n),i=new m.qY(t,n,s,this.nextTensorId());if(this.trackTensor(i,a),"string"===n){const e=this.state.tensorInfo.get(s),t=(0,d.SL)(r);this.state.numBytes+=t-e.bytes,e.bytes=t}return i}makeTensorFromDataId(e,t,n,a){const r={dataId:e,shape:t,dtype:n=n||"float32"};return this.makeTensorFromTensorInfo(r,a)}makeTensorFromTensorInfo(e,t){const{dataId:n,shape:a,dtype:r}=e,s=new m.qY(a,r,n,this.nextTensorId());return this.trackTensor(s,t),s}makeVariable(e,t=!0,n,a){n=n||this.nextVariableId().toString(),null!=a&&a!==e.dtype&&(e=e.cast(a));const r=new m.rT(e,t,n,this.nextTensorId());if(null!=this.state.registeredVariables[r.name])throw new Error(`Variable with name ${r.name} was already registered`);return this.state.registeredVariables[r.name]=r,this.incRef(r,this.backend),r}trackTensor(e,t){this.state.numTensors++,"string"===e.dtype&&this.state.numStringTensors++;let n=0;"complex64"!==e.dtype&&"string"!==e.dtype&&(n=e.size*d.jv(e.dtype)),this.state.numBytes+=n,this.state.tensorInfo.has(e.dataId)||(this.state.numDataBuffers++,this.state.tensorInfo.set(e.dataId,{backend:t||this.backend,dtype:e.dtype,shape:e.shape,bytes:n})),e instanceof m.rT||this.track(e)}incRef(e,t){this.trackTensor(e,t),this.backend.incRef(e.dataId)}removeDataId(e,t){this.state.tensorInfo.has(e)&&this.state.tensorInfo.get(e).backend===t&&(this.state.tensorInfo.delete(e),this.state.numDataBuffers--)}disposeTensor(e){if(!this.state.tensorInfo.has(e.dataId))return;const t=this.state.tensorInfo.get(e.dataId);if(this.state.numTensors--,"string"===e.dtype&&(this.state.numStringTensors--,this.state.numBytes-=t.bytes),"complex64"!==e.dtype&&"string"!==e.dtype){const t=e.size*d.jv(e.dtype);this.state.numBytes-=t}t.backend.disposeData(e.dataId)&&this.removeDataId(e.dataId,t.backend)}disposeVariables(){for(const e in this.state.registeredVariables){const t=this.state.registeredVariables[e];this.disposeVariable(t)}}disposeVariable(e){this.disposeTensor(e),null!=this.state.registeredVariables[e.name]&&delete this.state.registeredVariables[e.name]}memory(){const e=this.backend.memory();return e.numTensors=this.state.numTensors,e.numDataBuffers=this.state.numDataBuffers,e.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(e.unreliable=!0,null==e.reasons&&(e.reasons=[]),e.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),e}async profile(e){this.state.profiling=!0;const t=this.state.numBytes,n=this.state.numTensors;this.state.activeProfile.kernels=[],this.state.activeProfile.result=await e(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max(...this.state.activeProfile.kernels.map((e=>e.totalBytesSnapshot))),this.state.activeProfile.newBytes=this.state.numBytes-t,this.state.activeProfile.newTensors=this.state.numTensors-n;for(const e of this.state.activeProfile.kernels)e.kernelTimeMs=await e.kernelTimeMs,e.extraInfo=await e.extraInfo;return this.state.activeProfile}isTapeOn(){return this.state.gradientDepth>0&&0===this.state.kernelDepth}addTapeNode(e,t,n,a,r,s){const i={id:this.state.nextTapeNodeId++,kernelName:e,inputs:t,outputs:n,saved:r},p=(0,o.vQ)(e);null!=p&&(a=p.gradFunc),null!=a&&(i.gradient=e=>(e=e.map(((e,t)=>{if(null==e){const e=n[t],a=d.Ty(e.size,e.dtype);return this.makeTensor(a,e.shape,e.dtype)}return e})),a(e.length>1?e:e[0],r,s))),this.state.activeTape.push(i)}keep(e){return e.kept=!0,e}startTape(){0===this.state.gradientDepth&&(this.state.activeTape=[]),this.state.gradientDepth++}endTape(){this.state.gradientDepth--}startScope(e){const t={track:[],name:"unnamed scope",id:this.state.nextScopeId++};e&&(t.name=e),this.state.scopeStack.push(t),this.state.activeScope=t}endScope(e){const t=(0,f.getTensorsInContainer)(e),n=new Set(t.map((e=>e.id)));for(let e=0;e<this.state.activeScope.track.length;e++){const t=this.state.activeScope.track[e];t.kept||n.has(t.id)||t.dispose()}const a=this.state.scopeStack.pop();this.state.activeScope=0===this.state.scopeStack.length?null:this.state.scopeStack[this.state.scopeStack.length-1],t.forEach((e=>{e.kept||e.scopeId!==a.id||this.track(e)}))}gradients(e,t,n,a=!1){if(d.vA(t.length>0,(()=>"gradients() received an empty list of xs.")),null!=n&&"float32"!==n.dtype)throw new Error(`dy must have 'float32' dtype, but has '${n.dtype}'`);const r=this.scopedRun((()=>this.startTape()),(()=>this.endTape()),(()=>this.tidy("forward",e)));d.vA(r instanceof m.qY,(()=>"The result y returned by f() must be a tensor."));const s=function(e,t,n){const a={},r={};for(let e=0;e<t.length;e++)a[t[e].id]=!0;for(let n=0;n<e.length;n++){const s=e[n],i=s.inputs;for(const e in i){const n=i[e];let o=!1;for(let e=0;e<t.length;e++)if(a[n.id]){s.outputs.forEach((e=>a[e.id]=!0)),o=!0,r[s.id]=!0;break}if(o)break}}const s={};s[n.id]=!0;const i={};for(let t=e.length-1;t>=0;t--){const n=e[t],a=n.inputs;for(let e=0;e<n.outputs.length;e++)if(s[n.outputs[e].id]){for(const e in a)s[a[e].id]=!0,i[n.id]=!0;break}}const o=[];for(let t=0;t<e.length;t++){const n=e[t];if(r[n.id]&&i[n.id]){const e={};for(const t in n.inputs){const r=n.inputs[t];a[r.id]&&(e[t]=r)}const t=Object.assign({},n);t.inputs=e,t.outputs=n.outputs,o.push(t)}}return o}(this.state.activeTape,t,r);if(!a&&0===s.length&&t.length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");return this.tidy("backward",(()=>{const e={};e[r.id]=null==n?function(e){const t=(0,d.FZ)((0,d.Ze)(e),"float32");return w.makeTensor(t,e,"float32")}(r.shape):n,function(e,t,n,a){for(let r=t.length-1;r>=0;r--){const s=t[r],i=[];if(s.outputs.forEach((t=>{const n=e[t.id];null!=n?i.push(n):i.push(null)})),null==s.gradient)throw new Error(`Cannot compute gradient: gradient function not found for ${s.kernelName}.`);const o=s.gradient(i);for(const t in s.inputs){if(!(t in o))throw new Error(`Cannot backprop through input ${t}. Available gradients found: ${Object.keys(o)}.`);const r=n((()=>o[t]()));if("float32"!==r.dtype)throw new Error(`Error in gradient for op ${s.kernelName}. The gradient of input ${t} must have 'float32' dtype, but has '${r.dtype}'`);const i=s.inputs[t];if(!d.r1(r.shape,i.shape))throw new Error(`Error in gradient for op ${s.kernelName}. The gradient of input '${t}' has shape '${r.shape}', which does not match the shape of the input '${i.shape}'`);if(null==e[i.id])e[i.id]=r;else{const t=e[i.id];e[i.id]=a(t,r),t.dispose()}}}}(e,s,(e=>this.tidy(e)),x);const a=t.map((t=>e[t.id]));return 0===this.state.gradientDepth&&(this.state.activeTape.forEach((e=>{for(const t of e.saved)t.dispose()})),this.state.activeTape=null),{value:r,grads:a}}))}customGrad(e){return d.vA(d.Tn(e),(()=>"The f passed in customGrad(f) must be a function.")),(...t)=>{let n;d.vA(t.every((e=>e instanceof m.qY)),(()=>"The args passed in customGrad(f)(x1, x2,...) must all be tensors"));const a={};t.forEach(((e,t)=>{a[t]=e}));return this.runKernelFunc({forwardFunc:(a,r)=>(n=e(...t,r),d.vA(n.value instanceof m.qY,(()=>"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor")),d.vA(d.Tn(n.gradFunc),(()=>"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function.")),n.value),backwardsFunc:(e,a)=>{const r=n.gradFunc(e,a),s=Array.isArray(r)?r:[r];d.vA(s.length===t.length,(()=>"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...).")),d.vA(s.every((e=>e instanceof m.qY)),(()=>"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."));const i={};return s.forEach(((e,t)=>{i[t]=()=>e})),i},inputs:a})}}readSync(e){return this.state.tensorInfo.get(e).backend.readSync(e)}read(e){return this.state.tensorInfo.get(e).backend.read(e)}readToGPU(e,t){return this.state.tensorInfo.get(e).backend.readToGPU(e,t)}async time(e){const t=(0,l.now)(),n=await this.backend.time(e);return n.wallMs=(0,l.now)()-t,n}track(e){return null!=this.state.activeScope&&(e.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(e)),e}get registeredVariables(){return this.state.registeredVariables}reset(){this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new y;for(const e in this.registry)this.disposeRegisteredKernels(e),this.registry[e].dispose(),delete this.registry[e];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null}}function v(){const e=(0,s.L)();if(null==e._tfengine){const t=new r.OH(e);e._tfengine=new b(t)}return(0,r.tj)(e._tfengine.ENV),(0,m.qP)((()=>e._tfengine)),e._tfengine}b.nextTensorId=0,b.nextVariableId=0;const w=v();function x(e,t){const n={a:e,b:t};return w.runKernel(i.OMN,n)}},1743:(e,t,n)=>{"use strict";let a;function r(){if(null==a){let e;if("undefined"!==typeof window)e=window;else if("undefined"!==typeof global)e=global;else if("undefined"!==typeof process)e=process;else{if("undefined"===typeof self)throw new Error("Could not find a global object");e=self}a=e}return a}function s(e,t){const n=function(){const e=r();return null==e._tfGlobals&&(e._tfGlobals=new Map),e._tfGlobals}();if(n.has(e))return n.get(e);{const a=t();return n.set(e,a),n.get(e)}}n.d(t,{L:()=>r,m:()=>s})},1760:(e,t,n)=>{"use strict";n.d(t,{M:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({oneHot_:function(e,t,n=1,i=0,o="int32"){if(t<2)throw new Error(`Error in oneHot: depth must be >=2, but it is ${t}`);const p={indices:(0,s.YT)(e,"indices","oneHot","int32")},l={dtype:o,depth:t,onValue:n,offValue:i};return a.T2.runKernel(r.urI,p,l)}})},1830:(e,t,n)=>{"use strict";n.d(t,{Dv:()=>o,_X:()=>c,jY:()=>l,mu:()=>d,ok:()=>p,y7:()=>u});var a=n(1585),r=n(259),s=n(8189),i=n(5119);function o(e){return i.vA(i.Tn(e),(()=>"The f passed in grad(f) must be a function")),(t,n)=>{const r=(0,s.YT)(t,"x","tf.grad","string_or_numeric"),o=null!=n?(0,s.YT)(n,"dy","tf.grad"):null;return a.T2.tidy((()=>{const{value:t,grads:n}=a.T2.gradients((()=>e(r)),[r],o);return null!=o&&i.O3(t.shape,o.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),h(n),n[0]}))}}function p(e){return i.vA(i.Tn(e),(()=>"The f passed in grads(f) must be a function")),(t,n)=>{i.vA(Array.isArray(t),(()=>"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"));const r=(0,s.j1)(t,"args","tf.grads","string_or_numeric"),o=null!=n?(0,s.YT)(n,"dy","tf.grads"):null;return a.T2.tidy((()=>{const{value:t,grads:n}=a.T2.gradients((()=>e(...r)),r,o);return null!=o&&i.O3(t.shape,o.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),h(n),n}))}}function l(e){return i.vA(i.Tn(e),(()=>"The f passed in valueAndGrad(f) must be a function")),(t,n)=>{i.vA(t instanceof r.qY,(()=>"The x passed in valueAndGrad(f)(x) must be a tensor")),i.vA(null==n||n instanceof r.qY,(()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"));const{grads:s,value:o}=a.T2.gradients((()=>e(t)),[t],n);return h(s),{grad:s[0],value:o}}}function d(e){return i.vA(i.Tn(e),(()=>"The f passed in valueAndGrads(f) must be a function")),(t,n)=>{i.vA(Array.isArray(t)&&t.every((e=>e instanceof r.qY)),(()=>"The args passed in valueAndGrads(f)(args) must be array of tensors")),i.vA(null==n||n instanceof r.qY,(()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"));const s=a.T2.gradients((()=>e(...t)),t,n);return null!=n&&i.O3(s.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),h(s.grads),s}}function u(e,t){i.vA(i.Tn(e),(()=>"The f passed in variableGrads(f) must be a function")),i.vA(null==t||Array.isArray(t)&&t.every((e=>e instanceof r.rT)),(()=>"The varList passed in variableGrads(f, varList) must be an array of variables"));const n=null!=t;if(!n){t=[];for(const e in a.T2.registeredVariables)t.push(a.T2.registeredVariables[e])}const s=n?t.filter((e=>!e.trainable)):null,o=t.length;t=t.filter((e=>e.trainable)),i.vA(t.length>0,(()=>`variableGrads() expects at least one of the input variables to be trainable, but none of the ${o} variables is trainable.`));const{value:p,grads:l}=a.T2.gradients(e,t,null,!0);i.vA(l.some((e=>null!=e)),(()=>"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize().")),i.vA(0===p.rank,(()=>`The f passed in variableGrads(f) must return a scalar, but it returned a rank-${p.rank} tensor`));const d={};return t.forEach(((e,t)=>{null!=l[t]&&(d[e.name]=l[t])})),null!=s&&s.forEach((e=>d[e.name]=null)),{value:p,grads:d}}function c(e){return a.T2.customGrad(e)}function h(e){if(e.filter((e=>null==e)).length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.")}},1890:(e,t,n)=>{"use strict";n.d(t,{x:()=>o});var a=n(1585),r=n(5441),s=n(929),i=n(2302);const o=(0,s.op)({depthwiseConv2dNativeBackpropFilter_:function(e,t,n,s,o,p=[1,1],l){let d=e;3===e.rank&&(d=(0,i.t)(e,[1,e.shape[0],e.shape[1],e.shape[2]]));let u=t;3===u.rank&&(u=(0,i.t)(t,[1,t.shape[0],t.shape[1],t.shape[2]]));const c={x:d,dy:u},h={strides:s,pad:o,dimRoundingMode:l,dilations:p,filterShape:n};return a.T2.runKernel(r.X$8,c,h)}})},1895:(e,t,n)=>{"use strict";n.d(t,{c:()=>p});var a=n(1585),r=n(5441),s=n(5119),i=n(929),o=n(2302);const p=(0,i.op)({conv3DBackpropInput_:function(e,t,n,i,p){s.vA(e.length===t.rank,(()=>`Length of inShape (${e.length}) and rank of dy (${t.rank}) must match`));let l=e,d=t,u=!1;4===t.rank&&(u=!0,d=(0,o.t)(t,[1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]]),l=[1,e[0],e[1],e[2],e[3]]);const c=l[4],h=d.shape[4];s.vA(5===l.length,(()=>`Error in conv3dDerInput: inShape must be length 5, but got length ${l.length}.`)),s.vA(5===d.rank,(()=>`Error in conv3dDerInput: dy must be rank 5, but got rank ${d.rank}`)),s.vA(5===n.rank,(()=>`Error in conv3dDerInput: filter must be rank 5, but got rank ${n.rank}`)),s.vA(c===n.shape[3],(()=>`Error in conv3dDerInput: depth of input (${c}) must match input depth for filter ${n.shape[3]}.`)),s.vA(h===n.shape[4],(()=>`Error in conv3dDerInput: depth of output (${h}) must match output depth for filter ${n.shape[4]}.`));const m={dy:d,filter:n},f={pad:p,strides:i,inputShape:l},g=a.T2.runKernel(r.gC7,m,f);return u?(0,o.t)(g,[g.shape[1],g.shape[2],g.shape[3],g.shape[4]]):g}})},1902:(e,t,n)=>{"use strict";n.d(t,{x:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({real_:function(e){const t={input:(0,s.YT)(e,"input","real")};return a.T2.runKernel(r.LRy,t)}})},1938:(e,t,n)=>{"use strict";n.d(t,{T:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({max_:function(e,t=null,n=!1){const i={x:(0,s.YT)(e,"x","max")},o={reductionIndices:t,keepDims:n};return a.T2.runKernel(r.VAI,i,o)}})},2015:(e,t,n)=>{"use strict";n.d(t,{K:()=>i});var a=n(1585),r=n(5441),s=n(8189);const i=(0,n(929).op)({log1p_:function(e){const t={x:(0,s.YT)(e,"x","log1p")};return a.T2.runKernel(r.Cg$,t)}})},2046:(e,t,n)=>{"use strict";var a,r,s,i,o;n.d(t,{Nw:()=>c,Oj:()=>u,Tu:()=>l,ch:()=>d,rg:()=>a}),function(e){e.R0="R0",e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4",e.R5="R5",e.R6="R6"}(a||(a={})),function(e){e.float32="float32",e.int32="int32",e.bool="int32",e.complex64="complex64"}(r||(r={})),function(e){e.float32="float32",e.int32="int32",e.bool="bool",e.complex64="complex64"}(s||(s={})),function(e){e.float32="float32",e.int32="float32",e.bool="float32",e.complex64="complex64"}(i||(i={})),function(e){e.float32="complex64",e.int32="complex64",e.bool="complex64",e.complex64="complex64"}(o||(o={}));const p={float32:i,int32:r,bool:s,complex64:o};function l(e,t){if("string"===e||"string"===t){if("string"===e&&"string"===t)return"string";throw new Error(`Can not upcast ${e} with ${t}`)}return p[e][t]}function d(e){return l(e,"int32")}function u(e){return null!=e&&"object"===typeof e&&"texture"in e&&e.texture instanceof WebGLTexture}function c(e){return"undefined"!==typeof GPUBuffer&&null!=e&&"object"===typeof e&&"buffer"in e&&e.buffer instanceof GPUBuffer}},2058:(e,t,n)=>{"use strict";n.d(t,{r:()=>p});var a=n(1585),r=n(5441),s=n(565),i=n(8189),o=n(2198);const p=(0,n(929).op)({greater_:function(e,t){let n=(0,i.YT)(e,"a","greater","string_or_numeric"),p=(0,i.YT)(t,"b","greater","string_or_numeric");[n,p]=(0,s.makeTypesMatch)(n,p),(0,o.assertAndGetBroadcastShape)(n.shape,p.shape);const l={a:n,b:p};return a.T2.runKernel(r.XhZ,l)}})},2118:(e,t,n)=>{"use strict";n.d(t,{E:()=>p});var a=n(1585),r=n(5441),s=n(565),i=n(8189),o=n(2198);const p=(0,n(929).op)({notEqual_:function(e,t){let n=(0,i.YT)(e,"a","notEqual","string_or_numeric"),p=(0,i.YT)(t,"b","notEqual","string_or_numeric");[n,p]=(0,s.makeTypesMatch)(n,p),(0,o.assertAndGetBroadcastShape)(n.shape,p.shape);const l={a:n,b:p};return a.T2.runKernel(r.ylV,l)}})},2151:(e,t,n)=>{"use strict";n.d(t,{_:()=>p});var a=n(1585),r=n(5441),s=n(8189),i=n(3567),o=n(2198);const p=(0,n(929).op)({where_:function(e,t,n){const p=(0,s.YT)(t,"a","where"),l=(0,s.YT)(n,"b","where"),d=(0,s.YT)(e,"condition","where","bool"),u=(0,o.assertAndGetBroadcastShape)((0,o.assertAndGetBroadcastShape)(d.shape,p.shape),l.shape),c={condition:(0,i.h)(d,u),t:(0,i.h)(p,u),e:(0,i.h)(l,u)};return a.T2.runKernel(r.l6P,c)}})},2198:(e,t,n)=>{"use strict";function a(e,t){const n=e.length,a=[];for(let r=0;r<n;r++){const s=n-1-r,i=e[s]||1;(t[t.length-1-r]||1)>1&&1===i&&a.unshift(s)}return a}function r(e,t){const n=[];for(let a=0;a<t.length;a++){const r=e[e.length-a-1],s=t.length-a-1,i=t[s];(null==r||1===r&&i>1)&&n.unshift(s)}return n}function s(e,t){const n=Math.max(e.length,t.length),a=new Array(n);for(let r=0;r<n;r++){let s=e[e.length-r-1];null==s&&(s=1);let i=t[t.length-r-1];if(null==i&&(i=1),1===s)a[n-r-1]=i;else if(1===i)a[n-r-1]=s;else{if(s!==i){throw Error(`Operands could not be broadcast together with shapes ${e} and ${t}.`)}a[n-r-1]=s}}return a}n.r(t),n.d(t,{assertAndGetBroadcastShape:()=>s,getBroadcastDims:()=>a,getReductionAxes:()=>r})},2292:(e,t,n)=>{"use strict";n.d(t,{g:()=>m});var a=n(7148),r=n(5030),s=n(5040),i=n(9258),o=n(929),p=n(1902),l=n(2302),d=n(3262),u=n(5702),c=n(7986),h=n(3108);const m=(0,o.op)({irfft_:function(e){const t=e.shape[e.shape.length-1],n=e.size/t;let o;if(t<=2){const a=(0,l.t)(e,[n,t]);o=(0,h.K)(a)}else{const m=[n,2*(t-1)],f=(0,l.t)((0,p.x)(e),[n