`;return d[d.length-1]=" "+d[d.length-1]+"]"+(i?"":x),d}function ls(e){const t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}class Fo{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=Q(e),n!=null){const o=n.length;f(o===this.size,()=>`Lengthofvalues'${o}'doesnotmatchthesizeinferredbytheshape'${this.size}'.`)}if(t==="complex64")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||Op(t,this.size),this.strides=Gt(e)}set(e,...t){t.length===0&&(t=[0]),f(t.length===this.rank,()=>`Thenumberofprovidedcoordinates(${t.length})mustmatchtherank(${this.rank})`);const n=this.locToIndex(t);this.values[n]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(const o of e){if(o<0||o>=this.shape[t]){const r=`Requestedoutofrangeelementat${e}.Buffershape=${this.shape}`;throw new Error(r)}t++}let n=e[e.length-1];for(let o=0;o<e.length-1;++o)n+=this.strides[o]*e[o];return this.values[n]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)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(this.rank===0)return[];if(this.rank===1)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 qt().makeTensor(this.values,this.shape,this.dtype)}}let qt=null,Mo=null,kw=null;function Od(e){qt=e}function kd(e){Mo=e}function Dd(e){kw=e}class ee{constructor(e,t,n,o){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=Q(e),this.strides=Gt(e),this.dataId=n,this.id=o,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const e=await this.data();return Mo.buffer(this.shape,this.dtype,e)}bufferSync(){return Mo.buffer(this.shape,this.dtype,this.dataSync())}async array(){const e=await this.data();return Mn(this.shape,e)}arraySync(){return Mn(this.shape,this.dataSync())}async data(){this.throwIfDisposed();const e=qt().read(this.dataId);if(this.dtype==="string"){const t=await e;try{return t.map(n=>Ca(n))}catch(n){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return e}dataSync(){this.throwIfDisposed();const e=qt().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>Ca(t))}catch(t){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 qt().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){if(this.isDisposed)return;qt().disposeTensor(this),this.isDisposedInternal=!0}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return Mo.print(this,e)}clone(){return this.throwIfDisposed(),Mo.clone(this)}toString(e=!1){const t=this.dataSync();return Cd(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Mo.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),qt().makeVariable(this,e,t,n)}}Object.defineProperty(ee,Symbol.hasInstance,{value:e=>!!e&&e.dataId!=null&&e.shape!=null&&e.dtype!=null});class Ht extends ee{constructor(e,t,n,o){super(e.shape,e.dtype,e.dataId,o);this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtypeofthenewvalue(${e.dtype})andpreviousvalue(${this.dtype})mustmatch`);if(!Te(e.shape,this.shape))throw new Error(`shapeofthenewvalue(${e.shape})andpreviousvalue(${this.shape})mustmatch`);qt().disposeTensor(this),this.dataId=e.dataId,qt().incRef(this,null)}dispose(){qt().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty(Ht,Symbol.hasInstance,{value:e=>e instanceof ee&&e.assign!=null&&e.assign instanceof Function});var Bp;(function(e){e.R0="R0",e.R1="R1",e.R2
rank${i.rank}.`),f(X(t),()=>`ErrorinlocalResponseNormalization:depthRadiusmustbeanintegerbutgotdepthRadius${t}.`);let a=i,s=!1;i.rank===3&&(s=!0,a=y(i,[1,i.shape[0],i.shape[1],i.shape[2]]));const c=(d,b)=>{const x=d.localResponseNormalization4D(a,t,n,o,r);return b([a,x]),x},p={x:a},l={depthRadius:t,bias:n,alpha:o,beta:r},h=g.runKernelFunc(c,p,null,li,l);return s?y(h,[h.shape[1],h.shape[2],h.shape[3]]):h}const zl=m({localResponseNormalization_:Ky});function Jy(e){const t=u(e,"x","log"),n={x:t};return g.runKernelFunc((o,r)=>{const i=o.log(t);return r([t]),i},n,null,ai)}const yt=m({log_:Jy});function Xy(e){const t=u(e,"x","log1p"),n={x:t};return g.runKernelFunc((o,r)=>{const i=o.log1p(t);return r([t]),i},n,null,ci)}const Ls=m({log1p_:Xy});function Zy(e){return f(jt(e),()=>"The f passed in grad(f) must be a function"),(t,n)=>{const o=u(t,"x","tf.grad",null),r=n!=null?u(n,"dy","tf.grad"):null;return g.tidy(()=>{const{value:i,grads:a}=g.gradients(()=>e(o),[o],r);return r!=null&&P(i.shape,r.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Ma(a),a[0]})}}function Qy(e){return f(jt(e),()=>"The f passed in grads(f) must be a function"),(t,n)=>{f(Array.isArray(t),()=>"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s");const o=Zt(t,"args","tf.grads",null),r=n!=null?u(n,"dy","tf.grads"):null;return g.tidy(()=>{const{value:i,grads:a}=g.gradients(()=>e(...o),o,r);return r!=null&&P(i.shape,r.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Ma(a),a})}}function eL(e){return f(jt(e),()=>"The f passed in valueAndGrad(f) must be a function"),(t,n)=>{f(t instanceof ee,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),f(n==null||n instanceof ee,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");const{grads:o,value:r}=g.gradients(()=>e(t),[t],n);return Ma(o),{grad:o[0],value:r}}}function tL(e){return f(jt(e),()=>"The f passed in valueAndGrads(f) must be a function"),(t,n)=>{f(Array.isArray(t)&&t.every(r=>r instanceof ee),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),f(n==null||n instanceof ee,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");const o=g.gradients(()=>e(...t),t,n);return n!=null&&P(o.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Ma(o.grads),o}}function Yl(e,t){f(jt(e),()=>"The f passed in variableGrads(f) must be a function"),f(t==null||Array.isArray(t)&&t.every(p=>p instanceof Ht),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");const n=t!=null;if(!n){t=[];for(const p in g.registeredVariables)t.push(g.registeredVariables[p])}const o=n?t.filter(p=>!p.trainable):null,r=t.length;t=t.filter(p=>p.trainable),f(t.length>0,()=>`variableGrads()expectsatleastoneoftheinputvariablestobetrainable,butnoneofthe${r}variablesistrainable.`);const i=!0,{value:a,grads:s}=g.gradients(e,t,null,i);f(s.some(p=>p!=null),()=>"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()."),f(a.rank===0,()=>`ThefpassedinvariableGrads(f)mustreturnascalar,butitreturnedarank-${a.rank}tensor`);const c={};return t.forEach((p,l)=>{s[l]!=null&&(c[p.name]=s[l])}),o!=null&&o.forEach(p=>c[p.name]=null),{value:a,grads:c}}function Ke(e){return g.customGrad(e)}function Ma(e){const t=e.filter(n=>n==null).length;if(t>0)throw new Error(`Cannotcomputegradientofy=f(x)withrespecttox.Makesurethat
Expected:${i}.`)}}function qL(e,t){e().then(()=>t.fail(),()=>t())}function HL(e,t){const n=typeof t=="string"||typeof t=="number"||typeof t=="boolean"?[t]:t;return Rt(e)||Rt(e[0])||Rt(t)||Rt(t[0])?uh(e,n,(o,r)=>o==r):uh(e,t,(o,r)=>dh(o,r,0))}function zL(e,t,n){if(n==null&&(n=hh()),!dh(e,t,n))throw new Error(`Numbersdiffer:actual===${e},expected===${t}`)}function dh(e,t,n){return!isFinite(e)&&!isFinite(t)?!0:!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}function YL(e,t,n){for(let o=0;o<e.length;o++)if(e[o]<t||e[o]>n)throw new Error(`Valueoutofrange:${e[o]}low:${t},high:${n}`)}function VL(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}const Wa=gu(Ou());class Ns{constructor(e,t,n,o,r){this.mean=e,this.stdDev=t,this.dtype=n,this.nextVal=NaN,this.truncated=o,this.truncated&&(this.upper=this.mean+this.stdDev*2,this.lower=this.mean-this.stdDev*2);const i=r||Math.random();this.random=Wa.alea(i.toString())}nextValue(){if(!isNaN(this.nextVal)){const o=this.nextVal;return this.nextVal=NaN,o}let e,t,n=!1;for(;!n;){let o,r,i;do o=2*this.random()-1,r=2*this.random()-1,i=o*o+r*r;while(i>=1||i===0);const a=Math.sqrt(-2*Math.log(i)/i);e=this.mean+this.stdDev*o*a,t=this.mean+this.stdDev*r*a,(!this.truncated||this.isValidTruncated(e))&&(n=!0)}return(!this.truncated||this.isValidTruncated(t))&&(this.nextVal=this.convertValue(t)),this.convertValue(e)}convertValue(e){return this.dtype==null||this.dtype==="float32"?e:Math.round(e)}isValidTruncated(e){return e<=this.upper&&e>=this.lower}}class Kd{constructor(e,t,n,o){this.alpha=e,this.beta=1/t,this.dtype=n;const r=o||Math.random();this.randu=Wa.alea(r.toString()),this.randn=new Ns(0,1,n,!1,this.randu()),e<1?this.d=e+2/3:this.d=e-1/3,this.c=1/Math.sqrt(9*this.d)}nextValue(){let e,t,n,o,r,i;for(;;){do o=this.randn.nextValue(),i=1+this.c*o;while(i<=0);if(i*=i*i,e=o*o,t=1-.331*e*e,n=.5*e+this.d*(1-i+Math.log(i)),r=this.randu(),r<t||Math.log(r)<n)break}return i=1/this.beta*this.d*i,this.alpha<1&&(i*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(i)}convertValue(e){return this.dtype==="float32"?e:Math.round(e)}}class Jd{constructor(e=0,t=1,n,o){if(this.canReturnFloat=()=>this.dtype==null||this.dtype==="float32",this.min=e,this.range=t-e,this.dtype=n,o==null&&(o=Math.random()),typeof o=="number"&&(o=o.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error(`Thedifferencebetween${e}-${t}<=1anddtypeisnotfloat`);this.random=Wa.alea(o)}convertValue(e){return this.canReturnFloat()?e:Math.round(e)}nextValue(){return this.convertValue(this.min+this.range*this.random())}}function KL(e,t,n=1,o="float32",r){if(n==null&&(n=1),o==null&&(o="float32"),o!=="float32"&&o!=="int32")throw new Error(`Unsupporteddatatype${o}`);const i=new Kd(t,n,o,r),a=Be(e,o);for(let s=0;s<a.values.length;s++)a.values[s]=i.nextValue();return a.toTensor()}const mh=m({randomGamma_:KL});function JL(e,t=0,n=1,o,r){if(o!=null&&o==="bool")throw new Error(`Unsupporteddatatype${o}`);const i=new Ns(t,n,o,!1,r),a=Be(e,o);for(let s=0;s<a.values.length;s++)a.values[s]=i.nextValue();return a.toTensor()}const fh=m({randomNormal_:JL});function XL(e,t=0,n=1,o="float32",r){const i=Be(e,o),a=new Jd(t,n,null,r);for(let s=0;s<i.values.length;s++)i.values[s]=a.nextValue();return i.toTensor()}const Rs=m({randomUniform_:XL});function ce(e,t){at(e);const n=We(e,t);if(n.length!==1)throw new Error("tensor1d() requires values to be a flat/TypedArray");const o=null;return ze(e,o,n,t)}function Po(e,t,n=1,o="float32"){if(n===0)throw new Error("Cannot have a step of zero");const r=()=>{const a=e===t,s=e<t&&n<0,c=t<e&&n>1;if(a||s||c)return Ce([0],o);const p=Math.abs(Math.ceil((t-e)/n)),l=Pt(p,o);t<e&&n===1&&(n=-1),l[0]=e;for(let h=1;h<l.length;h++)l[h]=l[h-1]+n;return ce(l,o)},i={start:e,stop:t,step:n,dtype:o};return g.runKernelFunc(r,{},null,wp,i)}function ZL(e){const t=u(e,"x","reciprocal"),n={x:t};return g.runKernelFunc((o,r)=>{const i=o.reciprocal(t);return r([t]),i},n,null,Ti)}const gh=m({reciprocal_:ZL});function QL(e){const t=u(e,"x","relu"),n=(r,i)=>(i([t]),t.dtype==="bool"?_(t,"int32"):r.relu(t)),o={x
ManifestJSONhasweightswithnames:${s.join(", ")}.`)}const c=r.reduce((b,x,w)=>(x&&b.push(w),b),[]),p=[];c.forEach(b=>{t[b].paths.forEach(x=>{const w=n+(n.endsWith("/")?"":"/")+x;p.push(w)})});const l=await e(p),h={};let d=0;return c.forEach(b=>{const x=t[b].paths.length;let w=0;for(let A=0;A<x;A++)w+=l[d+A].byteLength;const L=new ArrayBuffer(w),S=new Uint8Array(L);let I=0;for(let A=0;A<x;A++){const E=new Uint8Array(l[d+A]);S.set(E,I),I+=E.byteLength}const N=i[b];N.forEach(A=>{const E=L.slice(A.groupOffset,A.groupOffset+A.sizeBytes),M=$h(E,[A.manifestEntry]);for(const D in M)h[D]=M[D]}),d+=x}),h}}const pI="application/octet-stream",lI="application/json";class qh{constructor(e,t){if(this.DEFAULT_METHOD="POST",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,t.fetchFunc!=null?(f(typeof t.fetchFunc=="function",()=>"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=t.fetchFunc):this.fetch=pe().platform.fetch,f(e!=null&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&f(e.length===2,()=>`URLpathsforhttpmusthavealengthof2,(actuallengthis${e.length}).`),this.path=e,t.requestInit!=null&&t.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");const t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;const n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],o={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,userDefinedMetadata:e.userDefinedMetadata,weightsManifest:n};t.body.append("model.json",new Blob([JSON.stringify(o)],{type:lI}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:pI}),"model.weights.bin");const r=await this.fetch(this.path,t);if(r.ok)return{modelArtifactsInfo:Ws(e),responses:[r]};throw new Error(`BrowserHTTPRequest.save()failedduetoHTTPresponsestatus${r.status}.`)}async load(){const e=await this.fetch(this.path,this.requestInit);if(!e.ok)throw new Error(`Requestto${this.path}failedwithstatuscode${e.status}.PleaseverifythisURLpointstothemodelJSONofthemodeltoload.`);let t;try{t=await e.json()}catch(l){let h=`FailedtoparsemodelJSONofresponsefrom${this.path}.`;throw this.path.endsWith(".pb")?h+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":h+=" Please make sure the server is serving valid JSON for this request.",new Error(h)}const n=t.modelTopology,o=t.weightsManifest,r=t.generatedBy,i=t.convertedBy,a=t.format,s=t.userDefinedMetadata;if(n==null&&o==null)throw new Error(`TheJSONfromHTTPpath${this.path}containsneithermodeltopologyormanifestforweights.`);let c,p;if(o!=null){const l=await this.loadWeights(o);[c,p]=l}return{modelTopology:n,weightSpecs:c,weightData:p,userDefinedMetadata:s,generatedBy:r,convertedBy:i,format:a}}async loadWeights(e){const t=Array.isArray(this.path)?this.path[1]:this.path,[n,o]=hI(t),r=this.weightPathPrefix||n,i=[];for(const c of e)i.push(...c.weights);const a=[];e.forEach(c=>{c.paths.forEach(p=>{a.push(r+p+o)})});const s=await Ph(a,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[i,Us(s)]}}qh.URL_SCHEME_REGEX=/^https?:\/\//;function hI(e){const t=e.lastIndexOf("/"),n=e.lastIndexOf("?"),o=e.substring(0,t),r=n>t?e.substring(n):"";return[o+"/",r]}function Hh(e){return e.match(qh.URL_SCHEME_REGEX)!=null}const lf=(e,t)=>{if(typeof fetch=="undefined"&&(t==null||t.fet