@vladmandic/face-api
Version:
JavaScript module for Face Detection and Face Recognition Using Tensorflow/JS
5 lines • 1.14 MB
JavaScript
var rf=Object.defineProperty,n9=Object.prototype.hasOwnProperty,XS=(r,l)=>()=>(l||(l={exports:{}},r(l.exports,l)),l.exports),T2=r=>rf(r,"__esModule",{value:!0}),$c=(r,l)=>{T2(r);for(var u in l)rf(r,u,{get:l[u],enumerable:!0})},s9=(r,l)=>{if(T2(r),typeof l=="object"||typeof l=="function")for(let u in l)!n9.call(r,u)&&u!=="default"&&rf(r,u,{get:()=>l[u],enumerable:!0});return r},He=r=>r&&r.__esModule?r:s9(rf({},"default",{value:r,enumerable:!0}),r);var F2=XS(i9=>{$c(i9,{FetchError:()=>Gn,Headers:()=>fi,Request:()=>ra,Response:()=>Mi,default:()=>g9});const qs=He(require("stream")),JS=He(require("http")),of=He(require("url")),A2=He(require("https")),uo=He(require("zlib")),r9=qs.default.Readable,Lr=Symbol("buffer"),ZS=Symbol("type");class Ou{constructor(){this[ZS]="";const r=arguments[0],l=arguments[1],u=[];let d=0;if(r){const g=r,I=Number(g.length);for(let S=0;S<I;S++){const x=g[S];let N;x instanceof Buffer?N=x:ArrayBuffer.isView(x)?N=Buffer.from(x.buffer,x.byteOffset,x.byteLength):x instanceof ArrayBuffer?N=Buffer.from(x):x instanceof Ou?N=x[Lr]:N=Buffer.from(typeof x=="string"?x:String(x)),d+=N.length,u.push(N)}}this[Lr]=Buffer.concat(u);let f=l&&l.type!==void 0&&String(l.type).toLowerCase();f&&!/[^\u0020-\u007E]/.test(f)&&(this[ZS]=f)}get size(){return this[Lr].length}get type(){return this[ZS]}text(){return Promise.resolve(this[Lr].toString())}arrayBuffer(){const r=this[Lr],l=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);return Promise.resolve(l)}stream(){const r=new r9;return r._read=function(){},r.push(this[Lr]),r.push(null),r}toString(){return"[object Blob]"}slice(){const r=this.size,l=arguments[0],u=arguments[1];let d,f;l===void 0?d=0:l<0?d=Math.max(r+l,0):d=Math.min(l,r),u===void 0?f=r:u<0?f=Math.max(r+u,0):f=Math.min(u,r);const g=Math.max(f-d,0),I=this[Lr],S=I.slice(d,d+g),x=new Ou([],{type:arguments[2]});return x[Lr]=S,x}}Object.defineProperties(Ou.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}});Object.defineProperty(Ou.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0});function Gn(r,l,u){Error.call(this,r),this.message=r,this.type=l,u&&(this.code=this.errno=u.code),Error.captureStackTrace(this,this.constructor)}Gn.prototype=Object.create(Error.prototype);Gn.prototype.constructor=Gn;Gn.prototype.name="FetchError";let QS;try{QS=require("encoding").convert}catch(r){}const Sr=Symbol("Body internals"),v2=qs.default.PassThrough;function Dn(r){var l=this,u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d=u.size;let f=d===void 0?0:d;var g=u.timeout;let I=g===void 0?0:g;r==null?r=null:N2(r)?r=Buffer.from(r.toString()):Eu(r)||(Buffer.isBuffer(r)||(Object.prototype.toString.call(r)==="[object ArrayBuffer]"?r=Buffer.from(r):ArrayBuffer.isView(r)?r=Buffer.from(r.buffer,r.byteOffset,r.byteLength):r instanceof qs.default||(r=Buffer.from(String(r))))),this[Sr]={body:r,disturbed:!1,error:null},this.size=f,this.timeout=I,r instanceof qs.default&&r.on("error",function(S){const x=S.name==="AbortError"?S:new Gn(`Invalid response body while trying to fetch ${l.url}: ${S.message}`,"system",S);l[Sr].error=x})}Dn.prototype={get body(){return this[Sr].body},get bodyUsed(){return this[Sr].disturbed},arrayBuffer(){return Uc.call(this).then(function(r){return r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)})},blob(){let r=this.headers&&this.headers.get("content-type")||"";return Uc.call(this).then(function(l){return Object.assign(new Ou([],{type:r.toLowerCase()}),{[Lr]:l})})},json(){var r=this;return Uc.call(this).then(function(l){try{return JSON.parse(l.toString())}catch(u){return Dn.Promise.reject(new Gn(`invalid json response body at ${r.url} reason: ${u.message}`,"invalid-json"))}})},text(){return Uc.call(this).then(function(r){return r.toString()})},buffer(){return Uc.call(this)},textConverted(){var r=this;return Uc.call(this).then(function(l){return o9(l,r.headers)})}};Object.defineProperties(Dn.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}});Dn.mixIn=function(r){for(const l of Object.getOwnPropertyNames(Dn.prototype))if(!(l in r)){const u=Object.getOwnPropertyDescriptor(Dn.prototype,l);Object.defineProperty(r,l,u)}};function Uc(){var r=this;if(this[Sr].disturbed)return Dn.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[Sr].disturbed=!0,this[Sr].error)return Dn.Promise.reject(this[Sr].error);let l=this.body;if(l===null)return Dn.Promise.resolve(Buffer.alloc(0));if(Eu(l)&&(l=l.stream()),Buffer.isBuffer(l))return Dn.Promise.resolve(l);if(!(l instanceof qs.default))return Dn.Promise.resolve(Buffer.alloc(0));let u=[],d=0,f=!1;return new Dn.Promise(function(g,I){let S;r.timeout&&(S=setTimeout(function(){f=!0,I(new Gn(`Response timeout while trying to fetch ${r.url} (over ${r.timeout}ms)`,"body-timeout"))},r.timeout)),l.on("error",function(x){x.name==="AbortError"?(f=!0,I(x)):I(new Gn(`Invalid response body while trying to fetch ${r.url}: ${x.message}`,"system",x))}),l.on("data",function(x){if(f||x===null)return;if(r.size&&d+x.length>r.size){f=!0,I(new Gn(`content size at ${r.url} over limit: ${r.size}`,"max-size"));return}d+=x.length,u.push(x)}),l.on("end",function(){if(f)return;clearTimeout(S);try{g(Buffer.concat(u,d))}catch(x){I(new Gn(`Could not create Buffer from response body for ${r.url}: ${x.message}`,"system",x))}})})}function o9(r,l){if(typeof QS!="function")throw new Error("The package `encoding` must be installed to use the textConverted() function");const u=l.get("content-type");let d="utf-8",f,g;return u&&(f=/charset=([^;]*)/i.exec(u)),g=r.slice(0,1024).toString(),!f&&g&&(f=/<meta.+?charset=(['"])(.+?)\1/i.exec(g)),!f&&g&&(f=/<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(g),f||(f=/<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(g),f&&f.pop()),f&&(f=/charset=(.*)/i.exec(f.pop()))),!f&&g&&(f=/<\?xml.+?encoding=(['"])(.+?)\1/i.exec(g)),f&&(d=f.pop(),(d==="gb2312"||d==="gbk")&&(d="gb18030")),QS(r,"UTF-8",d).toString()}function N2(r){return typeof r!="object"||typeof r.append!="function"||typeof r.delete!="function"||typeof r.get!="function"||typeof r.getAll!="function"||typeof r.has!="function"||typeof r.set!="function"?!1:r.constructor.name==="URLSearchParams"||Object.prototype.toString.call(r)==="[object URLSearchParams]"||typeof r.sort=="function"}function Eu(r){return typeof r=="object"&&typeof r.arrayBuffer=="function"&&typeof r.type=="string"&&typeof r.stream=="function"&&typeof r.constructor=="function"&&typeof r.constructor.name=="string"&&/^(Blob|File)$/.test(r.constructor.name)&&/^(Blob|File)$/.test(r[Symbol.toStringTag])}function C2(r){let l,u,d=r.body;if(r.bodyUsed)throw new Error("cannot clone body after it is used");return d instanceof qs.default&&typeof d.getBoundary!="function"&&(l=new v2,u=new v2,d.pipe(l),d.pipe(u),r[Sr].body=l,d=u),d}function R2(r){return r===null?null:typeof r=="string"?"text/plain;charset=UTF-8":N2(r)?"application/x-www-form-urlencoded;charset=UTF-8":Eu(r)?r.type||null:Buffer.isBuffer(r)||(Object.prototype.toString.call(r)==="[object ArrayBuffer]"||ArrayBuffer.isView(r))?null:typeof r.getBoundary=="function"?`multipart/form-data;boundary=${r.getBoundary()}`:r instanceof qs.default?null:"text/plain;charset=UTF-8"}function O2(r){const l=r.body;return l===null?0:Eu(l)?l.size:Buffer.isBuffer(l)?l.length:l&&typeof l.getLengthSync=="function"&&(l._lengthRetrievers&&l._lengthRetrievers.length==0||l.hasKnownLength&&l.hasKnownLength())?l.getLengthSync():null}function a9(r,l){const u=l.body;u===null?r.end():Eu(u)?u.stream().pipe(r):Buffer.isBuffer(u)?(r.write(u),r.end()):u.pipe(r)}Dn.Promise=global.Promise;const E2=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,eI=/[^\t\x20-\x7e\x80-\xff]/;function Du(r){if(r=`${r}`,E2.test(r)||r==="")throw new TypeError(`${r} is not a legal HTTP header name`)}function D2(r){if(r=`${r}`,eI.test(r))throw new TypeError(`${r} is not a legal HTTP header value`)}function Bc(r,l){l=l.toLowerCase();for(const u in r)if(u.toLowerCase()===l)return u;return}const ln=Symbol("map");class fi{constructor(){let r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0;if(this[ln]=Object.create(null),r instanceof fi){const l=r.raw(),u=Object.keys(l);for(const d of u)for(const f of l[d])this.append(d,f);return}if(!(r==null))if(typeof r=="object"){const l=r[Symbol.iterator];if(l!=null){if(typeof l!="function")throw new TypeError("Header pairs must be iterable");const u=[];for(const d of r){if(typeof d!="object"||typeof d[Symbol.iterator]!="function")throw new TypeError("Each header pair must be iterable");u.push(Array.from(d))}for(const d of u){if(d.length!==2)throw new TypeError("Each header pair must be a name/value tuple");this.append(d[0],d[1])}}else for(const u of Object.keys(r)){const d=r[u];this.append(u,d)}}else throw new TypeError("Provided initializer must be an object")}get(r){r=`${r}`,Du(r);const l=Bc(this[ln],r);return l===void 0?null:this[ln][l].join(", ")}forEach(r){let l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0,u=tI(this),d=0;for(;d<u.length;){var f=u[d];const g=f[0],I=f[1];r.call(l,I,g,this),u=tI(this),d++}}set(r,l){r=`${r}`,l=`${l}`,Du(r),D2(l);const u=Bc(this[ln],r);this[ln][u!==void 0?u:r]=[l]}append(r,l){r=`${r}`,l=`${l}`,Du(r),D2(l);const u=Bc(this[ln],r);u!==void 0?this[ln][u].push(l):this[ln][r]=[l]}has(r){return r=`${r}`,Du(r),Bc(this[ln],r)!==void 0}delete(r){r=`${r}`,Du(r);const l=Bc(this[ln],r);l!==void 0&&delete this[ln][l]}raw(){return this[ln]}keys(){return nI(this,"key")}values(){return nI(this,"value")}[Symbol.iterator](){return nI(this,"key+value")}}fi.prototype.entries=fi.prototype[Symbol.iterator];Object.defineProperty(fi.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0});Object.defineProperties(fi.prototype,{get:{enumerable:!0},forEach:{enumerable:!0},set:{enumerable:!0},append:{enumerable:!0},has:{enumerable:!0},delete:{enumerable:!0},keys:{enumerable:!0},values:{enumerable:!0},entries:{enumerable:!0}});function tI(r){let l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"key+value";const u=Object.keys(r[ln]).sort();return u.map(l==="key"?function(d){return d.toLowerCase()}:l==="value"?function(d){return r[ln][d].join(", ")}:function(d){return[d.toLowerCase(),r[ln][d].join(", ")]})}const sI=Symbol("internal");function nI(r,l){const u=Object.create(iI);return u[sI]={target:r,kind:l,index:0},u}const iI=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==iI)throw new TypeError("Value of `this` is not a HeadersIterator");var r=this[sI];const l=r.target,u=r.kind,d=r.index,f=tI(l,u),g=f.length;return d>=g?{value:void 0,done:!0}:(this[sI].index=d+1,{value:f[d],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));Object.defineProperty(iI,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});function c9(r){const l=Object.assign({__proto__:null},r[ln]),u=Bc(r[ln],"Host");return u!==void 0&&(l[u]=l[u][0]),l}function l9(r){const l=new fi;for(const u of Object.keys(r)){if(E2.test(u))continue;if(Array.isArray(r[u]))for(const d of r[u]){if(eI.test(d))continue;l[ln][u]===void 0?l[ln][u]=[d]:l[ln][u].push(d)}else eI.test(r[u])||(l[ln][u]=[r[u]])}return l}const po=Symbol("Response internals"),h9=JS.default.STATUS_CODES;class Mi{constructor(){let r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Dn.call(this,r,l);const u=l.status||200,d=new fi(l.headers);if(r!=null&&!d.has("Content-Type")){const f=R2(r);f&&d.append("Content-Type",f)}this[po]={url:l.url,status:u,statusText:l.statusText||h9[u],headers:d,counter:l.counter}}get url(){return this[po].url||""}get status(){return this[po].status}get ok(){return this[po].status>=200&&this[po].status<300}get redirected(){return this[po].counter>0}get statusText(){return this[po].statusText}get headers(){return this[po].headers}clone(){return new Mi(C2(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}Dn.mixIn(Mi.prototype);Object.defineProperties(Mi.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}});Object.defineProperty(Mi.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const Ir=Symbol("Request internals"),rI=of.default.parse,u9=of.default.format,d9="destroy"in qs.default.Readable.prototype;function af(r){return typeof r=="object"&&typeof r[Ir]=="object"}function p9(r){const l=r&&typeof r=="object"&&Object.getPrototypeOf(r);return!!(l&&l.constructor.name==="AbortSignal")}class ra{constructor(r){let l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},u;af(r)?u=rI(r.url):(r&&r.href?u=rI(r.href):u=rI(`${r}`),r={});let d=l.method||r.method||"GET";if(d=d.toUpperCase(),(l.body!=null||af(r)&&r.body!==null)&&(d==="GET"||d==="HEAD"))throw new TypeError("Request with GET/HEAD method cannot have body");let f=l.body!=null?l.body:af(r)&&r.body!==null?C2(r):null;Dn.call(this,f,{timeout:l.timeout||r.timeout||0,size:l.size||r.size||0});const g=new fi(l.headers||r.headers||{});if(f!=null&&!g.has("Content-Type")){const S=R2(f);S&&g.append("Content-Type",S)}let I=af(r)?r.signal:null;if("signal"in l&&(I=l.signal),I!=null&&!p9(I))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[Ir]={method:d,redirect:l.redirect||r.redirect||"follow",headers:g,parsedURL:u,signal:I},this.follow=l.follow!==void 0?l.follow:r.follow!==void 0?r.follow:20,this.compress=l.compress!==void 0?l.compress:r.compress!==void 0?r.compress:!0,this.counter=l.counter||r.counter||0,this.agent=l.agent||r.agent}get method(){return this[Ir].method}get url(){return u9(this[Ir].parsedURL)}get headers(){return this[Ir].headers}get redirect(){return this[Ir].redirect}get signal(){return this[Ir].signal}clone(){return new ra(this)}}Dn.mixIn(ra.prototype);Object.defineProperty(ra.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0});Object.defineProperties(ra.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}});function m9(r){const l=r[Ir].parsedURL,u=new fi(r[Ir].headers);if(u.has("Accept")||u.set("Accept","*/*"),!l.protocol||!l.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(l.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(r.signal&&r.body instanceof qs.default.Readable&&!d9)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let d=null;if(r.body==null&&/^(POST|PUT)$/i.test(r.method)&&(d="0"),r.body!=null){const g=O2(r);typeof g=="number"&&(d=String(g))}d&&u.set("Content-Length",d),u.has("User-Agent")||u.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),r.compress&&!u.has("Accept-Encoding")&&u.set("Accept-Encoding","gzip,deflate");let f=r.agent;return typeof f=="function"&&(f=f(l)),!u.has("Connection")&&!f&&u.set("Connection","close"),Object.assign({},l,{method:r.method,headers:c9(u),agent:f})}function ku(r){Error.call(this,r),this.type="aborted",this.message=r,Error.captureStackTrace(this,this.constructor)}ku.prototype=Object.create(Error.prototype);ku.prototype.constructor=ku;ku.prototype.name="AbortError";const k2=qs.default.PassThrough,f9=of.default.resolve;function mo(r,l){if(!mo.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return Dn.Promise=mo.Promise,new mo.Promise(function(u,d){const f=new ra(r,l),g=m9(f),I=(g.protocol==="https:"?A2.default:JS.default).request,S=f.signal;let x=null;const N=function(){let Q=new ku("The user aborted a request.");if(d(Q),f.body&&f.body instanceof qs.default.Readable&&f.body.destroy(Q),!x||!x.body)return;x.body.emit("error",Q)};if(S&&S.aborted){N();return}const E=function(){N(),U()},_=I(g);let A;S&&S.addEventListener("abort",E);function U(){_.abort(),S&&S.removeEventListener("abort",E),clearTimeout(A)}f.timeout&&_.once("socket",function(ne){A=setTimeout(function(){d(new Gn(`network timeout at: ${f.url}`,"request-timeout")),U()},f.timeout)}),_.on("error",function(ne){d(new Gn(`request to ${f.url} failed, reason: ${ne.message}`,"system",ne)),U()}),_.on("response",function(ne){clearTimeout(A);const Q=l9(ne.headers);if(mo.isRedirect(ne.statusCode)){const Ae=Q.get("Location"),Me=Ae===null?null:f9(f.url,Ae);switch(f.redirect){case"error":d(new Gn(`uri requested responds with a redirect, redirect mode is set to error: ${f.url}`,"no-redirect")),U();return;case"manual":if(Me!==null)try{Q.set("Location",Me)}catch(ct){d(ct)}break;case"follow":if(Me===null)break;if(f.counter>=f.follow){d(new Gn(`maximum redirect reached at: ${f.url}`,"max-redirect")),U();return}const et={headers:new fi(f.headers),follow:f.follow,counter:f.counter+1,agent:f.agent,compress:f.compress,method:f.method,body:f.body,signal:f.signal,timeout:f.timeout,size:f.size};if(ne.statusCode!==303&&f.body&&O2(f)===null){d(new Gn("Cannot follow redirect with body being a readable stream","unsupported-redirect")),U();return}(ne.statusCode===303||(ne.statusCode===301||ne.statusCode===302)&&f.method==="POST")&&(et.method="GET",et.body=void 0,et.headers.delete("content-length")),u(mo(new ra(Me,et))),U();return}}ne.once("end",function(){S&&S.removeEventListener("abort",E)});let M=ne.pipe(new k2);const fe={url:f.url,status:ne.statusCode,statusText:ne.statusMessage,headers:Q,size:f.size,timeout:f.timeout,counter:f.counter},ie=Q.get("Content-Encoding");if(!f.compress||f.method==="HEAD"||ie===null||ne.statusCode===204||ne.statusCode===304){x=new Mi(M,fe),u(x);return}const we={flush:uo.default.Z_SYNC_FLUSH,finishFlush:uo.default.Z_SYNC_FLUSH};if(ie=="gzip"||ie=="x-gzip"){M=M.pipe(uo.default.createGunzip(we)),x=new Mi(M,fe),u(x);return}if(ie=="deflate"||ie=="x-deflate"){const Ae=ne.pipe(new k2);Ae.once("data",function(Me){(Me[0]&15)===8?M=M.pipe(uo.default.createInflate()):M=M.pipe(uo.default.createInflateRaw()),x=new Mi(M,fe),u(x)});return}if(ie=="br"&&typeof uo.default.createBrotliDecompress=="function"){M=M.pipe(uo.default.createBrotliDecompress()),x=new Mi(M,fe),u(x);return}x=new Mi(M,fe),u(x)}),a9(_,f)})}mo.isRedirect=function(r){return r===301||r===302||r===303||r===307||r===308};mo.Promise=global.Promise;var g9=mo});var Ze=XS((cf,_2)=>{(function(r,l){typeof cf=="object"&&typeof _2!="undefined"?l(cf):typeof define=="function"&&define.amd?define(["exports"],l):(r=r||self,l(r.tf=r.tf||{}))})(cf,function(r){"use strict";const l=1e-7,u=1e-4;class d{constructor(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0}get(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)}set(e,t){this.dataIdsCount++,this.data.set(e,t)}has(e){return this.data.has(e)}delete(e){return this.dataIdsCount--,this.data.delete(e)}numDataIds(){return this.dataIdsCount}}class f{time(e){return g("time")}read(e){return g("read")}readSync(e){return g("readSync")}numDataIds(){return g("numDataIds")}disposeData(e){return g("disposeData")}write(e,t,n){return g("write")}move(e,t,n,s){return g("move")}memory(){return g("memory")}floatPrecision(){return g("floatPrecision")}epsilon(){return this.floatPrecision()===32?l:u}batchMatMul(e,t,n,s){return g("batchMatMul")}fusedBatchMatMul({a:e,b:t,transposeA:n,transposeB:s,bias:i,activation:o,preluActivationWeights:a}){return g("fusedBatchMatMul")}slice(e,t,n){return g("slice")}stridedSlice(e,t,n,s){return g("stridedSlice")}unstack(e,t){return g("unstack")}reverse(e,t){return g("reverse")}concat(e,t){return g("concat")}neg(e){return g("neg")}add(e,t){return g("add")}addN(e){return g("addN")}subtract(e,t){return g("subtract")}multiply(e,t){return g("multiply")}realDivide(e,t){return g("realDivide")}floorDiv(e,t){return g("floorDiv")}sum(e,t){return g("sum")}prod(e,t){return g("prod")}unsortedSegmentSum(e,t,n){return g("unsortedSegmentSum")}argMin(e,t){return g("argMin")}argMax(e,t){return g("argMax")}equal(e,t){return g("equal")}notEqual(e,t){return g("notEqual")}less(e,t){return g("less")}lessEqual(e,t){return g("lessEqual")}greater(e,t){return g("greater")}greaterEqual(e,t){return g("greaterEqual")}logicalNot(e){return g("logicalNot")}logicalAnd(e,t){return g("logicalAnd")}logicalOr(e,t){return g("logicalOr")}where(e){return g("where")}select(e,t,n){return g("select")}topk(e,t,n){return g("topk")}min(e,t){return g("min")}minimum(e,t){return g("minimum")}mod(e,t){return g("mod")}max(e,t){return g("max")}maximum(e,t){return g("maximum")}all(e,t){return g("all")}any(e,t){return g("any")}squaredDifference(e,t){return g("squaredDifference")}ceil(e){return g("ceil")}floor(e){return g("floor")}round(e){return g("round")}sign(e){return g("sign")}isNaN(e){return g("isNaN")}isInf(e){return g("isInf")}isFinite(e){return g("isFinite")}pow(e,t){return g("pow")}exp(e){return g("exp")}expm1(e){return g("expm1")}softmax(e,t){return g("softmax")}log(e){return g("log")}log1p(e){return g("log1p")}sqrt(e){return g("sqrt")}rsqrt(e){return g("rsqrt")}square(e){return g("square")}reciprocal(e){return g("reciprocal")}relu(e){return g("relu")}relu6(e){return g("relu6")}prelu(e,t){return g("prelu")}elu(e){return g("elu")}eluDer(e,t){return g("eluDer")}selu(e){return g("selu")}int(e){return g("int")}clip(e,t,n){return g("clip")}abs(e){return g("abs")}complexAbs(e){return g("complexAbs")}sigmoid(e){return g("sigmoid")}softplus(e){return g("softplus")}sin(e){return g("sin")}cos(e){return g("cos")}tan(e){return g("tan")}asin(e){return g("asin")}acos(e){return g("acos")}atan(e){return g("atan")}atan2(e,t){return g("atan2")}sinh(e){return g("sinh")}cosh(e){return g("cosh")}tanh(e){return g("tanh")}asinh(e){return g("asinh")}acosh(e){return g("acosh")}atanh(e){return g("atanh")}erf(e){return g("erf")}step(e,t){return g("step")}fusedConv2d({input:e,filter:t,convInfo:n,bias:s,activation:i,preluActivationWeights:o}){return g("fusedConv2d")}conv2d(e,t,n){return g("conv2d")}conv2dDerInput(e,t,n){return g("conv2dDerInput")}conv2dDerFilter(e,t,n){return g("conv2dDerFilter")}fusedDepthwiseConv2D({input:e,filter:t,convInfo:n,bias:s,activation:i,preluActivationWeights:o}){return g("fusedDepthwiseConv2D")}depthwiseConv2D(e,t,n){return g("depthwiseConv2D")}depthwiseConv2DDerInput(e,t,n){return g("depthwiseConv2DDerInput")}depthwiseConv2DDerFilter(e,t,n){return g("depthwiseConv2DDerFilter")}conv3d(e,t,n){return g("conv3d")}conv3dDerInput(e,t,n){return g("conv3dDerInput")}conv3dDerFilter(e,t,n){return g("conv3dDerFilter")}maxPool(e,t){return g("maxPool")}maxPoolBackprop(e,t,n,s){return g("maxPoolBackprop")}avgPool(e,t){return g("avgPool")}avgPoolBackprop(e,t,n){return g("avgPoolBackprop")}avgPool3d(e,t){return g("avgPool3d")}avgPool3dBackprop(e,t,n){return g("avgPool3dBackprop")}maxPool3d(e,t){return g("maxPool3d")}maxPool3dBackprop(e,t,n,s){return g("maxPool3dBackprop")}reshape(e,t){return g("reshape")}cast(e,t){return g("cast")}tile(e,t){return g("tile")}pad(e,t,n){return g("pad")}transpose(e,t){return g("transpose")}gather(e,t,n){return g("gather")}gatherND(e,t){return g("gatherND")}scatterND(e,t,n){return g("scatterND")}batchToSpaceND(e,t,n){return g("batchToSpaceND")}spaceToBatchND(e,t,n){return g("spaceToBatchND")}resizeBilinear(e,t,n,s){return g("resizeBilinear")}resizeBilinearBackprop(e,t,n){return g("resizeBilinearBackprop")}resizeNearestNeighbor(e,t,n,s){return g("resizeNearestNeighbor")}resizeNearestNeighborBackprop(e,t,n){return g("resizeNearestNeighborBackprop")}batchNorm(e,t,n,s,i,o){return g("batchNorm")}localResponseNormalization4D(e,t,n,s,i){return g("localResponseNormalization4D")}LRNGrad(e,t,n,s,i,o,a){return g("LRNGrad")}multinomial(e,t,n,s){return g("multinomial")}oneHot(e,t,n,s){return g("oneHot")}cumsum(e,t,n,s){return g("cumsum")}nonMaxSuppression(e,t,n,s,i){return g("nonMaxSuppression")}fft(e){return g("fft")}ifft(e){return g("ifft")}complex(e,t){return g("complex")}real(e){return g("real")}imag(e){return g("imag")}cropAndResize(e,t,n,s,i,o){return g("cropAndResize")}depthToSpace(e,t,n){return g("depthToSpace")}split(e,t,n){return g("split")}sparseToDense(e,t,n,s){return g("sparseToDense")}diag(e){return g("diag")}fill(e,t,n){return g("fill")}onesLike(e){return g("onesLike")}zerosLike(e){return g("zerosLike")}linspace(e,t,n){return g("linspace")}dispose(){return g("dispose")}}function g(e){throw new Error(`'${e}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`)}function I(e){let t=e.length,n=0,s=0;for(;t>0;)s=Math.random()*t|0,t--,n=e[t],e[t]=e[s],e[s]=n}function S(e,t,n){return Math.max(e,Math.min(t,n))}function x(e){return e%2===0?e:e+1}function N(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return t}function E(e,t){const n=Math.random();return t*n+(1-n)*e}function _(e,t){let n=0;for(let s=0;s<e.length;s++){const i=Number(e[s])-Number(t[s]);n+=i*i}return n}function A(e,t){if(!e)throw new Error(typeof t=="string"?t:t())}function U(e,t,n=""){A(ie(e,t),()=>n+` Shapes ${e} and ${t} must match`)}function ne(e){A(e!=null,()=>"The input to the tensor constructor must be a non-null value.")}function Q(e,t=[],n=!1){if(t==null&&(t=[]),Array.isArray(e)||un(e)&&!n)for(let s=0;s<e.length;++s)Q(e[s],t,n);else t.push(e);return t}function M(e){if(e.length===0)return 1;let t=e[0];for(let n=1;n<e.length;n++)t*=e[n];return t}function fe(e){return e.length===0}function ie(e,t){if(e===t)return!0;if(e==null||t==null)return!1;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function we(e){return e%1===0}function Ae(e){if(Math.tanh!=null)return Math.tanh(e);if(e===Infinity)return 1;if(e===-Infinity)return-1;{const t=Math.exp(2*e);return(t-1)/(t+1)}}function Me(e){const t=Math.ceil(Math.sqrt(e));return[t,Math.ceil(e/t)]}function et(e){const t=new Uint32Array(e);for(let n=0;n<e;++n)t[n]=n;return I(t),t}function ct(e,t){return t<=e.length?e:e+" ".repeat(t-e.length)}function $t(e,t=s=>0,n){return new Promise((s,i)=>{let o=0;const a=()=>{if(e()){s();return}o++;const c=t(o);if(n!=null&&o>=n){i();return}setTimeout(a,c)};a()})}function Vt(e,t){let n=1,s=-1;for(let o=0;o<e.length;++o)if(e[o]>=0)n*=e[o];else if(e[o]===-1){if(s!==-1)throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${o}`);s=o}else if(e[o]<0)throw Error(`Shapes can not be < 0. Found ${e[o]} at dim ${o}`);if(s===-1){if(t>0&&t!==n)throw Error(`Size(${t}) must match the product of shape ${e}`);return e}if(n===0)throw Error(`Cannot infer the missing size in [${e}] when there are 0 elements`);if(t%n!==0)throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${n}`);const i=e.slice();return i[s]=t/n,i}function je(e,t){const n=t.length;return e=e==null?t.map((s,i)=>i):[].concat(e),A(e.every(s=>s>=-n&&s<n),()=>`All values in axis param must be in range [-${n}, ${n}) but got axis ${e}`),A(e.every(s=>we(s)),()=>`All values in axis param must be integers but got axis ${e}`),e.map(s=>s<0?n+s:s)}function hn(e,t){const n=[],s=[],i=t!=null&&Array.isArray(t)&&t.length===0,o=t==null||i?null:je(t,e).sort();let a=0;for(let c=0;c<e.length;++c){if(o!=null){if(o[a]===c&&e[c]!==1)throw new Error(`Can't squeeze axis ${c} since its dim '${e[c]}' is not 1`);(o[a]==null||o[a]>c)&&e[c]===1&&(n.push(e[c]),s.push(c)),o[a]<=c&&a++}e[c]!==1&&(n.push(e[c]),s.push(c))}return{newShape:n,keptDims:s}}function bt(e,t){let n=null;if(e==null||e==="float32")n=new Float32Array(t);else if(e==="int32")n=new Int32Array(t);else if(e==="bool")n=new Uint8Array(t);else throw new Error(`Unknown data type ${e}`);return n}function Is(e,t){let n=null;if(e==null||e==="float32")n=new Float32Array(t);else if(e==="int32")n=new Int32Array(t);else if(e==="bool")n=new Uint8Array(t);else if(e==="string")n=new Array(t);else throw new Error(`Unknown data type ${e}`);return n}function _r(e,t){for(let n=0;n<e.length;n++){const s=e[n];if(isNaN(s)||!isFinite(s))throw Error(`A tensor of type ${t} being uploaded contains ${s}.`)}}function Wr(e){return e==="bool"||e==="complex64"||e==="float32"||e==="int32"||e==="string"}function Oa(e,t){return t==="complex64"||(t==="float32"&&e!=="complex64"||t==="int32"&&e!=="float32"&&e!=="complex64")?!1:!(t==="bool"&&e==="bool")}function un(e){return e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array}function iy(e){if(e==="float32"||e==="int32")return 4;if(e==="complex64")return 8;if(e==="bool")return 1;throw new Error(`Unknown dtype ${e}`)}function Xx(e){if(e==null)return 0;let t=0;return e.forEach(n=>t+=n.length),t}function Ji(e){return typeof e=="string"||e instanceof String}function Jx(e){return typeof e=="boolean"}function yd(e){return typeof e=="number"}function Ea(e){return Array.isArray(e)?Ea(e[0]):e instanceof Float32Array?"float32":e instanceof Int32Array||e instanceof Uint8Array?"int32":yd(e)?"float32":Ji(e)?"string":Jx(e)?"bool":"float32"}function $r(e){return!!(e&&e.constructor&&e.call&&e.apply)}function bd(e,t){for(let n=t;n<e;++n)if(e%n===0)return n;return e}function Ke(e){const t=e.length;if(t<2)return[];const n=new Array(t-1);n[t-2]=e[t-1];for(let s=t-3;s>=0;--s)n[s]=n[s+1]*e[s+1];return n}function Zx(e,t,n){const s=new Array;if(t.length===1){const i=t[0];for(let o=0;o<i;o++)s[o]=n[e+o]}else{const i=t[0],o=t.slice(1),a=o.reduce((c,h)=>c*h);for(let c=0;c<i;c++)s[c]=Zx(e+c*a,o,n)}return s}function xs(e,t){if(e.length===0)return t[0];const n=e.reduce((s,i)=>s*i);if(n===0)return[];if(n!==t.length)throw new Error(`[${e}] does not match the input size ${t.length}.`);return Zx(0,e,t)}function ry(e,t){const n=Da(e,t);for(let s=0;s<n.length;s++)n[s]=1;return n}function Da(e,t){if(t==null||t==="float32"||t==="complex64")return new Float32Array(e);if(t==="int32")return new Int32Array(e);if(t==="bool")return new Uint8Array(e);throw new Error(`Unknown data type ${t}`)}function oy(e,t){const n=e.reduce((s,i)=>s*i,1);if(t==null||t==="float32")return xs(e,new Float32Array(n));if(t==="int32")return xs(e,new Int32Array(n));if(t==="bool")return xs(e,new Uint8Array(n));throw new Error(`Unknown data type ${t}`)}function ay(e){e.forEach(t=>{A(Number.isInteger(t)&&t>=0,()=>`Tensor must have a shape comprised of positive integers but got shape [${e}].`)})}function Us(e,t,n){if(t===0)return 0;if(t===1)return e[0];let s=e[e.length-1];for(let i=0;i<e.length-1;++i)s+=n[i]*e[i];return s}function Co(e,t,n){if(t===0)return[];if(t===1)return[e];const s=new Array(t);for(let i=0;i<s.length-1;++i)s[i]=Math.floor(e/n[i]),e-=s[i]*n[i];return s[s.length-1]=e,s}function Ro(e){return e&&e.then&&typeof e.then=="function"}const Qx="tfjsflags";class eT{constructor(e){this.global=e,this.flags={},this.flagRegistry={},this.urlFlags={},this.populateURLFlags()}setPlatform(e,t){this.platform!=null&&console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`),this.platformName=e,this.platform=t}registerFlag(e,t,n){if(this.flagRegistry[e]={evaluationFn:t,setHook:n},this.urlFlags[e]!=null){const s=this.urlFlags[e];console.warn(`Setting feature override from URL ${e}: ${s}.`),this.set(e,s)}}async getAsync(e){return e in this.flags?this.flags[e]:(this.flags[e]=await this.evaluateFlag(e),this.flags[e])}get(e){if(e in this.flags)return this.flags[e];const t=this.evaluateFlag(e);if(Ro(t))throw new Error(`Flag ${e} cannot be synchronously evaluated. Please use getAsync() instead.`);return this.flags[e]=t,this.flags[e]}getNumber(e){return this.get(e)}getBool(e){return this.get(e)}getFlags(){return this.flags}get features(){return this.flags}set(e,t){if(this.flagRegistry[e]==null)throw new Error(`Cannot set flag ${e} as it has not been registered.`);this.flags[e]=t,this.flagRegistry[e].setHook!=null&&this.flagRegistry[e].setHook(t)}evaluateFlag(e){if(this.flagRegistry[e]==null)throw new Error(`Cannot evaluate flag '${e}': no evaluation function found.`);return this.flagRegistry[e].evaluationFn()}setFlags(e){this.flags=Object.assign({},e)}reset(){this.flags={},this.urlFlags={},this.populateURLFlags()}populateURLFlags(){if(typeof this.global=="undefined"||typeof this.global.location=="undefined"||typeof this.global.location.search=="undefined")return;const e=Tk(this.global.location.search);if(Qx in e){const t=e[Qx].split(",");t.forEach(n=>{const[s,i]=n.split(":");this.urlFlags[s]=vk(s,i)})}}}function Tk(e){const t={};return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(n,...s)=>(Ak(t,s[0],s[1]),s.join("="))),t}function Ak(e,t,n){e[decodeURIComponent(t)]=decodeURIComponent(n||"")}function vk(e,t){if(t=t.toLowerCase(),t==="true"||t==="false")return t==="true";if(`${+t}`===t)return+t;throw new Error(`Could not parse value flag value ${t} for flag ${e}.`)}function ae(){return r.ENV}r.ENV=null;function Nk(e){r.ENV=e}let cy;function tT(){if(cy==null){let e;if(typeof window!="undefined")e=window;else if(typeof global!="undefined")e=global;else if(typeof process!="undefined")e=process;else if(typeof self!="undefined")e=self;else throw new Error("Could not find a global object");cy=e}return cy}function Ck(){const e=tT();return e._tfGlobals==null&&(e._tfGlobals=new Map),e._tfGlobals}function nT(e,t){const n=Ck();if(n.has(e))return n.get(e);{const s=t();return n.set(e,s),n.get(e)}}const wd="Abs",Ll="Acos",Sl="Acosh",Oo="Add",ly="AddN",sT="All",iT="Any",hy="ArgMax",uy="ArgMin",Il="Asin",xl="Asinh",Tl="Atan",Al="Atanh",Ld="Atan2",vl="AvgPool",Sd="AvgPoolBackprop",dy="AvgPool3D",rT="AvgPool3DBackprop",Id="BatchMatMul",py="BatchToSpaceND",my="BroadcastTo",ka="Cast",Nl="Ceil",Cl="ClipByValue",xd="Complex",Rl="Concat",Td="Conv2D",fy="Conv2DBackpropFilter",Ad="Conv2DBackpropInput",vd="Conv3D",gy="Conv3DBackpropFilterV2",yy="Conv3DBackpropInputV2",Fa="Cos",Ol="Cosh",by="Cumsum",oT="CropAndResize",aT="DepthToSpace",Nd="DepthwiseConv2dNative",wy="DepthwiseConv2dNativeBackpropFilter",Ly="DepthwiseConv2dNativeBackpropInput",cT="Diag",Cd="Dilation2D",Rd="Dilation2DBackpropInput",Od="Dilation2DBackpropFilter",_a="Div",El="Elu",lT="EluGrad",Dl="Erf",hT="Equal",kl="Exp",Fl="Expm1",Ed="FFT",Sy="Fill",Dd="FlipLeftRight",_l="Floor",Iy="FloorDiv",Wl="FusedBatchNorm",xy="GatherV2",uT="GatherNd",dT="Greater",Ty="GreaterEqual",$l="Identity",kd="IFFT",Fd="Imag",Ul="IsFinite",Bl="IsInf",Ml="IsNan",pT="Less",mT="LessEqual",fT="LinSpace",Pl="Log",zl="Log1p",gT="LogicalAnd",_d="LogicalNot",yT="LogicalOr",Ay="LogSoftmax",vy="LRN",bT="LRNBackprop",Vl="Max",Ny="Maximum",Gl="MaxPool",Wd="MaxPoolBackprop",Cy="MaxPool3D",wT="MaxPool3DBackprop",$d="MaxPoolWithArgmax",Ry="Mean",Oy="Min",Ey="Minimum",Yl="MirrorPad",Dy="Mod",Wa="Multiply",ky="Negate",Hl="NotEqual",Fy="NonMaxSuppressionV3",Ud="NonMaxSuppressionV4",Bd="NonMaxSuppressionV5",_y="OnesLike",Wy="OneHot",Md="PadV2",Rk="Pool",$y="Pow",Pd="Prelu",LT="Prod",ST="Range",zd="Real",ql="Reciprocal",jl="Relu",Kl="Reshape",Uy="ResizeNearestNeighbor",IT="ResizeNearestNeighborGrad",By="ResizeBilinear",xT="ResizeBilinearGrad",Xl="Relu6",My="Reverse",Jl="Round",Zl="Rsqrt",TT="ScatterNd",Py="SelectV2",Ql="Selu",Vd="Slice",$a="Sin",eh="Sinh",th="Sign",nh="Sigmoid",sh="Softplus",ih="Sqrt",zy="Sum",Gd="SpaceToBatchND",Vy="SplitV",Gy="Softmax",Ua="SquaredDifference",Yd="Square",Ba="Sub",AT="SparseToDense",vT="StridedSlice",Ma="Tan",rh="Tanh",Yy="Tile",NT="TopK",oh="Transpose",Hd="Unique",Hy="Unpack",qy="UnsortedSegmentSum",jy="ZerosLike",ah="Step",qd="FromPixels",jd="RotateWithOffset",Kd="_FusedMatMul",Xd="FusedConv2D",Jd="FusedDepthwiseConv2D";const Pa=nT("kernelRegistry",()=>new Map),ch=nT("gradRegistry",()=>new Map);function Ky(e,t){const n=Jy(e,t);return Pa.get(n)}function Xy(e){return ch.get(e)}function Zd(e){const t=Pa.entries(),n=[];for(;;){const{done:s,value:i}=t.next();if(s)break;const[o,a]=i,[c]=o.split("_");c===e&&n.push(a)}return n}function Qd(e){const{kernelName:t,backendName:n}=e,s=Jy(t,n);Pa.has(s)&&console.warn(`The kernel '${t}' for backend '${n}' is already registered`),Pa.set(s,e)}function CT(e){const{kernelName:t}=e;ch.has(t)&&(ae().getBool("DEBUG")&&console.warn(`Overriding the gradient for '${t}'`)),ch.set(t,e)}function Ok(e,t){const n=Jy(e,t);if(!Pa.has(n))throw new Error(`The kernel '${e}' for backend '${t}' is not registered`);Pa.delete(n)}function Ek(e){if(!ch.has(e))throw new Error(`The gradient '${e}' for backend is not registered`);ch.delete(e)}function Dk(e,t){const n=Zd(e);n.forEach(s=>{const i=Object.assign({},s,{backendName:t});Qd(i)})}function Jy(e,t){return`${t}_${e}`}function RT(e,t){return t==="string"?ep(e):Ur([e],t)}function kk(e,t){return e instanceof Float32Array&&t==="float32"||e instanceof Int32Array&&t==="int32"||e instanceof Uint8Array&&t==="bool"}function Ur(e,t){if(t==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=Q(e)),ae().getBool("DEBUG")&&_r(e,t),kk(e,t))return e;if(t==null||t==="float32"||t==="complex64")return new Float32Array(e);if(t==="int32")return new Int32Array(e);if(t==="bool"){const n=new Uint8Array(e.length);for(let s=0;s<n.length;++s)Math.round(e[s])!==0&&(n[s]=1);return n}else throw new Error(`Unknown data type ${t}`)}function Jn(){return ae().platform.now()}function OT(e,t){return ae().platform.fetch(e,t)}function ep(e,t="utf-8"){return t=t||"utf-8",ae().platform.encode(e,t)}function lh(e,t="utf-8"){return t=t||"utf-8",ae().platform.decode(e,t)}var Fk=Object.freeze({__proto__:null,createScalarValue:RT,toTypedArray:Ur,now:Jn,fetch:OT,encodeString:ep,decodeString:lh,shuffle:I,clamp:S,nearestLargerEven:x,sum:N,randUniform:E,distSquared:_,assert:A,assertShapesMatch:U,assertNonNull:ne,flatten:Q,sizeFromShape:M,isScalarShape:fe,arraysEqual:ie,isInt:we,tanh:Ae,sizeToSquarishShape:Me,createShuffledIndices:et,rightPad:ct,repeatedTry:$t,inferFromImplicitShape:Vt,parseAxisParam:je,squeezeShape:hn,getTypedArrayFromDType:bt,getArrayFromDType:Is,checkConversionForErrors:_r,isValidDtype:Wr,hasEncodingLoss:Oa,isTypedArray:un,bytesPerElement:iy,bytesFromStringArray:Xx,isString:Ji,isBoolean:Jx,isNumber:yd,inferDtype:Ea,isFunction:$r,nearestDivisor:bd,computeStrides:Ke,toNestedArray:xs,makeOnesTypedArray:ry,makeZerosTypedArray:Da,makeZerosNestedTypedArray:oy,assertNonNegativeIntegerDimensions:ay,locToIndex:Us,indexToLoc:Co,isPromise:Ro});class _k{constructor(e,t){this.backendTimer=e,this.logger=t,t==null&&(this.logger=new $k)}profileKernel(e,t,n){let s;const i=()=>{s=n()},o=this.backendTimer.time(i);for(let c=0;c<s.length;c++){const h=s[c];h.data().then(p=>{Wk(p,h.dtype,e)})}const a={kernelName:e,outputs:s,inputs:t,timeMs:o.then(c=>c.kernelMs),extraInfo:o.then(c=>c.getExtraProfileInfo!=null?c.getExtraProfileInfo():"")};return a}logKernelProfile(e){const{kernelName:t,outputs:n,timeMs:s,inputs:i,extraInfo:o}=e;n.forEach(a=>{Promise.all([a.data(),s,o]).then(c=>{this.logger.logKernelProfile(t,a,c[0],c[1],i,c[2])})})}}function Wk(e,t,n){if(t!=="float32")return!1;for(let s=0;s<e.length;s++){const i=e[s];if(isNaN(i)||!isFinite(i))return console.warn(`Found ${i} in the result of '${n}'`),!0}return!1}class $k{logKernelProfile(e,t,n,s,i,o){const a=typeof s=="number"?ct(`${s}ms`,9):s.error,c=ct(e,25),h=t.rank,p=t.size,m=ct(t.shape.toString(),14);let y="";for(const b in i){const w=i[b];if(w!=null){const L=w.shape||t.shape,T=L.length;y+=`${b}: ${T}D ${T>0?L:""} `}}console.log(`%c${c} %c${a} %c${h}D ${m} %c${p} %c${y} %c${o}`,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")}}function Uk(e,t,n){const s={},i={};for(let h=0;h<t.length;h++)s[t[h].id]=!0;for(let h=0;h<e.length;h++){const p=e[h],m=p.inputs;for(const y in m){const b=m[y];let w=!1;for(let L=0;L<t.length;L++)if(s[b.id]){p.outputs.forEach(T=>s[T.id]=!0),w=!0,i[p.id]=!0;break}if(w)break}}const o={};o[n.id]=!0;const a={};for(let h=e.length-1;h>=0;h--){const p=e[h],m=p.inputs;for(let y=0;y<p.outputs.length;y++)if(o[p.outputs[y].id]){for(const b in m)o[m[b].id]=!0,a[p.id]=!0;break}}const c=[];for(let h=0;h<e.length;h++){const p=e[h];if(i[p.id]&&a[p.id]){const m={};for(const b in p.inputs){const w=p.inputs[b];s[w.id]&&(m[b]=w)}const y=Object.assign({},p);y.inputs=m,y.outputs=p.outputs,c.push(y)}}return c}function Bk(e,t,n,s){for(let i=t.length-1;i>=0;i--){const o=t[i],a=[];if(o.outputs.forEach(h=>{const p=e[h.id];p!=null?a.push(p):a.push(null)}),o.gradient==null)throw new Error(`Cannot compute gradient: gradient function not found for ${o.kernelName}.`);const c=o.gradient(a);for(const h in o.inputs){if(!(h in c))throw new Error(`Cannot backprop through input ${h}. Available gradients found: ${Object.keys(c)}.`);const p=n(()=>c[h]());if(p.dtype!=="float32")throw new Error(`Error in gradient for op ${o.kernelName}. The gradient of input ${h} must have 'float32' dtype, but has '${p.dtype}'`);const m=o.inputs[h];if(!ie(p.shape,m.shape))throw new Error(`Error in gradient for op ${o.kernelName}. The gradient of input '${h}' has shape '${p.shape}', which does not match the shape of the input '${m.shape}'`);if(e[m.id]==null)e[m.id]=p;else{const y=e[m.id];e[m.id]=s(y,p),y.dispose()}}}}const ET=20,hh=3,Zy=7;function Mk(e,t,n,s){const i=Ke(t),o=Pk(e,t,n,i),a=t.length,c=tp(e,t,n,i,o),h=["Tensor"];return s&&(h.push(` dtype: ${n}`),h.push(` rank: ${a}`),h.push(` shape: [${t}]`),h.push(" values:")),h.push(c.map(p=>" "+p).join(`
`)),h.join(`
`)}function Pk(e,t,n,s){const i=M(t),o=s[s.length-1],a=new Array(o).fill(0),c=t.length,h=n==="complex64"?dh(e):e;if(c>1)for(let p=0;p<i/o;p++){const m=p*o;for(let y=0;y<o;y++)a[y]=Math.max(a[y],uh(h[m+y],0,n).length)}return a}function uh(e,t,n){let s;return Array.isArray(e)?s=`${parseFloat(e[0].toFixed(Zy))} + ${parseFloat(e[1].toFixed(Zy))}j`:Ji(e)?s=`'${e}'`:n==="bool"?s=DT(e):s=parseFloat(e.toFixed(Zy)).toString(),ct(s,t)}function DT(e){return e===0?"false":"true"}function tp(e,t,n,s,i,o=!0){const a=n==="complex64"?2:1,c=t[0],h=t.length;if(h===0){if(n==="complex64"){const T=dh(e);return[uh(T[0],0,n)]}return n==="bool"?[DT(e[0])]:[e[0].toString()]}if(h===1){if(c>ET){const v=hh*a;let C=Array.from(e.slice(0,v)),O=Array.from(e.slice((c-hh)*a,c*a));return n==="complex64"&&(C=dh(C),O=dh(O)),["["+C.map((D,k)=>uh(D,i[k],n)).join(", ")+", ..., "+O.map((D,k)=>uh(D,i[c-hh+k],n)).join(", ")+"]"]}const T=n==="complex64"?dh(e):Array.from(e);return["["+T.map((v,C)=>uh(v,i[C],n)).join(", ")+"]"]}const p=t.slice(1),m=s.slice(1),y=s[0]*a,b=[];if(c>ET){for(let T=0;T<hh;T++){const v=T*y,C=v+y;b.push(...tp(e.slice(v,C),p,n,m,i,!1))}b.push("...");for(let T=c-hh;T<c;T++){const v=T*y,C=v+y;b.push(...tp(e.slice(v,C),p,n,m,i,T===c-1))}}else for(let T=0;T<c;T++){const v=T*y,C=v+y;b.push(...tp(e.slice(v,C),p,n,m,i,T===c-1))}const w=h===2?",":"";b[0]="["+b[0]+w;for(let T=1;T<b.length-1;T++)b[T]=" "+b[T]+w;let L=`,
`;for(let T=2;T<h;T++)L+=`
`;return b[b.length-1]=" "+b[b.length-1]+"]"+(o?"":L),b}function dh(e){const t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}class an{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=M(e),n!=null){const s=n.length;A(s===this.size,()=>`Length of values '${s}' does not match the size inferred by the shape '${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||Is(t,this.size),this.strides=Ke(e)}set(e,...t){t.length===0&&(t=[0]),A(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){e.length===0&&(e=[0]);let t=0;for(const s of e){if(s<0||s>=this.shape[t]){const i=`Requested out of range element at ${e}. Buffer shape=${this.shape}`;throw new Error(i)}t++}let n=e[e.length-1];for(let s=0;s<e.length-1;++s)n+=this.strides[s]*e[s];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 vi().makeTensor(this.values,this.shape,this.dtype)}}let vi=null,za=null,kT=null;function zk(e){vi=e}function Vk(e){za=e}function Gk(e){kT=e}class te{constructor(e,t,n,s){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=M(e),this.strides=Ke(e),this.dataId=n,this.id=s,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const e=await this.data();return za.buffer(this.shape,this.dtype,e)}bufferSync(){return za.buffer(this.shape,this.dtype,this.dataSync())}async array(){const e=await this.data();return xs(this.shape,e)}arraySync(){return xs(this.shape,this.dataSync())}async data(){this.throwIfDisposed();const e=vi().read(this.dataId);if(this.dtype==="string"){const t=await e;try{return t.map(n=>lh(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=vi().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>lh(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 vi().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){if(this.isDisposed)return;vi().disposeTensor(this),this.isDisposedInternal=!0}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return za.print(this,e)}clone(){return this.throwIfDisposed(),za.clone(this)}toString(e=!1){const t=this.dataSync();return Mk(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),za.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),vi().makeVariable(this,e,t,n)}}Object.defineProperty(te,Symbol.hasInstance,{value:e=>!!e&&e.data!=null&&e.dataSync!=null&&e.throwIfDisposed!=null});class ph extends te{constructor(e,t,n,s){super(e.shape,e.dtype,e.dataId,s);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(!ie(e.shape,this.shape))throw new Error(`shape of the new value (${e.shape}) and previous value (${this.shape}) must match`);vi().disposeTensor(this),this.dataId=e.dataId,vi().incRef(this,null)}dispose(){vi().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty(ph,Symbol.hasInstance,{value:e=>e instanceof te&&e.assign!=null&&e.assign instanceof Function});(function(e){e.R0="R0",e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4",e.R5="R5",e.R6="R6"})(r.Rank||(r.Rank={}));var Qy;(function(e){e.float32="float32",e.int32="int32",e.bool="int32",e.complex64="complex64"})(Qy||(Qy={}));var eb;(function(e){e.float32="float32",e.int32="int32",e.bool="bool",e.complex64="complex64"})(eb||(eb={}));var tb;(function(e){e.float32="float32",e.int32="float32",e.bool="float32",e.complex64="complex64"})(tb||(tb={}));var nb;(function(e){e.float32="complex64",e.int32="complex64",e.bool="complex64",e.complex64="complex64"})(nb||(nb={}));const Yk={float32:tb,int32:Qy,bool:eb,complex64:nb};function Bn(e,t){if(e==="string"||t==="string"){if(e==="string"&&t==="string")return"string";throw new Error(`Can not upcast ${e} with ${t}`)}return Yk[e][t]}function np(e){return Bn(e,"int32")}function Gt(e,t){if(e.dtype===t.dtype)return[e,t];const n=Bn(e.dtype,t.dtype);return[e.cast(n),t.cast(n)]}function FT(e,t){A(e.dtype===t.dtype,()=>`The dtypes of the first(${e.dtype}) and second(${t.dtype}) input must match`)}function sp(e,t){return t.some(n=>n.id===e.id)}function Zi(e){const t=[],n=new Set;return _T(e,t,n),t}function _T(e,t,n){if(e==null)return;if(e instanceof te){t.push(e);return}if(!Hk(e))return;const s=e;for(const i in s){const o=s[i];n.has(o)||(n.add(o),_T(o,t,n))}}function Hk(e){return Array.isArray(e)||typeof e=="object"}var qk=Object.freeze({__proto__:null,makeTypesMatch:Gt,assertTypesMatch:FT,isTensorInList:sp,getTensorsInContainer:Zi});class WT{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}}dispose(){for(const e in this.registeredVariables)this.registeredVariables[e].dispose()}}class mh{constructor(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new WT}async ready(){if(this.pendingBackendInit!=null)return this.pendingBackendInit.then(()=>{});if(this.backendInstance!=null)return;const e=this.getSortedBackends();for(let t=0;t<e.length;t++){const n=e[t],s=await this.initializeBackend(n).success;if(s){await this.setBackend(n);return}}throw new Error("Could not initialize any backends, all backend initializations failed.")}get backend(){if(this.pendingBackendInit!=null)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(this.backendInstance==null){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.registryFactor