`;return m[m.length-1]=" "+m[m.length-1]+"]"+(i?"":y),m}function Xi(e){const t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}class Sr{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=te(e),n!=null){const r=n.length;f(r===this.size,()=>`Lengthofvalues'${r}'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||Rp(t,this.size),this.strides=Ut(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 r of e){if(r<0||r>=this.shape[t]){const o=`Requestedoutofrangeelementat${e}.Buffershape=${this.shape}`;throw new Error(o)}t++}let n=e[e.length-1];for(let r=0;r<e.length-1;++r)n+=this.strides[r]*e[r];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 Bt().makeTensor(this.values,this.shape,this.dtype)}}let Bt=null,vr=null,Zw=null;function pd(e){Bt=e}function ld(e){vr=e}function hd(e){Zw=e}class ne{constructor(e,t,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=te(e),this.strides=Ut(e),this.dataId=n,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const e=await this.data();return vr.buffer(this.shape,this.dtype,e)}bufferSync(){return vr.buffer(this.shape,this.dtype,this.dataSync())}async array(){const e=await this.data();return Cn(this.shape,e)}arraySync(){return Cn(this.shape,this.dataSync())}async data(){this.throwIfDisposed();const e=Bt().read(this.dataId);if(this.dtype==="string"){const t=await e;try{return t.map(n=>pa(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=Bt().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>pa(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 Bt().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){if(this.isDisposed)return;Bt().disposeTensor(this),this.isDisposedInternal=!0}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return vr.print(this,e)}clone(){return this.throwIfDisposed(),vr.clone(this)}toString(e=!1){const t=this.dataSync();return ad(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),vr.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),Bt().makeVariable(this,e,t,n)}}Object.defineProperty(ne,Symbol.hasInstance,{value:e=>!!e&&e.dataId!=null&&e.shape!=null&&e.dtype!=null});class $t extends ne{constructor(e,t,n,r){super(e.shape,e.dtype,e.dataId,r);this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtypeofthenewvalue(${e.dtype})andpreviousvalue(${this.dtype})mustmatch`);if(!Se(e.shape,this.shape))throw new Error(`shapeofthenewvalue(${e.shape})andpreviousvalue(${this.shape})mustmatch`);Bt().disposeTensor(this),this.dataId=e.dataId,Bt().incRef(this,null)}dispose(){Bt().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty($t,Symbol.hasInstance,{value:e=>e instanceof ne&&e.assign!=null&&e.assign instanceof Function});var Fp;(function(e){e.R0="R0",e.R1="R1",e.
rank${i.rank}.`),f(X(t),()=>`ErrorinlocalResponseNormalization:depthRadiusmustbeanintegerbutgotdepthRadius${t}.`);let a=i,s=!1;i.rank===3&&(s=!0,a=x(i,[1,i.shape[0],i.shape[1],i.shape[2]]));const c=(m,b)=>{const y=m.localResponseNormalization4D(a,t,n,r,o);return b([a,y]),y},p={x:a},l={depthRadius:t,bias:n,alpha:r,beta:o},h=g.runKernelFunc(c,p,null,Xo,l);return s?x(h,[h.shape[1],h.shape[2],h.shape[3]]):h}const Pl=d({localResponseNormalization_:mL});function fL(e){const t=u(e,"x","log"),n={x:t};return g.runKernelFunc((r,o)=>{const i=r.log(t);return o([t]),i},n,null,Vo)}const wt=d({log_:fL});function gL(e){const t=u(e,"x","log1p"),n={x:t};return g.runKernelFunc((r,o)=>{const i=r.log1p(t);return o([t]),i},n,null,Ko)}const cs=d({log1p_:gL});function bL(e){return f(Mt(e),()=>"The f passed in grad(f) must be a function"),(t,n)=>{const r=u(t,"x","tf.grad",null),o=n!=null?u(n,"dy","tf.grad"):null;return g.tidy(()=>{const{value:i,grads:a}=g.gradients(()=>e(r),[r],o);return o!=null&&P(i.shape,o.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),fa(a),a[0]})}}function wL(e){return f(Mt(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 r=Vt(t,"args","tf.grads",null),o=n!=null?u(n,"dy","tf.grads"):null;return g.tidy(()=>{const{value:i,grads:a}=g.gradients(()=>e(...r),r,o);return o!=null&&P(i.shape,o.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),fa(a),a})}}function yL(e){return f(Mt(e),()=>"The f passed in valueAndGrad(f) must be a function"),(t,n)=>{f(t instanceof ne,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),f(n==null||n instanceof ne,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");const{grads:r,value:o}=g.gradients(()=>e(t),[t],n);return fa(r),{grad:r[0],value:o}}}function xL(e){return f(Mt(e),()=>"The f passed in valueAndGrads(f) must be a function"),(t,n)=>{f(Array.isArray(t)&&t.every(o=>o instanceof ne),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),f(n==null||n instanceof ne,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");const r=g.gradients(()=>e(...t),t,n);return n!=null&&P(r.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),fa(r.grads),r}}function ql(e,t){f(Mt(e),()=>"The f passed in variableGrads(f) must be a function"),f(t==null||Array.isArray(t)&&t.every(p=>p instanceof $t),()=>"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 r=n?t.filter(p=>!p.trainable):null,o=t.length;t=t.filter(p=>p.trainable),f(t.length>0,()=>`variableGrads()expectsatleastoneoftheinputvariablestobetrainable,butnoneofthe${o}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])}),r!=null&&r.forEach(p=>c[p.name]=null),{value:a,grads:c}}function Je(e){return g.customGrad(e)}function fa(e){const t=e.filter(n=>n==null).length;if(t>0)throw new Error(`Cannotcomputegradientofy=f(x)withrespecttox.Makesurethat
ManifestJSONhasweightswithnames:${s.join(", ")}.`)}const c=o.reduce((b,y,w)=>(y&&b.push(w),b),[]),p=[];c.forEach(b=>{t[b].paths.forEach(y=>{const w=n+(n.endsWith("/")?"":"/")+y;p.push(w)})});const l=await e(p),h={};let m=0;return c.forEach(b=>{const y=t[b].paths.length;let w=0;for(let N=0;N<y;N++)w+=l[m+N].byteLength;const L=new ArrayBuffer(w),v=new Uint8Array(L);let A=0;for(let N=0;N<y;N++){const O=new Uint8Array(l[m+N]);v.set(O,A),A+=O.byteLength}const R=i[b];R.forEach(N=>{const O=L.slice(N.groupOffset,N.groupOffset+N.sizeBytes),M=Uh(O,[N.manifestEntry]);for(const D in M)h[D]=M[D]}),m+=y}),h}}const RI="application/octet-stream",CI="application/json";class Gh{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=ce().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}],r={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(r)],{type:CI}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:RI}),"model.weights.bin");const o=await this.fetch(this.path,t);if(o.ok)return{modelArtifactsInfo:As(e),responses:[o]};throw new Error(`BrowserHTTPRequest.save()failedduetoHTTPresponsestatus${o.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,r=t.weightsManifest,o=t.generatedBy,i=t.convertedBy,a=t.format,s=t.userDefinedMetadata;if(n==null&&r==null)throw new Error(`TheJSONfromHTTPpath${this.path}containsneithermodeltopologyormanifestforweights.`);let c,p;if(r!=null){const l=await this.loadWeights(r);[c,p]=l}return{modelTopology:n,weightSpecs:c,weightData:p,userDefinedMetadata:s,generatedBy:o,convertedBy:i,format:a}}async loadWeights(e){const t=Array.isArray(this.path)?this.path[1]:this.path,[n,r]=EI(t),o=this.weightPathPrefix||n,i=[];for(const c of e)i.push(...c.weights);const a=[];e.forEach(c=>{c.paths.forEach(p=>{a.push(o+p+r)})});const s=await $h(a,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[i,Ts(s)]}}Gh.URL_SCHEME_REGEX=/^https?:\/\//;function EI(e){const t=e.lastIndexOf("/"),n=e.lastIndexOf("?"),r=e.substring(0,t),o=n>t?e.substring(n):"";return[r+"/",o]}function jh(e){return e.match(Gh.URL_SCHEME_REGEX)!=null}const $m=(e,t)=>{if(typeof fetch=="undefined"&&(t==null||t.f