mirror of https://github.com/vladmandic/human
4007 lines
1.1 MiB
4007 lines
1.1 MiB
var Es=Object.defineProperty,c2=Object.prototype.hasOwnProperty;var Le=(n,t)=>()=>(t||(t={exports:{}},n(t.exports,t)),t.exports),rf=n=>Es(n,"__esModule",{value:!0}),Sl=(n,t)=>{rf(n);for(var e in t)Es(n,e,{get:t[e],enumerable:!0})},h2=(n,t)=>{if(rf(n),typeof t=="object"||typeof t=="function")for(let e in t)!c2.call(n,e)&&e!=="default"&&Es(n,e,{get:()=>t[e],enumerable:!0});return n},Na=n=>n&&n.__esModule?n:h2(Es({},"default",{value:n,enumerable:!0}),n);var ff=Le(d2=>{Sl(d2,{FetchError:()=>Ut,Headers:()=>vn,Request:()=>Gi,Response:()=>Dn,default:()=>A2});const hn=Na(require("stream")),Ll=Na(require("http")),Ds=Na(require("url")),af=Na(require("https")),ci=Na(require("zlib")),p2=hn.default.Readable,$n=Symbol("buffer"),Il=Symbol("type");class xa{constructor(){this[Il]="";const n=arguments[0],t=arguments[1],e=[];let i=0;if(n){const a=n,s=Number(a.length);for(let o=0;o<s;o++){const l=a[o];let u;l instanceof Buffer?u=l:ArrayBuffer.isView(l)?u=Buffer.from(l.buffer,l.byteOffset,l.byteLength):l instanceof ArrayBuffer?u=Buffer.from(l):l instanceof xa?u=l[$n]:u=Buffer.from(typeof l=="string"?l:String(l)),i+=u.length,e.push(u)}}this[$n]=Buffer.concat(e);let r=t&&t.type!==void 0&&String(t.type).toLowerCase();r&&!/[^\u0020-\u007E]/.test(r)&&(this[Il]=r)}get size(){return this[$n].length}get type(){return this[Il]}text(){return Promise.resolve(this[$n].toString())}arrayBuffer(){const n=this[$n],t=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength);return Promise.resolve(t)}stream(){const n=new p2;return n._read=function(){},n.push(this[$n]),n.push(null),n}toString(){return"[object Blob]"}slice(){const n=this.size,t=arguments[0],e=arguments[1];let i,r;t===void 0?i=0:t<0?i=Math.max(n+t,0):i=Math.min(t,n),e===void 0?r=n:e<0?r=Math.max(n+e,0):r=Math.min(e,n);const a=Math.max(r-i,0),s=this[$n],o=s.slice(i,i+a),l=new xa([],{type:arguments[2]});return l[$n]=o,l}}Object.defineProperties(xa.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}});Object.defineProperty(xa.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0});function Ut(n,t,e){Error.call(this,n),this.message=n,this.type=t,e&&(this.code=this.errno=e.code),Error.captureStackTrace(this,this.constructor)}Ut.prototype=Object.create(Error.prototype);Ut.prototype.constructor=Ut;Ut.prototype.name="FetchError";let Al;try{Al=require("encoding").convert}catch(n){}const Xn=Symbol("Body internals"),sf=hn.default.PassThrough;function Ct(n){var t=this,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=e.size;let r=i===void 0?0:i;var a=e.timeout;let s=a===void 0?0:a;n==null?n=null:of(n)?n=Buffer.from(n.toString()):Ca(n)||(Buffer.isBuffer(n)||(Object.prototype.toString.call(n)==="[object ArrayBuffer]"?n=Buffer.from(n):ArrayBuffer.isView(n)?n=Buffer.from(n.buffer,n.byteOffset,n.byteLength):n instanceof hn.default||(n=Buffer.from(String(n))))),this[Xn]={body:n,disturbed:!1,error:null},this.size=r,this.timeout=s,n instanceof hn.default&&n.on("error",function(o){const l=o.name==="AbortError"?o:new Ut(`Invalid response body while trying to fetch ${t.url}: ${o.message}`,"system",o);t[Xn].error=l})}Ct.prototype={get body(){return this[Xn].body},get bodyUsed(){return this[Xn].disturbed},arrayBuffer(){return Er.call(this).then(function(n){return n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)})},blob(){let n=this.headers&&this.headers.get("content-type")||"";return Er.call(this).then(function(t){return Object.assign(new xa([],{type:n.toLowerCase()}),{[$n]:t})})},json(){var n=this;return Er.call(this).then(function(t){try{return JSON.parse(t.toString())}catch(e){return Ct.Promise.reject(new Ut(`invalid json response body at ${n.url} reason: ${e.message}`,"invalid-json"))}})},text(){return Er.call(this).then(function(n){return n.toString()})},buffer(){return Er.call(this)},textConverted(){var n=this;return Er.call(this).then(function(t){return f2(t,n.headers)})}};Object.defineProperties(Ct.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}});Ct.mixIn=function(n){for(const t of Object.getOwnPropertyNames(Ct.prototype))if(!(t in n)){const e=Object.getOwnPropertyDescriptor(Ct.prototype,t);Object.defineProperty(n,t,e)}};function Er(){var n=this;if(this[Xn].disturbed)return Ct.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[Xn].disturbed=!0,this[Xn].error)return Ct.Promise.reject(this[Xn].error);let t=this.body;if(t===null)return Ct.Promise.resolve(Buffer.alloc(0));if(Ca(t)&&(t=t.stream()),Buffer.isBuffer(t))return Ct.Promise.resolve(t);if(!(t instanceof hn.default))return Ct.Promise.resolve(Buffer.alloc(0));let e=[],i=0,r=!1;return new Ct.Promise(function(a,s){let o;n.timeout&&(o=setTimeout(function(){r=!0,s(new Ut(`Response timeout while trying to fetch ${n.url} (over ${n.timeout}ms)`,"body-timeout"))},n.timeout)),t.on("error",function(l){l.name==="AbortError"?(r=!0,s(l)):s(new Ut(`Invalid response body while trying to fetch ${n.url}: ${l.message}`,"system",l))}),t.on("data",function(l){if(r||l===null)return;if(n.size&&i+l.length>n.size){r=!0,s(new Ut(`content size at ${n.url} over limit: ${n.size}`,"max-size"));return}i+=l.length,e.push(l)}),t.on("end",function(){if(r)return;clearTimeout(o);try{a(Buffer.concat(e,i))}catch(l){s(new Ut(`Could not create Buffer from response body for ${n.url}: ${l.message}`,"system",l))}})})}function f2(n,t){if(typeof Al!="function")throw new Error("The package `encoding` must be installed to use the textConverted() function");const e=t.get("content-type");let i="utf-8",r,a;return e&&(r=/charset=([^;]*)/i.exec(e)),a=n.slice(0,1024).toString(),!r&&a&&(r=/<meta.+?charset=(['"])(.+?)\1/i.exec(a)),!r&&a&&(r=/<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(a),r||(r=/<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(a),r&&r.pop()),r&&(r=/charset=(.*)/i.exec(r.pop()))),!r&&a&&(r=/<\?xml.+?encoding=(['"])(.+?)\1/i.exec(a)),r&&(i=r.pop(),(i==="gb2312"||i==="gbk")&&(i="gb18030")),Al(n,"UTF-8",i).toString()}function of(n){return typeof n!="object"||typeof n.append!="function"||typeof n.delete!="function"||typeof n.get!="function"||typeof n.getAll!="function"||typeof n.has!="function"||typeof n.set!="function"?!1:n.constructor.name==="URLSearchParams"||Object.prototype.toString.call(n)==="[object URLSearchParams]"||typeof n.sort=="function"}function Ca(n){return typeof n=="object"&&typeof n.arrayBuffer=="function"&&typeof n.type=="string"&&typeof n.stream=="function"&&typeof n.constructor=="function"&&typeof n.constructor.name=="string"&&/^(Blob|File)$/.test(n.constructor.name)&&/^(Blob|File)$/.test(n[Symbol.toStringTag])}function lf(n){let t,e,i=n.body;if(n.bodyUsed)throw new Error("cannot clone body after it is used");return i instanceof hn.default&&typeof i.getBoundary!="function"&&(t=new sf,e=new sf,i.pipe(t),i.pipe(e),n[Xn].body=t,i=e),i}function uf(n){return n===null?null:typeof n=="string"?"text/plain;charset=UTF-8":of(n)?"application/x-www-form-urlencoded;charset=UTF-8":Ca(n)?n.type||null:Buffer.isBuffer(n)||(Object.prototype.toString.call(n)==="[object ArrayBuffer]"||ArrayBuffer.isView(n))?null:typeof n.getBoundary=="function"?`multipart/form-data;boundary=${n.getBoundary()}`:n instanceof hn.default?null:"text/plain;charset=UTF-8"}function cf(n){const t=n.body;return t===null?0:Ca(t)?t.size:Buffer.isBuffer(t)?t.length:t&&typeof t.getLengthSync=="function"&&(t._lengthRetrievers&&t._lengthRetrievers.length==0||t.hasKnownLength&&t.hasKnownLength())?t.getLengthSync():null}function m2(n,t){const e=t.body;e===null?n.end():Ca(e)?e.stream().pipe(n):Buffer.isBuffer(e)?(n.write(e),n.end()):e.pipe(n)}Ct.Promise=global.Promise;const hf=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,Tl=/[^\t\x20-\x7e\x80-\xff]/;function Ra(n){if(n=`${n}`,hf.test(n)||n==="")throw new TypeError(`${n} is not a legal HTTP header name`)}function df(n){if(n=`${n}`,Tl.test(n))throw new TypeError(`${n} is not a legal HTTP header value`)}function Dr(n,t){t=t.toLowerCase();for(const e in n)if(e.toLowerCase()===t)return e;return}const ct=Symbol("map");class vn{constructor(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:void 0;if(this[ct]=Object.create(null),n instanceof vn){const t=n.raw(),e=Object.keys(t);for(const i of e)for(const r of t[i])this.append(i,r);return}if(!(n==null))if(typeof n=="object"){const t=n[Symbol.iterator];if(t!=null){if(typeof t!="function")throw new TypeError("Header pairs must be iterable");const e=[];for(const i of n){if(typeof i!="object"||typeof i[Symbol.iterator]!="function")throw new TypeError("Each header pair must be iterable");e.push(Array.from(i))}for(const i of e){if(i.length!==2)throw new TypeError("Each header pair must be a name/value tuple");this.append(i[0],i[1])}}else for(const e of Object.keys(n)){const i=n[e];this.append(e,i)}}else throw new TypeError("Provided initializer must be an object")}get(n){n=`${n}`,Ra(n);const t=Dr(this[ct],n);return t===void 0?null:this[ct][t].join(", ")}forEach(n){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0,e=Nl(this),i=0;for(;i<e.length;){var r=e[i];const a=r[0],s=r[1];n.call(t,s,a,this),e=Nl(this),i++}}set(n,t){n=`${n}`,t=`${t}`,Ra(n),df(t);const e=Dr(this[ct],n);this[ct][e!==void 0?e:n]=[t]}append(n,t){n=`${n}`,t=`${t}`,Ra(n),df(t);const e=Dr(this[ct],n);e!==void 0?this[ct][e].push(t):this[ct][n]=[t]}has(n){return n=`${n}`,Ra(n),Dr(this[ct],n)!==void 0}delete(n){n=`${n}`,Ra(n);const t=Dr(this[ct],n);t!==void 0&&delete this[ct][t]}raw(){return this[ct]}keys(){return xl(this,"key")}values(){return xl(this,"value")}[Symbol.iterator](){return xl(this,"key+value")}}vn.prototype.entries=vn.prototype[Symbol.iterator];Object.defineProperty(vn.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0});Object.defineProperties(vn.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 Nl(n){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"key+value";const e=Object.keys(n[ct]).sort();return e.map(t==="key"?function(i){return i.toLowerCase()}:t==="value"?function(i){return n[ct][i].join(", ")}:function(i){return[i.toLowerCase(),n[ct][i].join(", ")]})}const Cl=Symbol("internal");function xl(n,t){const e=Object.create(Rl);return e[Cl]={target:n,kind:t,index:0},e}const Rl=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==Rl)throw new TypeError("Value of `this` is not a HeadersIterator");var n=this[Cl];const t=n.target,e=n.kind,i=n.index,r=Nl(t,e),a=r.length;return i>=a?{value:void 0,done:!0}:(this[Cl].index=i+1,{value:r[i],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));Object.defineProperty(Rl,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});function g2(n){const t=Object.assign({__proto__:null},n[ct]),e=Dr(n[ct],"Host");return e!==void 0&&(t[e]=t[e][0]),t}function v2(n){const t=new vn;for(const e of Object.keys(n)){if(hf.test(e))continue;if(Array.isArray(n[e]))for(const i of n[e]){if(Tl.test(i))continue;t[ct][e]===void 0?t[ct][e]=[i]:t[ct][e].push(i)}else Tl.test(n[e])||(t[ct][e]=[n[e]])}return t}const hi=Symbol("Response internals"),y2=Ll.default.STATUS_CODES;class Dn{constructor(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Ct.call(this,n,t);const e=t.status||200,i=new vn(t.headers);if(n!=null&&!i.has("Content-Type")){const r=uf(n);r&&i.append("Content-Type",r)}this[hi]={url:t.url,status:e,statusText:t.statusText||y2[e],headers:i,counter:t.counter}}get url(){return this[hi].url||""}get status(){return this[hi].status}get ok(){return this[hi].status>=200&&this[hi].status<300}get redirected(){return this[hi].counter>0}get statusText(){return this[hi].statusText}get headers(){return this[hi].headers}clone(){return new Dn(lf(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}Ct.mixIn(Dn.prototype);Object.defineProperties(Dn.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}});Object.defineProperty(Dn.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const Jn=Symbol("Request internals"),Ol=Ds.default.parse,b2=Ds.default.format,w2="destroy"in hn.default.Readable.prototype;function ks(n){return typeof n=="object"&&typeof n[Jn]=="object"}function S2(n){const t=n&&typeof n=="object"&&Object.getPrototypeOf(n);return!!(t&&t.constructor.name==="AbortSignal")}class Gi{constructor(n){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},e;ks(n)?e=Ol(n.url):(n&&n.href?e=Ol(n.href):e=Ol(`${n}`),n={});let i=t.method||n.method||"GET";if(i=i.toUpperCase(),(t.body!=null||ks(n)&&n.body!==null)&&(i==="GET"||i==="HEAD"))throw new TypeError("Request with GET/HEAD method cannot have body");let r=t.body!=null?t.body:ks(n)&&n.body!==null?lf(n):null;Ct.call(this,r,{timeout:t.timeout||n.timeout||0,size:t.size||n.size||0});const a=new vn(t.headers||n.headers||{});if(r!=null&&!a.has("Content-Type")){const o=uf(r);o&&a.append("Content-Type",o)}let s=ks(n)?n.signal:null;if("signal"in t&&(s=t.signal),s!=null&&!S2(s))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[Jn]={method:i,redirect:t.redirect||n.redirect||"follow",headers:a,parsedURL:e,signal:s},this.follow=t.follow!==void 0?t.follow:n.follow!==void 0?n.follow:20,this.compress=t.compress!==void 0?t.compress:n.compress!==void 0?n.compress:!0,this.counter=t.counter||n.counter||0,this.agent=t.agent||n.agent}get method(){return this[Jn].method}get url(){return b2(this[Jn].parsedURL)}get headers(){return this[Jn].headers}get redirect(){return this[Jn].redirect}get signal(){return this[Jn].signal}clone(){return new Gi(this)}}Ct.mixIn(Gi.prototype);Object.defineProperty(Gi.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0});Object.defineProperties(Gi.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}});function L2(n){const t=n[Jn].parsedURL,e=new vn(n[Jn].headers);if(e.has("Accept")||e.set("Accept","*/*"),!t.protocol||!t.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(t.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(n.signal&&n.body instanceof hn.default.Readable&&!w2)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let i=null;if(n.body==null&&/^(POST|PUT)$/i.test(n.method)&&(i="0"),n.body!=null){const a=cf(n);typeof a=="number"&&(i=String(a))}i&&e.set("Content-Length",i),e.has("User-Agent")||e.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),n.compress&&!e.has("Accept-Encoding")&&e.set("Accept-Encoding","gzip,deflate");let r=n.agent;return typeof r=="function"&&(r=r(t)),!e.has("Connection")&&!r&&e.set("Connection","close"),Object.assign({},t,{method:n.method,headers:g2(e),agent:r})}function Oa(n){Error.call(this,n),this.type="aborted",this.message=n,Error.captureStackTrace(this,this.constructor)}Oa.prototype=Object.create(Error.prototype);Oa.prototype.constructor=Oa;Oa.prototype.name="AbortError";const pf=hn.default.PassThrough,I2=Ds.default.resolve;function di(n,t){if(!di.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return Ct.Promise=di.Promise,new di.Promise(function(e,i){const r=new Gi(n,t),a=L2(r),s=(a.protocol==="https:"?af.default:Ll.default).request,o=r.signal;let l=null;const u=function(){let m=new Oa("The user aborted a request.");if(i(m),r.body&&r.body instanceof hn.default.Readable&&r.body.destroy(m),!l||!l.body)return;l.body.emit("error",m)};if(o&&o.aborted){u();return}const c=function(){u(),p()},h=s(a);let d;o&&o.addEventListener("abort",c);function p(){h.abort(),o&&o.removeEventListener("abort",c),clearTimeout(d)}r.timeout&&h.once("socket",function(f){d=setTimeout(function(){i(new Ut(`network timeout at: ${r.url}`,"request-timeout")),p()},r.timeout)}),h.on("error",function(f){i(new Ut(`request to ${r.url} failed, reason: ${f.message}`,"system",f)),p()}),h.on("response",function(f){clearTimeout(d);const m=v2(f.headers);if(di.isRedirect(f.statusCode)){const S=m.get("Location"),L=S===null?null:I2(r.url,S);switch(r.redirect){case"error":i(new Ut(`uri requested responds with a redirect, redirect mode is set to error: ${r.url}`,"no-redirect")),p();return;case"manual":if(L!==null)try{m.set("Location",L)}catch(C){i(C)}break;case"follow":if(L===null)break;if(r.counter>=r.follow){i(new Ut(`maximum redirect reached at: ${r.url}`,"max-redirect")),p();return}const N={headers:new vn(r.headers),follow:r.follow,counter:r.counter+1,agent:r.agent,compress:r.compress,method:r.method,body:r.body,signal:r.signal,timeout:r.timeout,size:r.size};if(f.statusCode!==303&&r.body&&cf(r)===null){i(new Ut("Cannot follow redirect with body being a readable stream","unsupported-redirect")),p();return}(f.statusCode===303||(f.statusCode===301||f.statusCode===302)&&r.method==="POST")&&(N.method="GET",N.body=void 0,N.headers.delete("content-length")),e(di(new Gi(L,N))),p();return}}f.once("end",function(){o&&o.removeEventListener("abort",c)});let g=f.pipe(new pf);const v={url:r.url,status:f.statusCode,statusText:f.statusMessage,headers:m,size:r.size,timeout:r.timeout,counter:r.counter},b=m.get("Content-Encoding");if(!r.compress||r.method==="HEAD"||b===null||f.statusCode===204||f.statusCode===304){l=new Dn(g,v),e(l);return}const w={flush:ci.default.Z_SYNC_FLUSH,finishFlush:ci.default.Z_SYNC_FLUSH};if(b=="gzip"||b=="x-gzip"){g=g.pipe(ci.default.createGunzip(w)),l=new Dn(g,v),e(l);return}if(b=="deflate"||b=="x-deflate"){const S=f.pipe(new pf);S.once("data",function(L){(L[0]&15)===8?g=g.pipe(ci.default.createInflate()):g=g.pipe(ci.default.createInflateRaw()),l=new Dn(g,v),e(l)});return}if(b=="br"&&typeof ci.default.createBrotliDecompress=="function"){g=g.pipe(ci.default.createBrotliDecompress()),l=new Dn(g,v),e(l);return}l=new Dn(g,v),e(l)}),m2(h,r)})}di.isRedirect=function(n){return n===301||n===302||n===303||n===307||n===308};di.Promise=global.Promise;var A2=di});var lr=Le(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});var El=function(n,t){return El=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var r in i)i.hasOwnProperty(r)&&(e[r]=i[r])},El(n,t)};function Zn(n,t){El(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function de(n,t,e,i){return new(e||(e=Promise))(function(r,a){function s(u){try{l(i.next(u))}catch(c){a(c)}}function o(u){try{l(i.throw(u))}catch(c){a(c)}}function l(u){u.done?r(u.value):new e(function(c){c(u.value)}).then(s,o)}l((i=i.apply(n,t||[])).next())})}function pe(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,r,a,s;return s={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(u){return function(c){return l([u,c])}}function l(u){if(i)throw new TypeError("Generator is already executing.");for(;e;)try{if(i=1,r&&(a=u[0]&2?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;(r=0,a)&&(u=[u[0]&2,a.value]);switch(u[0]){case 0:case 1:a=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,r=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){e.label=u[1];break}if(u[0]===6&&e.label<a[1]){e.label=a[1],a=u;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(u);break}a[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(n,e)}catch(c){u=[6,c],r=0}finally{i=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}var T2=1e-7,N2=1e-4,x2=function(){function n(t,e){this.backend=t,this.dataMover=e,this.data=new WeakMap,this.dataIdsCount=0}return n.prototype.get=function(t){return this.data.has(t)||this.dataMover.moveData(this.backend,t),this.data.get(t)},n.prototype.set=function(t,e){this.dataIdsCount++,this.data.set(t,e)},n.prototype.has=function(t){return this.data.has(t)},n.prototype.delete=function(t){return this.dataIdsCount--,this.data.delete(t)},n.prototype.numDataIds=function(){return this.dataIdsCount},n}(),mf=function(){function n(){}return n.prototype.time=function(t){return $("time")},n.prototype.read=function(t){return $("read")},n.prototype.readSync=function(t){return $("readSync")},n.prototype.numDataIds=function(){return $("numDataIds")},n.prototype.disposeData=function(t){return $("disposeData")},n.prototype.write=function(t,e,i){return $("write")},n.prototype.move=function(t,e,i,r){return $("move")},n.prototype.memory=function(){return $("memory")},n.prototype.floatPrecision=function(){return $("floatPrecision")},n.prototype.epsilon=function(){return this.floatPrecision()===32?T2:N2},n.prototype.batchMatMul=function(t,e,i,r){return $("batchMatMul")},n.prototype.fusedBatchMatMul=function(t){var e=t.a,i=t.b,r=t.transposeA,a=t.transposeB,s=t.bias,o=t.activation,l=t.preluActivationWeights;return $("fusedBatchMatMul")},n.prototype.slice=function(t,e,i){return $("slice")},n.prototype.stridedSlice=function(t,e,i,r){return $("stridedSlice")},n.prototype.unstack=function(t,e){return $("unstack")},n.prototype.reverse=function(t,e){return $("reverse")},n.prototype.concat=function(t,e){return $("concat")},n.prototype.neg=function(t){return $("neg")},n.prototype.add=function(t,e){return $("add")},n.prototype.addN=function(t){return $("addN")},n.prototype.subtract=function(t,e){return $("subtract")},n.prototype.multiply=function(t,e){return $("multiply")},n.prototype.realDivide=function(t,e){return $("realDivide")},n.prototype.floorDiv=function(t,e){return $("floorDiv")},n.prototype.sum=function(t,e){return $("sum")},n.prototype.prod=function(t,e){return $("prod")},n.prototype.unsortedSegmentSum=function(t,e,i){return $("unsortedSegmentSum")},n.prototype.argMin=function(t,e){return $("argMin")},n.prototype.argMax=function(t,e){return $("argMax")},n.prototype.equal=function(t,e){return $("equal")},n.prototype.notEqual=function(t,e){return $("notEqual")},n.prototype.less=function(t,e){return $("less")},n.prototype.lessEqual=function(t,e){return $("lessEqual")},n.prototype.greater=function(t,e){return $("greater")},n.prototype.greaterEqual=function(t,e){return $("greaterEqual")},n.prototype.logicalNot=function(t){return $("logicalNot")},n.prototype.logicalAnd=function(t,e){return $("logicalAnd")},n.prototype.logicalOr=function(t,e){return $("logicalOr")},n.prototype.where=function(t){return $("where")},n.prototype.select=function(t,e,i){return $("select")},n.prototype.topk=function(t,e,i){return $("topk")},n.prototype.min=function(t,e){return $("min")},n.prototype.minimum=function(t,e){return $("minimum")},n.prototype.mod=function(t,e){return $("mod")},n.prototype.max=function(t,e){return $("max")},n.prototype.maximum=function(t,e){return $("maximum")},n.prototype.all=function(t,e){return $("all")},n.prototype.any=function(t,e){return $("any")},n.prototype.squaredDifference=function(t,e){return $("squaredDifference")},n.prototype.ceil=function(t){return $("ceil")},n.prototype.floor=function(t){return $("floor")},n.prototype.round=function(t){return $("round")},n.prototype.sign=function(t){return $("sign")},n.prototype.isNaN=function(t){return $("isNaN")},n.prototype.isInf=function(t){return $("isInf")},n.prototype.isFinite=function(t){return $("isFinite")},n.prototype.pow=function(t,e){return $("pow")},n.prototype.exp=function(t){return $("exp")},n.prototype.expm1=function(t){return $("expm1")},n.prototype.softmax=function(t,e){return $("softmax")},n.prototype.log=function(t){return $("log")},n.prototype.log1p=function(t){return $("log1p")},n.prototype.sqrt=function(t){return $("sqrt")},n.prototype.rsqrt=function(t){return $("rsqrt")},n.prototype.square=function(t){return $("square")},n.prototype.reciprocal=function(t){return $("reciprocal")},n.prototype.relu=function(t){return $("relu")},n.prototype.relu6=function(t){return $("relu6")},n.prototype.prelu=function(t,e){return $("prelu")},n.prototype.elu=function(t){return $("elu")},n.prototype.eluDer=function(t,e){return $("eluDer")},n.prototype.selu=function(t){return $("selu")},n.prototype.int=function(t){return $("int")},n.prototype.clip=function(t,e,i){return $("clip")},n.prototype.abs=function(t){return $("abs")},n.prototype.complexAbs=function(t){return $("complexAbs")},n.prototype.sigmoid=function(t){return $("sigmoid")},n.prototype.softplus=function(t){return $("softplus")},n.prototype.sin=function(t){return $("sin")},n.prototype.cos=function(t){return $("cos")},n.prototype.tan=function(t){return $("tan")},n.prototype.asin=function(t){return $("asin")},n.prototype.acos=function(t){return $("acos")},n.prototype.atan=function(t){return $("atan")},n.prototype.atan2=function(t,e){return $("atan2")},n.prototype.sinh=function(t){return $("sinh")},n.prototype.cosh=function(t){return $("cosh")},n.prototype.tanh=function(t){return $("tanh")},n.prototype.asinh=function(t){return $("asinh")},n.prototype.acosh=function(t){return $("acosh")},n.prototype.atanh=function(t){return $("atanh")},n.prototype.erf=function(t){return $("erf")},n.prototype.step=function(t,e){return $("step")},n.prototype.fusedConv2d=function(t){var e=t.input,i=t.filter,r=t.convInfo,a=t.bias,s=t.activation,o=t.preluActivationWeights;return $("fusedConv2d")},n.prototype.conv2d=function(t,e,i){return $("conv2d")},n.prototype.conv2dDerInput=function(t,e,i){return $("conv2dDerInput")},n.prototype.conv2dDerFilter=function(t,e,i){return $("conv2dDerFilter")},n.prototype.fusedDepthwiseConv2D=function(t){var e=t.input,i=t.filter,r=t.convInfo,a=t.bias,s=t.activation,o=t.preluActivationWeights;return $("fusedDepthwiseConv2D")},n.prototype.depthwiseConv2D=function(t,e,i){return $("depthwiseConv2D")},n.prototype.depthwiseConv2DDerInput=function(t,e,i){return $("depthwiseConv2DDerInput")},n.prototype.depthwiseConv2DDerFilter=function(t,e,i){return $("depthwiseConv2DDerFilter")},n.prototype.conv3d=function(t,e,i){return $("conv3d")},n.prototype.conv3dDerInput=function(t,e,i){return $("conv3dDerInput")},n.prototype.conv3dDerFilter=function(t,e,i){return $("conv3dDerFilter")},n.prototype.maxPool=function(t,e){return $("maxPool")},n.prototype.maxPoolBackprop=function(t,e,i,r){return $("maxPoolBackprop")},n.prototype.avgPool=function(t,e){return $("avgPool")},n.prototype.avgPoolBackprop=function(t,e,i){return $("avgPoolBackprop")},n.prototype.avgPool3d=function(t,e){return $("avgPool3d")},n.prototype.avgPool3dBackprop=function(t,e,i){return $("avgPool3dBackprop")},n.prototype.maxPool3d=function(t,e){return $("maxPool3d")},n.prototype.maxPool3dBackprop=function(t,e,i,r){return $("maxPool3dBackprop")},n.prototype.reshape=function(t,e){return $("reshape")},n.prototype.cast=function(t,e){return $("cast")},n.prototype.tile=function(t,e){return $("tile")},n.prototype.pad=function(t,e,i){return $("pad")},n.prototype.transpose=function(t,e){return $("transpose")},n.prototype.gather=function(t,e,i){return $("gather")},n.prototype.gatherND=function(t,e){return $("gatherND")},n.prototype.scatterND=function(t,e,i){return $("scatterND")},n.prototype.batchToSpaceND=function(t,e,i){return $("batchToSpaceND")},n.prototype.spaceToBatchND=function(t,e,i){return $("spaceToBatchND")},n.prototype.resizeBilinear=function(t,e,i,r){return $("resizeBilinear")},n.prototype.resizeBilinearBackprop=function(t,e,i){return $("resizeBilinearBackprop")},n.prototype.resizeNearestNeighbor=function(t,e,i,r){return $("resizeNearestNeighbor")},n.prototype.resizeNearestNeighborBackprop=function(t,e,i){return $("resizeNearestNeighborBackprop")},n.prototype.batchNorm=function(t,e,i,r,a,s){return $("batchNorm")},n.prototype.localResponseNormalization4D=function(t,e,i,r,a){return $("localResponseNormalization4D")},n.prototype.LRNGrad=function(t,e,i,r,a,s,o){return $("LRNGrad")},n.prototype.multinomial=function(t,e,i,r){return $("multinomial")},n.prototype.oneHot=function(t,e,i,r){return $("oneHot")},n.prototype.cumsum=function(t,e,i,r){return $("cumsum")},n.prototype.nonMaxSuppression=function(t,e,i,r,a){return $("nonMaxSuppression")},n.prototype.fft=function(t){return $("fft")},n.prototype.ifft=function(t){return $("ifft")},n.prototype.complex=function(t,e){return $("complex")},n.prototype.real=function(t){return $("real")},n.prototype.imag=function(t){return $("imag")},n.prototype.cropAndResize=function(t,e,i,r,a,s){return $("cropAndResize")},n.prototype.depthToSpace=function(t,e,i){return $("depthToSpace")},n.prototype.split=function(t,e,i){return $("split")},n.prototype.sparseToDense=function(t,e,i,r){return $("sparseToDense")},n.prototype.diag=function(t){return $("diag")},n.prototype.fill=function(t,e,i){return $("fill")},n.prototype.onesLike=function(t){return $("onesLike")},n.prototype.zerosLike=function(t){return $("zerosLike")},n.prototype.linspace=function(t,e,i){return $("linspace")},n.prototype.dispose=function(){return $("dispose")},n}();function $(n){throw new Error("'"+n+"' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen")}var gf="tfjsflags",vf=function(){function n(t){this.global=t,this.flags={},this.flagRegistry={},this.urlFlags={},this.populateURLFlags()}return n.prototype.setPlatform=function(t,e){this.platform!=null&&console.warn("Platform "+this.platformName+" has already been set. "+("Overwriting the platform with "+e+".")),this.platformName=t,this.platform=e},n.prototype.registerFlag=function(t,e,i){if(this.flagRegistry[t]={evaluationFn:e,setHook:i},this.urlFlags[t]!=null){var r=this.urlFlags[t];console.warn("Setting feature override from URL "+t+": "+r+"."),this.set(t,r)}},n.prototype.getAsync=function(t){return de(this,void 0,void 0,function(){var e,i;return pe(this,function(r){switch(r.label){case 0:return t in this.flags?[2,this.flags[t]]:(e=this.flags,i=t,[4,this.evaluateFlag(t)]);case 1:return e[i]=r.sent(),[2,this.flags[t]]}})})},n.prototype.get=function(t){if(t in this.flags)return this.flags[t];var e=this.evaluateFlag(t);if(e instanceof Promise)throw new Error("Flag "+t+" cannot be synchronously evaluated. Please use getAsync() instead.");return this.flags[t]=e,this.flags[t]},n.prototype.getNumber=function(t){return this.get(t)},n.prototype.getBool=function(t){return this.get(t)},n.prototype.getFlags=function(){return this.flags},Object.defineProperty(n.prototype,"features",{get:function(){return this.flags},enumerable:!0,configurable:!0}),n.prototype.set=function(t,e){if(this.flagRegistry[t]==null)throw new Error("Cannot set flag "+t+" as it has not been registered.");this.flags[t]=e,this.flagRegistry[t].setHook!=null&&this.flagRegistry[t].setHook(e)},n.prototype.evaluateFlag=function(t){if(this.flagRegistry[t]==null)throw new Error("Cannot evaluate flag '"+t+"': no evaluation function found.");return this.flagRegistry[t].evaluationFn()},n.prototype.setFlags=function(t){this.flags=Object.assign({},t)},n.prototype.reset=function(){this.flags={},this.urlFlags={},this.populateURLFlags()},n.prototype.populateURLFlags=function(){var t=this;if(typeof this.global=="undefined"||typeof this.global.location=="undefined"||typeof this.global.location.search=="undefined")return;var e=C2(this.global.location.search);if(gf in e){var i=e[gf].split(",");i.forEach(function(r){var a=r.split(":"),s=a[0],o=a[1];t.urlFlags[s]=R2(s,o)})}},n}();function C2(n){var t={};return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(e){for(var i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];return O2(t,i[0],i[1]),i.join("=")}),t}function O2(n,t,e){n[decodeURIComponent(t)]=decodeURIComponent(e||"")}function R2(n,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 "+n+".")}function He(){return I.ENV}I.ENV=null;function E2(n){I.ENV=n}var Dl;function yf(){if(Dl==null){var n=void 0;if(typeof window!="undefined")n=window;else if(typeof global!="undefined")n=global;else if(typeof process!="undefined")n=process;else if(typeof self!="undefined")n=self;else throw new Error("Could not find a global object");Dl=n}return Dl}function D2(){var n=yf();return n._tfGlobals==null&&(n._tfGlobals=new Map),n._tfGlobals}function bf(n,t){var e=D2();if(e.has(n))return e.get(n);var i=t();return e.set(n,i),e.get(n)}var kl="Abs",Fl="Acos",Wl="Acosh",Fs="Add",Ul="AddN",wf="All",Sf="Any",Bl="ArgMax",zl="ArgMin",Pl="Asin",_l="Asinh",Ml="Atan",Hl="Atanh",Vl="Atan2",ql="AvgPool",Lf="AvgPoolBackprop",Gl="AvgPool3D",If="AvgPool3DBackprop",Yl="BatchMatMul",jl="BatchToSpaceND",Kl="BroadcastTo",Ws="Cast",$l="Ceil",Xl="ClipByValue",Af="Complex",Jl="Concat",Zl="Conv2D",Tf="Conv2DBackpropFilter",Ql="Conv2DBackpropInput",eu="Conv3D",Nf="Conv3DBackpropFilterV2",xf="Conv3DBackpropInputV2",tu="Cos",nu="Cosh",iu="Cumsum",Cf="CropAndResize",Rf="DepthToSpace",ru="DepthwiseConv2dNative",Of="DepthwiseConv2dNativeBackpropFilter",Ef="DepthwiseConv2dNativeBackpropInput",Df="Diag",au="Dilation2D",kf="Dilation2DBackpropInput",Ff="Dilation2DBackpropFilter",su="Div",ou="Elu",Wf="EluGrad",lu="Erf",Uf="Equal",uu="Exp",cu="Expm1",Bf="FFT",zf="Fill",Pf="FlipLeftRight",hu="Floor",du="FloorDiv",pu="FusedBatchNorm",fu="GatherV2",_f="GatherNd",Mf="Greater",mu="GreaterEqual",gu="Identity",Hf="IFFT",Vf="Imag",vu="IsFinite",yu="IsInf",bu="IsNan",qf="Less",Gf="LessEqual",Yf="LinSpace",wu="Log",Su="Log1p",jf="LogicalAnd",Kf="LogicalNot",$f="LogicalOr",Lu="LogSoftmax",Iu="LRN",Xf="LRNBackprop",Au="Max",Tu="Maximum",Nu="MaxPool",Jf="MaxPoolBackprop",xu="MaxPool3D",Zf="MaxPool3DBackprop",Qf="MaxPoolWithArgmax",k2="Mean",Cu="Min",Ru="Minimum",Ou="Mod",Eu="Multiply",Du="Negate",em="NotEqual",tm="NonMaxSuppressionV3",nm="NonMaxSuppressionV4",im="NonMaxSuppressionV5",ku="OnesLike",Fu="OneHot",Wu="PadV2",F2="Pool",Uu="Pow",Bu="Prelu",rm="Prod",am="Range",sm="Real",zu="Reciprocal",Pu="Relu",_u="Reshape",Mu="ResizeNearestNeighbor",om="ResizeNearestNeighborGrad",Hu="ResizeBilinear",lm="ResizeBilinearGrad",Vu="Relu6",qu="Reverse",Gu="Round",Yu="Rsqrt",um="ScatterNd",ju="SelectV2",Ku="Selu",$u="Slice",Xu="Sin",Ju="Sinh",Zu="Sign",Qu="Sigmoid",ec="Softplus",tc="Sqrt",nc="Sum",ic="SpaceToBatchND",rc="SplitV",ac="Softmax",sc="SquaredDifference",cm="Square",oc="Sub",hm="SparseToDense",dm="StridedSlice",lc="Tan",uc="Tanh",cc="Tile",pm="TopK",hc="Transpose",fm="Unique",dc="Unpack",pc="UnsortedSegmentSum",fc="ZerosLike",mc="Step",gc="FromPixels",mm="RotateWithOffset",vc="_FusedMatMul",yc="FusedConv2D",bc="FusedDepthwiseConv2D";var kr=bf("kernelRegistry",function(){return new Map}),Ea=bf("gradRegistry",function(){return new Map});function Sc(n,t){var e=wc(n,t);return kr.get(e)}function Lc(n){return Ea.get(n)}function Us(n){for(var t=kr.entries(),e=[];;){var i=t.next(),r=i.done,a=i.value;if(r)break;var s=a[0],o=a[1],l=s.split("_")[0];l===n&&e.push(o)}return e}function gm(n){var t=n.kernelName,e=n.backendName,i=wc(t,e);kr.has(i)&&console.warn("The kernel '"+t+"' for backend "+("'"+e+"' is already registered")),kr.set(i,n)}function vm(n){var t=n.kernelName;Ea.has(t)&&(He().getBool("DEBUG")&&console.warn("Overriding the gradient for '"+t+"'")),Ea.set(t,n)}function W2(n,t){var e=wc(n,t);if(!kr.has(e))throw new Error("The kernel '"+n+"' for backend "+("'"+t+"' is not registered"));kr.delete(e)}function U2(n){if(!Ea.has(n))throw new Error("The gradient '"+n+"' for backend is not registered");Ea.delete(n)}function B2(n,t){var e=Us(n);e.forEach(function(i){var r=Object.assign({},i,{backendName:t});gm(r)})}function wc(n,t){return t+"_"+n}function ym(n){for(var t=n.length,e=0,i=0;t>0;)i=Math.random()*t|0,t--,e=n[t],n[t]=n[i],n[i]=e}function Da(n,t,e){return Math.max(n,Math.min(t,e))}function z2(n){return n%2===0?n:n+1}function P2(n){for(var t=0,e=0;e<n.length;e++)t+=n[e];return t}function _2(n,t){var e=Math.random();return t*e+(1-e)*n}function M2(n,t){for(var e=0,i=0;i<n.length;i++){var r=Number(n[i])-Number(t[i]);e+=r*r}return e}function E(n,t){if(!n)throw new Error(typeof t=="string"?t:t())}function Be(n,t,e){e===void 0&&(e=""),E(dn(n,t),function(){return e+(" Shapes "+n+" and "+t+" must match")})}function Yi(n){E(n!=null,function(){return"The input to the tensor constructor must be a non-null value."})}function ji(n,t,e){if(t===void 0&&(t=[]),e===void 0&&(e=!1),t==null&&(t=[]),Array.isArray(n)||Dt(n)&&!e)for(var i=0;i<n.length;++i)ji(n[i],t,e);else t.push(n);return t}function ot(n){if(n.length===0)return 1;for(var t=n[0],e=1;e<n.length;e++)t*=n[e];return t}function H2(n){return n.length===0}function dn(n,t){if(n===t)return!0;if(n==null||t==null)return!1;if(n.length!==t.length)return!1;for(var e=0;e<n.length;e++)if(n[e]!==t[e])return!1;return!0}function rt(n){return n%1===0}function V2(n){if(Math.tanh!=null)return Math.tanh(n);if(n===Infinity)return 1;if(n===-Infinity)return-1;var t=Math.exp(2*n);return(t-1)/(t+1)}function q2(n){var t=Math.ceil(Math.sqrt(n));return[t,Math.ceil(n/t)]}function G2(n){for(var t=new Uint32Array(n),e=0;e<n;++e)t[e]=e;return ym(t),t}function ka(n,t){return t<=n.length?n:n+" ".repeat(t-n.length)}function Y2(n,t,e){return t===void 0&&(t=function(i){return 0}),new Promise(function(i,r){var a=0,s=function(){if(n()){i();return}a++;var o=t(a);if(e!=null&&a>=e){r();return}setTimeout(s,o)};s()})}function bm(n,t){for(var e=1,i=-1,r=0;r<n.length;++r)if(n[r]>=0)e*=n[r];else if(n[r]===-1){if(i!==-1)throw Error("Shapes can only have 1 implicit size. "+("Found -1 at dim "+i+" and dim "+r));i=r}else if(n[r]<0)throw Error("Shapes can not be < 0. Found "+n[r]+" at dim "+r);if(i===-1){if(t>0&&t!==e)throw Error("Size("+t+") must match the product of shape "+n);return n}if(e===0)throw Error("Cannot infer the missing size in ["+n+"] when there are 0 elements");if(t%e!==0)throw Error("The implicit shape can't be a fractional number. "+("Got "+t+" / "+e));var a=n.slice();return a[i]=t/e,a}function Qe(n,t){var e=t.length;return n=n==null?t.map(function(i,r){return r}):[].concat(n),E(n.every(function(i){return i>=-e&&i<e}),function(){return"All values in axis param must be in range [-"+e+", "+e+") but "+("got axis "+n)}),E(n.every(function(i){return rt(i)}),function(){return"All values in axis param must be integers but "+("got axis "+n)}),n.map(function(i){return i<0?e+i:i})}function wm(n,t){for(var e=[],i=[],r=t!=null&&Array.isArray(t)&&t.length===0,a=t==null||r?null:Qe(t,n).sort(),s=0,o=0;o<n.length;++o){if(a!=null){if(a[s]===o&&n[o]!==1)throw new Error("Can't squeeze axis "+o+" since its dim '"+n[o]+"' is not 1");(a[s]==null||a[s]>o)&&n[o]===1&&(e.push(n[o]),i.push(o)),a[s]<=o&&s++}n[o]!==1&&(e.push(n[o]),i.push(o))}return{newShape:e,keptDims:i}}function Bs(n,t){var e=null;if(n==null||n==="float32")e=new Float32Array(t);else if(n==="int32")e=new Int32Array(t);else if(n==="bool")e=new Uint8Array(t);else throw new Error("Unknown data type "+n);return e}function Sm(n,t){var e=null;if(n==null||n==="float32")e=new Float32Array(t);else if(n==="int32")e=new Int32Array(t);else if(n==="bool")e=new Uint8Array(t);else if(n==="string")e=new Array(t);else throw new Error("Unknown data type "+n);return e}function Lm(n,t){for(var e=0;e<n.length;e++){var i=n[e];if(isNaN(i)||!isFinite(i))throw Error("A tensor of type "+t+" being uploaded contains "+i+".")}}function Im(n){return n==="bool"||n==="complex64"||n==="float32"||n==="int32"||n==="string"}function Am(n,t){return t==="complex64"||(t==="float32"&&n!=="complex64"||t==="int32"&&n!=="float32"&&n!=="complex64")?!1:!(t==="bool"&&n==="bool")}function Dt(n){return n instanceof Float32Array||n instanceof Int32Array||n instanceof Uint8Array}function Tm(n){if(n==="float32"||n==="int32")return 4;if(n==="complex64")return 8;if(n==="bool")return 1;throw new Error("Unknown dtype "+n)}function Nm(n){if(n==null)return 0;var t=0;return n.forEach(function(e){return t+=e.length}),t}function pi(n){return typeof n=="string"||n instanceof String}function xm(n){return typeof n=="boolean"}function Cm(n){return typeof n=="number"}function zs(n){return Array.isArray(n)?zs(n[0]):n instanceof Float32Array?"float32":n instanceof Int32Array||n instanceof Uint8Array?"int32":Cm(n)?"float32":pi(n)?"string":xm(n)?"bool":"float32"}function fi(n){return!!(n&&n.constructor&&n.call&&n.apply)}function Ps(n,t){for(var e=t;e<n;++e)if(n%e===0)return e;return n}function Fr(n){var t=n.length;if(t<2)return[];var e=new Array(t-1);e[t-2]=n[t-1];for(var i=t-3;i>=0;--i)e[i]=e[i+1]*n[i+1];return e}function j2(n,t){return t==="string"?Ic(n):_s([n],t)}function _s(n,t){if(t==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(n)&&(n=ji(n)),He().getBool("DEBUG")&&Lm(n,t),K2(n,t))return n;if(t==null||t==="float32"||t==="complex64")return new Float32Array(n);if(t==="int32")return new Int32Array(n);if(t==="bool"){for(var e=new Uint8Array(n.length),i=0;i<e.length;++i)Math.round(n[i])!==0&&(e[i]=1);return e}else throw new Error("Unknown data type "+t)}function Rm(n,t,e){var i=new Array;if(t.length===1)for(var r=t[0],a=0;a<r;a++)i[a]=e[n+a];else for(var r=t[0],s=t.slice(1),o=s.reduce(function(u,c){return u*c}),a=0;a<r;a++)i[a]=Rm(n+a*o,s,e);return i}function Wr(n,t){if(n.length===0)return t[0];var e=n.reduce(function(i,r){return i*r});if(e===0)return[];if(e!==t.length)throw new Error("["+n+"] does not match the input size "+t.length+".");return Rm(0,n,t)}function K2(n,t){return n instanceof Float32Array&&t==="float32"||n instanceof Int32Array&&t==="int32"||n instanceof Uint8Array&&t==="bool"}function Ac(n,t){for(var e=Ur(n,t),i=0;i<e.length;i++)e[i]=1;return e}function Ur(n,t){if(t==null||t==="float32"||t==="complex64")return new Float32Array(n);if(t==="int32")return new Int32Array(n);if(t==="bool")return new Uint8Array(n);throw new Error("Unknown data type "+t)}function $2(n,t){var e=n.reduce(function(i,r){return i*r},1);if(t==null||t==="float32")return Wr(n,new Float32Array(e));if(t==="int32")return Wr(n,new Int32Array(e));if(t==="bool")return Wr(n,new Uint8Array(e));throw new Error("Unknown data type "+t)}function Tc(){return He().platform.now()}function Nc(n){n.forEach(function(t){E(Number.isInteger(t)&&t>=0,function(){return"Tensor must have a shape comprised of positive integers but got "+("shape ["+n+"].")})})}function X2(n,t){return He().platform.fetch(n,t)}function Ic(n,t){return t===void 0&&(t="utf-8"),t=t||"utf-8",He().platform.encode(n,t)}function xc(n,t){return t===void 0&&(t="utf-8"),t=t||"utf-8",He().platform.decode(n,t)}function J2(n,t,e){if(t===0)return 0;if(t===1)return n[0];for(var i=n[n.length-1],r=0;r<n.length-1;++r)i+=e[r]*n[r];return i}function Z2(n,t,e){if(t===0)return[];if(t===1)return[n];for(var i=new Array(t),r=0;r<i.length-1;++r)i[r]=Math.floor(n/e[r]),n-=i[r]*e[r];return i[i.length-1]=n,i}var Q2={__proto__:null,shuffle:ym,clamp:Da,nearestLargerEven:z2,sum:P2,randUniform:_2,distSquared:M2,assert:E,assertShapesMatch:Be,assertNonNull:Yi,flatten:ji,sizeFromShape:ot,isScalarShape:H2,arraysEqual:dn,isInt:rt,tanh:V2,sizeToSquarishShape:q2,createShuffledIndices:G2,rightPad:ka,repeatedTry:Y2,inferFromImplicitShape:bm,parseAxisParam:Qe,squeezeShape:wm,getTypedArrayFromDType:Bs,getArrayFromDType:Sm,checkConversionForErrors:Lm,isValidDtype:Im,hasEncodingLoss:Am,isTypedArray:Dt,bytesPerElement:Tm,bytesFromStringArray:Nm,isString:pi,isBoolean:xm,isNumber:Cm,inferDtype:zs,isFunction:fi,nearestDivisor:Ps,computeStrides:Fr,createScalarValue:j2,toTypedArray:_s,toNestedArray:Wr,makeOnesTypedArray:Ac,makeZerosTypedArray:Ur,makeZerosNestedTypedArray:$2,now:Tc,assertNonNegativeIntegerDimensions:Nc,fetch:X2,encodeString:Ic,decodeString:xc,locToIndex:J2,indexToLoc:Z2};var nA=function(){function n(t,e){this.backendTimer=t,this.logger=e,e==null&&(this.logger=new tA)}return n.prototype.profileKernel=function(t,e,i){for(var r,a=function(){r=i()},s=this.backendTimer.time(a),o=function(c){var h=r[c];h.data().then(function(d){eA(d,h.dtype,t)})},l=0;l<r.length;l++)o(l);var u={kernelName:t,outputs:r,inputs:e,timeMs:s.then(function(c){return c.kernelMs}),extraInfo:s.then(function(c){return c.getExtraProfileInfo!=null?c.getExtraProfileInfo():""})};return u},n.prototype.logKernelProfile=function(t){var e=this,i=t.kernelName,r=t.outputs,a=t.timeMs,s=t.inputs,o=t.extraInfo;r.forEach(function(l){Promise.all([l.data(),a,o]).then(function(u){e.logger.logKernelProfile(i,l,u[0],u[1],s,u[2])})})},n}();function eA(n,t,e){if(t!=="float32")return!1;for(var i=0;i<n.length;i++){var r=n[i];if(isNaN(r)||!isFinite(r))return console.warn("Found "+r+" in the result of '"+e+"'"),!0}return!1}var tA=function(){function n(){}return n.prototype.logKernelProfile=function(t,e,i,r,a,s){var o=typeof r=="number"?ka(r+"ms",9):r.error,l=ka(t,25),u=e.rank,c=e.size,h=ka(e.shape.toString(),14),d="";for(var p in a){var f=a[p];if(f!=null){var m=f.shape||e.shape,g=m.length;d+=p+": "+g+"D "+(g>0?m:"")+" "}}console.log("%c"+l+" %c"+o+" %c"+u+"D "+h+" %c"+c+" %c"+d+" %c"+s,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},n}();function iA(n,t,e){for(var i={},r={},a=0;a<t.length;a++)i[t[a].id]=!0;for(var a=0;a<n.length;a++){var s=n[a],o=s.inputs;for(var l in o){for(var u=o[l],c=!1,h=0;h<t.length;h++)if(i[u.id]){s.outputs.forEach(function(w){return i[w.id]=!0}),c=!0,r[s.id]=!0;break}if(c)break}}var d={};d[e.id]=!0;for(var p={},a=n.length-1;a>=0;a--)for(var s=n[a],o=s.inputs,h=0;h<s.outputs.length;h++)if(d[s.outputs[h].id]){for(var l in o)d[o[l].id]=!0,p[s.id]=!0;break}for(var f=[],a=0;a<n.length;a++){var s=n[a];if(r[s.id]&&p[s.id]){var m={};for(var l in s.inputs){var g=s.inputs[l];i[g.id]&&(m[l]=g)}var v=Object.assign({},s);v.inputs=m,v.outputs=s.outputs,f.push(v)}}return f}function rA(n,t,e,i){for(var r=function(s){var o=t[s],l=[];if(o.outputs.forEach(function(d){var p=n[d.id];p!=null?l.push(p):l.push(null)}),o.gradient==null)throw new Error("Cannot compute gradient: gradient function not found "+("for "+o.kernelName+"."));var u=o.gradient(l),c=function(d){if(!(d in u))throw new Error("Cannot backprop through input "+d+". "+("Available gradients found: "+Object.keys(u)+"."));var p=e(function(){return u[d]()});if(p.dtype!=="float32")throw new Error("Error in gradient for op "+o.kernelName+". The gradient of input "+(d+" must have 'float32' dtype, but has '"+p.dtype+"'"));var f=o.inputs[d];if(!dn(p.shape,f.shape))throw new Error("Error in gradient for op "+o.kernelName+". The gradient of input "+("'"+d+"' has shape '"+p.shape+"', which does not match ")+("the shape of the input '"+f.shape+"'"));if(n[f.id]==null)n[f.id]=p;else{var m=n[f.id];n[f.id]=i(m,p),m.dispose()}};for(var h in o.inputs)c(h)},a=t.length-1;a>=0;a--)r(a)}var Om=20,Fa=3,Cc=7;function sA(n,t,e,i){var r=Fr(t),a=aA(n,t,e,r),s=t.length,o=Ms(n,t,e,r,a),l=["Tensor"];return i&&(l.push(" dtype: "+e),l.push(" rank: "+s),l.push(" shape: ["+t+"]"),l.push(" values:")),l.push(o.map(function(u){return" "+u}).join(`
|
|
`)),l.join(`
|
|
`)}function aA(n,t,e,i){var r=ot(t),a=i[i.length-1],s=new Array(a).fill(0),o=t.length,l=e==="complex64"?Ua(n):n;if(o>1)for(var u=0;u<r/a;u++)for(var c=u*a,h=0;h<a;h++)s[h]=Math.max(s[h],Wa(l[c+h],0,e).length);return s}function Wa(n,t,e){var i;return Array.isArray(n)?i=parseFloat(n[0].toFixed(Cc))+" + "+(parseFloat(n[1].toFixed(Cc))+"j"):pi(n)?i="'"+n+"'":e==="bool"?i=Em(n):i=parseFloat(n.toFixed(Cc)).toString(),ka(i,t)}function Em(n){return n===0?"false":"true"}function Ms(n,t,e,i,r,a){a===void 0&&(a=!0);var s=e==="complex64"?2:1,o=t[0],l=t.length;if(l===0){if(e==="complex64"){var u=Ua(n);return[Wa(u[0],0,e)]}return e==="bool"?[Em(n[0])]:[n[0].toString()]}if(l===1){if(o>Om){var c=Fa*s,h=Array.from(n.slice(0,c)),d=Array.from(n.slice((o-Fa)*s,o*s));return e==="complex64"&&(h=Ua(h),d=Ua(d)),["["+h.map(function(C,R){return Wa(C,r[R],e)}).join(", ")+", ..., "+d.map(function(C,R){return Wa(C,r[o-Fa+R],e)}).join(", ")+"]"]}var p=e==="complex64"?Ua(n):Array.from(n);return["["+p.map(function(C,R){return Wa(C,r[R],e)}).join(", ")+"]"]}var f=t.slice(1),m=i.slice(1),g=i[0]*s,v=[];if(o>Om){for(var b=0;b<Fa;b++){var w=b*g,S=w+g;v.push.apply(v,Ms(n.slice(w,S),f,e,m,r,!1))}v.push("...");for(var b=o-Fa;b<o;b++){var w=b*g,S=w+g;v.push.apply(v,Ms(n.slice(w,S),f,e,m,r,b===o-1))}}else for(var b=0;b<o;b++){var w=b*g,S=w+g;v.push.apply(v,Ms(n.slice(w,S),f,e,m,r,b===o-1))}var L=l===2?",":"";v[0]="["+v[0]+L;for(var b=1;b<v.length-1;b++)v[b]=" "+v[b]+L;for(var N=`,
|
|
`,b=2;b<l;b++)N+=`
|
|
`;return v[v.length-1]=" "+v[v.length-1]+"]"+(a?"":N),v}function Ua(n){for(var t=[],e=0;e<n.length;e+=2)t.push([n[e],n[e+1]]);return t}var Hs=function(){function n(t,e,i){var r=this;if(this.dtype=e,this.shape=t.slice(),this.size=ot(t),i!=null){var a=i.length;E(a===this.size,function(){return"Length of values '"+a+"' does not match the size "+("inferred by the shape '"+r.size+"'.")})}if(e==="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=i||Sm(e,this.size),this.strides=Fr(t)}return n.prototype.set=function(t){for(var e=this,i=[],r=1;r<arguments.length;r++)i[r-1]=arguments[r];i.length===0&&(i=[0]),E(i.length===this.rank,function(){return"The number of provided coordinates ("+i.length+") must "+("match the rank ("+e.rank+")")});var a=this.locToIndex(i);this.values[a]=t},n.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];t.length===0&&(t=[0]);for(var i=0,r=0,a=t;r<a.length;r++){var s=a[r];if(s<0||s>=this.shape[i]){var o="Requested out of range element at "+t+". "+(" Buffer shape="+this.shape);throw new Error(o)}i++}for(var l=t[t.length-1],u=0;u<t.length-1;++u)l+=this.strides[u]*t[u];return this.values[l]},n.prototype.locToIndex=function(t){if(this.rank===0)return 0;if(this.rank===1)return t[0];for(var e=t[t.length-1],i=0;i<t.length-1;++i)e+=this.strides[i]*t[i];return e},n.prototype.indexToLoc=function(t){if(this.rank===0)return[];if(this.rank===1)return[t];for(var e=new Array(this.shape.length),i=0;i<e.length-1;++i)e[i]=Math.floor(t/this.strides[i]),t-=e[i]*this.strides[i];return e[e.length-1]=t,e},Object.defineProperty(n.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),n.prototype.toTensor=function(){return kn().makeTensor(this.values,this.shape,this.dtype)},n}(),kn=null,Br=null;function oA(n){kn=n}function lA(n){Br=n}var Y=function(){function n(t,e,i,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=t.slice(),this.dtype=e||"float32",this.size=ot(t),this.strides=Fr(t),this.dataId=i,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}return Object.defineProperty(n.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),n.prototype.buffer=function(){return de(this,void 0,void 0,function(){var t;return pe(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,Br.buffer(this.shape,this.dtype,t)]}})})},n.prototype.bufferSync=function(){return Br.buffer(this.shape,this.dtype,this.dataSync())},n.prototype.array=function(){return de(this,void 0,void 0,function(){var t;return pe(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,Wr(this.shape,t)]}})})},n.prototype.arraySync=function(){return Wr(this.shape,this.dataSync())},n.prototype.data=function(){return de(this,void 0,void 0,function(){var t,e;return pe(this,function(i){switch(i.label){case 0:return this.throwIfDisposed(),t=kn().read(this.dataId),this.dtype==="string"?[4,t]:[3,2];case 1:e=i.sent();try{return[2,e.map(function(r){return xc(r)})]}catch(r){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}i.label=2;case 2:return[2,t]}})})},n.prototype.dataSync=function(){this.throwIfDisposed();var t=kn().readSync(this.dataId);if(this.dtype==="string")try{return t.map(function(e){return xc(e)})}catch(e){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return t},n.prototype.bytes=function(){return de(this,void 0,void 0,function(){var t;return pe(this,function(e){switch(e.label){case 0:return this.throwIfDisposed(),[4,kn().read(this.dataId)];case 1:return t=e.sent(),this.dtype==="string"?[2,t]:[2,new Uint8Array(t.buffer)]}})})},n.prototype.dispose=function(){if(this.isDisposed)return;kn().disposeTensor(this),this.isDisposedInternal=!0},Object.defineProperty(n.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!0,configurable:!0}),n.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.")},n.prototype.print=function(t){return t===void 0&&(t=!1),Br.print(this,t)},n.prototype.clone=function(){return this.throwIfDisposed(),Br.clone(this)},n.prototype.toString=function(t){t===void 0&&(t=!1);var e=this.dataSync();return sA(e,this.shape,this.dtype,t)},n.prototype.cast=function(t){return this.throwIfDisposed(),Br.cast(this,t)},n.prototype.variable=function(t,e,i){return t===void 0&&(t=!0),this.throwIfDisposed(),kn().makeVariable(this,t,e,i)},n}();Object.defineProperty(Y,Symbol.hasInstance,{value:function(n){return!!n&&n.data!=null&&n.dataSync!=null&&n.throwIfDisposed!=null}});var Ba=function(n){Zn(t,n);function t(e,i,r,a){var s=n.call(this,e.shape,e.dtype,e.dataId,a)||this;return s.trainable=i,s.name=r,s}return t.prototype.assign=function(e){if(e.dtype!==this.dtype)throw new Error("dtype of the new value ("+e.dtype+") and "+("previous value ("+this.dtype+") must match"));if(!dn(e.shape,this.shape))throw new Error("shape of the new value ("+e.shape+") and "+("previous value ("+this.shape+") must match"));kn().disposeTensor(this),this.dataId=e.dataId,kn().incRef(this,null)},t.prototype.dispose=function(){kn().disposeVariable(this),this.isDisposedInternal=!0},t}(Y);Object.defineProperty(Ba,Symbol.hasInstance,{value:function(n){return n instanceof Y&&n.assign!=null&&n.assign instanceof Function}});(function(n){n.R0="R0",n.R1="R1",n.R2="R2",n.R3="R3",n.R4="R4",n.R5="R5",n.R6="R6"})(I.Rank||(I.Rank={}));var Rc;(function(n){n.float32="float32",n.int32="int32",n.bool="int32",n.complex64="complex64"})(Rc||(Rc={}));var Oc;(function(n){n.float32="float32",n.int32="int32",n.bool="bool",n.complex64="complex64"})(Oc||(Oc={}));var Ec;(function(n){n.float32="float32",n.int32="float32",n.bool="float32",n.complex64="complex64"})(Ec||(Ec={}));var Dc;(function(n){n.float32="complex64",n.int32="complex64",n.bool="complex64",n.complex64="complex64"})(Dc||(Dc={}));var uA={float32:Ec,int32:Rc,bool:Oc,complex64:Dc};function Vs(n,t){if(n==="string"||t==="string"){if(n==="string"&&t==="string")return"string";throw new Error("Can not upcast "+n+" with "+t)}return uA[n][t]}function cA(n){return Vs(n,"int32")}function at(n,t){if(n.dtype===t.dtype)return[n,t];var e=Vs(n.dtype,t.dtype);return[n.cast(e),t.cast(e)]}function Dm(n,t){E(n.dtype===t.dtype,function(){return"The dtypes of the first("+n.dtype+") and"+(" second("+t.dtype+") input must match")})}function hA(n,t){return t.some(function(e){return e.id===n.id})}function kc(n){var t=[],e=new Set;return km(n,t,e),t}function km(n,t,e){if(n==null)return;if(n instanceof Y){t.push(n);return}if(!dA(n))return;var i=n;for(var r in i){var a=i[r];e.has(a)||(e.add(a),km(a,t,e))}}function dA(n){return Array.isArray(n)||typeof n=="object"}var pA={__proto__:null,makeTypesMatch:at,assertTypesMatch:Dm,isTensorInList:hA,getTensorsInContainer:kc};var Fm=function(){function n(){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}}return n.prototype.dispose=function(){for(var t in this.registeredVariables)this.registeredVariables[t].dispose()},n}(),gA=function(){function n(t){this.ENV=t,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new Fm}return n.prototype.ready=function(){return de(this,void 0,void 0,function(){var t,e,i,r;return pe(this,function(a){switch(a.label){case 0:if(this.pendingBackendInit!=null)return[2,this.pendingBackendInit.then(function(){})];if(this.backendInstance!=null)return[2];t=this.getSortedBackends(),e=0,a.label=1;case 1:return e<t.length?(i=t[e],[4,this.initializeBackend(i).success]):[3,5];case 2:return r=a.sent(),r?[4,this.setBackend(i)]:[3,4];case 3:return a.sent(),[2];case 4:return e++,[3,1];case 5:throw new Error("Could not initialize any backends, all backend initializations failed.")}})})},Object.defineProperty(n.prototype,"backend",{get:function(){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){var t=this.initializeBackendsAndReturnBest(),e=t.name,i=t.asyncInit;if(i)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},enumerable:!0,configurable:!0}),n.prototype.backendNames=function(){return Object.keys(this.registryFactory)},n.prototype.findBackend=function(t){if(!(t in this.registry))if(t in this.registryFactory){var e=this.initializeBackend(t).asyncInit;if(e)return null}else return null;return this.registry[t]},n.prototype.findBackendFactory=function(t){return t in this.registryFactory?this.registryFactory[t].factory:null},n.prototype.registerBackend=function(t,e,i){return i===void 0&&(i=1),t in this.registryFactory?(console.warn(t+" backend was already registered. Reusing existing backend factory."),!1):(this.registryFactory[t]={factory:e,priority:i},!0)},n.prototype.setBackend=function(t){return de(this,void 0,void 0,function(){var e,i,r,a,s;return pe(this,function(o){switch(o.label){case 0:if(this.registryFactory[t]==null)throw new Error("Backend name '"+t+"' not found in registry");return this.backendName=t,this.registry[t]==null?(this.backendInstance=null,e=this.initializeBackend(t),i=e.success,r=e.asyncInit,r?[4,i]:[3,2]):[3,4];case 1:return s=o.sent(),[3,3];case 2:s=i,o.label=3;case 3:if(a=s,!a)return[2,!1];o.label=4;case 4:return this.backendInstance=this.registry[t],this.setupRegisteredKernels(),this.profiler=new nA(this.backendInstance),[2,!0]}})})},n.prototype.setupRegisteredKernels=function(){var t=this,e=Us(this.backendName);e.forEach(function(i){i.setupFunc!=null&&i.setupFunc(t.backendInstance)})},n.prototype.disposeRegisteredKernels=function(t){var e=this,i=Us(t);i.forEach(function(r){r.disposeFunc!=null&&r.disposeFunc(e.registry[t])})},n.prototype.initializeBackend=function(t){var e=this,i=this.registryFactory[t];if(i==null)throw new Error("Cannot initialize backend "+t+", no registration found.");try{var r=i.factory();if(r&&!(r instanceof mf)&&typeof r.then=="function"){var a=++this.pendingBackendInitId,s=r.then(function(o){return a<e.pendingBackendInitId?!1:(e.registry[t]=o,e.pendingBackendInit=null,!0)}).catch(function(o){return a<e.pendingBackendInitId||(e.pendingBackendInit=null,console.warn("Initialization of backend "+t+" failed"),console.warn(o.stack||o.message)),!1});return this.pendingBackendInit=s,{success:s,asyncInit:!0}}else return this.registry[t]=r,{success:!0,asyncInit:!1}}catch(o){return console.warn("Initialization of backend "+t+" failed"),console.warn(o.stack||o.message),{success:!1,asyncInit:!1}}},n.prototype.removeBackend=function(t){if(!(t in this.registryFactory))throw new Error(t+" backend not found in registry");this.backendName===t&&this.pendingBackendInit!=null&&this.pendingBackendInitId++,t in this.registry&&(this.disposeRegisteredKernels(t),this.registry[t].dispose(),delete this.registry[t]),delete this.registryFactory[t],this.backendName===t&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null)},n.prototype.getSortedBackends=function(){var t=this;if(Object.keys(this.registryFactory).length===0)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort(function(e,i){return t.registryFactory[i].priority-t.registryFactory[e].priority})},n.prototype.initializeBackendsAndReturnBest=function(){for(var t=this.getSortedBackends(),e=0;e<t.length;e++){var i=t[e],r=this.initializeBackend(i),a=r.success,s=r.asyncInit;if(s||a)return{name:i,asyncInit:s}}throw new Error("Could not initialize any backends, all backend initializations failed.")},n.prototype.moveData=function(t,e){var i=this.state.tensorInfo.get(e),r=i.backend,a=this.readSync(e);r.disposeData(e),i.backend=t,t.move(e,a,i.shape,i.dtype),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++},n.prototype.tidy=function(t,e){var i=this,r=null;if(e==null){if(typeof t!="function")throw new Error("Please provide a function to tidy()");e=t}else{if(typeof t!="string"&&!(t instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if(typeof e!="function")throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");r=t}var a;return this.scopedRun(function(){return i.startScope(r)},function(){return i.endScope(a)},function(){return a=e(),a instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),a})},n.prototype.scopedRun=function(t,e,i){t();try{var r=i();return e(),r}catch(a){throw e(),a}},n.prototype.nextTensorId=function(){return n.nextTensorId++},n.prototype.nextVariableId=function(){return n.nextVariableId++},n.prototype.clone=function(t){var e=this.makeTensorFromDataId(t.dataId,t.shape,t.dtype),i={x:t},r=function(s){return{x:function(){var o="float32",l={x:s},u={dtype:o};return z.runKernelFunc(function(c){return c.cast(s,o)},l,null,Ws,u)}}},a=[];return this.addTapeNode(this.state.activeScope.name,i,[e],r,a,{}),e},n.prototype.runKernel=function(t,e,i,r,a){var s=null,o=null;return this.runKernelFunc(s,e,o,t,i,r,a)},n.prototype.shouldCheckForMemLeaks=function(){return this.ENV.getBool("IS_TEST")},n.prototype.checkKernelForMemLeak=function(t,e,i){var r=this.backend.numDataIds(),a=0;i.forEach(function(l){a+=l.dtype==="complex64"?3:1});var s=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],o=r-e-a-s;if(o>0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak "+("("+o+" data ids) after running '"+t+"'"))},n.prototype.runKernelFunc=function(t,e,i,r,a,s,o){var l=this,u,c=[],h=this.isTapeOn();r==null&&(r=this.state.activeScope!=null?this.state.activeScope.name:"");var d=this.state.numBytes,p=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);var f,m=Sc(r,this.backendName),g;if(m!=null)f=function(){var w=l.backend.numDataIds();g=m.kernelFunc({inputs:e,attrs:a,backend:l.backend});var S=Array.isArray(g)?g:[g];l.shouldCheckForMemLeaks()&&l.checkKernelForMemLeak(r,w,S);var L=S.map(function(R){var D=R.dataId,k=R.shape,W=R.dtype;return l.makeTensorFromDataId(D,k,W)});if(h){var N=l.getTensorsForGradient(r,e,L);if(N==null){o==null&&(o=[]);var C=L.filter(function(R,D){return o[D]});N=(s||[]).slice().concat(C)}c=l.saveTensorsForBackwardMode(N)}return L};else{var v=function(w){if(!h)return;c=w.map(function(S){return l.keep(l.clone(S))})};f=function(){var w=l.backend.numDataIds();g=l.tidy(function(){return t(l.backend,v)});var S=Array.isArray(g)?g:[g];return l.shouldCheckForMemLeaks()&&l.checkKernelForMemLeak(r,w,S),S}}var b;return this.scopedRun(function(){return l.state.kernelDepth++},function(){return l.state.kernelDepth--},function(){!l.ENV.getBool("DEBUG")&&!l.state.profiling?u=f():(b=l.profiler.profileKernel(r,e,function(){return f()}),l.ENV.getBool("DEBUG")&&l.profiler.logKernelProfile(b),u=b.outputs)}),h&&this.addTapeNode(r,e,u,i,c,a),this.state.profiling&&this.state.activeProfile.kernels.push({name:r,bytesAdded:this.state.numBytes-d,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-p,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(e).map(function(w){return e[w]!=null?e[w].shape:null}),outputShapes:u.map(function(w){return w.shape}),kernelTimeMs:b.timeMs,extraInfo:b.extraInfo}),Array.isArray(g)?u:u[0]},n.prototype.saveTensorsForBackwardMode=function(t){var e=this,i=t.map(function(r){return e.keep(e.clone(r))});return i},n.prototype.getTensorsForGradient=function(t,e,i){var r=Lc(t);if(r!=null){var a=r.inputsToSave||[],s=r.outputsToSave||[],o=void 0;r.saveAllInputs?(E(Array.isArray(e),function(){return"saveAllInputs is true, expected inputs to be an array."}),o=Object.keys(e).map(function(u){return e[u]})):o=a.map(function(u){return e[u]});var l=i.filter(function(u,c){return s[c]});return o.concat(l)}return null},n.prototype.makeTensor=function(t,e,i,r){if(t==null)throw new Error("Values passed to engine.makeTensor() are null");i=i||"float32",r=r||this.backend;var a=t;i==="string"&&pi(t[0])&&(a=t.map(function(c){return Ic(c)}));var s=r.write(a,e,i),o=new Y(e,i,s,this.nextTensorId());if(this.incRef(o,r),i==="string"){var l=this.state.tensorInfo.get(s),u=Nm(a);this.state.numBytes+=u-l.bytes,l.bytes=u}return o},n.prototype.makeTensorFromDataId=function(t,e,i,r){i=i||"float32";var a=new Y(e,i,t,this.nextTensorId());return this.incRef(a,r),a},n.prototype.makeVariable=function(t,e,i,r){e===void 0&&(e=!0),i=i||this.nextVariableId().toString(),r!=null&&r!==t.dtype&&(t=t.cast(r));var a=new Ba(t,e,i,this.nextTensorId());if(this.state.registeredVariables[a.name]!=null)throw new Error("Variable with name "+a.name+" was already registered");return this.state.registeredVariables[a.name]=a,this.incRef(a,this.backend),a},n.prototype.incRef=function(t,e){var i=this.state.tensorInfo.has(t.dataId)?this.state.tensorInfo.get(t.dataId).refCount:0;if(this.state.numTensors++,t.dtype==="string"&&this.state.numStringTensors++,i===0){this.state.numDataBuffers++;var r=0;t.dtype!=="complex64"&&t.dtype!=="string"&&(r=t.size*Tm(t.dtype)),this.state.tensorInfo.set(t.dataId,{backend:e||this.backend,dtype:t.dtype,shape:t.shape,bytes:r,refCount:0}),this.state.numBytes+=r}this.state.tensorInfo.get(t.dataId).refCount++,t instanceof Ba||this.track(t)},n.prototype.disposeTensor=function(t){if(!this.state.tensorInfo.has(t.dataId))return;this.state.numTensors--,t.dtype==="string"&&this.state.numStringTensors--;var e=this.state.tensorInfo.get(t.dataId),i=e.refCount;i<=1?(t.dtype!=="complex64"&&(this.state.numBytes-=e.bytes),this.state.numDataBuffers--,e.backend.disposeData(t.dataId),this.state.tensorInfo.delete(t.dataId)):this.state.tensorInfo.get(t.dataId).refCount--},n.prototype.disposeVariables=function(){for(var t in this.state.registeredVariables){var e=this.state.registeredVariables[t];this.disposeVariable(e)}},n.prototype.disposeVariable=function(t){this.disposeTensor(t),this.state.registeredVariables[t.name]!=null&&delete this.state.registeredVariables[t.name]},n.prototype.memory=function(){var t=this.backend.memory();return t.numTensors=this.state.numTensors,t.numDataBuffers=this.state.numDataBuffers,t.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(t.unreliable=!0,t.reasons==null&&(t.reasons=[]),t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),t},n.prototype.profile=function(t){return de(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u;return pe(this,function(c){switch(c.label){case 0:return this.state.profiling=!0,e=this.state.numBytes,i=this.state.numTensors,this.state.activeProfile.kernels=[],r=this.state.activeProfile,[4,t()];case 1:r.result=c.sent(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map(function(h){return h.totalBytesSnapshot})),this.state.activeProfile.newBytes=this.state.numBytes-e,this.state.activeProfile.newTensors=this.state.numTensors-i,a=0,s=this.state.activeProfile.kernels,c.label=2;case 2:return a<s.length?(o=s[a],l=o,[4,o.kernelTimeMs]):[3,6];case 3:return l.kernelTimeMs=c.sent(),u=o,[4,o.extraInfo];case 4:u.extraInfo=c.sent(),c.label=5;case 5:return a++,[3,2];case 6:return[2,this.state.activeProfile]}})})},n.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&this.state.kernelDepth===0},n.prototype.addTapeNode=function(t,e,i,r,a,s){var o=this,l={id:this.state.nextTapeNodeId++,kernelName:t,inputs:e,outputs:i,saved:a},u=Lc(t);u!=null&&(r=u.gradFunc),r!=null&&(l.gradient=function(c){return c=c.map(function(h,d){if(h==null){var p=i[d],f=Ur(p.size,p.dtype);return o.makeTensor(f,p.shape,p.dtype)}return h}),r(c.length>1?c:c[0],a,s)}),this.state.activeTape.push(l)},n.prototype.keep=function(t){return t.kept=!0,t},n.prototype.startTape=function(){this.state.gradientDepth===0&&(this.state.activeTape=[]),this.state.gradientDepth++},n.prototype.endTape=function(){this.state.gradientDepth--},n.prototype.startScope=function(t){var e={track:[],name:"unnamed scope",id:this.state.nextScopeId++};t&&(e.name=t),this.state.scopeStack.push(e),this.state.activeScope=e},n.prototype.endScope=function(t){for(var e=this,i=kc(t),r=new Set(i.map(function(l){return l.id})),a=0;a<this.state.activeScope.track.length;a++){var s=this.state.activeScope.track[a];!s.kept&&!r.has(s.id)&&s.dispose()}var o=this.state.scopeStack.pop();this.state.activeScope=this.state.scopeStack.length===0?null:this.state.scopeStack[this.state.scopeStack.length-1],i.forEach(function(l){!l.kept&&l.scopeId===o.id&&e.track(l)})},n.prototype.gradients=function(t,e,i,r){var a=this;if(r===void 0&&(r=!1),E(e.length>0,function(){return"gradients() received an empty list of xs."}),i!=null&&i.dtype!=="float32")throw new Error("dy must have 'float32' dtype, but has '"+i.dtype+"'");var s=this.scopedRun(function(){return a.startTape()},function(){return a.endTape()},function(){return a.tidy("forward",t)});E(s instanceof Y,function(){return"The result y returned by f() must be a tensor."});var o=iA(this.state.activeTape,e,s);if(!r&&o.length===0&&e.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",function(){var l={};l[s.id]=i??fA(s.shape),rA(l,o,function(c){return a.tidy(c)},mA);var u=e.map(function(c){return l[c.id]});return a.state.gradientDepth===0&&(a.state.activeTape.forEach(function(c){for(var h=0,d=c.saved;h<d.length;h++){var p=d[h];p.dispose()}}),a.state.activeTape=null),{value:s,grads:u}})},n.prototype.customGrad=function(t){var e=this;return E(fi(t),function(){return"The f passed in customGrad(f) must be a function."}),function(){for(var i=[],r=0;r<arguments.length;r++)i[r]=arguments[r];E(i.every(function(o){return o instanceof Y}),function(){return"The args passed in customGrad(f)(x1, x2,...) must all be tensors"});var a,s={};return i.forEach(function(o,l){s[l]=o}),e.runKernelFunc(function(o,l){return a=t.apply(void 0,i.concat([l])),E(a.value instanceof Y,function(){return"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"}),E(fi(a.gradFunc),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."}),a.value},s,function(o,l){var u=a.gradFunc(o,l),c=Array.isArray(u)?u:[u];E(c.length===i.length,function(){return"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(...)."}),E(c.every(function(d){return d instanceof Y}),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."});var h={};return c.forEach(function(d,p){h[p]=function(){return d}}),h})}},n.prototype.readSync=function(t){var e=this.state.tensorInfo.get(t);return e.backend.readSync(t)},n.prototype.read=function(t){var e=this.state.tensorInfo.get(t);return e.backend.read(t)},n.prototype.time=function(t){return de(this,void 0,void 0,function(){var e,i;return pe(this,function(r){switch(r.label){case 0:return e=Tc(),[4,this.backend.time(t)];case 1:return i=r.sent(),i.wallMs=Tc()-e,[2,i]}})})},n.prototype.track=function(t){return this.state.activeScope!=null&&(t.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(t)),t},Object.defineProperty(n.prototype,"registeredVariables",{get:function(){return this.state.registeredVariables},enumerable:!0,configurable:!0}),n.prototype.reset=function(){this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new Fm;for(var t in this.registry)this.disposeRegisteredKernels(t),this.registry[t].dispose(),delete this.registry[t];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null},n.nextTensorId=0,n.nextVariableId=0,n}();function fA(n){var t=Ac(ot(n),"float32");return z.makeTensor(t,n,"float32")}function Wm(){var n=yf();if(n._tfengine==null){var t=new vf(n);n._tfengine=new gA(t)}return E2(n._tfengine.ENV),oA(function(){return n._tfengine}),n._tfengine}var z=Wm();function mA(n,t){var e={a:n,b:t};return z.runKernelFunc(function(i,r){var a=i.add(n,t);return r([n,t]),a},e,null,Fs)}function vA(){return typeof navigator!="undefined"&&navigator!=null}function yA(){if(vA()){var n=navigator.userAgent||navigator.vendor||window.opera;return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(n)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(n.substr(0,4))}return!1}function Um(){return typeof window!="undefined"&&window.document!=null||typeof WorkerGlobalScope!="undefined"}var bA={__proto__:null,isMobile:yA,isBrowser:Um};var Qn=He();Qn.registerFlag("DEBUG",function(){return!1},function(n){n&&console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.")});Qn.registerFlag("IS_BROWSER",function(){return Um()});Qn.registerFlag("IS_NODE",function(){return typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof process.versions.node!="undefined"});Qn.registerFlag("IS_CHROME",function(){return typeof navigator!="undefined"&&navigator!=null&&navigator.userAgent!=null&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)});Qn.registerFlag("PROD",function(){return!1});Qn.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",function(){return Qn.getBool("DEBUG")});Qn.registerFlag("DEPRECATION_WARNINGS_ENABLED",function(){return!0});Qn.registerFlag("IS_TEST",function(){return!1});function Fn(n,t){var e=n;if(Dt(n))return t==="string"?[]:[n.length];if(!Array.isArray(n))return[];for(var i=[];Array.isArray(e)||Dt(e)&&t!=="string";)i.push(e.length),e=e[0];return Array.isArray(n)&&He().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY")&&Bm(n,i,[]),i}function Bm(n,t,e){if(e=e||[],!Array.isArray(n)&&!Dt(n)){E(t.length===0,function(){return"Element arr["+e.join("][")+"] is a primitive, "+("but should be an array/TypedArray of "+t[0]+" elements")});return}E(t.length>0,function(){return"Element arr["+e.join("][")+"] should be a primitive, "+("but is an array of "+n.length+" elements")}),E(n.length===t[0],function(){return"Element arr["+e.join("][")+"] should have "+t[0]+" "+("elements, but has "+n.length+" elements")});for(var i=t.slice(1),r=0;r<n.length;++r)Bm(n[r],i,e.concat(r))}function zm(n,t,e,i){if(n==null)return;if(n!=="numeric"&&n!==t||n==="numeric"&&t==="string")throw new Error("Argument '"+e+"' passed to '"+i+"' must "+("be "+n+" tensor, but got "+t+" tensor"))}function O(n,t,e,i){if(i===void 0&&(i="numeric"),n instanceof Y)return zm(i,n.dtype,t,e),n;var r=zs(n);if(r!=="string"&&["bool","int32","float32"].indexOf(i)>=0&&(r=i),zm(i,r,t,e),n==null||!Dt(n)&&!Array.isArray(n)&&typeof n!="number"&&typeof n!="boolean"&&typeof n!="string"){var a=n==null?"null":n.constructor.name;throw new Error("Argument '"+t+"' passed to '"+e+"' must be a "+("Tensor or TensorLike, but got '"+a+"'"))}var s=Fn(n,r);!Dt(n)&&!Array.isArray(n)&&(n=[n]);var o=!0,l=r!=="string"?_s(n,r):ji(n,[],o);return z.makeTensor(l,s,r)}function za(n,t,e,i){if(i===void 0&&(i="numeric"),!Array.isArray(n))throw new Error("Argument "+t+" passed to "+e+" must be a `Tensor[]` or `TensorLike[]`");var r=n;return r.map(function(a,s){return O(a,t+"["+s+"]",e)},i)}var Pm="__op";function U(n){var t=Object.keys(n);if(t.length!==1)throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with "+(t.length+" keys."));var e=t[0],i=n[e];e.endsWith("_")&&(e=e.substring(0,e.length-1)),e=e+Pm;var r=function(){for(var a=[],s=0;s<arguments.length;s++)a[s]=arguments[s];z.startScope(e);try{var o=i.apply(void 0,a);return o instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),z.endScope(o),o}catch(l){throw z.endScope(null),l}};return Object.defineProperty(r,"name",{value:e,configurable:!0}),r}function wA(n,t){var e=O(n,"real","complex"),i=O(t,"imag","complex");Be(e.shape,i.shape,"real and imag shapes, "+e.shape+" and "+i.shape+", must match in call to tf.complex().");var r=function(s){return s.complex(e,i)},a={real:e,imag:i};return z.runKernelFunc(r,a,null,Af)}var mi=U({complex_:wA});function gi(n,t,e,i){if(i==null&&(i=zs(n)),i==="complex64")throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!Dt(n)&&!Array.isArray(n)&&typeof n!="number"&&typeof n!="boolean"&&typeof n!="string")throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");if(t!=null){Nc(t);var r=ot(t),a=ot(e);E(r===a,function(){return"Based on the provided shape, ["+t+"], the tensor should have "+(r+" values but has "+a)});for(var s=0;s<e.length;++s){var o=e[s],l=s===e.length-1?o!==ot(t.slice(s)):!0;E(e[s]===t[s]||!l,function(){return"Error creating a new Tensor. Inferred shape "+("("+e+") does not match the provided ")+("shape ("+t+"). ")})}}return!Dt(n)&&!Array.isArray(n)&&(n=[n]),t=t||e,n=i!=="string"?_s(n,i):ji(n,[],!0),z.makeTensor(n,t,i)}function vi(n,t,e){var i=Fn(n,e);return gi(n,t,i,e)}var Fc={float32:4,float16:2,int32:4,uint16:2,uint8:1,bool:1,complex64:8};var qs=4;function LA(n,t){return de(this,void 0,void 0,function(){var e,i,r,a,s,o,l=this;return pe(this,function(u){switch(u.label){case 0:for(e=[],i=[],r=Array.isArray(n)?n.map(function(c){return c.name}):Object.keys(n),a=function(c){var h=r[c],d=Array.isArray(n)?n[c].tensor:n[h];if(d.dtype!=="float32"&&d.dtype!=="int32"&&d.dtype!=="bool"&&d.dtype!=="string"&&d.dtype!=="complex64")throw new Error("Unsupported dtype in weight '"+h+"': "+d.dtype);var p={name:h,shape:d.shape,dtype:d.dtype};if(d.dtype==="string"){var f=new Promise(function(m){return de(l,void 0,void 0,function(){var g,v,b,w,S,L,N;return pe(this,function(C){switch(C.label){case 0:return[4,d.bytes()];case 1:for(g=C.sent(),v=g.reduce(function(R,D){return R+D.length},0)+qs*g.length,b=new Uint8Array(v),w=0,S=0;S<g.length;S++)L=g[S],N=new Uint8Array(new Uint32Array([L.length]).buffer),b.set(N,w),w+=qs,b.set(L,w),w+=L.length;return m(b),[2]}})})});i.push(f)}else i.push(d.data());t!=null&&(p.group=t),e.push(p)},s=0;s<r.length;++s)a(s);return[4,Promise.all(i)];case 1:return o=u.sent(),[2,{data:SA(o),specs:e}]}})})}function _m(n,t){for(var e={},i,r=0,a=0,s=t;a<s.length;a++){var o=s[a],l=o.name,u=o.dtype,c=o.shape,h=ot(c),d=void 0;if("quantization"in o){var p=o.quantization;if(p.dtype==="uint8"||p.dtype==="uint16"){if(!("min"in p&&"scale"in p))throw new Error("Weight "+o.name+" with quantization "+p.dtype+" doesn't have corresponding metadata min and scale.")}else if(p.dtype==="float16"){if(u!=="float32")throw new Error("Weight "+o.name+" is quantized with "+p.dtype+" "+("which only supports weights of type float32 not "+u+"."))}else throw new Error("Weight "+o.name+" has unknown "+("quantization dtype "+p.dtype+". ")+"Supported quantization dtypes are: 'uint8', 'uint16', and 'float16'.");var f=Fc[p.dtype],m=n.slice(r,r+h*f),g=p.dtype==="uint8"?new Uint8Array(m):new Uint16Array(m);if(u==="float32")if(p.dtype==="uint8"||p.dtype==="uint16"){d=new Float32Array(g.length);for(var v=0;v<g.length;v++){var b=g[v];d[v]=b*p.scale+p.min}}else if(p.dtype==="float16")i===void 0&&(i=IA()),d=i(g);else throw new Error("Unsupported quantization type "+p.dtype+" for weight type float32.");else if(u==="int32"){if(p.dtype!=="uint8"&&p.dtype!=="uint16")throw new Error("Unsupported quantization type "+p.dtype+" for weight type int32.");d=new Int32Array(g.length);for(var v=0;v<g.length;v++){var b=g[v];d[v]=Math.round(b*p.scale+p.min)}}else throw new Error("Unsupported dtype in weight '"+l+"': "+u);r+=h*f}else if(u==="string"){var w=ot(o.shape);d=[];for(var v=0;v<w;v++){var S=new Uint32Array(n.slice(r,r+qs))[0];r+=qs;var L=new Uint8Array(n.slice(r,r+S));d.push(L),r+=S}}else{var N=Fc[u],m=n.slice(r,r+h*N);if(u==="float32")d=new Float32Array(m);else if(u==="int32")d=new Int32Array(m);else if(u==="bool")d=new Uint8Array(m);else if(u==="complex64"){d=new Float32Array(m);for(var C=new Float32Array(d.length/2),R=new Float32Array(d.length/2),v=0;v<C.length;v++)C[v]=d[v*2],R[v]=d[v*2+1];var D=vi(C,c,"float32"),k=vi(R,c,"float32");e[l]=mi(D,k)}else throw new Error("Unsupported dtype in weight '"+l+"': "+u);r+=h*N}u!=="complex64"&&(e[l]=vi(d,c,u))}return e}function SA(n){if(n===null)throw new Error("Invalid input value: "+JSON.stringify(n));var t=0,e=[];n.forEach(function(a){if(t+=a.byteLength,e.push(a.byteLength===a.buffer.byteLength?a:new a.constructor(a)),!(a instanceof Float32Array||a instanceof Int32Array||a instanceof Uint8Array))throw new Error("Unsupported TypedArray subtype: "+a.constructor.name)});var i=new Uint8Array(t),r=0;return e.forEach(function(a){i.set(new Uint8Array(a.buffer),r),r+=a.byteLength}),i.buffer}var Wc=typeof Buffer!="undefined"&&(typeof Blob=="undefined"||typeof atob=="undefined"||typeof btoa=="undefined");function Mm(n){return Wc?Buffer.byteLength(n):new Blob([n]).size}function AA(n){if(Wc)return Buffer.from(n).toString("base64");for(var t=new Uint8Array(n),e="",i=0,r=t.length;i<r;i++)e+=String.fromCharCode(t[i]);return btoa(e)}function TA(n){if(Wc){var t=Buffer.from(n,"base64");return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}for(var e=atob(n),i=new Uint8Array(e.length),r=0;r<e.length;++r)i.set([e.charCodeAt(r)],r);return i.buffer}function Uc(n){if(n.length===1)return n[0];var t=0;n.forEach(function(r){t+=r.byteLength});var e=new Uint8Array(t),i=0;return n.forEach(function(r){e.set(new Uint8Array(r),i),i+=r.byteLength}),e.buffer}function Hm(n){var t="/";for(n=n.trim();n.endsWith(t);)n=n.slice(0,n.length-1);var e=n.split(t);return e[e.length-1]}function Pa(n){if(n.modelTopology instanceof ArrayBuffer)throw new Error("Expected JSON model topology, received ArrayBuffer.");return{dateSaved:new Date,modelTopologyType:"JSON",modelTopologyBytes:n.modelTopology==null?0:Mm(JSON.stringify(n.modelTopology)),weightSpecsBytes:n.weightSpecs==null?0:Mm(JSON.stringify(n.weightSpecs)),weightDataBytes:n.weightData==null?0:n.weightData.byteLength}}function NA(){var n=function(i){for(var r=i<<13,a=0;(r&8388608)===0;)a-=8388608,r<<=1;return r&=~8388608,a+=947912704,r|a},t=new Uint32Array(2048);t[0]=0;for(var e=1;e<1024;e++)t[e]=n(e);for(var e=1024;e<2048;e++)t[e]=939524096+(e-1024<<13);return t}function xA(){var n=new Uint32Array(64);n[0]=0,n[31]=1199570944,n[32]=2147483648,n[63]=3347054592;for(var t=1;t<31;t++)n[t]=t<<23;for(var t=33;t<63;t++)n[t]=2147483648+(t-32<<23);return n}function CA(){for(var n=new Uint32Array(64),t=0;t<64;t++)n[t]=1024;return n[0]=n[32]=0,n}function IA(){var n=NA(),t=xA(),e=CA();return function(i){for(var r=new ArrayBuffer(4*i.length),a=new Uint32Array(r),s=0;s<i.length;s++){var o=i[s],l=n[e[o>>10]+(o&1023)]+t[o>>10];a[s]=l}return new Float32Array(r)}}var nn=function(){function n(){this.saveRouters=[],this.loadRouters=[]}return n.getInstance=function(){return n.instance==null&&(n.instance=new n),n.instance},n.registerSaveRouter=function(t){n.getInstance().saveRouters.push(t)},n.registerLoadRouter=function(t){n.getInstance().loadRouters.push(t)},n.getSaveHandlers=function(t){return n.getHandlers(t,"save")},n.getLoadHandlers=function(t,e){return n.getHandlers(t,"load",e)},n.getHandlers=function(t,e,i){var r=[],a=e==="load"?n.getInstance().loadRouters:n.getInstance().saveRouters;return a.forEach(function(s){var o=s(t,i);o!==null&&r.push(o)}),r},n}(),RA=function(n){return nn.registerSaveRouter(n)},OA=function(n){return nn.registerLoadRouter(n)},EA=function(n){return nn.getSaveHandlers(n)},DA=function(n,t){return nn.getLoadHandlers(n,t)};var Bc="tensorflowjs",zc=1,Ki="models_store",yi="model_info_store";function Vm(){if(!He().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");var n=typeof window=="undefined"?self:window,t=n.indexedDB||n.mozIndexedDB||n.webkitIndexedDB||n.msIndexedDB||n.shimIndexedDB;if(t==null)throw new Error("The current browser does not appear to support IndexedDB.");return t}function Pc(n){var t=n.result;t.createObjectStore(Ki,{keyPath:"modelPath"}),t.createObjectStore(yi,{keyPath:"modelPath"})}var zr=function(){function n(t){if(this.indexedDB=Vm(),t==null||!t)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=t}return n.prototype.save=function(t){return de(this,void 0,void 0,function(){return pe(this,function(e){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return[2,this.databaseAction(this.modelPath,t)]})})},n.prototype.load=function(){return de(this,void 0,void 0,function(){return pe(this,function(t){return[2,this.databaseAction(this.modelPath)]})})},n.prototype.databaseAction=function(t,e){var i=this;return new Promise(function(r,a){var s=i.indexedDB.open(Bc,zc);s.onupgradeneeded=function(){return Pc(s)},s.onsuccess=function(){var o=s.result;if(e==null){var l=o.transaction(Ki,"readonly"),u=l.objectStore(Ki),c=u.get(i.modelPath);c.onsuccess=function(){if(c.result==null)return o.close(),a(new Error("Cannot find model with path '"+i.modelPath+"' in IndexedDB."));r(c.result.modelArtifacts)},c.onerror=function(g){return o.close(),a(c.error)},l.oncomplete=function(){return o.close()}}else{var h=Pa(e),d=o.transaction(yi,"readwrite"),p=d.objectStore(yi),f=p.put({modelPath:i.modelPath,modelArtifactsInfo:h}),m;f.onsuccess=function(){m=o.transaction(Ki,"readwrite");var g=m.objectStore(Ki),v=g.put({modelPath:i.modelPath,modelArtifacts:e,modelArtifactsInfo:h});v.onsuccess=function(){return r({modelArtifactsInfo:h})},v.onerror=function(b){p=d.objectStore(yi);var w=p.delete(i.modelPath);w.onsuccess=function(){return o.close(),a(v.error)},w.onerror=function(S){return o.close(),a(v.error)}}},f.onerror=function(g){return o.close(),a(f.error)},d.oncomplete=function(){m==null?o.close():m.oncomplete=function(){return o.close()}}}},s.onerror=function(o){return a(s.error)}})},n.URL_SCHEME="indexeddb://",n}(),qm=function(n){return He().getBool("IS_BROWSER")&&(!Array.isArray(n)&&n.startsWith(zr.URL_SCHEME))?kA(n.slice(zr.URL_SCHEME.length)):null};nn.registerSaveRouter(qm);nn.registerLoadRouter(qm);function kA(n){return new zr(n)}function FA(n){return n.startsWith(zr.URL_SCHEME)?n.slice(zr.URL_SCHEME.length):n}var WA=function(){function n(){this.indexedDB=Vm()}return n.prototype.listModels=function(){return de(this,void 0,void 0,function(){var t=this;return pe(this,function(e){return[2,new Promise(function(i,r){var a=t.indexedDB.open(Bc,zc);a.onupgradeneeded=function(){return Pc(a)},a.onsuccess=function(){var s=a.result,o=s.transaction(yi,"readonly"),l=o.objectStore(yi),u=l.getAll();u.onsuccess=function(){for(var c={},h=0,d=u.result;h<d.length;h++){var p=d[h];c[p.modelPath]=p.modelArtifactsInfo}i(c)},u.onerror=function(c){return s.close(),r(u.error)},o.oncomplete=function(){return s.close()}},a.onerror=function(s){return r(a.error)}})]})})},n.prototype.removeModel=function(t){return de(this,void 0,void 0,function(){var e=this;return pe(this,function(i){return t=FA(t),[2,new Promise(function(r,a){var s=e.indexedDB.open(Bc,zc);s.onupgradeneeded=function(){return Pc(s)},s.onsuccess=function(){var o=s.result,l=o.transaction(yi,"readwrite"),u=l.objectStore(yi),c=u.get(t),h;c.onsuccess=function(){if(c.result==null)return o.close(),a(new Error("Cannot find model with path '"+t+"' in IndexedDB."));var d=u.delete(t),p=function(){h=o.transaction(Ki,"readwrite");var f=h.objectStore(Ki),m=f.delete(t);m.onsuccess=function(){return r(c.result.modelArtifactsInfo)},m.onerror=function(g){return a(c.error)}};d.onsuccess=p,d.onerror=function(f){return p(),o.close(),a(c.error)}},c.onerror=function(d){return o.close(),a(c.error)},l.oncomplete=function(){h==null?o.close():h.oncomplete=function(){return o.close()}}},s.onerror=function(o){return a(s.error)}})]})})},n}();var ei="/",Pr="tensorflowjs_models",Gm="info",UA="model_topology",BA="weight_specs",zA="weight_data",PA="model_metadata";function Ym(n){return{info:[Pr,n,Gm].join(ei),topology:[Pr,n,UA].join(ei),weightSpecs:[Pr,n,BA].join(ei),weightData:[Pr,n,zA].join(ei),modelMetadata:[Pr,n,PA].join(ei)}}function _A(n){var t=n.split(ei);if(t.length<3)throw new Error("Invalid key format: "+n);return t.slice(1,t.length-1).join(ei)}function MA(n){return n.startsWith(_r.URL_SCHEME)?n.slice(_r.URL_SCHEME.length):n}var _r=function(){function n(t){if(!He().getBool("IS_BROWSER")||typeof window=="undefined"||typeof window.localStorage=="undefined")throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,t==null||!t)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=t,this.keys=Ym(this.modelPath)}return n.prototype.save=function(t){return de(this,void 0,void 0,function(){var e,i,r;return pe(this,function(a){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");e=JSON.stringify(t.modelTopology),i=JSON.stringify(t.weightSpecs),r=Pa(t);try{return this.LS.setItem(this.keys.info,JSON.stringify(r)),this.LS.setItem(this.keys.topology,e),this.LS.setItem(this.keys.weightSpecs,i),this.LS.setItem(this.keys.weightData,AA(t.weightData)),this.LS.setItem(this.keys.modelMetadata,JSON.stringify({format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,userDefinedMetadata:t.userDefinedMetadata})),[2,{modelArtifactsInfo:r}]}catch(s){throw this.LS.removeItem(this.keys.info),this.LS.removeItem(this.keys.topology),this.LS.removeItem(this.keys.weightSpecs),this.LS.removeItem(this.keys.weightData),this.LS.removeItem(this.keys.modelMetadata),new Error("Failed to save model '"+this.modelPath+"' to local storage: size quota being exceeded is a possible cause of this failure: "+("modelTopologyBytes="+r.modelTopologyBytes+", ")+("weightSpecsBytes="+r.weightSpecsBytes+", ")+("weightDataBytes="+r.weightDataBytes+"."))}return[2]})})},n.prototype.load=function(){return de(this,void 0,void 0,function(){var t,e,i,r,a,s,o;return pe(this,function(l){if(t=JSON.parse(this.LS.getItem(this.keys.info)),t==null)throw new Error("In local storage, there is no model with name '"+this.modelPath+"'");if(t.modelTopologyType!=="JSON")throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");if(e={},i=JSON.parse(this.LS.getItem(this.keys.topology)),i==null)throw new Error("In local storage, the topology of model '"+this.modelPath+"' is missing.");if(e.modelTopology=i,r=JSON.parse(this.LS.getItem(this.keys.weightSpecs)),r==null)throw new Error("In local storage, the weight specs of model '"+this.modelPath+"' are missing.");if(e.weightSpecs=r,a=this.LS.getItem(this.keys.modelMetadata),a!=null&&(s=JSON.parse(a),e.format=s.format,e.generatedBy=s.generatedBy,e.convertedBy=s.convertedBy,e.userDefinedMetadata=s.userDefinedMetadata),o=this.LS.getItem(this.keys.weightData),o==null)throw new Error("In local storage, the binary weight values of model "+("'"+this.modelPath+"' are missing."));return e.weightData=TA(o),[2,e]})})},n.URL_SCHEME="localstorage://",n}(),jm=function(n){return He().getBool("IS_BROWSER")&&(!Array.isArray(n)&&n.startsWith(_r.URL_SCHEME))?HA(n.slice(_r.URL_SCHEME.length)):null};nn.registerSaveRouter(jm);nn.registerLoadRouter(jm);function HA(n){return new _r(n)}var VA=function(){function n(){E(He().getBool("IS_BROWSER"),function(){return"Current environment is not a web browser"}),E(typeof window=="undefined"||typeof window.localStorage!="undefined",function(){return"Current browser does not appear to support localStorage"}),this.LS=window.localStorage}return n.prototype.listModels=function(){return de(this,void 0,void 0,function(){var t,e,i,r,a,s;return pe(this,function(o){for(t={},e=Pr+ei,i=ei+Gm,r=0;r<this.LS.length;++r)a=this.LS.key(r),a.startsWith(e)&&a.endsWith(i)&&(s=_A(a),t[s]=JSON.parse(this.LS.getItem(a)));return[2,t]})})},n.prototype.removeModel=function(t){return de(this,void 0,void 0,function(){var e,i;return pe(this,function(r){if(t=MA(t),e=Ym(t),this.LS.getItem(e.info)==null)throw new Error("Cannot find model at path '"+t+"'");return i=JSON.parse(this.LS.getItem(e.info)),this.LS.removeItem(e.info),this.LS.removeItem(e.topology),this.LS.removeItem(e.weightSpecs),this.LS.removeItem(e.weightData),[2,i]})})},n}();var Mr="://",bi=function(){function n(){this.managers={}}return n.getInstance=function(){return n.instance==null&&(n.instance=new n),n.instance},n.registerManager=function(t,e){E(t!=null,function(){return"scheme must not be undefined or null."}),t.endsWith(Mr)&&(t=t.slice(0,t.indexOf(Mr))),E(t.length>0,function(){return"scheme must not be an empty string."});var i=n.getInstance();E(i.managers[t]==null,function(){return"A model store manager is already registered for scheme '"+t+"'."}),i.managers[t]=e},n.getManager=function(t){var e=this.getInstance().managers[t];if(e==null)throw new Error("Cannot find model manager for scheme '"+t+"'");return e},n.getSchemes=function(){return Object.keys(this.getInstance().managers)},n}();function Gs(n){if(n.indexOf(Mr)===-1)throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+(""+bi.getSchemes().join(",")));return{scheme:n.split(Mr)[0],path:n.split(Mr)[1]}}function Km(n,t,e){return e===void 0&&(e=!1),de(this,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h;return pe(this,function(d){switch(d.label){case 0:return E(n!==t,function(){return"Old path and new path are the same: '"+n+"'"}),i=nn.getLoadHandlers(n),E(i.length>0,function(){return"Copying failed because no load handler is found for source URL "+n+"."}),E(i.length<2,function(){return"Copying failed because more than one ("+i.length+") "+("load handlers for source URL "+n+".")}),r=i[0],a=nn.getSaveHandlers(t),E(a.length>0,function(){return"Copying failed because no save handler is found for destination "+("URL "+t+".")}),E(a.length<2,function(){return"Copying failed because more than one ("+i.length+") "+("save handlers for destination URL "+t+".")}),s=a[0],o=Gs(n).scheme,l=Gs(n).path,u=o===Gs(n).scheme,[4,r.load()];case 1:return c=d.sent(),e&&u?[4,bi.getManager(o).removeModel(l)]:[3,3];case 2:d.sent(),d.label=3;case 3:return[4,s.save(c)];case 4:return h=d.sent(),e&&!u?[4,bi.getManager(o).removeModel(l)]:[3,6];case 5:d.sent(),d.label=6;case 6:return[2,h.modelArtifactsInfo]}})})}function qA(){return de(this,void 0,void 0,function(){var n,t,e,i,r,a,s,o;return pe(this,function(l){switch(l.label){case 0:n=bi.getSchemes(),t={},e=0,i=n,l.label=1;case 1:return e<i.length?(r=i[e],[4,bi.getManager(r).listModels()]):[3,4];case 2:a=l.sent();for(s in a)o=r+Mr+s,t[o]=a[s];l.label=3;case 3:return e++,[3,1];case 4:return[2,t]}})})}function GA(n){return de(this,void 0,void 0,function(){var t,e;return pe(this,function(i){return t=Gs(n),e=bi.getManager(t.scheme),[2,e.removeModel(t.path)]})})}function YA(n,t){return de(this,void 0,void 0,function(){var e;return pe(this,function(i){return e=!1,[2,Km(n,t,e)]})})}function jA(n,t){return de(this,void 0,void 0,function(){var e;return pe(this,function(i){return e=!0,[2,Km(n,t,e)]})})}var KA=function(){function n(){}return n.prototype.fetch=function(t,e){return fetch(t,e)},n.prototype.now=function(){return performance.now()},n.prototype.encode=function(t,e){if(e!=="utf-8"&&e!=="utf8")throw new Error("Browser's encoder only supports utf-8, but got "+e);return this.textEncoder==null&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(t)},n.prototype.decode=function(t,e){return new TextDecoder(e).decode(t)},n}();if(He().get("IS_BROWSER")){He().setPlatform("browser",new KA);try{bi.registerManager(_r.URL_SCHEME,new VA)}catch(n){}try{bi.registerManager(zr.URL_SCHEME,new WA)}catch(n){}}var $A={importFetch:function(){return ff()}},_c,XA=function(){function n(){this.util=require("util"),this.textEncoder=new this.util.TextEncoder}return n.prototype.fetch=function(t,e){return He().global.fetch!=null?He().global.fetch(t,e):(_c==null&&(_c=$A.importFetch()),_c(t,e))},n.prototype.now=function(){var t=process.hrtime();return t[0]*1e3+t[1]/1e6},n.prototype.encode=function(t,e){if(e!=="utf-8"&&e!=="utf8")throw new Error("Node built-in encoder only supports utf-8, but got "+e);return this.textEncoder.encode(t)},n.prototype.decode=function(t,e){return t.length===0?"":new this.util.TextDecoder(e).decode(t)},n}();He().get("IS_NODE")&&He().setPlatform("node",new XA);function Wn(n,t,e){return t===void 0&&(t="float32"),t=t||"float32",Nc(n),new Hs(n,t,e)}function JA(n,t){var e=O(n,"x","cast");if(!Im(t))throw new Error("Failed to cast to unknown dtype "+t);if(t==="string"&&e.dtype!=="string"||t!=="string"&&e.dtype==="string")throw new Error("Only strings can be casted to strings");var i={x:e},r={dtype:t};return z.runKernelFunc(function(a){return a.cast(e,t)},i,null,Ws,r)}var ue=U({cast_:JA});function ZA(n){var t=O(n,"x","clone",null),e=function(){return z.makeTensorFromDataId(t.dataId,t.shape,t.dtype)},i={x:t};return z.runKernelFunc(e,i,null,gu)}var $i=U({clone_:ZA});function $m(n,t){t===void 0&&(t=!1),console.log(n.toString(t))}Wm();var QA={buffer:Wn,cast:ue,clone:$i,print:$m};lA(QA);var eT="model",tT=".json",nT=".weights.bin";function Xm(n){return new Promise(function(t){return setTimeout(t)}).then(n)}var Mc=function(){function n(t){if(!He().getBool("IS_BROWSER"))throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");t.startsWith(n.URL_SCHEME)&&(t=t.slice(n.URL_SCHEME.length)),(t==null||t.length===0)&&(t=eT),this.modelTopologyFileName=t+tT,this.weightDataFileName=t+nT}return n.prototype.save=function(t){return de(this,void 0,void 0,function(){var e,i,r,a,s,o;return pe(this,function(l){switch(l.label){case 0:if(typeof document=="undefined")throw new Error("Browser downloads are not supported in this environment since `document` is not present");if(e=window.URL.createObjectURL(new Blob([t.weightData],{type:"application/octet-stream"})),!(t.modelTopology instanceof ArrayBuffer))return[3,1];throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");case 1:return i=[{paths:["./"+this.weightDataFileName],weights:t.weightSpecs}],r={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,weightsManifest:i},a=window.URL.createObjectURL(new Blob([JSON.stringify(r)],{type:"application/json"})),s=this.jsonAnchor==null?document.createElement("a"):this.jsonAnchor,s.download=this.modelTopologyFileName,s.href=a,[4,Xm(function(){return s.dispatchEvent(new MouseEvent("click"))})];case 2:return l.sent(),t.weightData!=null?(o=this.weightDataAnchor==null?document.createElement("a"):this.weightDataAnchor,o.download=this.weightDataFileName,o.href=e,[4,Xm(function(){return o.dispatchEvent(new MouseEvent("click"))})]):[3,4];case 3:l.sent(),l.label=4;case 4:return[2,{modelArtifactsInfo:Pa(t)}]}})})},n.URL_SCHEME="downloads://",n}(),iT=function(){function n(t){if(t==null||t.length<1)throw new Error("When calling browserFiles, at least 1 file is required, "+("but received "+t));this.files=t}return n.prototype.load=function(){return de(this,void 0,void 0,function(){var t,e,i=this;return pe(this,function(r){return t=this.files[0],e=this.files.slice(1),[2,new Promise(function(a,s){var o=new FileReader;o.onload=function(l){var u=JSON.parse(l.target.result),c=u.modelTopology;if(c==null){s(new Error("modelTopology field is missing from file "+t.name));return}e.length===0&&a({modelTopology:c});var h=u.weightsManifest;if(h==null){s(new Error("weightManifest field is missing from file "+t.name));return}var d;try{d=i.checkManifestAndWeightFiles(h,e)}catch(g){s(g);return}var p=[],f=[],m=[];h.forEach(function(g){g.paths.forEach(function(v){f.push(v),m.push(null)}),p.push.apply(p,g.weights)}),h.forEach(function(g){g.paths.forEach(function(v){var b=new FileReader;b.onload=function(w){var S=w.target.result,L=f.indexOf(v);m[L]=S,m.indexOf(null)===-1&&a({modelTopology:c,weightSpecs:p,weightData:Uc(m),format:u.format,generatedBy:u.generatedBy,convertedBy:u.convertedBy,userDefinedMetadata:u.userDefinedMetadata})},b.onerror=function(w){return s("Failed to weights data from file of path '"+v+"'.")},b.readAsArrayBuffer(d[v])})})},o.onerror=function(l){return s("Failed to read model topology and weights manifest JSON "+("from file '"+t.name+"'. BrowserFiles supports loading ")+"Keras-style tf.Model artifacts only.")},o.readAsText(t)})]})})},n.prototype.checkManifestAndWeightFiles=function(t,e){for(var i=[],r=e.map(function(u){return Hm(u.name)}),a={},s=0,o=t;s<o.length;s++){var l=o[s];l.paths.forEach(function(u){var c=Hm(u);if(i.indexOf(c)!==-1)throw new Error("Duplicate file basename found in weights manifest: "+("'"+c+"'"));if(i.push(c),r.indexOf(c)===-1)throw new Error("Weight file with basename '"+c+"' is not provided.");a[u]=e[r.indexOf(c)]})}if(i.length!==e.length)throw new Error("Mismatch in the number of files in weights manifest "+("("+i.length+") and the number of weight files provided ")+("("+e.length+")."));return a},n}(),aT=function(n){return He().getBool("IS_BROWSER")&&(!Array.isArray(n)&&n.startsWith(Mc.URL_SCHEME))?rT(n.slice(Mc.URL_SCHEME.length)):null};nn.registerSaveRouter(aT);function rT(n){return n===void 0&&(n="model"),new Mc(n)}function sT(n){return new iT(n)}function Jm(n,t,e,i){s(n),e=e??0,i=i??1,o(e,i);var r=0,a=function(l){return l.then(function(u){var c=e+ ++r/n.length*(i-e);return t(c),u}),l};function s(l){E(l!=null&&Array.isArray(l)&&l.length>0,function(){return"promises must be a none empty array"})}function o(l,u){E(l>=0&&l<=1,function(){return"Progress fraction must be in range [0, 1], but "+("got startFraction "+l)}),E(u>=0&&u<=1,function(){return"Progress fraction must be in range [0, 1], but "+("got endFraction "+u)}),E(u>=l,function(){return"startFraction must be no more than endFraction, but "+("got startFraction "+l+" and endFraction ")+(""+u)})}return Promise.all(n.map(a))}function Zm(n,t){return de(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u,c,h,d;return pe(this,function(p){switch(p.label){case 0:return t==null&&(t={}),e=t.fetchFunc==null?He().platform.fetch:t.fetchFunc,i=n.map(function(f){return e(f,t.requestInit,{isBinary:!0})}),r=0,a=.5,t.onProgress==null?[4,Promise.all(i)]:[3,2];case 1:return o=p.sent(),[3,4];case 2:return[4,Jm(i,t.onProgress,r,a)];case 3:o=p.sent(),p.label=4;case 4:return s=o,l=s.map(function(f){return f.arrayBuffer()}),u=.5,c=1,t.onProgress==null?[4,Promise.all(l)]:[3,6];case 5:return d=p.sent(),[3,8];case 6:return[4,Jm(l,t.onProgress,u,c)];case 7:d=p.sent(),p.label=8;case 8:return h=d,[2,h]}})})}function oT(n,t,e,i){return t===void 0&&(t=""),de(this,void 0,void 0,function(){var r,a;return pe(this,function(s){return r=function(o){return Zm(o,{requestInit:i})},a=Qm(r),[2,a(n,t,e)]})})}function Qm(n){var t=this;return function(e,i,r){return i===void 0&&(i=""),de(t,void 0,void 0,function(){var a,s,o,l,u,c,h,d,p,f;return pe(this,function(m){switch(m.label){case 0:if(a=e.map(function(){return!1}),s={},o=r!=null?r.map(function(){return!1}):[],l=[],e.forEach(function(g,v){var b=0;g.weights.forEach(function(w){var S="quantization"in w?w.quantization.dtype:w.dtype,L=Fc[S]*ot(w.shape),N=function(){a[v]=!0,s[v]==null&&(s[v]=[]),s[v].push({manifestEntry:w,groupOffset:b,sizeBytes:L})};r!=null?r.forEach(function(C,R){C===w.name&&(N(),o[R]=!0)}):N(),l.push(w.name),b+=L})}),!o.every(function(g){return g}))throw u=r.filter(function(g,v){return!o[v]}),new Error("Could not find weights in manifest with names: "+(u.join(", ")+`.
|
|
`)+"Manifest JSON has weights with names: "+(l.join(", ")+"."));return c=a.reduce(function(g,v,b){return v&&g.push(b),g},[]),h=[],c.forEach(function(g){e[g].paths.forEach(function(v){var b=i+(i.endsWith("/")?"":"/")+v;h.push(b)})}),[4,n(h)];case 1:return d=m.sent(),p={},f=0,c.forEach(function(g){for(var v=e[g].paths.length,b=0,w=0;w<v;w++)b+=d[f+w].byteLength;for(var S=new ArrayBuffer(b),L=new Uint8Array(S),N=0,C=0;C<v;C++){var R=new Uint8Array(d[f+C]);L.set(R,N),N+=R.byteLength}var D=s[g];D.forEach(function(k){var W=S.slice(k.groupOffset,k.groupOffset+k.sizeBytes),F=_m(W,[k.manifestEntry]);for(var P in F)p[P]=F[P]}),f+=v}),[2,p]}})})}}var lT="application/octet-stream",uT="application/json",eg=function(){function n(t,e){if(this.DEFAULT_METHOD="POST",e==null&&(e={}),this.weightPathPrefix=e.weightPathPrefix,this.onProgress=e.onProgress,this.weightUrlConverter=e.weightUrlConverter,e.fetchFunc!=null?(E(typeof e.fetchFunc=="function",function(){return"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"}),this.fetch=e.fetchFunc):this.fetch=He().platform.fetch,E(t!=null&&t.length>0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(t)&&E(t.length===2,function(){return"URL paths for http must have a length of 2, "+("(actual length is "+t.length+").")}),this.path=t,e.requestInit!=null&&e.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=e.requestInit||{}}return n.prototype.save=function(t){return de(this,void 0,void 0,function(){var e,i,r,a;return pe(this,function(s){switch(s.label){case 0:if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return e=Object.assign({method:this.DEFAULT_METHOD},this.requestInit),e.body=new FormData,i=[{paths:["./model.weights.bin"],weights:t.weightSpecs}],r={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,userDefinedMetadata:t.userDefinedMetadata,weightsManifest:i},e.body.append("model.json",new Blob([JSON.stringify(r)],{type:uT}),"model.json"),t.weightData!=null&&e.body.append("model.weights.bin",new Blob([t.weightData],{type:lT}),"model.weights.bin"),[4,this.fetch(this.path,e)];case 1:if(a=s.sent(),a.ok)return[2,{modelArtifactsInfo:Pa(t),responses:[a]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+(a.status+"."))}})})},n.prototype.load=function(){return de(this,void 0,void 0,function(){var t,e,i,r,a,s,o,l,u,c,h,d,p,f,m;return pe(this,function(g){switch(g.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(t=g.sent(),!t.ok)throw new Error("Request to "+this.path+" failed with status code "+(t.status+". Please verify this URL points to ")+"the model JSON of the model to load.");g.label=2;case 2:return g.trys.push([2,4,,5]),[4,t.json()];case 3:return e=g.sent(),[3,5];case 4:throw i=g.sent(),r="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?r+=" 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.":r+=" Please make sure the server is serving valid JSON for this request.",new Error(r);case 5:if(a=e.modelTopology,s=e.weightsManifest,o=e.generatedBy,l=e.convertedBy,u=e.format,c=e.userDefinedMetadata,a==null&&s==null)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return s!=null?[4,this.loadWeights(s)]:[3,7];case 6:p=g.sent(),h=p[0],d=p[1],g.label=7;case 7:return f={modelTopology:a,weightSpecs:h,weightData:d,userDefinedMetadata:c,generatedBy:o,convertedBy:l,format:u},m=e.modelInitializer,m&&(f.modelInitializer=m),[2,f]}})})},n.prototype.loadWeights=function(t){return de(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u,c,h,d,p,f,m,g,v,b,w,S,L,N;return pe(this,function(C){switch(C.label){case 0:for(e=Array.isArray(this.path)?this.path[1]:this.path,i=cT(e),r=i[0],a=i[1],s=this.weightPathPrefix||r,o=[],l=0,u=t;l<u.length;l++)c=u[l],o.push.apply(o,c.weights);for(h=[],d=[],p=0,f=t;p<f.length;p++)for(m=f[p],g=0,v=m.paths;g<v.length;g++)b=v[g],this.weightUrlConverter!=null?d.push(this.weightUrlConverter(b)):h.push(s+b+a);return this.weightUrlConverter?(S=(w=h.push).apply,L=[h],[4,Promise.all(d)]):[3,2];case 1:S.apply(w,L.concat([C.sent()])),C.label=2;case 2:return[4,Zm(h,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress})];case 3:return N=C.sent(),[2,[o,Uc(N)]]}})})},n.URL_SCHEME_REGEX=/^https?:\/\//,n}();function cT(n){var t=n.lastIndexOf("/"),e=n.lastIndexOf("?"),i=n.substring(0,t),r=e>t?n.substring(e):"";return[i+"/",r]}function Hc(n){return n.match(eg.URL_SCHEME_REGEX)!=null}var tg=function(n,t){if(typeof fetch=="undefined"&&(t==null||t.fetchFunc==null))return null;var e=!0;return Array.isArray(n)?e=n.every(function(i){return Hc(i)}):e=Hc(n),e?Vc(n,t):null};nn.registerSaveRouter(tg);nn.registerLoadRouter(tg);function Vc(n,t){return new eg(n,t)}function hT(n,t){return Vc(n,t)}var qc=function(){function n(t){this.modelArtifacts=t}return n.prototype.load=function(){return de(this,void 0,void 0,function(){return pe(this,function(t){return[2,this.modelArtifacts]})})},n}(),dT=function(){function n(t){this.saveHandler=t}return n.prototype.save=function(t){return de(this,void 0,void 0,function(){return pe(this,function(e){return[2,this.saveHandler(t)]})})},n}();function pT(n,t,e,i){if(arguments.length===1){var r=n.modelTopology!=null||n.weightSpecs!=null;return r?new qc(n):(console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new qc({modelTopology:n}))}else return console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new qc({modelTopology:n,weightSpecs:t,weightData:e,trainingConfig:i})}function fT(n){return new dT(n)}var mT={__proto__:null,browserFiles:sT,browserHTTPRequest:hT,concatenateArrayBuffers:Uc,decodeWeights:_m,encodeWeights:LA,fromMemory:pT,getLoadHandlers:DA,getModelArtifactsInfoForJSON:Pa,getSaveHandlers:EA,http:Vc,isHTTPScheme:Hc,loadWeights:oT,registerLoadRouter:OA,registerSaveRouter:RA,weightsLoaderFactory:Qm,withSaveHandler:fT,copyModel:YA,listModels:qA,moveModel:jA,removeModel:GA};function gT(n,t){var e=O(n,"x","reshape",null),i={x:e},r={shape:t},a=function(s,o){return t=bm(t,e.size),E(e.size===ot(t),function(){return"new shape and old shape must have the same number of elements."}),o([e]),s.reshape(e,t)};return z.runKernelFunc(a,i,null,_u,r)}var V=U({reshape_:gT});function vT(n,t,e,i){var r;e===void 0&&(e=!1),i===void 0&&(i=!1);var a=O(n,"a","matMul"),s=O(t,"b","matMul");r=at(a,s),a=r[0],s=r[1],E(a.rank>=2&&s.rank>=2&&a.rank===s.rank,function(){return"Error in matMul: inputs must have the same rank of at least 2, "+("got ranks "+a.rank+" and "+s.rank+".")});var o=e?a.shape[a.rank-2]:a.shape[a.rank-1],l=i?s.shape[s.rank-1]:s.shape[s.rank-2],u=e?a.shape[a.rank-1]:a.shape[a.rank-2],c=i?s.shape[s.rank-2]:s.shape[s.rank-1],h=a.shape.slice(0,-2),d=s.shape.slice(0,-2),p=ot(h),f=ot(d);E(dn(h,d),function(){return"Error in matMul: outer dimensions ("+h+") and ("+(d+") of Tensors with shapes "+a.shape+" and ")+(s.shape+" must match.")}),E(o===l,function(){return"Error in matMul: inner shapes ("+o+") and ("+(l+") of Tensors with shapes "+a.shape+" and ")+(s.shape+" and transposeA="+e)+(" and transposeB="+i+" must match.")});var m=a.shape.slice(0,-2).concat([u,c]),g=e?V(a,[p,o,u]):V(a,[p,u,o]),v=i?V(s,[f,c,l]):V(s,[f,l,c]),b=function(N,C){return C([g,v]),N.batchMatMul(g,v,e,i)},w={a:g,b:v},S={transposeA:e,transposeB:i},L=z.runKernelFunc(b,w,null,Yl,S);return V(L,m)}var We=U({matMul_:vT});function yT(n,t,e,i){if(e===void 0&&(e=1),i===void 0&&(i=0),t<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+t);var r=O(n,"indices","oneHot","int32"),a=r.shape.concat([t]),s=function(u,c){return c([r]),V(u.oneHot(V(r,[r.size]),t,e,i),a)},o={indices:r},l={depth:t,onValue:e,offValue:i};return z.runKernelFunc(s,o,null,Fu,l)}var Ys=U({oneHot_:yT});function bT(n,t){var e=O(n,"x","transpose");if(t==null&&(t=e.shape.map(function(a,s){return s}).reverse()),E(e.rank===t.length,function(){return"Error in transpose: rank of input "+e.rank+" "+("must match length of perm "+t+".")}),t.forEach(function(a){E(a>=0&&a<e.rank,function(){return"All entries in 'perm' must be between 0 and "+(e.rank-1)+(" but got "+t)})}),e.rank<=1)return e.clone();var i={x:e},r={perm:t};return z.runKernelFunc(function(a){return a.transpose(e,t)},i,null,hc,r)}var ut=U({transpose_:bT});function wT(n,t,e){var i=O(n,"labels","confusionMatrix"),r=O(t,"predictions","confusionMatrix");E(e==null||e>0&&Number.isInteger(e),function(){return"If provided, numClasses must be a positive integer, "+("but got "+e)}),E(i.rank===1,function(){return"Expected the rank of labels to be 1, but got "+i.rank}),E(r.rank===1,function(){return"Expected the rank of predictions to be 1, "+("but got "+r.rank)}),E(i.shape[0]===r.shape[0],function(){return"Mismatch in the number of examples: "+(i.shape[0]+" vs. "+r.shape[0]+". ")+"Labels and predictions should have the same number of elements."}),E(e>0&&Number.isInteger(e),function(){return"numClasses is required to be a positive integer, but got "+(""+e)});var a=Ys(ue(i,"int32"),e),s=Ys(ue(r,"int32"),e),o=ut(a);return ue(We(o,s),"int32")}var ST=U({confusionMatrix_:wT});var LT={__proto__:null,confusionMatrix:ST};function ng(n,t,e){if(Yi(n),t!=null&&t.length!==3)throw new Error("tensor3d() requires shape to have three numbers");var i=Fn(n,e);if(i.length!==3&&i.length!==1)throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");if(i.length===1&&t==null)throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");return gi(n,t,i,e)}var Hr;function IT(n,t){if(t===void 0&&(t=3),t>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(n==null)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var e=!1,i=!1,r=!1,a=!1,s=!1;if(n.data instanceof Uint8Array)e=!0;else if(typeof ImageData!="undefined"&&n instanceof ImageData)i=!0;else if(typeof HTMLVideoElement!="undefined"&&n instanceof HTMLVideoElement)r=!0;else if(typeof HTMLImageElement!="undefined"&&n instanceof HTMLImageElement)a=!0;else if(n.getContext!=null)s=!0;else throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, "+("but was "+n.constructor.name));if(r){var o=2;if(r&&n.readyState<o)throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.")}var l=Sc(gc,z.backendName);if(l!=null){var u={pixels:n},c={numChannels:t};return z.runKernel(gc,u,c)}var h=r?[n.videoWidth,n.videoHeight]:[n.width,n.height],d=h[0],p=h[1],f;s?f=n.getContext("2d").getImageData(0,0,d,p).data:i||e?f=n.data:(a||r)&&(Hr==null&&(Hr=document.createElement("canvas").getContext("2d")),Hr.canvas.width=d,Hr.canvas.height=p,Hr.drawImage(n,0,0,d,p),f=Hr.getImageData(0,0,d,p).data);var m;if(t===4)m=new Int32Array(f);else{var g=d*p;m=new Int32Array(g*t);for(var v=0;v<g;v++)for(var b=0;b<t;++b)m[v*t+b]=f[v*4+b]}var w=[p,d,t];return ng(m,w,"int32")}function AT(n,t){return de(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u,c,h,d,p,f,m,g,v;return pe(this,function(b){switch(b.label){case 0:if(e=O(n,"img","toPixels"),n instanceof Y||(i=e,e=ue(i,"int32"),i.dispose()),e.rank!==2&&e.rank!==3)throw new Error("toPixels only supports rank 2 or 3 tensors, got rank "+e.rank+".");if(r=e.shape.slice(0,2),a=r[0],s=r[1],o=e.rank===2?1:e.shape[2],o>4||o===2)throw new Error("toPixels only supports depth of size "+("1, 3 or 4 but got "+o));if(e.dtype!=="float32"&&e.dtype!=="int32")throw new Error("Unsupported type for toPixels: "+e.dtype+". Please use float32 or int32 tensors.");return[4,e.data()];case 1:for(l=b.sent(),u=e.dtype==="float32"?255:1,c=new Uint8ClampedArray(s*a*4),h=0;h<a*s;++h){for(d=[0,0,0,255],p=0;p<o;p++){if(f=l[h*o+p],e.dtype==="float32"){if(f<0||f>1)throw new Error("Tensor values for a float32 Tensor must be in the "+("range [0 - 1] but encountered "+f+"."))}else if(e.dtype==="int32"&&(f<0||f>255))throw new Error("Tensor values for a int32 Tensor must be in the "+("range [0 - 255] but encountered "+f+"."));o===1?(d[0]=f*u,d[1]=f*u,d[2]=f*u):d[p]=f*u}m=h*4,c[m+0]=Math.round(d[0]),c[m+1]=Math.round(d[1]),c[m+2]=Math.round(d[2]),c[m+3]=Math.round(d[3])}return t!=null&&(t.width=s,t.height=a,g=t.getContext("2d"),v=new ImageData(c,s,a),g.putImageData(v,0,0)),e!==n&&e.dispose(),[2,c]}})})}var TT=U({fromPixels_:IT}),NT={__proto__:null,toPixels:AT,fromPixels:TT};function ig(n,t){if(n.rank<1)throw new Error("tf.gatherND() expects the input to be rank 1 or higher,"+(" but the rank was "+n.rank+"."));if(t.rank<1)throw new Error("tf.gatherND() expects the indices to be rank 1 or higher,"+(" but the rank was "+t.rank+"."));if(t.dtype!=="int32")throw new Error("tf.gatherND() expects the indices to be int32 type,"+(" but the dtype was "+t.dtype+"."));if(t.shape[t.rank-1]>n.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+(t.shape[t.rank-1]+" vs. "+n.rank));if(n.size===0)throw new Error("Requested more than 0 entries, but input is empty."+(" Input shape: "+n.shape+"."));for(var e=t.shape,i=e[e.length-1],r=1,a=0;a<e.length-1;++a)r*=e[a];var s=n.shape,o=e.slice();o.pop();for(var l=1,a=i;a<n.rank;++a)l*=s[a],o.push(s[a]);var u=Fr(n.shape).map(function(c){return c/l}).concat([1]).slice(0,i);return[o,r,l,u]}var xT={__proto__:null,prepareAndValidate:ig};function Gc(n,t,e){var i=t.rank>1?t.shape[t.rank-1]:1,r=t.rank>1?t.rank-1:1,a="Must have updates.shape = indices.shape[:batchDim] + "+("shape[sliceDim:], got updates.shape: "+e.shape)+(", indices.shape: "+t.shape+", shape: "+n)+(", sliceDim: "+i+", and batchDim: "+r+".");if(e.rank<r)throw new Error(a+(" update.rank < "+r+". "));if(n.length<i+(e.rank-r))throw new Error(a+(" Output shape length < "+(i+(e.rank-r))));if(e.rank!==r+n.length-i)throw new Error(a+(" update.rank != "+(r+n.length-i)));for(var s=0;s<r;++s)if(e.shape[s]!==t.shape[s])throw new Error(a+(" updates.shape["+s+"] ("+e.shape[s]+") != indices.shape["+s+"] ("+t.shape[s]+")."));for(var s=0;s<e.rank-r;++s)if(e.shape[s+r]!==n[s+i])throw new Error(a+(" updates.shape["+(s+r)+"] ("+e.shape[s+r]+") != shape["+(s+r)+"] ("+n[s+r]+")"))}function Yc(n,t,e){if(t.rank<1)throw new Error("tf.scatterND() expects the indices to be rank 1 or higher,"+(" but the rank was "+t.rank+"."));if(n.rank<1)throw new Error("tf.scatterND() expects the updates to be rank 1 or higher,"+(" but the rank was "+n.rank+"."));if(t.dtype!=="int32")throw new Error("The dtype of 'indices' should be int32, but got dtype: "+t.dtype);if(e.length<1)throw new Error("Output rank must be greater or equal to 1, but got shape: "+e);if(e.length===0){if(t.size===0)throw new Error("Indices specified for empty output. indices shape: "+t.shape);if(n.size===0)throw new Error("Updates specified for empty output. updates shape: "+n.shape)}Gc(e,t,n)}function rg(n,t,e){for(var i=t.shape.length,r=i>1?t.shape[i-1]:1,a=e.length,s=1,o=r;o<a;++o)s*=e[o];var l=r<1?1:r,u=ot(t.shape)/l,c=Fr(e.slice(0,r)).concat([1]),h=ot(e);return{sliceRank:r,numUpdates:u,sliceSize:s,strides:c,outputSize:h}}var CT={__proto__:null,validateUpdateShape:Gc,validateInput:Yc,calculateShapes:rg};function ag(n,t,e){var i=n.shape.length;E(i===t.length,function(){return"Error in slice"+i+"D: Length of begin "+t+" must "+("match the rank of the array ("+i+").")}),E(i===e.length,function(){return"Error in slice"+i+"D: Length of size "+e+" must "+("match the rank of the array ("+i+").")});for(var r=function(s){E(t[s]+e[s]<=n.shape[s],function(){return"Error in slice"+i+"D: begin["+s+"] + size["+s+"] "+("("+(t[s]+e[s])+") would overflow input.shape["+s+"] ("+n.shape[s]+")")})},a=0;a<i;++a)r(a)}function js(n){for(var t=[],e=0;n>0;)n&1&&t.push(e),n/=2,e++;return t}function sg(n,t,e){for(var i=[],r=0;r<n.length;r++)i[r]=Math.ceil((t[r]-n[r])/e[r]);return i}function og(n,t,e,i){for(var r=n.slice(),a=r.length;a<i.length;a++)r.push(1);for(var a=0;a<e;a++)a===0?r[t]=1:(r.splice(t,0,1),r.pop());return r}function lg(n,t,e){return e<=n?e:e-(t-1)}function ug(n,t){for(var e=[],i=0;i<n;i++)e.push(t+i);return e}function mg(n,t,e,i,r,a,s,o,l){var u=n.length,c=new Array(u),h=new Array(u),d=new Array(u);if(t.length&&e>0){var p=t[0],f=e+1;c=cg(s,p,f,i,n),h=hg(o,p,f,r,n),d=og(a,p,f,n)}else for(var m=0;m<u;m++)c[m]=pg(s,i,a,n,m,l),h[m]=fg(o,r,a,n,m,l),d[m]=dg(a,m,l);return{begin:c,end:h,strides:d}}function cg(n,t,e,i,r){for(var a=r.slice(),s=ug(e,t),o=0;o<a.length;o++)if(s.indexOf(o)>-1)a[o]=0;else{var l=lg(t,e,o),u=i[l];n&1<<l&&(u=0),a[o]=u}return a}function hg(n,t,e,i,r){for(var a=r.slice(),s=ug(e,t),o=0;o<a.length;o++)if(s.indexOf(o)>-1)a[o]=Number.MAX_SAFE_INTEGER;else{var l=lg(t,e,o),u=i[l];n&1<<l&&(u=Number.MAX_SAFE_INTEGER),a[o]=u}for(var c=0;c<a.length;c++){var h=r[c];a[c]<0&&(a[c]+=h),a[c]=Da(0,a[c],r[c])}return a}function dg(n,t,e){var i=n[t];return(e&1<<t||i==null)&&(i=1),i}function pg(n,t,e,i,r,a){var s=t[r],o=e[r]||1;(n&1<<r||a&1<<r||s==null)&&(o>0?s=Number.MIN_SAFE_INTEGER:s=Number.MAX_SAFE_INTEGER);var l=i[r];return s<0&&(s+=l),s=Da(0,s,l-1),s}function fg(n,t,e,i,r,a){var s=t[r],o=e[r]||1;(n&1<<r||a&1<<r||s==null)&&(o>0?s=Number.MAX_SAFE_INTEGER:s=Number.MIN_SAFE_INTEGER);var l=i[r];return s<0&&(s+=l),o>0?s=Da(0,s,l):s=Da(-1,s,l-1),s}function RT(n,t,e){for(var i=e.length,r=0;r<e.length;r++)if(e[r]>1){i=r;break}for(var r=i+1;r<e.length;r++)if(t[r]>0||e[r]!==n[r])return!1;return!0}function OT(n,t){for(var e=n.length>0?n[n.length-1]:1,i=0;i<n.length-1;i++)e+=n[i]*t[i];return e}function jc(n,t,e){var i,r=n.shape.length;typeof t=="number"?i=[t].concat(new Array(r-1).fill(0)):t.length<r?i=t.concat(new Array(r-t.length).fill(0)):i=t.slice(),i.forEach(function(s){E(s!==-1,function(){return"slice() does not support negative begin indexing."})});var a;return e==null?a=new Array(r).fill(-1):typeof e=="number"?a=[e].concat(new Array(r-1).fill(-1)):e.length<r?a=e.concat(new Array(r-e.length).fill(-1)):a=e,a=a.map(function(s,o){return s>=0?s:(E(s===-1,function(){return"Negative size values should be exactly -1 but got "+(s+" for the slice() size at index "+o+".")}),n.shape[o]-i[o])}),[i,a]}var gg={__proto__:null,assertParamsValid:ag,maskToAxes:js,computeOutShape:sg,stridesWithElidedDims:og,getNormalizedAxes:mg,startIndicesWithElidedDims:cg,stopIndicesWithElidedDims:hg,stridesForAxis:dg,startForAxis:pg,stopForAxis:fg,isSliceContinous:RT,computeFlatOffset:OT,parseSliceParams:jc};var vg=function(){function n(){}return n.prototype.getClassName=function(){return this.constructor.className},n.fromConfig=function(t,e){return new t(e)},n}(),yg=function(){function n(){this.classNameMap={}}return n.getMap=function(){return n.instance==null&&(n.instance=new n),n.instance},n.register=function(t){n.getMap().classNameMap[t.className]=[t,t.fromConfig]},n}();function wi(n){E(n.className!=null,function(){return"Class being registered does not have the static className property defined."}),E(typeof n.className=="string",function(){return"className is required to be a string, but got type "+typeof n.className}),E(n.className.length>0,function(){return"Class being registered has an empty-string as its className, which is disallowed."}),yg.register(n)}var ET={__proto__:null,Serializable:vg,SerializationMap:yg,registerClass:wi};var DT=.001,bg=.1;function kT(n,t,e){return e==null&&(e=Kc()),$c(n,t,function(i,r){return Xc(i,r,e)})}function Kc(){return z.backend.floatPrecision()===32?DT:bg}function $c(n,t,e){var i=!0;if((Dt(n)||Dt(t))&&(i=!1),Dt(n)&&Dt(t)&&(i=!0),i){var r=n.constructor.name,a=t.constructor.name;if(r!==a)throw new Error("Arrays are of different type. Actual: "+r+". "+("Expected: "+a))}if(Array.isArray(n)&&Array.isArray(t)){var s=Fn(n),o=Fn(t);if(!dn(s,o))throw new Error("Arrays have different shapes. "+("Actual: ["+s+"]. Expected: ["+o+"]"))}var l=Dt(n)?n:ji(n),u=Dt(t)?t:ji(t);if(l.length!==u.length)throw new Error("Arrays have different lengths actual: "+l.length+" vs "+("expected: "+u.length+`.
|
|
`)+("Actual: "+l+`.
|
|
`)+("Expected: "+u+"."));for(var c=0;c<u.length;++c){var h=l[c],d=u[c];if(!e(h,d))throw new Error("Arrays differ: actual["+c+"] = "+h+", expected["+c+"] = "+d+`.
|
|
`+("Actual: "+l+`.
|
|
`)+("Expected: "+u+"."))}}function FT(n,t){n().then(function(){return t.fail()},function(){return t()})}function WT(n,t){var e=typeof t=="string"||typeof t=="number"||typeof t=="boolean"?[t]:t;return pi(n)||pi(n[0])||pi(t)||pi(t[0])?$c(n,e,function(i,r){return i==r}):$c(n,t,function(i,r){return Xc(i,r,0)})}function UT(n,t,e){if(e==null&&(e=Kc()),!Xc(n,t,e))throw new Error("Numbers differ: actual === "+n+", expected === "+t)}function Xc(n,t,e){return!isFinite(n)&&!isFinite(t)?!0:!(isNaN(n)||isNaN(t)||Math.abs(n-t)>e)}function BT(n,t,e){for(var i=0;i<n.length;i++)if(n[i]<t||n[i]>e)throw new Error("Value out of range:"+n[i]+" low: "+t+", high: "+e)}function zT(n,t){expect(new Float32Array(n)).toEqual(new Float32Array(t))}var PT={__proto__:null,TEST_EPSILON_FLOAT16:bg,expectArraysClose:kT,testEpsilon:Kc,expectPromiseToFail:FT,expectArraysEqual:WT,expectNumbersClose:UT,expectValuesInRange:BT,expectArrayBuffersEqual:zT};var _T="2.6.0";function MT(){He().set("PROD",!0)}function HT(){He().set("DEBUG",!0)}function VT(){He().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function At(n){He().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(n+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function qT(){z.disposeVariables()}function GT(){return z}function YT(){return z.memory()}function jT(n){return z.profile(n)}function mt(n,t){return z.tidy(n,t)}function Mt(n){var t=kc(n);t.forEach(function(e){return e.dispose()})}function wg(n){return z.keep(n)}function KT(n){return z.time(n)}function $T(n){return z.setBackend(n)}function XT(){return z.ready()}function JT(){return z.backendName}function ZT(n){z.removeBackend(n)}function QT(n){return z.findBackend(n)}function e1(n){return z.findBackendFactory(n)}function t1(n,t,e){return e===void 0&&(e=1),z.registerBackend(n,t,e)}function n1(){return z.backend}function i1(n,t){He().setPlatform(n,t)}function r1(n,t){var e,i=O(n,"a","add"),r=O(t,"b","add");e=at(i,r),i=e[0],r=e[1];var a=function(o,l){var u=o.add(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,Fs)}var fe=U({add_:r1});function a1(n,t){var e,i=O(n,"a","floorDiv"),r=O(t,"b","floorDiv");e=at(i,r),i=e[0],r=e[1];var a=function(o,l){var u=o.floorDiv(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,du)}var Jc=U({floorDiv_:a1});function s1(n,t){var e,i=O(n,"a","div"),r=O(t,"b","div");if(e=at(i,r),i=e[0],r=e[1],i.dtype==="int32"&&r.dtype==="int32")return Jc(i,r);var a=function(l,u){var c=l.realDivide(i,r);return u([i,r]),c},s={a:i,b:r},o={};return z.runKernelFunc(a,s,null,su,o)}var Ie=U({div_:s1});function o1(n,t){var e,i=O(n,"a","mul"),r=O(t,"b","mul");e=at(i,r),i=e[0],r=e[1];var a=function(o,l){var u=o.multiply(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,Eu)}var J=U({mul_:o1});function l1(n){var t=O(n,"x","abs"),e={x:t};return z.runKernelFunc(function(i,r){return r([t]),t.dtype==="complex64"?i.complexAbs(t):i.abs(t)},e,null,kl)}var Kt=U({abs_:l1});function u1(n){var t=O(n,"x","acos"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.acos(t);return r([t]),a},e,null,Fl)}var Sg=U({acos_:u1});function c1(n){var t=O(n,"x","acosh"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.acosh(t);return r([t]),a},e,null,Wl)}var Lg=U({acosh_:c1});function h1(n){E(Array.isArray(n),function(){return"The argument passed to tf.addN() must be a list of tensors"}),E(n.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+(""+n.length)});var t=n.map(function(a,s){return O(a,"tensors"+s,"addN")}),e=t[0];t.forEach(function(a){if(a.dtype!==e.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),t.forEach(function(a){if(!dn(a.shape,e.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var i=function(a,s){var o=a.addN(t);return s(t),o},r=t;return z.runKernelFunc(i,r,null,Ul)}var d1=U({addN_:h1});function Zc(n,t){for(var e=0;e<n.length;++e)if(n[n.length-e-1]!==t-1-e)return!1;return!0}function Ig(n,t,e){for(var i=n.length+t.length,r=[],a=0,s=0,o=0;o<i;o++)e.indexOf(o)===-1?r.push(n[a++]):r.push(t[s++]);return r}function Ag(n,t){for(var e=[],i=n.length,r=0;r<i;r++)t.indexOf(r)===-1&&e.push(n[r]);var a=t.map(function(s){return n[s]});return[e,a]}function rn(n,t){var e=t.map(function(i){return 1});return Ig(n,e,t)}function p1(n,t,e){E(Zc(t,e),function(){return n+" supports only inner-most axes for now. "+("Got axes "+t+" and rank-"+e+" input.")})}function an(n,t){if(Zc(n,t))return null;for(var e=[],i=0;i<t;++i)n.indexOf(i)===-1&&e.push(i);return n.forEach(function(r){return e.push(r)}),e}function Ks(n){return n.map(function(t,e){return[e,t]}).sort(function(t,e){return t[1]-e[1]}).map(function(t){return t[0]})}function Un(n,t){for(var e=[],i=t-n;i<t;++i)e.push(i);return e}function f1(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","all","bool"),r=function(o){var l=Qe(t,i.shape),u=l,c=an(u,i.rank);c!=null&&(i=ut(i,c),u=Un(u.length,i.rank));var h=o.all(i,u);if(e){var d=rn(h.shape,l);return V(h,d)}return h},a={x:i},s={axis:t,keepDims:e};return z.runKernelFunc(r,a,null,wf,s)}var Tg=U({all_:f1});function m1(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","any","bool"),r=function(o){var l=Qe(t,i.shape),u=l,c=an(u,i.rank);c!=null&&(i=ut(i,c),u=Un(u.length,i.rank));var h=o.any(i,u);if(e){var d=rn(h.shape,l);return V(h,d)}return h},a={x:i},s={axis:t,keepDims:e};return z.runKernelFunc(r,a,null,Sf,s)}var Ng=U({any_:m1});function g1(n,t){t===void 0&&(t=0);var e=O(n,"x","argMax"),i=function(s,o){o([e]);var l=Qe(t,e.shape),u=an(l,e.rank);return u!=null&&(e=ut(e,u),l=Un(l.length,e.rank)),s.argMax(e,l[0])},r={x:e},a={axis:t};return z.runKernelFunc(i,r,null,Bl,a)}var xg=U({argMax_:g1});function v1(n,t){t===void 0&&(t=0);var e=O(n,"x","argMin"),i=function(s,o){o([e]),t==null&&(t=0);var l=Qe(t,e.shape),u=an(l,e.rank);return u!=null&&(e=ut(e,u),l=Un(l.length,e.rank)),s.argMin(e,l[0])},r={x:e},a={axis:t};return z.runKernelFunc(i,r,null,zl,a)}var Cg=U({argMin_:v1});function y1(n){var t=O(n,"x","asin"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.asin(t);return r([t]),a},e,null,Pl)}var Rg=U({asin_:y1});function b1(n){var t=O(n,"x","asinh"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.asinh(t);return r([t]),a},e,null,_l)}var Og=U({asinh_:b1});function w1(n){var t=O(n,"x","atan"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.atan(t);return r([t]),a},e,null,Ml)}var Eg=U({atan_:w1});function S1(n,t){var e,i=O(n,"a","atan2"),r=O(t,"b","atan2");e=at(i,r),i=e[0],r=e[1];var a=function(o,l){var u=o.atan2(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,Vl)}var Dg=U({atan2_:S1});function L1(n){var t=O(n,"x","atanh"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.atanh(t);return r([t]),a},e,null,Hl)}var kg=U({atanh_:L1});function I1(n,t,e,i,r,a){r===void 0&&(r="NHWC");var s=n[3],o=t.concat([s]),l=_a(r);return Bn(n,o,e,a,i,null,null,l)}function Vr(n,t,e,i,r,a,s){s===void 0&&(s="channelsLast");var o=$s(t),l=o[0],u=o[1],c;if(s==="channelsLast")c=[l,u,n[3],n[3]];else if(s==="channelsFirst")c=[l,u,n[1],n[1]];else throw new Error("Unknown dataFormat "+s);return Bn(n,c,e,i,r,a,!1,s)}function Ha(n,t,e,i,r,a,s){s===void 0&&(s="NDHWC");var o=Qc(t),l=o[0],u=o[1],c=o[2],h,d;if(s==="NDHWC")d="channelsLast",h=[l,u,c,n[4],n[4]];else if(s==="NCDHW")d="channelsFirst",h=[l,u,c,n[1],n[1]];else throw new Error("Unknown dataFormat "+s);return Ma(n,h,e,i,r,!1,d,a)}function Bn(n,t,e,i,r,a,s,o){s===void 0&&(s=!1),o===void 0&&(o="channelsLast");var l=[-1,-1,-1,-1],u=l[0],c=l[1],h=l[2],d=l[3];if(o==="channelsLast")u=n[0],c=n[1],h=n[2],d=n[3];else if(o==="channelsFirst")u=n[0],d=n[1],c=n[2],h=n[3];else throw new Error("Unknown dataFormat "+o);var p=t[0],f=t[1],m=t[3],g=$s(e),v=g[0],b=g[1],w=$s(i),S=w[0],L=w[1],N=qr(p,S),C=qr(f,L),R=A1(r,c,h,v,b,N,C,a,o),D=R.padInfo,k=R.outHeight,W=R.outWidth,F=s?m*d:m,P;return o==="channelsFirst"?P=[u,F,k,W]:o==="channelsLast"&&(P=[u,k,W,F]),{batchSize:u,dataFormat:o,inHeight:c,inWidth:h,inChannels:d,outHeight:k,outWidth:W,outChannels:F,padInfo:D,strideHeight:v,strideWidth:b,filterHeight:p,filterWidth:f,effectiveFilterHeight:N,effectiveFilterWidth:C,dilationHeight:S,dilationWidth:L,inShape:n,outShape:P,filterShape:t}}function Ma(n,t,e,i,r,a,s,o){a===void 0&&(a=!1),s===void 0&&(s="channelsLast");var l=[-1,-1,-1,-1,-1],u=l[0],c=l[1],h=l[2],d=l[3],p=l[4];if(s==="channelsLast")u=n[0],c=n[1],h=n[2],d=n[3],p=n[4];else if(s==="channelsFirst")u=n[0],p=n[1],c=n[2],h=n[3],d=n[4];else throw new Error("Unknown dataFormat "+s);var f=t[0],m=t[1],g=t[2],v=t[4],b=Qc(e),w=b[0],S=b[1],L=b[2],N=Qc(i),C=N[0],R=N[1],D=N[2],k=qr(f,C),W=qr(m,R),F=qr(g,D),P=T1(r,c,h,d,w,S,L,k,W,F,o),H=P.padInfo,_=P.outDepth,j=P.outHeight,K=P.outWidth,q=a?v*p:v,G;return s==="channelsFirst"?G=[u,q,_,j,K]:s==="channelsLast"&&(G=[u,_,j,K,q]),{batchSize:u,dataFormat:s,inDepth:c,inHeight:h,inWidth:d,inChannels:p,outDepth:_,outHeight:j,outWidth:K,outChannels:q,padInfo:H,strideDepth:w,strideHeight:S,strideWidth:L,filterDepth:f,filterHeight:m,filterWidth:g,effectiveFilterDepth:k,effectiveFilterHeight:W,effectiveFilterWidth:F,dilationDepth:C,dilationHeight:R,dilationWidth:D,inShape:n,outShape:G,filterShape:t}}function N1(n,t,e,i,r){i==null&&(i=eh(n,t,e));var a=n[0],s=n[1],o=Xi((a-t+2*i)/e+1,r);E(rt(o),function(){return"The output # of rows ("+o+") must be an integer. Change the stride and/or zero pad parameters"});var l=Xi((s-t+2*i)/e+1,r);return E(rt(l),function(){return"The output # of columns ("+l+") must be an integer. Change the stride and/or zero pad parameters"}),[o,l]}function x1(n,t,e,i,r,a){r==null&&(r=eh(n,t,i));var s=n[0],o=n[1],l=n[2],u=Xi((s-t+2*r)/i+1,a);E(rt(u),function(){return"The output # of depths ("+u+") must be an integer. Change the stride and/or zero pad parameters"});var c=Xi((o-t+2*r)/i+1,a);E(rt(c),function(){return"The output # of rows ("+c+") must be an integer. Change the stride and/or zero pad parameters"});var h=Xi((l-t+2*r)/i+1,a);return E(rt(h),function(){return"The output # of columns ("+h+") must be an integer. Change the stride and/or zero pad parameters"}),[u,c,h,e]}function eh(n,t,e,i){i===void 0&&(i=1);var r=qr(t,i);return Math.floor((n[0]*(e-1)-e+r)/2)}function $s(n){return typeof n=="number"?[n,n,n]:n.length===2?[n[0],n[1],1]:n}function Qc(n){return typeof n=="number"?[n,n,n]:n}function qr(n,t){return t<=1?n:n+(n-1)*(t-1)}function A1(n,t,e,i,r,a,s,o,l){var u,c,h;if(typeof n=="number"){var d=n===0?"VALID":"NUMBER";u={top:n,bottom:n,left:n,right:n,type:d};var p=N1([t,e],a,i,n,o);c=p[0],h=p[1]}else if(n==="same"){c=Math.ceil(t/i),h=Math.ceil(e/r);var f=Math.max(0,(c-1)*i+a-t),m=Math.max(0,(h-1)*r+s-e),g=Math.floor(f/2),v=f-g,b=Math.floor(m/2),w=m-b;u={top:g,bottom:v,left:b,right:w,type:"SAME"}}else if(n==="valid")u={top:0,bottom:0,left:0,right:0,type:"VALID"},c=Math.ceil((t-a+1)/i),h=Math.ceil((e-s+1)/r);else if(typeof n=="object"){var S=l==="channelsLast"?n[1][0]:n[2][0],v=l==="channelsLast"?n[1][1]:n[2][1],b=l==="channelsLast"?n[2][0]:n[3][0],w=l==="channelsLast"?n[2][1]:n[3][1],d=S===0&&v===0&&b===0&&w===0?"VALID":"EXPLICIT";u={top:S,bottom:v,left:b,right:w,type:d},c=Xi((t-a+S+v)/i+1,o),h=Xi((e-s+b+w)/r+1,o)}else throw Error("Unknown padding parameter: "+n);return{padInfo:u,outHeight:c,outWidth:h}}function T1(n,t,e,i,r,a,s,o,l,u,c){var h,d,p,f;if(typeof n=="number"){var m=n===0?"VALID":"NUMBER";h={top:n,bottom:n,left:n,right:n,front:n,back:n,type:m};var g=x1([t,e,i,1],o,1,r,n,c);d=g[0],p=g[1],f=g[2]}else if(n==="same"){d=Math.ceil(t/r),p=Math.ceil(e/a),f=Math.ceil(i/s);var v=(d-1)*r+o-t,b=(p-1)*a+l-e,w=(f-1)*s+u-i,S=Math.floor(v/2),L=v-S,N=Math.floor(b/2),C=b-N,R=Math.floor(w/2),D=w-R;h={top:N,bottom:C,left:R,right:D,front:S,back:L,type:"SAME"}}else if(n==="valid")h={top:0,bottom:0,left:0,right:0,front:0,back:0,type:"VALID"},d=Math.ceil((t-o+1)/r),p=Math.ceil((e-l+1)/a),f=Math.ceil((i-u+1)/s);else throw Error("Unknown padding parameter: "+n);return{padInfo:h,outDepth:d,outHeight:p,outWidth:f}}function Xi(n,t){if(!t)return n;switch(t){case"round":return Math.round(n);case"ceil":return Math.ceil(n);case"floor":return Math.floor(n);default:throw new Error("Unknown roundingMode "+t)}}function Si(n){var t=$s(n),e=t[0],i=t[1],r=t[2];return e===1&&i===1&&r===1}function Ht(n,t){return Si(n)||Si(t)}function _a(n){if(n==="NHWC")return"channelsLast";if(n==="NCHW")return"channelsFirst";throw new Error("Unknown dataFormat "+n)}function C1(n,t,e,i,r){var a=O(n,"x","avgPool","float32"),s=1;E(Ht(e,s),function(){return"Error in avgPool: Either strides or dilations must be 1. "+("Got strides "+e+" and dilations '"+s+"'")});var o=a,l=!1;a.rank===3&&(l=!0,o=V(a,[1,a.shape[0],a.shape[1],a.shape[2]])),E(o.rank===4,function(){return"Error in avgPool: x must be rank 4 but got rank "+o.rank+"."}),r!=null&&E(rt(i),function(){return"Error in avgPool: pad must be an integer when using, "+("dimRoundingMode "+r+" but got pad "+i+".")});var u=function(p,f){var m=Vr(o.shape,t,e,1,i,r);return f([o]),m.filterWidth===1&&m.filterHeight===1&&dn(m.inShape,m.outShape)?o.clone():p.avgPool(o,m)},c={x:o},h={filterSize:t,strides:e,pad:i,dimRoundingMode:r},d=z.runKernelFunc(u,c,null,ql,h);return d=ue(d,a.dtype),l?V(d,[d.shape[1],d.shape[2],d.shape[3]]):d}var th=U({avgPool_:C1});function R1(n,t,e,i,r,a,s){a===void 0&&(a="NDHWC"),s==null?s=[1,1,1]:At("dilations is deprecated, this field will be gone in v3.0.0.");var o=O(n,"x","avgPool3d","float32"),l=o,u=!1;o.rank===4&&(u=!0,l=V(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]])),E(l.rank===5,function(){return"Error in avgPool3d: x must be rank 5 but got rank "+l.rank+"."}),E(a==="NDHWC",function(){return"Error in avgPool3d: Only NDHWC is currently supported, "+("but got dataFormat of "+a)}),E(Ht(e,s),function(){return"Error in avgPool3d: Either strides or dilations must be 1. "+("Got strides "+e+" and dilations '"+s+"'")}),r!=null&&E(rt(i),function(){return"Error in avgPool3d: pad must be an integer when using, "+("dimRoundingMode "+r+" but got pad "+i+".")});var c=function(f,m){s==null&&(s=[1,1,1]);var g=Ha(l.shape,t,e,s,i,r,a);return m([l]),f.avgPool3d(l,g)},h={x:l},d={filterSize:t,strides:e,pad:i,dimRoundingMode:r,dataFormat:a,dilations:s},p=z.runKernelFunc(c,h,null,Gl,d);return p=ue(p,l.dtype),u?V(p,[p.shape[1],p.shape[2],p.shape[3],p.shape[4]]):p}var O1=U({avgPool3d_:R1});function Fg(n,t){var e=n[0].length;n.forEach(function(r,a){E(r.length===e,function(){return"Error in concat"+e+"D: rank of tensors["+a+"] must be the same "+("as the rank of the rest ("+e+")")})}),E(t>=0&&t<e,function(){return"Error in concat"+e+"D: axis must be between 0 and "+(e-1)+"."});var i=n[0];n.forEach(function(r,a){for(var s=0;s<e;s++)E(s===t||r[s]===i[s],function(){return"Error in concat"+e+"D: Shape of tensors["+a+"] ("+r+") "+("does not match the shape of the rest ("+i+") ")+("along the non-concatenated axis "+a+".")})})}function Wg(n,t){for(var e=n[0].slice(),i=1;i<n.length;i++)e[t]+=n[i][t];return e}function E1(n,t){t===void 0&&(t=0),E(n.length>=1,function(){return"Pass at least one tensor to concat"});var e=za(n,"tensors","concat");e[0].dtype==="complex64"&&e.forEach(function(s){if(s.dtype!=="complex64")throw new Error(`Cannot concatenate complex64 tensors with a tensor
|
|
with dtype `+s.dtype+". ")});var i=function(s,o){var l=Qe(t,e[0].shape)[0],u=Wg(e.map(function(d){return d.shape}),l);if(ot(u)===0)return vi([],u);if(e=e.filter(function(d){return d.size>0}),e.length===1)return e[0];var c=e.map(function(d){return d.shape});Fg(c,l);var h=s.concat(e,l);return o(e),h},r=e,a={axis:t};return z.runKernelFunc(i,r,null,Jl,a)}var Rt=U({concat_:E1});function D1(n){var t=O(n,"x","sigmoid"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.sigmoid(t);return r([a]),a},e,null,Qu)}var Ji=U({sigmoid_:D1});function k1(n,t,e){var i=O(n,"x","slice");if(i.rank===0)throw new Error("Slicing scalar is not possible");var r=function(o,l){var u=jc(i,t,e),c=u[0],h=u[1];return ag(i,c,h),l([i]),o.slice(i,c,h)},a={x:i},s={begin:t,size:e};return z.runKernelFunc(r,a,null,$u,s)}var ze=U({slice_:k1});function F1(n){var t=O(n,"x","tanh"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.tanh(t);return r([a]),a},e,null,uc)}var Xs=U({tanh_:F1});function W1(n,t,e,i,r,a){var s=O(n,"forgetBias","basicLSTMCell"),o=O(t,"lstmKernel","basicLSTMCell"),l=O(e,"lstmBias","basicLSTMCell"),u=O(i,"data","basicLSTMCell"),c=O(r,"c","basicLSTMCell"),h=O(a,"h","basicLSTMCell"),d=Rt([u,h],1),p=We(d,o),f=fe(p,l),m=f.shape[0],g=f.shape[1]/4,v=[m,g],b=ze(f,[0,0],v),w=ze(f,[0,g],v),S=ze(f,[0,g*2],v),L=ze(f,[0,g*3],v),N=fe(J(Ji(b),Xs(w)),J(c,Ji(fe(s,S)))),C=J(Xs(N),Ji(L));return[N,C]}var U1=U({basicLSTMCell_:W1});function B1(n,t,e){var i=O(n,"x","batchToSpaceND"),r=t.reduce(function(l,u){return l*u});E(i.rank>=1+t.length,function(){return"input rank is "+i.rank+" but should be > than blockShape.length "+t.length}),E(e.length===t.length,function(){return"crops.length is "+e.length+" but should be equal to blockShape.length "+t.length}),E(i.shape[0]%r===0,function(){return"input tensor batch is "+i.shape[0]+" but is not divisible by the product of "+("the elements of blockShape "+t.join(" * ")+" === "+r)});var a=function(l){return l.batchToSpaceND(i,t,e)},s={x:i},o={blockShape:t,crops:e};return z.runKernelFunc(a,s,null,jl,o)}var Js=U({batchToSpaceND_:B1});function z1(n){var t;return n.rank===0||n.rank===1?t=V(n,[1,1,1,n.size]):n.rank===2?t=V(n,[1,1,n.shape[0],n.shape[1]]):n.rank===3?t=V(n,[1,n.shape[0],n.shape[1],n.shape[2]]):t=n,t}function P1(n,t,e,i,r,a){a==null&&(a=.001);var s=O(n,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(e,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));var c;i!=null&&(c=O(i,"offset","batchNorm")),E(o.rank===l.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),E(c==null||o.rank===c.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),E(u==null||o.rank===u.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."});var h=z1(s),d=function(g,v){return v([h,o,l,u]),g.batchNorm(h,Zs(o),Zs(l),Zs(c),Zs(u),a)},p={x:h,scale:u,offset:c,mean:o,variance:l},f={varianceEpsilon:a},m=z.runKernelFunc(d,p,null,pu,f);return V(m,s.shape)}function Zs(n){return n==null?null:n.rank===0?V(n,[n.size]):n.rank===1?n:n.rank===2?V(n,[1,1,n.shape[0],n.shape[1]]):n.rank===3?V(n,[1,n.shape[0],n.shape[1],n.shape[2]]):n}var Va=U({batchNorm_:P1});function _1(n,t,e,i,r,a){var s=O(n,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(e,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));var c;return i!=null&&(c=O(i,"offset","batchNorm")),E(s.rank===2,function(){return"Error in batchNorm2D: x must be rank 2 but got rank "+(s.rank+".")}),E(o.rank===2||o.rank===1,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but "+("got rank "+o.rank+".")}),E(l.rank===2||l.rank===1,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 "+("but got rank "+l.rank+".")}),u!=null&&E(u.rank===2||u.rank===1,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 "+("but got rank "+u.rank+".")}),c!=null&&E(c.rank===2||c.rank===1,function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 "+("but got rank "+c.rank+".")}),Va(s,o,l,c,u,a)}var M1=U({batchNorm2d_:_1});function H1(n,t,e,i,r,a){var s=O(n,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(e,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));var c;return i!=null&&(c=O(i,"offset","batchNorm")),E(s.rank===3,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+(s.rank+".")}),E(o.rank===3||o.rank===1,function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but "+("got rank "+o.rank+".")}),E(l.rank===3||l.rank===1,function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 "+("but got rank "+l.rank+".")}),u!=null&&E(u.rank===3||u.rank===1,function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 "+("but got rank "+u.rank+".")}),c!=null&&E(c.rank===3||c.rank===1,function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 "+("but got rank "+c.rank+".")}),Va(s,o,l,c,u,a)}var V1=U({batchNorm3d_:H1});function q1(n,t,e,i,r,a){var s=O(n,"x","batchNorm"),o=O(t,"mean","batchNorm"),l=O(e,"variance","batchNorm"),u;r!=null&&(u=O(r,"scale","batchNorm"));var c;return i!=null&&(c=O(i,"offset","batchNorm")),E(s.rank===4,function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+(s.rank+".")}),E(o.rank===4||o.rank===1,function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but "+("got rank "+o.rank+".")}),E(l.rank===4||l.rank===1,function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 "+("but got rank "+l.rank+".")}),u!=null&&E(u.rank===4||u.rank===1,function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 "+("but got rank "+u.rank+".")}),c!=null&&E(c.rank===4||c.rank===1,function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 "+("but got rank "+c.rank+".")}),Va(s,o,l,c,u,a)}var G1=U({batchNorm4d_:q1});function Y1(n,t){var e=O(n,"broadcastTo","x"),i=e.shape;if(t.some(function(d){return!(d>0)||d%1!==0}))throw new Error("broadcastTo(): Invalid broadcast shape ["+t+"].");if(t.length<e.rank)throw new Error("broadcastTo(): shape.length="+t.length+" < input.rank="+e.rank+".");if(t.length>e.rank){for(var r=e.shape.slice();r.length<t.length;)r.unshift(1);e=V(e,r)}for(var a=e.shape,s=Array.from(t),o=t.length-1;o>=0;o--)if(a[o]===t[o])s[o]=1;else if(e.shape[o]!==1)throw new Error("broadcastTo(): ["+i+"] cannot be broadcast to ["+t+"].");var l=s.map(function(d,p){return d>1?p:-1}).filter(function(d){return d>=0});if(l.length===0)return $i(e);var u=function(d){return d.tile(e,s)},c={x:e},h={shape:t,inputShape:a};return z.runKernelFunc(u,c,null,Kl,h)}var Qs=U({broadcastTo_:Y1});function j1(n){var t=O(n,"x","ceil"),e={x:t};return z.runKernelFunc(function(i){return i.ceil(t)},e,null,$l)}var Ug=U({ceil_:j1});function K1(n,t,e){var i=O(n,"x","clipByValue");E(t<=e,function(){return"Error in clip: min ("+t+") must be "+("less than or equal to max ("+e+").")});var r={x:i},a={clipValueMin:t,clipValueMax:e};return z.runKernelFunc(function(s,o){var l=s.clip(i,t,e);return o([i]),l},r,null,Xl,a)}var Bg=U({clipByValue_:K1});function $1(n){return Rt(n,0)}var X1=U({concat1d_:$1});function J1(n,t){return Rt(n,t)}var Z1=U({concat2d_:J1});function Q1(n,t){return Rt(n,t)}var eN=U({concat3d_:Q1});function tN(n,t){return Rt(n,t)}var nN=U({concat4d_:tN});function iN(n,t,e,i,r,a,s){r===void 0&&(r="NHWC"),a===void 0&&(a=[1,1]);var o=O(n,"x","conv2d"),l=O(t,"filter","conv2d"),u=o,c=!1;o.rank===3&&(c=!0,u=V(o,[1,o.shape[0],o.shape[1],o.shape[2]])),E(u.rank===4,function(){return"Error in conv2d: input must be rank 4, but got rank "+u.rank+"."}),E(l.rank===4,function(){return"Error in conv2d: filter must be rank 4, but got rank "+(l.rank+".")}),s!=null&&E(rt(i),function(){return"Error in conv2d: pad must be an integer when using, "+("dimRoundingMode "+s+" but got pad "+i+".")});var h=r==="NHWC"?u.shape[3]:u.shape[1];E(h===l.shape[2],function(){return"Error in conv2d: depth of input ("+h+") must match "+("input depth for filter "+l.shape[2]+".")}),E(Ht(e,a),function(){return"Error in conv2D: Either strides or dilations must be 1. "+("Got strides "+e+" and dilations '"+a+"'")});var d=function(g,v){var b=_a(r),w=Bn(u.shape,l.shape,e,a,i,s,!1,b),S=g.conv2d(u,l,w);return v([u,l]),S},p={x:u,filter:l},f={strides:e,pad:i,dataFormat:r,dilations:a,dimRoundingMode:s},m=z.runKernelFunc(d,p,null,Zl,f);return c?V(m,[m.shape[1],m.shape[2],m.shape[3]]):m}var Gr=U({conv2d_:iN});function rN(n,t,e,i,r,a,s){r===void 0&&(r="NWC"),a===void 0&&(a=1);var o=O(n,"x","conv1d"),l=O(t,"filter","conv1d"),u=o,c=!1;o.rank===2&&(c=!0,u=V(o,[1,o.shape[0],o.shape[1]])),E(u.rank===3,function(){return"Error in conv1d: input must be rank 3, but got rank "+u.rank+"."}),E(l.rank===3,function(){return"Error in conv1d: filter must be rank 3, but got rank "+(l.rank+".")}),s!=null&&E(rt(i),function(){return"Error in conv1d: pad must be an integer when using, "+("dimRoundingMode "+s+" but got pad "+i+".")}),E(u.shape[2]===l.shape[1],function(){return"Error in conv1d: depth of input ("+u.shape[2]+") must match "+("input depth for filter "+l.shape[1]+".")}),E(Ht(e,a),function(){return"Error in conv1D: Either stride or dilation must be 1. "+("Got stride "+e+" and dilation '"+a+"'")}),E(r==="NWC",function(){return"Error in conv1d: got dataFormat of "+r+" but only NWC is currently supported."});var h=V(l,[1,l.shape[0],l.shape[1],l.shape[2]]),d=V(u,[u.shape[0],1,u.shape[1],u.shape[2]]),p=[1,e],f=[1,a],m="NHWC",g=Gr(d,h,p,i,m,f,s);return c?V(g,[g.shape[2],g.shape[3]]):V(g,[g.shape[0],g.shape[2],g.shape[3]])}var zg=U({conv1d_:rN});function aN(n,t,e,i,r,a,s){a===void 0&&(a="NHWC"),E(n.length===t.rank,function(){return"Length of inShape "+("("+n.length+") and rank of dy ("+t.rank+") must match")});var o=n,l=t,u=!1;t.rank===3&&(u=!0,l=V(t,[1,t.shape[0],t.shape[1],t.shape[2]]),o=[1,n[0],n[1],n[2]]),E(o.length===4,function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+(o.length+".")}),E(l.rank===4,function(){return"Error in conv2dDerInput: dy must be rank 4, but got "+("rank "+l.rank)}),E(e.rank===4,function(){return"Error in conv2dDerInput: filter must be rank 4, but got "+("rank "+e.rank)});var c=a==="NHWC"?o[3]:o[1],h=a==="NHWC"?l.shape[3]:l.shape[1];E(c===e.shape[2],function(){return"Error in conv2dDerInput: depth of input ("+c+") must "+("match input depth for filter "+e.shape[2]+".")}),E(h===e.shape[3],function(){return"Error in conv2dDerInput: depth of output ("+h+") must "+("match output depth for filter "+e.shape[3]+".")}),s!=null&&E(rt(r),function(){return"Error in conv2dDerInput: pad must be an integer when using, "+("dimRoundingMode "+s+" but got pad "+r+".")});var d=function(g,v){var b=1,w=_a(a),S=Bn(o,e.shape,i,b,r,s,!1,w),L=g.conv2dDerInput(l,e,S);return v([l,e]),L},p={dy:l,filter:e},f={strides:i,pad:r,dataFormat:a,dimRoundingMode:s,inputShape:o},m=z.runKernelFunc(d,p,null,Ql,f);return u?V(m,[m.shape[1],m.shape[2],m.shape[3]]):m}var nh=U({conv2DBackpropInput_:aN});function sN(n,t,e,i,r,a){var s=O(n,"x","conv2dTranspose"),o=O(t,"filter","conv2dTranspose");return nh(e,s,o,i,r,"NHWC",a)}var Pg=U({conv2dTranspose_:sN});function oN(n,t,e,i,r,a){r===void 0&&(r="NDHWC"),a===void 0&&(a=[1,1,1]);var s=O(n,"x","conv3d"),o=O(t,"filter","conv3d"),l=s,u=!1;s.rank===4&&(u=!0,l=V(s,[1,s.shape[0],s.shape[1],s.shape[2],s.shape[3]])),E(l.rank===5,function(){return"Error in conv3d: input must be rank 5, but got rank "+l.rank+"."}),E(o.rank===5,function(){return"Error in conv3d: filter must be rank 5, but got rank "+(o.rank+".")}),E(l.shape[4]===o.shape[3],function(){return"Error in conv3d: depth of input ("+l.shape[4]+") must match "+("input depth for filter "+o.shape[3]+".")}),E(Ht(e,a),function(){return"Error in conv3D: Either strides or dilations must be 1. "+("Got strides "+e+" and dilations '"+a+"'")}),E(r==="NDHWC",function(){return"Error in conv3d: got dataFormat of "+r+" but only NDHWC is currently supported."});var c=function(f,m){var g=Ma(l.shape,o.shape,e,a,i),v=f.conv3d(l,o,g);return m([l,o]),v},h={x:l,filter:o},d={strides:e,pad:i,dataFormat:r,dilations:a},p=z.runKernelFunc(c,h,null,eu,d);return u?V(p,[p.shape[1],p.shape[2],p.shape[3],p.shape[4]]):p}var lN=U({conv3d_:oN});function uN(n,t,e,i,r){E(n.length===t.rank,function(){return"Length of inShape "+("("+n.length+") and rank of dy ("+t.rank+") must match")});var a=n,s=t,o=!1;t.rank===4&&(o=!0,s=V(t,[1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]]),a=[1,n[0],n[1],n[2],n[3]]);var l=a[4],u=s.shape[4];E(a.length===5,function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+(a.length+".")}),E(s.rank===5,function(){return"Error in conv3dDerInput: dy must be rank 5, but got "+("rank "+s.rank)}),E(e.rank===5,function(){return"Error in conv3dDerInput: filter must be rank 5, but got "+("rank "+e.rank)}),E(l===e.shape[3],function(){return"Error in conv3dDerInput: depth of input ("+l+") must "+("match input depth for filter "+e.shape[3]+".")}),E(u===e.shape[4],function(){return"Error in conv3dDerInput: depth of output ("+u+") must "+("match output depth for filter "+e.shape[4]+".")});var c=function(f){var m=1,g=Ma(a,e.shape,i,m,r);return f.conv3dDerInput(s,e,g)},h={dy:s},d={pad:r},p=z.runKernelFunc(c,h,null,xf,d);return o?V(p,[p.shape[1],p.shape[2],p.shape[3],p.shape[4]]):p}var _g=U({conv3DBackpropInput_:uN});function cN(n,t,e,i,r){var a=O(n,"x","conv3dTranspose"),s=O(t,"filter","conv3dTranspose");return _g(e,a,s,i,r)}var hN=U({conv3dTranspose_:cN});function dN(n){var t=O(n,"x","cos"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.cos(t);return r([t]),a},e,null,tu)}var eo=U({cos_:dN});function pN(n){var t=O(n,"x","cosh"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.cosh(t);return r([t]),a},e,null,nu)}var ih=U({cosh_:pN});function fN(n,t,e,i){t===void 0&&(t=0),e===void 0&&(e=!1),i===void 0&&(i=!1);var r=O(n,"x","cumsum"),a=function(l,u){var c=an([t],r.rank),h=r;c!=null&&(h=ut(r,c));var d=Un(1,r.rank)[0],p=l.cumsum(h,d,e,i);if(u([r]),c!=null){var f=Ks(c);p=ut(p,f)}return p},s={x:r},o={axis:t,exclusive:e,reverse:i};return z.runKernelFunc(a,s,null,iu,o)}var rh=U({cumsum_:fN});function mN(n,t,e){e===void 0&&(e="NHWC");var i=O(n,"x","depthToSpace"),r=e==="NHWC"?i.shape[1]:i.shape[2],a=e==="NHWC"?i.shape[2]:i.shape[3],s=e==="NHWC"?i.shape[3]:i.shape[1];E(r*t>=0,function(){return`Negative dimension size caused by overflow when multiplying
|
|
`+r+" and "+t+` for depthToSpace with input shape
|
|
`+i.shape}),E(a*t>=0,function(){return`Negative dimension size caused by overflow when multiplying
|
|
`+a+" and "+t+` for depthToSpace with input shape
|
|
`+i.shape}),E(s%(t*t)===0,function(){return"Dimension size must be evenly divisible by "+t*t+" but is "+s+" for depthToSpace with input shape "+i.shape});var o=function(c){return c.depthToSpace(i,t,e)},l={x:i},u={blockSize:t,dataFormat:e};return z.runKernelFunc(o,l,null,Rf,u)}var Mg=U({depthToSpace_:mN});function gN(n,t,e,i,r,a,s){r===void 0&&(r="NHWC"),a===void 0&&(a=[1,1]);var o=O(n,"x","depthwiseConv2d"),l=O(t,"filter","depthwiseConv2d"),u=o,c=!1;o.rank===3&&(c=!0,u=V(o,[1,o.shape[0],o.shape[1],o.shape[2]])),E(u.rank===4,function(){return"Error in depthwiseConv2d: input must be rank 4, but got "+("rank "+u.rank+".")}),E(l.rank===4,function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+(l.rank+".")}),E(u.shape[3]===l.shape[2],function(){return"Error in depthwiseConv2d: number of input channels "+("("+u.shape[3]+") must match the inChannels dimension in ")+("filter "+l.shape[2]+".")}),s!=null&&E(rt(i),function(){return"Error in depthwiseConv2d: pad must be an integer when using, "+("dimRoundingMode "+s+" but got pad "+i+".")});var h=function(m,g){a==null&&(a=[1,1]),E(Ht(e,a),function(){return"Error in depthwiseConv2d: Either strides or dilations must be "+("1. Got strides "+e+" and dilations '"+a+"'")});var v=Bn(u.shape,l.shape,e,a,i,s,!0),b=m.depthwiseConv2D(u,l,v);return g([u,l]),b},d={x:u,filter:l},p={strides:e,pad:i,dataFormat:r,dilations:a,dimRoundingMode:s},f=z.runKernelFunc(h,d,null,ru,p);return c?V(f,[f.shape[1],f.shape[2],f.shape[3]]):f}var qa=U({depthwiseConv2d_:gN});function vN(n){var t=O(n,"x","diag"),e=function(r){var a=V(t,[t.size]),s=r.diag(a),o=n.shape.concat(n.shape);return V(s,o)},i={x:t};return z.runKernelFunc(e,i,null,Df)}var yN=U({diag_:vN});function bN(n,t,e,i,r,a){r===void 0&&(r=[1,1]),a===void 0&&(a="NHWC");var s=O(n,"x","dilation2d"),o=O(t,"filter","dilation2d");E(s.rank===3||s.rank===4,function(){return"Error in dilation2d: input must be rank 3 or 4, but got rank "+(s.rank+".")}),E(o.rank===3,function(){return"Error in dilation2d: filter must be rank 3, but got rank "+(o.rank+".")}),E(a==="NHWC",function(){return"Error in dilation2d: Only NHWC is currently supported, "+("but got dataFormat of "+a)});var l=s,u=!1;s.rank===3&&(l=V(s,[1,s.shape[0],s.shape[1],s.shape[2]]),u=!0);var c={x:l,filter:o},h={strides:e,pad:i,dilations:r},d=z.runKernel(au,c,h);return u?V(d,[d.shape[1],d.shape[2],d.shape[3]]):d}var Hg=U({dilation2d_:bN});function wN(n,t){for(var e=n.length,i=[],r=0;r<e;r++){var a=e-1-r,s=n[a]||1,o=t[t.length-1-r]||1;o>1&&s===1&&i.unshift(a)}return i}function gt(n,t){for(var e=[],i=0;i<t.length;i++){var r=n[n.length-i-1],a=t.length-i-1,s=t[a];(r==null||r===1&&s>1)&&e.unshift(a)}return e}function et(n,t){for(var e=[],i=Math.max(n.length,t.length),r=0;r<i;r++){var a=n[n.length-r-1];a==null&&(a=1);var s=t[t.length-r-1];if(s==null&&(s=1),a===1)e.unshift(s);else if(s===1)e.unshift(a);else if(a!==s){var o="Operands could not be broadcast together with shapes "+(n+" and "+t+".");throw Error(o)}else e.unshift(a)}return e}function SN(n,t){var e,i=O(n,"a","equal"),r=O(t,"b","equal");e=at(i,r),i=e[0],r=e[1],et(i.shape,r.shape);var a=function(o){return o.equal(i,r)},s={a:i,b:r};return z.runKernelFunc(a,s,null,Uf)}var Ga=U({equal_:SN});function LN(n,t,e){var i=O(t,"a","where"),r=O(e,"b","where"),a=O(n,"condition","where","bool"),s=et(i.shape,r.shape),o=Qs(i,s),l=Qs(r,s);a.rank===1&&E(a.shape[0]===i.shape[0],function(){return"The first dimension of `a` must match the size of `condition`."}),a.rank!==1&&Be(a.shape,l.shape,"Error in where: ");var u=function(h,d){var p=h.select(a,o,l);return d([a]),p},c={condition:a,t:o,e:l};return z.runKernelFunc(u,c,null,ju)}var yn=U({where_:LN});function IN(n){var t=O(n,"x","zerosLike"),e={x:t};return z.runKernelFunc(function(i){return i.zerosLike(t)},e,null,fc)}var Ee=U({zerosLike_:IN});function AN(n,t){var e,i=O(n,"a","div"),r=O(t,"b","div");e=at(i,r),i=e[0],r=e[1];var a=Ie(i,r),s=Ee(a),o=Ga(r,s);return yn(o,s,a)}var Vg=U({divNoNan_:AN});function TN(n,t){var e=O(n,"t1","dot"),i=O(t,"t2","dot");E((e.rank===1||e.rank===2)&&(i.rank===1||i.rank===2),function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+(e.rank+" and "+i.rank+".")});var r=e.rank===1?e.size:e.shape[1],a=i.rank===1?i.size:i.shape[0];if(E(r===a,function(){return"Error in dot: inner dimensions of inputs must match, but got "+(r+" and "+a+".")}),e.rank===1&&i.rank===1){var s=V(e,[1,-1]),o=V(i,[-1,1]),l=We(s,o);return V(l,[])}else if(e.rank===1&&i.rank===2){var s=V(e,[1,-1]),o=V(i,[i.shape[0],i.shape[1]]),l=We(s,o);return V(l,[l.size])}else if(e.rank===2&&i.rank===1){var o=V(i,[-1,1]),l=We(e,o);return V(l,[l.size])}else{var o=V(i,[i.shape[0],i.shape[1]]),l=We(e,o);return l}}var qg=U({dot_:TN});function NN(n){var t=O(n,"x","elu"),e=function(r,a){var s=r.elu(t);return a([s]),s},i={x:t};return z.runKernelFunc(e,i,null,ou)}var ah=U({elu_:NN});function xN(n){var t=O(n,"x","erf");E(t.dtype==="int32"||t.dtype==="float32",function(){return"Input dtype must be `int32` or `float32`."}),t.dtype==="int32"&&(t=ue(t,"float32"));var e={x:t};return z.runKernelFunc(function(i,r){var a=i.erf(t);return r([t]),a},e,null,lu)}var Gg=U({erf_:xN});function CN(n){var t=O(n,"x","exp"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.exp(t);return r([a]),a},e,null,uu)}var bn=U({exp_:CN});function RN(n,t){t===void 0&&(t=0);var e=null,i=O(n,"x","expandDims",e);E(t<=i.rank,function(){return"Axis must be <= rank of the tensor"});var r=i.shape.slice();return t<0&&(E(-(i.rank+1)<=t,function(){return"Axis must be in the interval ["+-(i.rank+1)+", "+i.rank+"]"}),t=i.rank+t+1),r.splice(t,0,1),V(i,r)}var wn=U({expandDims_:RN});function ON(n){var t=O(n,"x","expm1"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.expm1(t);return r([t]),a},e,null,cu)}var Yg=U({expm1_:ON});function EN(n,t){var e=null,i=O(n,"x","tile",e);E(i.rank===t.length,function(){return"Error in transpose: rank of input "+i.rank+" "+("must match length of reps "+t+".")});var r=function(l,u){var c=l.tile(i,t);return u([i]),c},a=[i],s={x:i},o={reps:t};return z.runKernelFunc(r,s,null,cc,o,a)}var Yr=U({tile_:EN});function DN(n,t,e,i){i===void 0&&(i="float32"),t==null&&(t=n);for(var r=Wn([n,t],i),a=n<=t?n:t,s=0;s<a;++s)r.set(1,s,s);var o=V(r.toTensor(),[n,t]);if(e==null)return o;if(e.length===1)return Yr(wn(o,0),[e[0],1,1]);if(e.length===2)return Yr(wn(wn(o,0),0),[e[0],e[1],1,1]);if(e.length===3)return Yr(wn(wn(wn(o,0),0),0),[e[0],e[1],e[2],1,1]);throw new Error("eye() currently supports only 1D and 2D "+("batchShapes, but received "+e.length+"D."))}var jg=U({eye_:DN});function sh(n,t,e){var i={shape:n,value:t,dtype:e};return z.runKernelFunc(function(r){return r.fill(n,t,e)},{},null,zf,i)}function kN(n){var t=O(n,"x","floor"),e={x:t};return z.runKernelFunc(function(i){return i.floor(t)},e,null,hu)}var to=U({floor_:kN});var oh=30;function FN(n){return n<=oh?n:Ps(n,Math.floor(Math.sqrt(n)))}function WN(n,t){var e=!1,i;for(n<=oh?(i=n,e=!0):i=Ps(n,Math.floor(Math.sqrt(n)));!e;)i>t||i===n?e=!0:i=Ps(n,i+1);return i}function UN(n,t,e){for(var i=[],r=n.length,a=0;a<r;a++)a!==t?i.push(n[a]):i.push(e);return i}function Kg(n,t,e){for(var i=n.shape[e],r=[],a=1,s=1,o=0;o<e;o++)r.push(n.shape[o]),a*=n.shape[o];for(var o=0;o<t.rank;o++)r.push(t.shape[o]);for(var o=e+1;o<n.rank;o++)r.push(n.shape[o]),s*=n.shape[o];return{batchSize:a,sliceSize:s,dimSize:i,outputShape:r}}var BN={__proto__:null,segOpComputeOptimalWindowSize:WN,computeOutShape:UN,collectGatherOpShapeInfo:Kg};function zN(n,t,e){e===void 0&&(e=0);var i=O(n,"x","gather"),r=O(t,"indices","gather","int32"),a={x:i,indices:r},s={axis:e},o=function(l,u){var c=Qe(e,i.shape)[0],h=Kg(i,r,c),d=l.gather(i,V(r,[r.size]),c);return u([i,r]),V(d,h.outputShape)};return z.runKernelFunc(o,a,null,fu,s)}var no=U({gather_:zN});function PN(n,t){var e,i=O(n,"a","greater"),r=O(t,"b","greater");e=at(i,r),i=e[0],r=e[1],et(i.shape,r.shape);var a=function(o){return o.greater(i,r)},s={a:i,b:r};return z.runKernelFunc(a,s,null,Mf)}var Li=U({greater_:PN});function _N(n,t){var e,i=O(n,"a","greaterEqual"),r=O(t,"b","greaterEqual");e=at(i,r),i=e[0],r=e[1],et(i.shape,r.shape);var a=function(o,l){var u=o.greaterEqual(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,mu)}var Zi=U({greaterEqual_:_N});function MN(n){var t=O(n,"input","imag"),e=function(r){return r.imag(t)},i={input:t};return z.runKernelFunc(e,i,null,Vf)}var io=U({imag_:MN});function HN(n){var t=O(n,"x","isFinite"),e={x:t};return z.runKernelFunc(function(i){return i.isFinite(t)},e,null,vu)}var $g=U({isFinite_:HN});function VN(n){var t=O(n,"x","isInf"),e={x:t};return z.runKernelFunc(function(i){return i.isInf(t)},e,null,yu)}var Xg=U({isInf_:VN});function qN(n){var t=O(n,"x","isNaN"),e={x:t};return z.runKernelFunc(function(i){return i.isNaN(t)},e,null,bu)}var Jg=U({isNaN_:qN});function GN(n,t){var e,i=O(n,"a","maximum"),r=O(t,"b","maximum");e=at(i,r),i=e[0],r=e[1],i.dtype==="bool"&&(i=ue(i,"int32"),r=ue(r,"int32")),et(i.shape,r.shape);var a=function(o,l){var u=o.maximum(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,Tu)}var jr=U({maximum_:GN});function be(n,t){if((Dt(n)&&t!=="string"||Array.isArray(n))&&t!=="complex64")throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");if(t==="string"&&Dt(n)&&!(n instanceof Uint8Array))throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");var e=[],i=[];return gi(n,e,i,t)}function YN(n,t){t===void 0&&(t=.2);var e=O(n,"x","leakyRelu");return jr(J(be(t),e),e)}var Zg=U({leakyRelu_:YN});function jN(n,t){var e,i=O(n,"a","less"),r=O(t,"b","less");e=at(i,r),i=e[0],r=e[1],et(i.shape,r.shape);var a=function(o){return o.less(i,r)},s={a:i,b:r};return z.runKernelFunc(a,s,null,qf)}var ro=U({less_:jN});function KN(n,t){var e,i=O(n,"a","lessEqual"),r=O(t,"b","lessEqual");e=at(i,r),i=e[0],r=e[1],et(i.shape,r.shape);var a=function(o,l){var u=o.lessEqual(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,Gf)}var Qi=U({lessEqual_:KN});function $N(n,t,e){if(e<=0)throw new Error("The number of values should be positive.");var i={start:n,stop:t,num:e};return z.runKernelFunc(function(r){return r.linspace(n,t,e)},{},null,Yf,i)}function XN(n,t,e,i,r){t===void 0&&(t=5),e===void 0&&(e=1),i===void 0&&(i=1),r===void 0&&(r=.5);var a=O(n,"x","localResponseNormalization");E(a.rank===4||a.rank===3,function(){return`Error in localResponseNormalization: x must be rank 3 or 4 but got
|
|
rank `+a.rank+"."}),E(rt(t),function(){return"Error in localResponseNormalization: depthRadius must be an "+("integer but got depthRadius "+t+".")});var s=a,o=!1;a.rank===3&&(o=!0,s=V(a,[1,a.shape[0],a.shape[1],a.shape[2]]));var l=function(d,p){var f=d.localResponseNormalization4D(s,t,e,i,r);return p([s,f]),f},u={x:s},c={depthRadius:t,bias:e,alpha:i,beta:r},h=z.runKernelFunc(l,u,null,Iu,c);return o?V(h,[h.shape[1],h.shape[2],h.shape[3]]):h}var Qg=U({localResponseNormalization_:XN});function JN(n){var t=O(n,"x","log"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.log(t);return r([t]),a},e,null,wu)}var er=U({log_:JN});function ZN(n){var t=O(n,"x","log1p"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.log1p(t);return r([t]),a},e,null,Su)}var lh=U({log1p_:ZN});function QN(n){return E(fi(n),function(){return"The f passed in grad(f) must be a function"}),function(t,e){var i=O(t,"x","tf.grad",null),r=e!=null?O(e,"dy","tf.grad"):null;return z.tidy(function(){var a=z.gradients(function(){return n(i)},[i],r),s=a.value,o=a.grads;return r!=null&&Be(s.shape,r.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),ao(o),o[0]})}}function ex(n){return E(fi(n),function(){return"The f passed in grads(f) must be a function"}),function(t,e){E(Array.isArray(t),function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"});var i=za(t,"args","tf.grads",null),r=e!=null?O(e,"dy","tf.grads"):null;return z.tidy(function(){var a=z.gradients(function(){return n.apply(void 0,i)},i,r),s=a.value,o=a.grads;return r!=null&&Be(s.shape,r.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),ao(o),o})}}function tx(n){return E(fi(n),function(){return"The f passed in valueAndGrad(f) must be a function"}),function(t,e){E(t instanceof Y,function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"}),E(e==null||e instanceof Y,function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"});var i=z.gradients(function(){return n(t)},[t],e),r=i.grads,a=i.value;return ao(r),{grad:r[0],value:a}}}function nx(n){return E(fi(n),function(){return"The f passed in valueAndGrads(f) must be a function"}),function(t,e){E(Array.isArray(t)&&t.every(function(r){return r instanceof Y}),function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"}),E(e==null||e instanceof Y,function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"});var i=z.gradients(function(){return n.apply(void 0,t)},t,e);return e!=null&&Be(i.value.shape,e.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),ao(i.grads),i}}function ev(n,t){E(fi(n),function(){return"The f passed in variableGrads(f) must be a function"}),E(t==null||Array.isArray(t)&&t.every(function(h){return h instanceof Ba}),function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"});var e=t!=null;if(!e){t=[];for(var i in z.registeredVariables)t.push(z.registeredVariables[i])}var r=e?t.filter(function(h){return!h.trainable}):null,a=t.length;t=t.filter(function(h){return h.trainable}),E(t.length>0,function(){return"variableGrads() expects at least one of the input variables to "+("be trainable, but none of the "+a+" variables is ")+"trainable."});var s=!0,o=z.gradients(n,t,null,s),l=o.value,u=o.grads;E(u.some(function(h){return h!=null}),function(){return"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()."}),E(l.rank===0,function(){return"The f passed in variableGrads(f) must return a scalar, but it "+("returned a rank-"+l.rank+" tensor")});var c={};return t.forEach(function(h,d){u[d]!=null&&(c[h.name]=u[d])}),r!=null&&r.forEach(function(h){return c[h.name]=null}),{value:l,grads:c}}function zn(n){return z.customGrad(n)}function ao(n){var t=n.filter(function(e){return e==null}).length;if(t>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.`)}function ix(n){var t=O(n,"x","neg"),e={x:t};return z.runKernelFunc(function(i){return i.neg(t)},e,null,Du)}var vt=U({neg_:ix});function rx(n){var t=O(n,"x","softplus"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.softplus(t);return r([t]),a},e,null,ec)}var uh=U({softplus_:rx});function ax(n){var t=O(n,"x","logSigmoid"),e=zn(function(i){var r=vt(uh(vt(i))),a=function(s){var o=J(s,Ji(vt(i)));return o};return{value:r,gradFunc:a}});return e(t)}var tv=U({logSigmoid_:ax});function sx(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","max"),r=function(o,l){var u=Qe(t,i.shape),c=u,h=an(c,i.rank),d=i;h!=null&&(d=ut(i,h),c=Un(c.length,d.rank));var p=o.max(d,c);h!=null&&d.dispose();var f=p;if(e){var m=rn(f.shape,Qe(t,i.shape));f=V(f,m),p.dispose()}return l([i,f]),f},a={x:i},s={reductionIndices:t,keepDims:e};return z.runKernelFunc(r,a,null,Au,s)}var tr=U({max_:sx});function ox(n,t){var e,i=O(n,"a","sub"),r=O(t,"b","sub");e=at(i,r),i=e[0],r=e[1];var a=function(o,l){var u=o.subtract(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,oc)}var ge=U({sub_:ox});function lx(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","sum");i.dtype==="bool"&&(i=ue(i,"int32"));var r=function(o,l){l([i]);var u=Qe(t,i.shape),c=an(u,i.rank),h=u,d=i;c!=null&&(d=ut(i,c),h=Un(h.length,i.rank));var p=o.sum(d,h);if(e){var f=rn(p.shape,u);p=V(p,f)}return p},a={x:i},s={axis:t,keepDims:e};return z.runKernelFunc(r,a,null,nc,s)}var Ae=U({sum_:lx});function ux(n,t){t===void 0&&(t=-1);var e=O(n,"logits","logSoftmax");if(t===-1&&(t=e.rank-1),t!==e.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. "+("Logits was rank "+e.rank+" and axis was "+t));var i=function(s,o){var l=!0,u=tr(n,t,!0),c=ge(n,u),h=ge(ue(c,"float32"),er(Ae(bn(c),t,l)));return o([h]),h},r={logits:e},a={axis:t};return z.runKernelFunc(i,r,null,Lu,a)}var nv=U({logSoftmax_:ux});function cx(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","logSumExp"),r=Qe(t,i.shape),a=tr(i,r,!0),s=ge(i,a),o=bn(s),l=Ae(o,r),u=er(l),c=fe(V(a,u.shape),u);if(e){var h=rn(c.shape,r);return V(c,h)}return c}var ch=U({logSumExp_:cx});function hx(n,t){var e=O(n,"a","logicalAnd","bool"),i=O(t,"b","logicalAnd","bool");et(e.shape,i.shape);var r={a:e,b:i};return z.runKernelFunc(function(a){return a.logicalAnd(e,i)},r,null,jf)}var nr=U({logicalAnd_:hx});function dx(n){var t=O(n,"x","logicalNot","bool"),e={x:t};return z.runKernelFunc(function(i){return i.logicalNot(t)},e,null,Kf)}var so=U({logicalNot_:dx});function px(n,t){var e=O(n,"a","logicalOr","bool"),i=O(t,"b","logicalOr","bool");et(e.shape,i.shape);var r={a:e,b:i};return z.runKernelFunc(function(a){return a.logicalOr(e,i)},r,null,$f)}var hh=U({logicalOr_:px});function fx(n,t){var e=O(n,"a","logicalXor","bool"),i=O(t,"b","logicalXor","bool");return et(e.shape,i.shape),nr(hh(n,t),so(nr(n,t)))}var iv=U({logicalXor_:fx});function mx(n,t,e,i,r){var a=O(n,"x","maxPool"),s=1,o=a,l=!1;a.rank===3&&(l=!0,o=V(a,[1,a.shape[0],a.shape[1],a.shape[2]])),E(o.rank===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+o.rank+"."}),E(Ht(e,s),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+e+" and dilations '"+s+"'")}),r!=null&&E(rt(i),function(){return"Error in maxPool: pad must be an integer when using, "+("dimRoundingMode "+r+" but got pad "+i+".")});var u=function(p,f){var m=Vr(o.shape,t,e,1,i,r),g;return m.filterWidth===1&&m.filterHeight===1&&dn(m.inShape,m.outShape)?g=o.clone():g=p.maxPool(o,m),f([o,g]),g},c={x:o},h={filterSize:t,strides:e,pad:i,dimRoundingMode:r},d=z.runKernelFunc(u,c,null,Nu,h);return l?V(d,[d.shape[1],d.shape[2],d.shape[3]]):d}var dh=U({maxPool_:mx});function gx(n,t,e,i,r,a,s){t===void 0&&(t=[1,1,1]),a===void 0&&(a="NDHWC"),s==null?s=[1,1,1]:At("dilations is deprecated, this field will be gone in v3.0.0.");var o=O(n,"x","maxPool3d"),l=o,u=!1;o.rank===4&&(u=!0,l=V(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]])),E(l.rank===5,function(){return"Error in maxPool3d: x must be rank 5 but got rank "+l.rank+"."}),E(a==="NDHWC",function(){return"Error in maxPool3d: Only NDHWC is currently supported, "+("but got dataFormat of "+a)}),E(Ht(e,s),function(){return"Error in maxPool3d: Either strides or dilations must be 1. "+("Got strides "+e+" and dilations '"+s+"'")}),r!=null&&E(rt(i),function(){return"Error in maxPool3d: pad must be an integer when using, "+("dimRoundingMode "+r+" but got pad "+i+".")});var c=function(f,m){s==null&&(s=[1,1,1]);var g=Ha(l.shape,t,e,s,i,r,a),v=f.maxPool3d(l,g);return m([l,v]),v},h={x:l},d={filterSize:t,strides:e,pad:i,dimRoundingMode:r,dataFormat:a,dilations:s},p=z.runKernelFunc(c,h,null,xu,d);return u?V(p,[p.shape[1],p.shape[2],p.shape[3],p.shape[4]]):p}var vx=U({maxPool3d_:gx});function yx(n,t,e,i,r){r===void 0&&(r=!1);var a=O(n,"x","maxPoolWithArgmax"),s={x:a},o={filterSize:t,strides:e,pad:i,includeBatchInIndex:r},l=z.runKernel(Qf,s,o);return{result:l[0],indexes:l[1]}}var bx=U({maxPoolWithArgmax_:yx});function ti(n,t){if(t===void 0&&(t="float32"),t==="complex64"){var e=ti(n,"float32"),i=ti(n,"float32");return mi(e,i)}var r=Ur(ot(n),t);return z.makeTensor(r,n,t)}function Kr(n,t){if(t===void 0&&(t="float32"),t==="complex64"){var e=Kr(n,"float32"),i=ti(n,"float32");return mi(e,i)}var r=Ac(ot(n),t);return z.makeTensor(r,n,t)}function wx(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","mean"),r=Qe(t,i.shape),a=Ag(i.shape,r),s=a[1],o=ot(s),l=zn(function(u){var c=be(o),h=c.dtype===u.dtype?u:ue(u,c.dtype),d=Ie(h,c),p=Ae(d,t,e),f=function(m){var g=u.shape.slice();r.forEach(function(w){g[w]=1});var v=V(m,g),b=Ie(J(v,Kr(u.shape,"float32")),o);return b};return{value:p,gradFunc:f}});return l(i)}var Ya=U({mean_:wx});function Sx(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","min"),r=function(o,l){var u=Qe(t,i.shape),c=u,h=an(c,i.rank),d=i;h!=null&&(d=ut(i,h),c=Un(c.length,i.rank));var p=o.min(d,c);h!=null&&d.dispose();var f=p;if(e){var m=rn(f.shape,u);f=V(p,m),p.dispose()}return l([i,f]),f},a={x:i},s={axis:t,keepDims:e};return z.runKernelFunc(r,a,null,Cu,s)}var oo=U({min_:Sx});function Lx(n,t){var e,i=O(n,"a","minimum"),r=O(t,"b","minimum");e=at(i,r),i=e[0],r=e[1],i.dtype==="bool"&&(i=ue(i,"int32"),r=ue(r,"int32")),et(i.shape,r.shape);var a=function(o,l){var u=o.minimum(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,Ru)}var lo=U({minimum_:Lx});function Ix(n,t){var e,i=O(n,"a","mod"),r=O(t,"b","mod");e=at(i,r),i=e[0],r=e[1];var a=function(o,l){var u=o.mod(i,r);return l([i,r]),u},s={a:i,b:r};return z.runKernelFunc(a,s,null,Ou)}var ph=U({mod_:Ix});function Ax(n){var t=O(n,"x","square"),e={},i=[t],r=[];return z.runKernelFunc(function(a,s){return s([t]),a.square(t)},{x:t},null,"Square",e,i,r)}var Ye=U({square_:Ax});function Tx(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1),n=O(n,"x","moments");var i=Qe(t,n.shape),r=Ya(n,i,e),a=r.shape;e||(a=rn(r.shape,i));var s=Ye(ge(ue(n,"float32"),V(r,a))),o=Ya(s,i,e);return{mean:r,variance:o}}var Nx=U({moments_:Tx});function xx(n,t,e,i){for(var r=O(t,"data","multiRNNCell"),a=za(e,"c","multiRNNCell"),s=za(i,"h","multiRNNCell"),o=r,l=[],u=0;u<n.length;u++){var c=n[u](o,a[u],s[u]);l.push(c[0]),l.push(c[1]),o=c[1]}for(var h=[],d=[],u=0;u<l.length;u+=2)h.push(l[u]),d.push(l[u+1]);return[h,d]}var Cx=U({multiRNNCell_:xx});function Rx(n,t,e,i){i===void 0&&(i=!1);var r=O(n,"logits","multinomial"),a=r.size,s=r.rank;if(a<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+(a+"."));if(s>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+s);e=e||Math.random();var o=s===1?V(r,[1,-1]):r,l=z.runKernelFunc(function(u){return u.multinomial(o,i,t,e)},{logits2D:o});return s===1?V(l,[l.size]):l}var Ox=U({multinomial_:Rx});function Ex(n,t){var e,i=O(n,"a","notEqual"),r=O(t,"b","notEqual");e=at(i,r),i=e[0],r=e[1],et(i.shape,r.shape);var a=function(o){return o.notEqual(i,r)},s={a:i,b:r};return z.runKernelFunc(a,s,null,em)}var uo=U({notEqual_:Ex});function Dx(n){var t=O(n,"input","real"),e=function(r){return r.real(t)},i={input:t};return z.runKernelFunc(e,i,null,sm)}var ja=U({real_:Dx});function kx(n){var t=O(n,"x","onesLike"),e=function(r,a){if(t.dtype==="complex64"){var s=fh(ja(t)),o=Ee(io(t));return mi(s,o)}return r.onesLike(t)},i={x:t};return z.runKernelFunc(e,i,null,ku)}var fh=U({onesLike_:kx});function Fx(n,t){var e=O(n,"v1","outerProduct"),i=O(t,"v2","outerProduct");E(e.rank===1&&i.rank===1,function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+(e.rank+" and "+i.rank+".")});var r=V(e,[-1,1]),a=V(i,[1,-1]);return We(r,a)}var Wx=U({outerProduct_:Fx});function Ux(n,t,e){e===void 0&&(e=0);var i=O(n,"x","pad");if(i.rank===0)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var r=function(o,l){return l([i]),o.pad(i,t,e)},a={paddings:t,constantValue:e},s={x:i};return z.runKernelFunc(r,s,null,Wu,a)}var ir=U({pad_:Ux});function Bx(n,t,e){return e===void 0&&(e=0),E(t.length===2,function(){return"Invalid number of paddings. Must be length of 2."}),ir(n,[t],e)}var zx=U({pad1d_:Bx});function Px(n,t,e){return e===void 0&&(e=0),E(t.length===2&&t[0].length===2&&t[1].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ir(n,t,e)}var _x=U({pad2d_:Px});function Mx(n,t,e){return e===void 0&&(e=0),E(t.length===3&&t[0].length===2&&t[1].length===2&&t[2].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ir(n,t,e)}var Hx=U({pad3d_:Mx});function Vx(n,t,e){return e===void 0&&(e=0),E(t.length===4&&t[0].length===2&&t[1].length===2&&t[2].length===2&&t[3].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ir(n,t,e)}var qx=U({pad4d_:Vx});function Gx(n,t,e){var i=O(n,"x","spaceToBatchND");E(i.rank>=1+t.length,function(){return"input rank "+i.rank+" should be > than [blockShape] "+t.length}),E(e.length===t.length,function(){return"paddings.shape[0] "+e.length+" must be equal to [blockShape] "+t.length}),E(i.shape.reduce(function(o,l,u){return u>0&&u<=t.length?o&&(l+e[u-1][0]+e[u-1][1])%t[u-1]===0:o},!0),function(){return"input spatial dimensions "+i.shape.slice(1)+" with paddings "+e.toString()+" must be divisible by blockShapes "+t.toString()});var r=function(o){return o.spaceToBatchND(i,t,e)},a={x:i},s={blockShape:t,paddings:e};return z.runKernelFunc(r,a,null,ic,s)}var co=U({spaceToBatchND_:Gx});function Kx(n,t,e,i,r,a){r==null&&(r=[1,1]),a==null&&(a=1),i===0&&(i="valid");var s=O(n,"x","maxPool"),o=s,l=!1;s.rank===3&&(l=!0,o=V(s,[1,s.shape[0],s.shape[1],s.shape[2]])),E(Ht(a,r),function(){return"Error in pool: Either strides or dilations must be 1. "+("Got strides "+a+" and dilations '"+r+"'")});var u=Vr(o.shape,t,a,r,i),c=[u.dilationHeight,u.dilationWidth],h;i==="same"?h=jx([u.filterHeight,u.filterWidth],c):h=[[0,0],[0,0]];var d=c[0]===1&&c[1]===1,p=Yx([u.inHeight,u.inWidth],c,h),f=p[0],m=p[1],g=d?i:"valid",v=d?o:co(o,c,f),b=e==="avg"?function(){return th(v,t,a,g)}:function(){return dh(v,t,a,g)},w=b(),S=d?w:Js(w,c,m);return l?V(S,[S.shape[1],S.shape[2],S.shape[3]]):S}function Yx(n,t,e){var i=e.map(function(c){return c[0]}),r=e.map(function(c){return c[1]}),a=n.concat(i,r),s=t.map(function(c,h){return(c-a[h]%c)%c}),o=r.map(function(c,h){return c+s[h]}),l=t.map(function(c,h){return[i[h],o[h]]}),u=t.map(function(c,h){return[0,s[h]]});return[l,u]}function jx(n,t){var e=n.map(function(s,o){return s+(s-1)*(t[o]-1)}),i=e.map(function(s){return s-1}),r=i.map(function(s){return Math.floor(s/2)}),a=i.map(function(s,o){return s-r[o]});return i.map(function(s,o){return[r[o],a[o]]})}var rv=U({pool_:Kx});function $x(n,t){var e,i=O(n,"base","pow"),r=O(t,"exp","pow");e=at(i,r),i=e[0],r=e[1];var a={a:i,b:r},s=function(o,l){var u=o.pow(i,r);return l([i,r,u]),u};return z.runKernelFunc(s,a,null,Uu)}var ni=U({pow_:$x});function Xx(n,t){var e=O(n,"x","prelu"),i=O(t,"alpha","prelu"),r=function(s,o){var l=s.prelu(e,i);return o([e,i]),l},a={x:e,alpha:i};return z.runKernelFunc(r,a,null,Bu)}var mh=U({prelu_:Xx});function Jx(n,t,e){t===void 0&&(t=null),e===void 0&&(e=!1);var i=O(n,"x","prod"),r=function(o){i.dtype==="bool"&&(i=ue(i,"int32"));var l=Qe(t,i.shape),u=an(l,i.rank),c=l,h=i;u!=null&&(h=ut(i,u),c=Un(c.length,i.rank));var d=o.prod(h,c);if(e){var p=rn(d.shape,l);d=V(d,p)}return d},a={x:i},s={axis:t,keepDims:e};return z.runKernelFunc(r,a,null,rm,s)}var av=U({prod_:Jx});function Zx(n,t,e){var i=ot(n),r=null;if(e==null||e==="float32")r=new Float32Array(i);else if(e==="int32")r=new Int32Array(i);else if(e==="bool")r=new Uint8Array(i);else throw new Error("Unknown data type "+e);for(var a=0;a<i;a++)r[a]=t();return z.makeTensor(r,n,e)}var Qx=U({rand_:Zx}),$r=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function rr(n,t){return t={exports:{}},n(t,t.exports),t.exports}var eC=rr(function(n){(function(t,e,i){function r(l){var u=this,c=o();u.next=function(){var h=2091639*u.s0+u.c*23283064365386963e-26;return u.s0=u.s1,u.s1=u.s2,u.s2=h-(u.c=h|0)},u.c=1,u.s0=c(" "),u.s1=c(" "),u.s2=c(" "),u.s0-=c(l),u.s0<0&&(u.s0+=1),u.s1-=c(l),u.s1<0&&(u.s1+=1),u.s2-=c(l),u.s2<0&&(u.s2+=1),c=null}function a(l,u){return u.c=l.c,u.s0=l.s0,u.s1=l.s1,u.s2=l.s2,u}function s(l,u){var c=new r(l),h=u&&u.state,d=c.next;return d.int32=function(){return c.next()*4294967296|0},d.double=function(){return d()+(d()*2097152|0)*11102230246251565e-32},d.quick=d,h&&(typeof h=="object"&&a(h,c),d.state=function(){return a(c,{})}),d}function o(){var l=4022871197,u=function(c){c=c.toString();for(var h=0;h<c.length;h++){l+=c.charCodeAt(h);var d=.02519603282416938*l;l=d>>>0,d-=l,d*=l,l=d>>>0,d-=l,l+=d*4294967296}return(l>>>0)*23283064365386963e-26};return u}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.alea=s})($r,n,!1)}),tC=rr(function(n){(function(t,e,i){function r(o){var l=this,u="";l.x=0,l.y=0,l.z=0,l.w=0,l.next=function(){var h=l.x^l.x<<11;return l.x=l.y,l.y=l.z,l.z=l.w,l.w^=l.w>>>19^h^h>>>8},o===(o|0)?l.x=o:u+=o;for(var c=0;c<u.length+64;c++)l.x^=u.charCodeAt(c)|0,l.next()}function a(o,l){return l.x=o.x,l.y=o.y,l.z=o.z,l.w=o.w,l}function s(o,l){var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(typeof c=="object"&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xor128=s})($r,n,!1)}),nC=rr(function(n){(function(t,e,i){function r(o){var l=this,u="";l.next=function(){var h=l.x^l.x>>>2;return l.x=l.y,l.y=l.z,l.z=l.w,l.w=l.v,(l.d=l.d+362437|0)+(l.v=l.v^l.v<<4^(h^h<<1))|0},l.x=0,l.y=0,l.z=0,l.w=0,l.v=0,o===(o|0)?l.x=o:u+=o;for(var c=0;c<u.length+64;c++)l.x^=u.charCodeAt(c)|0,c==u.length&&(l.d=l.x<<10^l.x>>>4),l.next()}function a(o,l){return l.x=o.x,l.y=o.y,l.z=o.z,l.w=o.w,l.v=o.v,l.d=o.d,l}function s(o,l){var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(typeof c=="object"&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xorwow=s})($r,n,!1)}),iC=rr(function(n){(function(t,e,i){function r(o){var l=this;l.next=function(){var c=l.x,h=l.i,d,p;return d=c[h],d^=d>>>7,p=d^d<<24,d=c[h+1&7],p^=d^d>>>10,d=c[h+3&7],p^=d^d>>>3,d=c[h+4&7],p^=d^d<<7,d=c[h+7&7],d=d^d<<13,p^=d^d<<9,c[h]=p,l.i=h+1&7,p};function u(c,h){var d,p,f=[];if(h===(h|0))p=f[0]=h;else for(h=""+h,d=0;d<h.length;++d)f[d&7]=f[d&7]<<15^h.charCodeAt(d)+f[d+1&7]<<13;for(;f.length<8;)f.push(0);for(d=0;d<8&&f[d]===0;++d);for(d==8?p=f[7]=-1:p=f[d],c.x=f,c.i=0,d=256;d>0;--d)c.next()}u(l,o)}function a(o,l){return l.x=o.x.slice(),l.i=o.i,l}function s(o,l){o==null&&(o=+new Date);var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(c.x&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xorshift7=s})($r,n,!1)}),rC=rr(function(n){(function(t,e,i){function r(o){var l=this;l.next=function(){var c=l.w,h=l.X,d=l.i,p,f;return l.w=c=c+1640531527|0,f=h[d+34&127],p=h[d=d+1&127],f^=f<<13,p^=p<<17,f^=f>>>15,p^=p>>>12,f=h[d]=f^p,l.i=d,f+(c^c>>>16)|0};function u(c,h){var d,p,f,m,g,v=[],b=128;for(h===(h|0)?(p=h,h=null):(h=h+"\0",p=0,b=Math.max(b,h.length)),f=0,m=-32;m<b;++m)h&&(p^=h.charCodeAt((m+32)%h.length)),m===0&&(g=p),p^=p<<10,p^=p>>>15,p^=p<<4,p^=p>>>13,m>=0&&(g=g+1640531527|0,d=v[m&127]^=p+g,f=d==0?f+1:0);for(f>=128&&(v[(h&&h.length||0)&127]=-1),f=127,m=4*128;m>0;--m)p=v[f+34&127],d=v[f=f+1&127],p^=p<<13,d^=d<<17,p^=p>>>15,d^=d>>>12,v[f]=p^d;c.w=g,c.X=v,c.i=f}u(l,o)}function a(o,l){return l.i=o.i,l.w=o.w,l.X=o.X.slice(),l}function s(o,l){o==null&&(o=+new Date);var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(c.X&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xor4096=s})($r,n,!1)}),aC=rr(function(n){(function(t,e,i){function r(o){var l=this,u="";l.next=function(){var h=l.b,d=l.c,p=l.d,f=l.a;return h=h<<25^h>>>7^d,d=d-p|0,p=p<<24^p>>>8^f,f=f-h|0,l.b=h=h<<20^h>>>12^d,l.c=d=d-p|0,l.d=p<<16^d>>>16^f,l.a=f-h|0},l.a=0,l.b=0,l.c=2654435769|0,l.d=1367130551,o===Math.floor(o)?(l.a=o/4294967296|0,l.b=o|0):u+=o;for(var c=0;c<u.length+20;c++)l.b^=u.charCodeAt(c)|0,l.next()}function a(o,l){return l.a=o.a,l.b=o.b,l.c=o.c,l.d=o.d,l}function s(o,l){var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(typeof c=="object"&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.tychei=s})($r,n,!1)}),ar=rr(function(n){(function(t,e){var i=this,r=256,a=6,s=52,o="random",l=e.pow(r,a),u=e.pow(2,s),c=u*2,h=r-1,d;function p(S,L,N){var C=[];L=L==!0?{entropy:!0}:L||{};var R=v(g(L.entropy?[S,w(t)]:S??b(),3),C),D=new f(C),k=function(){for(var W=D.g(a),F=l,P=0;W<u;)W=(W+P)*r,F*=r,P=D.g(1);for(;W>=c;)W/=2,F/=2,P>>>=1;return(W+P)/F};return k.int32=function(){return D.g(4)|0},k.quick=function(){return D.g(4)/4294967296},k.double=k,v(w(D.S),t),(L.pass||N||function(W,F,P,H){return H&&(H.S&&m(H,D),W.state=function(){return m(D,{})}),P?(e[o]=W,F):W})(k,R,"global"in L?L.global:this==e,L.state)}e["seed"+o]=p;function f(S){var L,N=S.length,C=this,R=0,D=C.i=C.j=0,k=C.S=[];for(N||(S=[N++]);R<r;)k[R]=R++;for(R=0;R<r;R++)k[R]=k[D=h&D+S[R%N]+(L=k[R])],k[D]=L;(C.g=function(W){for(var F,P=0,H=C.i,_=C.j,j=C.S;W--;)F=j[H=h&H+1],P=P*r+j[h&(j[H]=j[_=h&_+F])+(j[_]=F)];return C.i=H,C.j=_,P})(r)}function m(S,L){return L.i=S.i,L.j=S.j,L.S=S.S.slice(),L}function g(S,L){var N=[],C=typeof S,R;if(L&&C=="object")for(R in S)try{N.push(g(S[R],L-1))}catch(D){}return N.length?N:C=="string"?S:S+"\0"}function v(S,L){for(var N=S+"",C,R=0;R<N.length;)L[h&R]=h&(C^=L[h&R]*19)+N.charCodeAt(R++);return w(L)}function b(){try{var S;return d&&(S=d.randomBytes)?S=S(r):(S=new Uint8Array(r),(i.crypto||i.msCrypto).getRandomValues(S)),w(S)}catch(C){var L=i.navigator,N=L&&L.plugins;return[+new Date,i,N,i.screen,w(t)]}}function w(S){return String.fromCharCode.apply(0,S)}if(v(e.random(),t),n.exports){n.exports=p;try{d=require("crypto")}catch(S){}}})([],Math)});ar.alea=eC;ar.xor128=tC;ar.xorwow=nC;ar.xorshift7=iC;ar.xor4096=rC;ar.tychei=aC;var sC=ar,gh=sC.alea;var vh=function(){function n(t,e,i,r,a){this.mean=t,this.stdDev=e,this.dtype=i,this.nextVal=NaN,this.truncated=r,this.truncated&&(this.upper=this.mean+this.stdDev*2,this.lower=this.mean-this.stdDev*2);var s=a||Math.random();this.random=gh(s.toString())}return n.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var t=this.nextVal;return this.nextVal=NaN,t}for(var e,i,r=!1;!r;){var a=void 0,s=void 0,o=void 0;do a=2*this.random()-1,s=2*this.random()-1,o=a*a+s*s;while(o>=1||o===0);var l=Math.sqrt(-2*Math.log(o)/o);e=this.mean+this.stdDev*a*l,i=this.mean+this.stdDev*s*l,(!this.truncated||this.isValidTruncated(e))&&(r=!0)}return(!this.truncated||this.isValidTruncated(i))&&(this.nextVal=this.convertValue(i)),this.convertValue(e)},n.prototype.convertValue=function(t){return this.dtype==null||this.dtype==="float32"?t:Math.round(t)},n.prototype.isValidTruncated=function(t){return t<=this.upper&&t>=this.lower},n}(),oC=function(){function n(t,e,i,r){this.alpha=t,this.beta=1/e,this.dtype=i;var a=r||Math.random();this.randu=gh(a.toString()),this.randn=new vh(0,1,i,!1,this.randu()),t<1?this.d=t+2/3:this.d=t-1/3,this.c=1/Math.sqrt(9*this.d)}return n.prototype.nextValue=function(){for(var t,e,i,r,a,s;;){do r=this.randn.nextValue(),s=1+this.c*r;while(s<=0);if(s*=s*s,t=r*r,e=1-.331*t*t,i=.5*t+this.d*(1-s+Math.log(s)),a=this.randu(),a<e||Math.log(a)<i)break}return s=1/this.beta*this.d*s,this.alpha<1&&(s*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(s)},n.prototype.convertValue=function(t){return this.dtype==="float32"?t:Math.round(t)},n}(),lC=function(){function n(t,e,i,r){var a=this;if(t===void 0&&(t=0),e===void 0&&(e=1),this.canReturnFloat=function(){return a.dtype==null||a.dtype==="float32"},this.min=t,this.range=e-t,this.dtype=i,r==null&&(r=Math.random()),typeof r=="number"&&(r=r.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error("The difference between "+t+" - "+e+" <= 1 and dtype is not float");this.random=gh(r)}return n.prototype.convertValue=function(t){return this.canReturnFloat()?t:Math.round(t)},n.prototype.nextValue=function(){return this.convertValue(this.min+this.range*this.random())},n}();function uC(n,t,e,i,r){if(e===void 0&&(e=1),i===void 0&&(i="float32"),e==null&&(e=1),i==null&&(i="float32"),i!=="float32"&&i!=="int32")throw new Error("Unsupported data type "+i);for(var a=new oC(t,e,i,r),s=Wn(n,i),o=0;o<s.values.length;o++)s.values[o]=a.nextValue();return s.toTensor()}var cC=U({randomGamma_:uC});function hC(n,t,e,i,r){if(t===void 0&&(t=0),e===void 0&&(e=1),i!=null&&i==="bool")throw new Error("Unsupported data type "+i);for(var a=new vh(t,e,i,!1,r),s=Wn(n,i),o=0;o<s.values.length;o++)s.values[o]=a.nextValue();return s.toTensor()}var dC=U({randomNormal_:hC});function pC(n,t,e,i,r){t===void 0&&(t=0),e===void 0&&(e=1),i===void 0&&(i="float32");for(var a=Wn(n,i),s=new lC(t,e,null,r),o=0;o<a.values.length;o++)a.values[o]=s.nextValue();return a.toTensor()}var sv=U({randomUniform_:pC});function Xr(n,t){Yi(n);var e=Fn(n,t);if(e.length!==1)throw new Error("tensor1d() requires values to be a flat/TypedArray");var i=null;return gi(n,i,e,t)}function yh(n,t,e,i){if(e===void 0&&(e=1),i===void 0&&(i="float32"),e===0)throw new Error("Cannot have a step of zero");var r=function(){var s=n===t,o=n<t&&e<0,l=t<n&&e>1;if(s||o||l)return ti([0],i);var u=Math.abs(Math.ceil((t-n)/e)),c=Ur(u,i);t<n&&e===1&&(e=-1),c[0]=n;for(var h=1;h<c.length;h++)c[h]=c[h-1]+e;return Xr(c,i)},a={start:n,stop:t,step:e,dtype:i};return z.runKernelFunc(r,{},null,am,a)}function fC(n){var t=O(n,"x","reciprocal"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.reciprocal(t);return r([t]),a},e,null,zu)}var ov=U({reciprocal_:fC});function mC(n){var t=O(n,"x","relu"),e=function(r,a){return a([t]),t.dtype==="bool"?ue(t,"int32"):r.relu(t)},i={x:t};return z.runKernelFunc(e,i,null,Pu)}var Ka=U({relu_:mC});function gC(n){var t=O(n,"x","relu6"),e=function(r,a){return a([t]),t.dtype==="bool"?ue(t,"int32"):r.relu6(t)},i={x:t};return z.runKernelFunc(e,i,null,Vu)}var bh=U({relu6_:gC});function vC(n,t){var e=O(n,"x","reverse"),i=function(s){var o=Qe(t,e.shape);if(e.rank===0)return $i(e);var l=s.reverse(e,o);return V(l,e.shape)},r={x:e},a={dims:t};return z.runKernelFunc(i,r,null,qu,a)}var ii=U({reverse_:vC});function yC(n){var t=O(n,"x","reverse");return E(t.rank===1,function(){return"Error in reverse1D: x must be rank 1 but got rank "+t.rank+"."}),ii(t,0)}var bC=U({reverse1d_:yC});function wC(n,t){var e=O(n,"x","reverse");return E(e.rank===2,function(){return"Error in reverse2D: x must be rank 2 but got rank "+e.rank+"."}),ii(e,t)}var SC=U({reverse2d_:wC});function LC(n,t){var e=O(n,"x","reverse");return E(e.rank===3,function(){return"Error in reverse3D: x must be rank 3 but got rank "+e.rank+"."}),ii(e,t)}var IC=U({reverse3d_:LC});function AC(n,t){var e=O(n,"x","reverse");return E(e.rank===4,function(){return"Error in reverse4D: x must be rank 4 but got rank "+e.rank+"."}),ii(e,t)}var TC=U({reverse4d_:AC});function NC(n){var t=O(n,"x","round"),e={x:t};return z.runKernelFunc(function(i){return i.round(t)},e,null,Gu)}var lv=U({round_:NC});function xC(n){var t=O(n,"x","rsqrt"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.rsqrt(t);return r([t]),a},e,null,Yu)}var wh=U({rsqrt_:xC});function CC(n){var t=O(n,"x","selu"),e=function(r,a){var s=r.selu(t);return a([t]),s},i={x:t};return z.runKernelFunc(e,i,null,Ku)}var uv=U({selu_:CC});function RC(n,t,e,i,r,a,s){a===void 0&&(a=[1,1]),s===void 0&&(s="NHWC");var o=O(n,"x","separableConv2d"),l=O(t,"depthwiseFilter","separableConv2d"),u=O(e,"pointwiseFilter","separableConv2d"),c=o,h=!1;if(o.rank===3&&(h=!0,c=V(o,[1,o.shape[0],o.shape[1],o.shape[2]])),s==="NCHW")throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");E(c.rank===4,function(){return"Error in separableConv2d: input must be rank 4, but got "+("rank "+c.rank+".")}),E(l.rank===4,function(){return"Error in separableConv2d: depthwise filter must be rank 4, but "+("got rank "+l.rank+".")}),E(u.rank===4,function(){return"Error in separableConv2d: pointwise filter must be rank 4, but "+("got rank "+l.rank+".")}),E(u.shape[0]===1,function(){return"Error in separableConv2d: the first dimension of pointwise filter "+(" must be 1, but got "+u.shape[0]+".")}),E(u.shape[1]===1,function(){return"Error in separableConv2d: the second dimension of pointwise "+("filter must be 1, but got "+u.shape[1]+".")});var d=l.shape[2],p=l.shape[3];E(u.shape[2]===d*p,function(){return"Error in separableConv2d: the third dimension of pointwise filter "+("must be "+d*p+", ")+("but got "+u.shape[2]+".")});var f=qa(c,l,i,r,s,a),m=1,g=Gr(f,u,m,"valid",s);return h?V(g,[g.shape[1],g.shape[2],g.shape[3]]):g}var cv=U({separableConv2d_:RC});function OC(n,t){return de(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u,c,l,h;return pe(this,function(d){switch(d.label){case 0:return e=O(n,"x","setdiff1d"),i=O(t,"y","setdiff1d"),E(e.dtype===i.dtype,function(){return"x and y should have the same dtype, but got x ("+e.dtype+") and y ("+i.dtype+")."}),E(e.rank===1,function(){return"x should be 1D tensor, but got x ("+e.shape+")."}),E(i.rank===1,function(){return"y should be 1D tensor, but got y ("+i.shape+")."}),[4,e.data()];case 1:return r=d.sent(),[4,i.data()];case 2:for(a=d.sent(),s=new Set(a),o=0,l=0;l<r.length;l++)s.has(r[l])||o++;for(u=new Hs([o],e.dtype),c=new Hs([o],"int32"),l=0,h=0;l<r.length;l++)s.has(r[l])||(u.values[h]=r[l],c.values[h]=l,h++);return[2,[u.toTensor(),c.toTensor()]]}})})}var EC=OC;function DC(n){var t=O(n,"x","sign"),e={x:t};return z.runKernelFunc(function(i){return i.sign(t)},e,null,Zu)}var hv=U({sign_:DC});function kC(n){var t=O(n,"x","sin"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.sin(t);return r([t]),a},e,null,Xu)}var Sh=U({sin_:kC});function FC(n){var t=O(n,"x","sinh"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.sinh(t);return r([t]),a},e,null,Ju)}var Lh=U({sinh_:FC});function WC(n,t,e){var i=O(n,"x","slice1d");return E(i.rank===1,function(){return"slice1d expects a rank-1 tensor, but got a rank-"+i.rank+" tensor"}),ze(i,[t],[e])}var UC=U({slice1d_:WC});function BC(n,t,e){var i=O(n,"x","slice2d");return E(i.rank===2,function(){return"slice2d expects a rank-2 tensor, but got a rank-"+i.rank+" tensor"}),ze(i,t,e)}var zC=U({slice2d_:BC});function PC(n,t,e){var i=O(n,"x","slice3d");return E(i.rank===3,function(){return"slice3d expects a rank-3 tensor, but got a rank-"+i.rank+" tensor"}),ze(i,t,e)}var _C=U({slice3d_:PC});function MC(n,t,e){var i=O(n,"x","slice4d");return E(i.rank===4,function(){return"slice4d expects a rank-4 tensor, but got a rank-"+i.rank+" tensor"}),ze(i,t,e)}var HC=U({slice4d_:MC});function VC(n,t){t===void 0&&(t=-1);var e=O(n,"logits","softmax","float32");if(t===-1&&(t=e.rank-1),t!==e.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. "+("Logits was rank "+e.rank+" and dim was "+t));var i={logits:e},r={dim:t};return z.runKernelFunc(function(a,s){var o=a.softmax(e,t);return s([o]),o},i,null,ac,r)}var dv=U({softmax_:VC});function qC(n){E(n.dtype==="complex64",function(){return"The dtype for tf.spectral.fft() must be complex64 "+("but got "+n.dtype+".")});var t={input:n};return z.runKernelFunc(function(e){var i=n.shape[n.shape.length-1],r=n.size/i,a=n.as2D(r,i),s=e.fft(a);return s.reshape(n.shape)},t,null,Bf)}var ho=U({fft_:qC});function GC(n){E(n.dtype==="complex64",function(){return"The dtype for tf.spectral.ifft() must be complex64 "+("but got "+n.dtype+".")});var t={input:n};return z.runKernelFunc(function(e){var i=n.shape[n.shape.length-1],r=n.size/i,a=V(n,[r,i]),s=e.ifft(a);return V(s,n.shape)},t,null,Hf)}var $a=U({ifft_:GC});function YC(n){var t=n.shape[n.shape.length-1],e=n.size/t,i;if(t<=2){var r=V(n,[e,t]);i=$a(r)}else{var a=[e,2*(t-1)],s=V(ja(n),[e,t]),o=V(io(n),[e,t]),l=ii(ze(s,[0,1],[e,t-2]),1),u=J(ii(ze(o,[0,1],[e,t-2]),1),be(-1)),c=Rt([s,l],1),h=Rt([o,u],1),r=V(mi(c,h),[a[0],a[1]]);i=$a(r)}if(i=ja(i),n.rank===3&&n.shape[0]!==0){var d=i,p=n.shape[0];i=V(i,[p,i.shape[0]/p,i.shape[1]]),d.dispose()}return i}var Ih=U({irfft_:YC});function pv(n,t,e){e===void 0&&(e=0);var i=[];if(typeof t=="number")E(n.shape[e]%t===0,function(){return"Number of splits must evenly divide the axis."}),i=new Array(t).fill(n.shape[e]/t);else{var r=t.reduce(function(o,l){return l===-1&&(o+=1),o},0);E(r<=1,function(){return"There should be only one negative value in split array."});var a=t.indexOf(-1);if(a!==-1){var s=t.reduce(function(o,l){return l>0?o+l:o});t[a]=n.shape[e]-s}E(n.shape[e]===t.reduce(function(o,l){return o+l}),function(){return"The sum of sizes must match the size of the axis dimension."}),i=t}return i}function jC(n,t,e){e===void 0&&(e=0);var i=O(n,"x","split"),r=function(o,l){var u=Qe(e,i.shape)[0],c=pv(i,t,u);return o.split(i,c,u)},a={x:i},s={numOrSizeSplits:t,axis:e};return z.runKernelFunc(r,a,null,rc,s)}var Jr=U({split_:jC});function KC(n,t){E(n.dtype==="float32",function(){return"The dtype for rfft() must be real value but got "+n.dtype});var e=n.shape[n.shape.length-1],i=n.size/e,r;if(t!=null&&t<e){var a=n.shape.map(function(v){return 0}),s=n.shape.map(function(v){return v});s[n.shape.length-1]=t,r=ze(n,a,s),e=t}else if(t!=null&&t>e){var o=n.shape.map(function(v){return v});o[n.shape.length-1]=t-e,r=Rt([n,ti(o)],n.shape.length-1),e=t}else r=n;var l=Ee(r),u=V(mi(r,l),[i,e]),c=ho(u),h=Math.floor(e/2)+1,d=ja(c),p=io(c),f=Jr(d,[h,e-h],d.shape.length-1),m=Jr(p,[h,e-h],p.shape.length-1),g=r.shape.slice();return g[r.shape.length-1]=h,V(mi(f[0],m[0]),g)}var po=U({rfft_:KC});function $C(n){var t=O(n,"x","sqrt"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.sqrt(t);return r([t]),a},e,null,tc)}var Vt=U({sqrt_:$C});function XC(n,t){var e,i=O(n,"a","squaredDifference"),r=O(t,"b","squaredDifference");e=at(i,r),i=e[0],r=e[1],et(i.shape,r.shape);var a=function(l,u){var c=l.squaredDifference(i,r);return u([i,r]),c},s={a:i,b:r},o={};return z.runKernelFunc(a,s,null,sc,o)}var fo=U({squaredDifference_:XC});function JC(n,t){var e=O(n,"x","squeeze");return V(e,wm(e.shape,t).newShape)}var mo=U({squeeze_:JC});function ZC(n,t){t===void 0&&(t=0);var e=za(n,"tensors","stack");if(E(e.length>=1,function(){return"Pass at least one tensor to tf.stack"}),e.length===1)return wn(e[0],t);var i=e[0].rank,r=e[0].shape,a=e[0].dtype;E(t<=i,function(){return"Axis must be <= rank of the tensor"}),e.forEach(function(o){Be(r,o.shape,"All tensors passed to stack must have matching shapes"),E(a===o.dtype,function(){return"All tensors passed to stack must have matching dtypes"})});var s=e.map(function(o){return wn(o,t)});return Rt(s,t)}var sr=U({stack_:ZC});function QC(n,t){t===void 0&&(t=0);var e=O(n,"x","step"),i={x:e},r={alpha:t};return z.runKernelFunc(function(a){return a.step(e,t)},i,null,mc,r)}var Zr=U({step_:QC});function eR(n,t,e,i,r,a,s,o,l){r===void 0&&(r=0),a===void 0&&(a=0),s===void 0&&(s=0),o===void 0&&(o=0),l===void 0&&(l=0);var u=O(n,"x","stridedSlice"),c=function(p){i==null&&(i=new Array(t.length));var f=js(s);if(f.length>1)throw new Error("Multiple ellipses in slice is not allowed.");if(s!==0&&o!==0)throw new Error("Using both ellipsisMask and newAxisMask is not yet supported.");if(s!==0&&l!==0)throw new Error("Using both ellipsisMask and shrinkAxisMask is not yet supported.");var m=u.rank-t.length,g=js(o),v=u.shape.slice();g.forEach(function(W){t[W]=0,e[W]=1,v.splice(W,0,1)}),u=V(u,v);var b=mg(u.shape,f,m,t,e,i,r,a,s),w=b.begin,S=b.end,L=b.strides;t=w,e=S,i=L;var N=js(l);N.forEach(function(W){e[W]=t[W]+1,i[W]=1});var C=sg(t,e,i),R=C.filter(function(W,F){return N.indexOf(F)===-1}),D=i.every(function(W){return W===1});if(D)return V(ze(u,t,C),R);var k=p.stridedSlice(u,t,e,i);return V(k,R)},h={x:u},d={begin:t,end:e,strides:i,beginMask:r,endMask:a,ellipsisMask:s,newAxisMask:o,shrinkAxisMask:l};return z.runKernelFunc(c,h,null,dm,d)}var fv=U({stridedSlice_:eR});function tR(n){var t=O(n,"x","tan"),e={x:t};return z.runKernelFunc(function(i,r){var a=i.tan(t);return r([t]),a},e,null,lc)}var mv=U({tan_:tR});function Xa(n,t,e){if(Yi(n),t!=null&&t.length!==2)throw new Error("tensor2d() requires shape to have two numbers");var i=Fn(n,e);if(i.length!==2&&i.length!==1)throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");if(i.length===1&&t==null)throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");return gi(n,t,i,e)}function nR(n,t,e){if(Yi(n),t!=null&&t.length!==4)throw new Error("tensor4d() requires shape to have four numbers");var i=Fn(n,e);if(i.length!==4&&i.length!==1)throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");if(i.length===1&&t==null)throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");return gi(n,t,i,e)}function iR(n,t,e){if(Yi(n),t!=null&&t.length!==5)throw new Error("tensor5d() requires shape to have five numbers");var i=Fn(n,e);if(i.length!==5&&i.length!==1)throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");if(i.length===1&&t==null)throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");return gi(n,t,i,e)}function rR(n,t,e){if(Yi(n),t!=null&&t.length!==6)throw new Error("tensor6d() requires shape to have six numbers");var i=Fn(n,e);if(i.length!==6&&i.length!==1)throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");if(i.length===1&&t==null)throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");return t=t||i,gi(n,t,i,e)}function aR(n,t,e){t===void 0&&(t=1),e===void 0&&(e=!0);var i=O(n,"x","topk");if(i.rank===0)throw new Error("topk() expects the input to be of rank 1 or higher");var r=i.shape[i.shape.length-1];if(t>r)throw new Error("'k' passed to topk() must be <= the last dimension ("+r+") "+("but got "+t));var a={x:i},s={k:t,sorted:e},o=z.runKernelFunc(function(c){return c.topk(i,t,e)},a,null,pm,s),l=o[0],u=o[1];return{values:l,indices:u}}var gv=U({topk_:aR});function sR(n,t,e,i,r){if(t===void 0&&(t=0),e===void 0&&(e=1),i!=null&&i==="bool")throw new Error("Unsupported data type $ { dtype }");for(var a=new vh(t,e,i,!0,r),s=Wn(n,i),o=0;o<s.values.length;o++)s.values[o]=a.nextValue();return s.toTensor()}var oR=U({truncatedNormal_:sR});function lR(n,t){t===void 0&&(t=0);var e=O(n,"x","unique",null);E(e.rank>0,function(){return"The input tensor must be at least 1D"});var i={x:e},r={axis:t},a=z.runKernel(fm,i,r),s=a[0],o=a[1];return{values:s,indices:o}}var vv=U({unique_:lR});function uR(n,t,e){var i=O(n,"x","unsortedSegmentSum"),r=O(t,"segmentIds","unsortedSegmentSum","int32");E(rt(e),function(){return"numSegments must be of dtype int"});var a={x:i,segmentIds:r},s={numSegments:e},o=function(l,u){var c=l.unsortedSegmentSum(i,r,e);return u([r]),c};return z.runKernelFunc(o,a,null,pc,s)}var Ah=U({unsortedSegmentSum_:uR});function cR(n,t){t===void 0&&(t=0);var e=O(n,"x","unstack");E(t>=-e.shape.length&&t<e.shape.length,function(){return"Axis = "+t+" is not in [-"+e.shape.length+", "+e.shape.length+")"}),t<0&&(t+=e.shape.length);var i={value:e},r={axis:t},a=function(s){return s.unstack(e,t)};return z.runKernelFunc(a,i,null,dc,r)}var go=U({unstack_:cR});function hR(n,t,e,i){return t===void 0&&(t=!0),z.makeVariable(n,t,e,i)}function yv(n,t){for(var e=[],i=0;i<t.length;i++)t[i]&&e.push(i);for(var r=Wn(n,"int32"),a=Wn([e.length,n.length],"int32"),i=0;i<e.length;i++){var s=r.indexToLoc(e[i]),o=i*n.length;a.values.set(s,o)}return a.toTensor()}function dR(n){return de(this,void 0,void 0,function(){var t,e,i;return pe(this,function(r){switch(r.label){case 0:return t=O(n,"condition","whereAsync","bool"),[4,t.data()];case 1:return e=r.sent(),i=yv(t.shape,e),n!==t&&t.dispose(),[2,i]}})})}var bv=dR;function pR(n,t,e){return de(this,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h,d,p,f,m;return pe(this,function(g){switch(g.label){case 0:for(i=O(n,"tensor","boolMask"),r=O(t,"mask","boolMask","bool"),a=e??0,s=r.rank,o=i.shape,E(s>0,function(){return"mask cannot be scalar"}),Be(o.slice(a,a+s),r.shape,"mask's shape must match the first K dimensions of tensor's shape,"),l=1,u=a;u<a+s;u++)l*=o[u];return c=o.slice(0,a).concat([l],o.slice(a+s)),h=V(i,c),d=V(r,[-1]),[4,bv(d)];case 1:return p=g.sent(),f=mo(p,[1]),m=no(h,f,a),n!==i&&i.dispose(),t!==r&&r.dispose(),f.dispose(),h.dispose(),d.dispose(),p.dispose(),[2,m]}})})}var fR=pR;function mR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","notEqualStrict"),i=O(t,"b","notEqualStrict");return Be(e.shape,i.shape,"Error in notEqualStrict: "),uo(e,i)}function gR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","lessStrict"),i=O(t,"b","lessStrict");return Be(e.shape,i.shape,"Error in lessStrict: "),ro(e,i)}function vR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","equalStrict"),i=O(t,"b","equalStrict");return Be(e.shape,i.shape,"Error in equalStrict: "),Ga(e,i)}function yR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","lessEqualStrict"),i=O(t,"b","lessEqualStrict");return Be(e.shape,i.shape,"Error in lessEqualStrict: "),Qi(e,i)}function bR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","greaterStrict"),i=O(t,"b","greaterStrict");return Be(e.shape,i.shape,"Error in greaterStrict: "),Li(e,i)}function wR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","greaterEqualStrict"),i=O(t,"b","greaterEqualStrict");return Be(e.shape,i.shape,"Error in greaterEqualStrict: "),Zi(e,i)}var wv=U({equalStrict_:vR}),Sv=U({greaterEqualStrict_:wR}),Lv=U({greaterStrict_:bR}),Iv=U({lessEqualStrict_:yR}),Av=U({lessStrict_:gR}),Tv=U({notEqualStrict_:mR});function SR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","addStrict"),i=O(t,"b","addStrict");return Be(e.shape,i.shape,"Error in addStrict: "),fe(e,i)}function LR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","subStrict"),i=O(t,"b","subStrict");return Be(e.shape,i.shape,"Error in subStrict: "),ge(e,i)}function IR(n,t){return At("strict variants of ops have been deprecated and will be removed in future"),Be(n.shape,t.shape,"Error in powStrict: "),ni(n,t)}function AR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","mul"),i=O(t,"b","mul");return Be(e.shape,i.shape,"Error in multiplyStrict: "),J(e,i)}function TR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","div"),i=O(t,"b","div");return Be(e.shape,i.shape,"Error in divideStrict: "),Ie(e,i)}function NR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","modStrict"),i=O(t,"b","modStrict");return Be(e.shape,i.shape,"Error in modStrict: "),ph(e,i)}function xR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","minimumStrict"),i=O(t,"b","minimumStrict");return Be(e.shape,i.shape,"Error in minimumStrict: "),lo(e,i)}function CR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","maximumStrict"),i=O(t,"b","maximumStrict");return Be(e.shape,i.shape,"Error in maximumStrict: "),jr(e,i)}function RR(n,t){At("strict variants of ops have been deprecated and will be removed in future");var e=O(n,"a","squaredDifferenceStrict"),i=O(t,"b","squaredDifferenceStrict");return Be(e.shape,i.shape,"Error in squaredDifferenceStrict: "),fo(e,i)}var Nv=U({addStrict_:SR}),xv=U({divStrict_:TR}),Cv=U({maximumStrict_:CR}),Rv=U({minimumStrict_:xR}),Ov=U({modStrict_:NR}),Ev=U({mulStrict_:AR}),Dv=U({powStrict_:IR}),kv=U({squaredDifferenceStrict_:RR}),Fv=U({subStrict_:LR});function OR(n,t,e,i){t===void 0&&(t="euclidean"),e===void 0&&(e=null),i===void 0&&(i=!1),n=O(n,"x","norm");var r=Wv(n,t,e),a=r.shape;if(i){var s=Qe(e,n.shape);a=rn(r.shape,s)}return V(r,a)}function Wv(n,t,e){if(e===void 0&&(e=null),n.rank===0)return Kt(n);if(n.rank!==1&&e===null)return Wv(V(n,[-1]),t,e);if(n.rank===1||typeof e=="number"||Array.isArray(e)&&e.length===1){if(t===1)return Ae(Kt(n),e);if(t===Infinity)return tr(Kt(n),e);if(t===-Infinity)return oo(Kt(n),e);if(t==="euclidean"||t===2)return Vt(Ae(ni(Kt(n),be(2,"int32")),e));throw new Error("Error in norm: invalid ord value: "+t)}if(Array.isArray(e)&&e.length===2){if(t===1)return tr(Ae(Kt(n),e[0]),e[1]-1);if(t===Infinity)return tr(Ae(Kt(n),e[1]),e[0]);if(t===-Infinity)return oo(Ae(Kt(n),e[1]),e[0]);if(t==="fro"||t==="euclidean")return Vt(Ae(Ye(n),e));throw new Error("Error in norm: invalid ord value: "+t)}throw new Error("Error in norm: invalid axis: "+e)}var vo=U({norm_:OR});function ER(n,t,e,i,r){r===void 0&&(r=!0);var a=O(n,"v","movingAverage"),s=O(t,"x","movingAverage"),o=O(e,"decay","movingAverage");Dm(a,s),E(dn(a.shape,s.shape),function(){return"Shape mismatch in v and x"});var l=be(1),u=ge(l,o),c=J(ge(s,a),u);if(r){E(i!=null,function(){return"When using zeroDebias: true, step is required."});var h=O(i,"step","movingAverage");c=Ie(c,ge(l,ni(o,h)))}return fe(a,c)}var DR=U({movingAverage_:ER});function kR(n,t,e){var i=O(n,"indices","scatterND","int32"),r=O(t,"updates","scatterND");Yc(r,i,e);var a=function(l){return l.scatterND(i,r,e)},s={indices:i,updates:r},o={shape:e};return z.runKernelFunc(a,s,null,um,o)}var FR=U({scatterND_:kR});function WR(n,t,e,i){if(n.dtype!=="int32")throw new Error("tf.sparseToDense() expects the indices to be int32 type,"+(" but the dtype was "+n.dtype+"."));if(n.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix,"+(" but got shape "+n.shape+"."));var r=n.rank>0?n.shape[0]:1,a=n.rank>1?n.shape[1]:1;if(e.length!==a)throw new Error("outputShape has incorrect number of elements:,"+(" "+e.length+", should be: "+a+"."));var s=t.size;if(!(t.rank===0||t.rank===1&&s===r))throw new Error("sparseValues has incorrect shape "+(t.shape+", should be [] or ["+r+"]"));if(t.dtype!==i.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}function UR(n,t,e,i){i===void 0&&(i=0);var r=O(n,"sparseIndices","sparseToDense","int32"),a=O(t,"sparseValues","sparseToDense"),s=O(i,"defaultValue","sparseToDense",a.dtype);WR(r,a,e,s);var o={sparseIndices:r,sparseValues:a,defaultValue:s},l={outputShape:e};return z.runKernelFunc(function(u){return u.sparseToDense(r,a,e,s)},o,null,hm,l)}var BR=U({sparseToDense_:UR});function zR(n,t){var e=O(t,"indices","gatherND","int32"),i=O(n,"x","gatherND"),r=function(s){return s.gatherND(i,e)},a={params:i,indices:e};return z.runKernelFunc(r,a,null,_f)}var PR=U({gatherND_:zR});function _R(n,t){if(t==null)return n.shape.slice();if(dn(n.shape,t))return t;if(n.shape.length===t.length){for(var e=[],i=0;i<n.shape.length;i++)t[i]==null&&n.shape[i]!=null?e.push(n.shape[i]):e.push(t[i]);return e}return t}function MR(n,t,e,i){var r=O(n,"x","dropout");if(E(r.dtype==="float32",function(){return"x has to be a floating point tensor since it's going to be "+("scaled, but got a "+r.dtype+" tensor instead.")}),E(t>=0&&t<1,function(){return"rate must be a float in the range [0, 1), but got "+t+"."}),t===0)return n instanceof Y?r.clone():r;var a=_R(r,e),s=1-t,o=Ie(to(fe(sv(a,0,1,"float32",i),s)),s);return J(r,o)}var HR=U({dropout_:MR});function Uv(n){return Math.floor(Math.pow(2,Math.ceil(Math.log(n)/Math.log(2))))}function Th(n,t,e){for(var i=1-n%2,r=new Float32Array(n),a=0;a<n;++a){var s=2*Math.PI*a/(n+i-1);r[a]=t-e*Math.cos(s)}return Xr(r,"float32")}function VR(n,t,e){return e===void 0&&(e=1),de(this,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h,d,p,f,m,g,g;return pe(this,function(v){switch(v.label){case 0:return i=O(n,"predictions","inTopK"),r=O(t,"targets","inTopK"),E(i.rank>1,function(){return"inTopK() expects the predictions to be of rank 2 or higher, "+("but got "+i.rank)}),E(i.rank-1===r.rank,function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+(i.rank+" and targets rank "+r.rank)}),Be(i.shape.slice(0,i.shape.length-1),r.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),a=i.shape[i.shape.length-1],E(e>0&&e<=a,function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last "+("dimension ("+a+"), but got "+e)}),[4,i.data()];case 1:return s=v.sent(),[4,r.data()];case 2:for(o=v.sent(),l=[s.length/a,a],u=l[0],c=l[1],h=Bs("bool",u),d=0;d<u;d++){for(p=d*c,f=s.subarray(p,p+c),m=[],g=0;g<f.length;g++)m.push({value:f[g],index:g});for(m.sort(function(b,w){return w.value-b.value}),h[d]=0,g=0;g<e;g++)if(m[g].index===o[d]){h[d]=1;break}}return n!==i&&i.dispose(),t!==r&&r.dispose(),[2,vi(h,r.shape,"bool")]}})})}var qR=VR;function GR(n,t,e,i,r,a,s){a===void 0&&(a="NHWC");var o=n;n.rank===3&&(o=V(n,[1,n.shape[0],n.shape[1],n.shape[2]]));var l=t;l.rank===3&&(l=V(t,[1,t.shape[0],t.shape[1],t.shape[2]])),E(o.rank===4,function(){return"Error in conv2dDerFilter: input must be rank 4, but got shape "+(o.shape+".")}),E(l.rank===4,function(){return"Error in conv2dDerFilter: dy must be rank 4, but got shape "+(l.shape+".")}),E(e.length===4,function(){return"Error in conv2dDerFilter: filterShape must be length 4, but got "+(e+".")});var u=a==="NHWC"?o.shape[3]:o.shape[1],c=a==="NHWC"?l.shape[3]:l.shape[1];E(u===e[2],function(){return"Error in conv2dDerFilter: depth of input "+u+") must "+("match input depth in filter ("+e[2]+".")}),E(c===e[3],function(){return"Error in conv2dDerFilter: depth of dy ("+c+") must "+("match output depth for filter ("+e[3]+").")}),s!=null&&E(rt(r),function(){return"Error in conv2dDerFilter: pad must be an integer when using, "+("dimRoundingMode "+s+" but got pad "+r+".")});var h=function(f){var m=1,g=_a(a),v=Bn(o.shape,e,i,m,r,s,!1,g);return f.conv2dDerFilter(o,l,v)},d={x:o,dy:l},p={strides:i,pad:r,dataFormat:a,dimRoundingMode:s};return z.runKernelFunc(h,d,null,Tf,p)}var Nh=U({conv2DBackpropFilter_:GR});function yo(n,t,e){if(e==null||e==="linear")return n;if(e==="relu")return J(n,Zr(t));throw new Error("Cannot compute gradient for fused activation "+e+".")}function bo(n,t){var e=t,i=gt(n.shape,t.shape);return i.length>0&&(e=Ae(e,i)),V(e,n.shape)}function wo(n,t,e){if(t==="linear")return n;if(t==="relu")return Ka(n);if(t==="elu")return ah(n);if(t==="relu6")return bh(n);if(t==="prelu")return mh(n,e);throw new Error("Unknown fused activation "+t+".")}var So=function(n,t){var e=n>0;return!e||t==="linear"};function YR(n){var t=n.x,e=n.filter,i=n.strides,r=n.pad,a=n.dataFormat,s=a===void 0?"NHWC":a,o=n.dilations,l=o===void 0?[1,1]:o,u=n.dimRoundingMode,c=n.bias,h=n.activation,d=h===void 0?"linear":h,p=n.preluActivationWeights;if(d=d||"linear",So(z.state.gradientDepth,d)===!1){var f=Gr(t,e,i,r,s,l,u);return c!=null&&(f=fe(f,c)),wo(f,d,p)}var m=O(t,"x","conv2d"),g=O(e,"filter","conv2d"),v=m,b=!1;m.rank===3&&(b=!0,v=V(m,[1,m.shape[0],m.shape[1],m.shape[2]])),E(v.rank===4,function(){return"Error in fused conv2d: input must be rank 4, but got rank "+(v.rank+".")}),E(g.rank===4,function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+(g.rank+".")}),u!=null&&E(rt(r),function(){return"Error in fused conv2d: pad must be an integer when using, "+("dimRoundingMode "+u+" but got pad "+r+".")}),E(v.shape[3]===g.shape[2],function(){return"Error in conv2d: depth of input ("+v.shape[3]+") must match "+("input depth for filter "+g.shape[2]+".")}),E(Ht(i,l),function(){return"Error in conv2D: Either strides or dilations must be 1. "+("Got strides "+i+" and dilations '"+l+"'")}),E(s==="NHWC",function(){return"Error in conv2d: got dataFormat of "+s+" but only NHWC is currently supported."});var w=Bn(v.shape,g.shape,i,l,r,u),S;c!=null&&(S=O(c,"bias","fused conv2d"),S=at(S,m)[0],et(w.outShape,S.shape));var L;p!=null&&(L=O(p,"prelu weights","fused conv2d"));var N=function(F,P){var H=P,_=H[0],j=H[1],K=H[2],q=H[3],G=yo(F,K,d);E(Si(l),function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 "+("are not yet supported in gradients. Got dilations '"+l+"'")});var Z=nh(j.shape,G,_,i,r),X=Nh(j,G,_.shape,i,r),ee=[Z,X];if(q!=null){var ne=bo(q,G);ee.push(ne)}return ee},C=function(F){var P=F.fusedConv2d({input:v,filter:g,convInfo:w,bias:S,activation:d,preluActivationWeights:L});return P},R={x:v,filter:g,bias:S,preluActivationWeights:L},D={strides:i,pad:r,dataFormat:s,dilations:l,dimRoundingMode:u,activation:d};if(c==null){var k=zn(function(F,P,H){var _=z.runKernelFunc(C,R,null,yc,D);return H([P,F,_]),b&&(_=V(_,[_.shape[1],_.shape[2],_.shape[3]])),{value:_,gradFunc:N}});return k(v,g)}else{var W=zn(function(F,P,H,_){var j=z.runKernelFunc(C,R,null,yc,D);return _([P,F,j,H]),b&&(j=V(j,[j.shape[1],j.shape[2],j.shape[3]])),{value:j,gradFunc:N}});return W(v,g,S)}}var jR=U({fusedConv2d_:YR});function KR(n,t,e,i){var r=n;n.rank===3&&(r=V(n,[1,n.shape[0],n.shape[1],n.shape[2]]));var a=t;a.rank===3&&(a=V(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var s=function(l){return l.depthwiseConv2DDerFilter(r,a,i)},o={x:r,dy:a};return z.runKernelFunc(s,o,null,Of)}var Bv=U({depthwiseConv2dNativeBackpropFilter_:KR});function $R(n,t,e,i){var r=t,a=!1;t.rank===3&&(a=!0,r=V(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var s=function(u){return u.depthwiseConv2DDerInput(r,e,i)},o={dy:r},l=z.runKernelFunc(s,o,null,Ef);return a?V(l,[l.shape[1],l.shape[2],l.shape[3]]):l}var zv=U({depthwiseConv2dNativeBackpropInput_:$R});function XR(n){var t=n.x,e=n.filter,i=n.strides,r=n.pad,a=n.dataFormat,s=a===void 0?"NHWC":a,o=n.dilations,l=o===void 0?[1,1]:o,u=n.dimRoundingMode,c=n.bias,h=n.activation,d=h===void 0?"linear":h,p=n.preluActivationWeights;if(So(z.state.gradientDepth,d)===!1){var f=qa(t,e,i,r,s,l,u);return c!=null&&(f=fe(f,c)),wo(f,d,p)}var m=O(t,"x","depthwiseConv2d"),g=O(e,"filter","depthwiseConv2d"),v=m,b=!1;m.rank===3&&(b=!0,v=V(m,[1,m.shape[0],m.shape[1],m.shape[2]])),E(v.rank===4,function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got "+("rank "+v.rank+".")}),E(g.rank===4,function(){return"Error in fused depthwiseConv2d: filter must be rank 4, "+("but got rank "+g.rank+".")}),E(v.shape[3]===g.shape[2],function(){return"Error in fused depthwiseConv2d: number of input channels "+("("+v.shape[3]+") must match the inChannels dimension in ")+("filter "+g.shape[2]+".")}),l==null&&(l=[1,1]),E(Ht(i,l),function(){return"Error in fused depthwiseConv2d: Either strides or dilations must "+("be 1. Got strides "+i+" and dilations '"+l+"'")}),u!=null&&E(rt(r),function(){return"Error in fused depthwiseConv2d: pad must be an integer when "+("using dimRoundingMode "+u+" but got pad "+r+".")});var w=Bn(v.shape,g.shape,i,l,r,u,!0),S;c!=null&&(S=O(c,"bias","fused conv2d"),S=at(S,m)[0],et(w.outShape,S.shape));var L;p!=null&&(L=O(p,"prelu weights","fused depthwiseConv2d"));var N=function(F,P){E(Si(l),function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations "+("'"+l+"'")});var H=P[0],_=P[1],j=P[2],K=P[3],q=yo(F,j,d),G=zv(_.shape,q,H,w),Z=Bv(_,q,H.shape,w);if(K!=null){var X=bo(S,q);return[G,Z,X]}return[G,Z]},C=function(F){var P=F.fusedDepthwiseConv2D({input:v,filter:g,convInfo:w,bias:S,activation:d,preluActivationWeights:L});return P},R={x:v,filter:g,bias:S,preluActivationWeights:L},D={strides:i,pad:r,dataFormat:s,dilations:l,dimRoundingMode:u,activation:d};if(c==null){var k=zn(function(F,P,H){var _=z.runKernelFunc(C,R,null,bc,D);return H([P,F,_]),b&&(_=V(_,[_.shape[1],_.shape[2],_.shape[3]])),{value:_,gradFunc:N}});return k(v,g)}else{var W=zn(function(F,P,H,_){var j=z.runKernelFunc(C,R,null,bc,D);return _([P,F,j,H]),b&&(j=V(j,[j.shape[1],j.shape[2],j.shape[3]])),{value:j,gradFunc:N}});return W(v,g,S)}}var JR=U({fusedDepthwiseConv2d_:XR});function ZR(n){var t,e=n.a,i=n.b,r=n.transposeA,a=r===void 0?!1:r,s=n.transposeB,o=s===void 0?!1:s,l=n.bias,u=n.activation,c=u===void 0?"linear":u,h=n.preluActivationWeights;if(So(z.state.gradientDepth,c)===!1){var d=We(e,i,a,o);return l!=null&&(d=fe(d,l)),wo(d,c,h)}var p=O(e,"a","fused matMul"),f=O(i,"b","fused matMul");t=at(p,f),p=t[0],f=t[1];var m=a?p.shape[p.rank-2]:p.shape[p.rank-1],g=o?f.shape[f.rank-1]:f.shape[f.rank-2],v=a?p.shape[p.rank-1]:p.shape[p.rank-2],b=o?f.shape[f.rank-2]:f.shape[f.rank-1],w=p.shape.slice(0,-2),S=f.shape.slice(0,-2),L=ot(w),N=ot(S);E(p.rank>=2&&f.rank>=2&&p.rank===f.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least "+("2, got ranks "+p.rank+" and "+f.rank+".")}),E(dn(w,S),function(){return"Error in fused matMul: outer dimensions ("+w+") and ("+(S+") of Tensors with shapes "+p.shape+" and ")+(f.shape+" must match.")}),E(m===g,function(){return"Error in fused matMul: inner shapes ("+m+") and ("+(g+") of Tensors with shapes "+p.shape+" and ")+(f.shape+" and transposeA="+a)+(" and transposeB="+o+" must match.")});var C=p.shape.slice(0,-2).concat([v,b]),R=a?V(p,[L,m,v]):V(p,[L,v,m]),D=o?V(f,[N,b,g]):V(f,[N,g,b]),k;l!=null&&(k=O(l,"bias","fused matMul"),k=at(k,p)[0],et(C,k.shape));var W;h!=null&&(W=O(h,"prelu weights","fused matMul"));var F=function(q,G){var Z=G[0],X=G[1],ee=G[2],ne=G[3],ie=yo(V(q,ee.shape),ee,c),te,re;if(!a&&!o?(te=We(ie,X,!1,!0),re=We(Z,ie,!0,!1)):!a&&o?(te=We(ie,X,!1,!1),re=We(ie,Z,!0,!1)):a&&!o?(te=We(X,ie,!1,!0),re=We(Z,ie,!1,!1)):(te=We(X,ie,!0,!0),re=We(ie,Z,!0,!0)),l!=null){var le=bo(ne,ie);return[te,re,le]}else return[te,re]},P=function(q){var G=q.fusedBatchMatMul({a:R,b:D,transposeA:a,transposeB:o,bias:k,activation:c,preluActivationWeights:W});return G},H={a:R,b:D,bias:k,preluActivationWeights:W},_={transposeA:a,transposeB:o,activation:c};if(l==null){var j=zn(function(q,G,Z){var X=z.runKernelFunc(P,H,null,vc,_);return Z([q,G,X]),{value:V(X,C),gradFunc:F}});return j(R,D)}else{var K=zn(function(q,G,Z,X){var ee=z.runKernelFunc(P,H,null,vc,_);return X([q,G,ee,Z]),{value:V(ee,C),gradFunc:F}});return K(R,D,k)}}var QR=U({fusedMatMul_:ZR});var eO={__proto__:null,conv2d:jR,depthwiseConv2d:JR,matMul:QR};function tO(n){return Th(n,.54,.46)}var nO=U({hammingWindow_:tO});function iO(n){return Th(n,.5,.5)}var Pv=U({hannWindow_:iO});function rO(n,t,e,i,r){i===void 0&&(i=!1),r===void 0&&(r=0);for(var a=0,s=[];a+t<=n.size;)s.push(ze(n,a,t)),a+=e;if(i)for(;a<n.size;){var o=a+t-n.size,l=Rt([ze(n,a,t-o),sh([o],r)]);s.push(l),a+=e}return s.length===0?Xa([],[0,t]):V(Rt(s),[s.length,t])}var _v=U({frame_:rO});function aO(n,t,e,i,r){r===void 0&&(r=Pv),i==null&&(i=Uv(t));for(var a=_v(n,t,e),s=J(a,r(t)),o=[],l=0;l<a.shape[0];l++)o.push(po(ze(s,[l,0],[1,t]),i));return Rt(o)}var sO=U({stft_:aO});function oO(n,t,e,i,r,a){var s=O(n,"image","cropAndResize"),o=O(t,"boxes","cropAndResize","float32"),l=O(e,"boxInd","cropAndResize","int32");r=r||"bilinear",a=a||0;var u=o.shape[0];E(s.rank===4,function(){return"Error in cropAndResize: image must be rank 4,"+("but got rank "+s.rank+".")}),E(o.rank===2&&o.shape[1]===4,function(){return"Error in cropAndResize: boxes must be have size ["+u+",4] "+("but had shape "+o.shape+".")}),E(l.rank===1&&l.shape[0]===u,function(){return"Error in cropAndResize: boxInd must be have size ["+u+"] "+("but had shape "+o.shape+".")}),E(i.length===2,function(){return"Error in cropAndResize: cropSize must be of length 2, but got "+("length "+i.length+".")}),E(i[0]>=1&&i[1]>=1,function(){return"cropSize must be atleast [1,1], but was "+i}),E(r==="bilinear"||r==="nearest",function(){return"method must be bilinear or nearest, but was "+r});var c=function(f){return f.cropAndResize(s,o,l,i,r,a)},h={image:s,boxes:o,boxInd:l},d={method:r,extrapolationValue:a,cropSize:i},p=z.runKernelFunc(c,h,null,Cf,d);return p}var lO=U({cropAndResize_:oO});function uO(n){var t=O(n,"image","flipLeftRight","float32");E(t.rank===4,function(){return"Error in flipLeftRight: image must be rank 4,"+("but got rank "+t.rank+".")});var e={image:t},i=z.runKernel(Pf,e,{});return i}var cO=U({flipLeftRight_:uO});function hO(n,t,e,i){e===void 0&&(e=0),i===void 0&&(i=.5);var r=O(n,"image","rotateWithOffset","float32");E(r.rank===4,function(){return"Error in rotateWithOffset: image must be rank 4,"+("but got rank "+r.rank+".")});var a={image:r},s={radians:t,fillValue:e,center:i},o=z.runKernel(mm,a,s);return o}var dO=U({rotateWithOffset_:hO});function Qr(n,t,e,i,r,a){i==null&&(i=.5),r==null&&(r=Number.NEGATIVE_INFINITY),a==null&&(a=0);var s=n.shape[0];return e=Math.min(e,s),E(0<=i&&i<=1,function(){return"iouThreshold must be in [0, 1], but was '"+i+"'"}),E(n.rank===2,function(){return"boxes must be a 2D tensor, but was of rank '"+n.rank+"'"}),E(n.shape[1]===4,function(){return"boxes must have 4 columns, but 2nd dimension was "+n.shape[1]}),E(t.rank===1,function(){return"scores must be a 1D tensor"}),E(t.shape[0]===s,function(){return"scores has incompatible shape with boxes. Expected "+s+", "+("but was "+t.shape[0])}),E(0<=a&&a<=1,function(){return"softNmsSigma must be in [0, 1], but was '"+a+"'"}),{maxOutputSize:e,iouThreshold:i,scoreThreshold:r,softNmsSigma:a}}function pO(n,t,e,i,r){i===void 0&&(i=.5),r===void 0&&(r=Number.NEGATIVE_INFINITY);var a=O(n,"boxes","nonMaxSuppression"),s=O(t,"scores","nonMaxSuppression"),o=Qr(a,s,e,i,r);e=o.maxOutputSize,i=o.iouThreshold,r=o.scoreThreshold;var l={maxOutputSize:e,iouThreshold:i,scoreThreshold:r};return z.runKernelFunc(function(u){return u.nonMaxSuppression(a,s,e,i,r)},{boxes:a,scores:s},null,tm,l)}var fO=U({nonMaxSuppression_:pO});function gO(n,t,e){var i=mO(n,t,e),r=i<0?-(i+1):i;n.splice(r,0,t)}function mO(n,t,e){return yO(n,t,e||vO)}function vO(n,t){return n>t?1:n<t?-1:0}function yO(n,t,e){for(var i=0,r=n.length,a=0,s=!1;i<r;){a=i+(r-i>>>1);var o=e(t,n[a]);o>0?i=a+1:(r=a,s=!o)}return s?i:-i-1}function Mv(n,t,e,i,r){return xh(n,t,e,i,r,0).selectedIndices}function Hv(n,t,e,i,r,a){return xh(n,t,e,i,r,0,!1,a,!0)}function Vv(n,t,e,i,r,a){return xh(n,t,e,i,r,a,!0)}function xh(n,t,e,i,r,a,s,o,l){s===void 0&&(s=!1),o===void 0&&(o=!1),l===void 0&&(l=!1);for(var u=[],c=0;c<t.length;c++)t[c]>r&&u.push({score:t[c],boxIndex:c,suppressBeginIndex:0});u.sort(qv);for(var h=a>0?-.5/a:0,d=[],p=[];d.length<e&&u.length>0;){var f=u.pop(),m=f.score,g=f.boxIndex,v=f.suppressBeginIndex;if(m<r)break;for(var b=!1,w=d.length-1;w>=v;--w){var S=bO(n,g,d[w]);if(S>=i){b=!0;break}if(f.score=f.score*wO(i,h,S),f.score<=r)break}f.suppressBeginIndex=d.length,b||(f.score===m?(d.push(g),p.push(f.score)):f.score>r&&gO(u,f,qv))}var L=d.length,N=e-L;o&&N>0&&(d.push.apply(d,new Array(N).fill(0)),p.push.apply(p,new Array(N).fill(0)));var C={selectedIndices:Xr(d,"int32")};return s&&(C.selectedScores=Xr(p,"float32")),l&&(C.validOutputs=be(L,"int32")),C}function bO(n,t,e){var i=n.subarray(t*4,t*4+4),r=n.subarray(e*4,e*4+4),a=Math.min(i[0],i[2]),s=Math.min(i[1],i[3]),o=Math.max(i[0],i[2]),l=Math.max(i[1],i[3]),u=Math.min(r[0],r[2]),c=Math.min(r[1],r[3]),h=Math.max(r[0],r[2]),d=Math.max(r[1],r[3]),p=(o-a)*(l-s),f=(h-u)*(d-c);if(p<=0||f<=0)return 0;var m=Math.max(a,u),g=Math.max(s,c),v=Math.min(o,h),b=Math.min(l,d),w=Math.max(v-m,0)*Math.max(b-g,0);return w/(p+f-w)}function wO(n,t,e){var i=Math.exp(t*e*e);return e<=n?i:0}function qv(n,t){return n.score-t.score||n.score===t.score&&t.boxIndex-n.boxIndex}function SO(n,t,e,i,r){return i===void 0&&(i=.5),r===void 0&&(r=Number.NEGATIVE_INFINITY),de(this,void 0,void 0,function(){var a,s,o,l,u,c,h;return pe(this,function(d){switch(d.label){case 0:return a=O(n,"boxes","nonMaxSuppressionAsync"),s=O(t,"scores","nonMaxSuppressionAsync"),o=Qr(a,s,e,i,r),e=o.maxOutputSize,i=o.iouThreshold,r=o.scoreThreshold,[4,Promise.all([a.data(),s.data()])];case 1:return l=d.sent(),u=l[0],c=l[1],h=Mv(u,c,e,i,r),a!==n&&a.dispose(),s!==t&&s.dispose(),[2,h]}})})}var LO=SO;function IO(n,t,e,i,r,a){i===void 0&&(i=.5),r===void 0&&(r=Number.NEGATIVE_INFINITY),a===void 0&&(a=0);var s=O(n,"boxes","nonMaxSuppression"),o=O(t,"scores","nonMaxSuppression"),l=Qr(s,o,e,i,r,a);e=l.maxOutputSize,i=l.iouThreshold,r=l.scoreThreshold,a=l.softNmsSigma;var u={boxes:s,scores:o},c={maxOutputSize:e,iouThreshold:i,scoreThreshold:r,softNmsSigma:a},h=z.runKernel(im,u,c);return{selectedIndices:h[0],selectedScores:h[1]}}var AO=U({nonMaxSuppressionWithScore_:IO});function TO(n,t,e,i,r,a){return i===void 0&&(i=.5),r===void 0&&(r=Number.NEGATIVE_INFINITY),a===void 0&&(a=0),de(this,void 0,void 0,function(){var s,o,l,u,c,h,d;return pe(this,function(p){switch(p.label){case 0:return s=O(n,"boxes","nonMaxSuppressionAsync"),o=O(t,"scores","nonMaxSuppressionAsync"),l=Qr(s,o,e,i,r,a),e=l.maxOutputSize,i=l.iouThreshold,r=l.scoreThreshold,a=l.softNmsSigma,[4,Promise.all([s.data(),o.data()])];case 1:return u=p.sent(),c=u[0],h=u[1],d=Vv(c,h,e,i,r,a),s!==n&&s.dispose(),o!==t&&o.dispose(),[2,d]}})})}var NO=TO;function xO(n,t,e,i,r,a){i===void 0&&(i=.5),r===void 0&&(r=Number.NEGATIVE_INFINITY),a===void 0&&(a=!1);var s=O(n,"boxes","nonMaxSuppression"),o=O(t,"scores","nonMaxSuppression"),l=Qr(s,o,e,i,r,null),u=l.maxOutputSize,c=l.iouThreshold,h=l.scoreThreshold,d={boxes:s,scores:o},p={maxOutputSize:u,iouThreshold:c,scoreThreshold:h,padToMaxOutputSize:a},f=z.runKernel(nm,d,p);return{selectedIndices:f[0],validOutputs:f[1]}}var CO=U({nonMaxSuppressionPadded_:xO});function RO(n,t,e,i,r,a){return i===void 0&&(i=.5),r===void 0&&(r=Number.NEGATIVE_INFINITY),a===void 0&&(a=!1),de(this,void 0,void 0,function(){var s,o,l,u,c,h,d,p,f,m;return pe(this,function(g){switch(g.label){case 0:return s=O(n,"boxes","nonMaxSuppressionAsync"),o=O(t,"scores","nonMaxSuppressionAsync"),l=Qr(s,o,e,i,r,null),u=l.maxOutputSize,c=l.iouThreshold,h=l.scoreThreshold,[4,Promise.all([s.data(),o.data()])];case 1:return d=g.sent(),p=d[0],f=d[1],m=Hv(p,f,u,c,h,a),s!==n&&s.dispose(),o!==t&&o.dispose(),[2,m]}})})}var OO=RO;function EO(n,t,e){e===void 0&&(e=!1);var i=O(n,"images","resizeBilinear");E(i.rank===3||i.rank===4,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got "+("rank "+i.rank+".")}),E(t.length===2,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+(t+".")});var r=i,a=!1;i.rank===3&&(a=!0,r=V(i,[1,i.shape[0],i.shape[1],i.shape[2]]));var s=t[0],o=t[1],l=function(d,p){return p([r]),d.resizeBilinear(r,s,o,e)},u={images:r},c={alignCorners:e,size:t},h=z.runKernelFunc(l,u,null,Hu,c);return a?V(h,[h.shape[1],h.shape[2],h.shape[3]]):h}var Gv=U({resizeBilinear_:EO});function DO(n,t,e){e===void 0&&(e=!1);var i=O(n,"images","resizeNearestNeighbor");E(i.rank===3||i.rank===4,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got "+("rank "+i.rank+".")}),E(t.length===2,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+(t+".")}),E(i.dtype==="float32"||i.dtype==="int32",function(){return"`images` must have `int32` or `float32` as dtype"});var r=i,a=!1;i.rank===3&&(a=!0,r=V(i,[1,i.shape[0],i.shape[1],i.shape[2]]));var s=t[0],o=t[1],l={images:r},u={alignCorners:e,size:t},c=function(d,p){return p([r]),d.resizeNearestNeighbor(r,s,o,e)},h=z.runKernelFunc(c,l,null,Mu,u);return a?V(h,[h.shape[1],h.shape[2],h.shape[3]]):h}var Yv=U({resizeNearestNeighbor_:DO});function kO(n,t,e){E(t%1===0,function(){return"bandPart(): numLower must be an integer, got "+t+"."}),E(e%1===0,function(){return"bandPart(): numUpper must be an integer, got "+e+"."});var i=O(n,"a","bandPart");E(i.rank>=2,function(){return"bandPart(): Rank must be at least 2, got "+i.rank+"."});var r=i.shape,a=i.shape.slice(-2),s=a[0],o=a[1];if(!(t<=s))throw new Error("bandPart(): numLower ("+t+")"+(" must not be greater than the number of rows ("+s+")."));if(!(e<=o))throw new Error("bandPart(): numUpper ("+e+")"+(" must not be greater than the number of columns ("+o+")."));t<0&&(t=s),e<0&&(e=o);var l=V(yh(0,s,1,"int32"),[-1,1]),u=yh(0,o,1,"int32"),c=ge(l,u),h=nr(Qi(c,be(+t,"int32")),Zi(c,be(-e,"int32"))),d=ti([s,o],i.dtype);return V(sr(go(V(i,[-1,s,o])).map(function(p){return yn(h,p,d)})),r)}var FO=U({bandPart_:kO});function WO(n){var t;if(Array.isArray(n)){t=!1,E(n!=null&&n.length>0,function(){return"Gram-Schmidt process: input must not be null, undefined, or empty"});for(var e=n[0].shape[0],i=function(l){E(n[l].shape[0]===e,function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: "+("("+n[l].shape[0]+" vs. "+e+")")})},r=1;r<n.length;++r)i(r)}else t=!0,n=Jr(n,n.shape[0],0).map(function(l){return mo(l,[0])});E(n.length<=n[0].shape[0],function(){return"Gram-Schmidt: Number of vectors ("+n.length+") exceeds "+("number of dimensions ("+n[0].shape[0]+").")});for(var a=[],s=n,o=function(l){a.push(z.tidy(function(){var u=s[l];if(l>0)for(var c=0;c<l;++c){var h=J(Ae(J(a[c],u)),a[c]);u=ge(u,h)}return Ie(u,vo(u,"euclidean"))}))},r=0;r<n.length;++r)o(r);return t?sr(a,0):a}var UO=U({gramSchmidt_:WO});function BO(n,t){if(t===void 0&&(t=!1),E(n.rank>=2,function(){return"qr() requires input tensor to have a rank >= 2, but got rank "+n.rank}),n.rank===2)return jv(n,t);var e=n.shape.slice(0,n.shape.length-2).reduce(function(l,u){return l*u}),i=go(V(n,[e,n.shape[n.shape.length-2],n.shape[n.shape.length-1]]),0),r=[],a=[];i.forEach(function(l){var u=jv(l,t),c=u[0],h=u[1];r.push(c),a.push(h)});var s=V(sr(r,0),n.shape),o=V(sr(a,0),n.shape);return[s,o]}function jv(n,t){return t===void 0&&(t=!1),z.tidy(function(){E(n.shape.length===2,function(){return"qr2d() requires a 2D Tensor, but got a "+n.shape.length+"D Tensor."});for(var e=n.shape[0],i=n.shape[1],r=jg(e),a=$i(n),s=Xa([[1]],[1,1]),o=$i(s),l=e>=i?i:e,u=function(h){var d,p=a,f=o,m=r;d=z.tidy(function(){var g=ze(a,[h,h],[e-h,1]),v=vo(g),b=ze(a,[h,h],[1,1]),w=yn(Li(b,0),Xa([[-1]]),Xa([[1]])),S=ge(b,J(w,v)),L=Ie(g,S);L.shape[0]===1?o=$i(s):o=Rt([s,ze(L,[1,0],[L.shape[0]-1,L.shape[1]])],0);var N=vt(Ie(We(w,S),v)),C=ze(a,[h,0],[e-h,i]),R=J(N,o),D=ut(o);if(h===0)a=ge(C,We(R,We(D,C)));else{var k=ge(C,We(R,We(D,C)));a=Rt([ze(a,[0,0],[h,i]),k],0)}var W=ut(R),F=ze(r,[0,h],[e,r.shape[1]-h]);if(h===0)r=ge(F,We(We(F,o),W));else{var P=ge(F,We(We(F,o),W));r=Rt([ze(r,[0,0],[e,h]),P],1)}return[o,a,r]}),o=d[0],a=d[1],r=d[2],Mt([p,f,m])},c=0;c<l;++c)u(c);return!t&&e>i&&(r=ze(r,[0,0],[e,i]),a=ze(a,[0,0],[i,i])),[r,a]})}var zO=U({qr_:BO});(function(n){n[n.NONE=0]="NONE",n[n.MEAN=1]="MEAN",n[n.SUM=2]="SUM",n[n.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS"})(I.Reduction||(I.Reduction={}));function PO(n,t,e){e===void 0&&(e=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=O(n,"losses","computeWeightedLoss"),r=null;t!=null&&(r=O(t,"weights","computeWeightedLoss"));var a=r==null?i:J(i,r);if(e===I.Reduction.NONE)return a;if(e===I.Reduction.SUM)return Ae(a);if(e===I.Reduction.MEAN){if(r==null)return Ya(a);var s=i.size/r.size,o=Ie(Ae(a),Ae(r));return s>1?Ie(o,be(s)):o}if(e===I.Reduction.SUM_BY_NONZERO_WEIGHTS){if(r==null)return Ie(Ae(a),be(i.size));var l=J(r,Kr(i.shape)),u=ue(Ae(uo(l,be(0))),"float32");return Ie(Ae(a),u)}throw Error("Unknown reduction: "+e)}var ri=U({computeWeightedLoss_:PO});function _O(n,t,e,i){i===void 0&&(i=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var r=O(n,"labels","absoluteDifference"),a=O(t,"predictions","absoluteDifference"),s=null;e!=null&&(s=O(e,"weights","absoluteDifference")),Be(r.shape,a.shape,"Error in absoluteDifference: ");var o=Kt(ge(r,a));return ri(o,s,i)}var MO=U({absoluteDifference_:_O});function HO(n,t,e,i,r){r===void 0&&(r=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=O(n,"labels","cosineDistance"),s=O(t,"predictions","cosineDistance"),o=null;i!=null&&(o=O(i,"weights","cosineDistance")),Be(a.shape,s.shape,"Error in cosineDistance: ");var l=be(1),u=ge(l,Ae(J(a,s),e,!0));return ri(u,o,r)}var VO=U({cosineDistance_:HO});function qO(n,t,e,i){i===void 0&&(i=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var r=O(n,"labels","hingeLoss"),a=O(t,"predictions","hingeLoss"),s=null;e!=null&&(s=O(e,"weights","hingeLoss")),Be(r.shape,a.shape,"Error in hingeLoss: ");var o=be(1);r=ge(J(be(2),r),o);var l=Ka(ge(o,J(r,a)));return ri(l,s,i)}var GO=U({hingeLoss_:qO});function YO(n,t,e,i,r){i===void 0&&(i=1),r===void 0&&(r=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=O(n,"labels","huberLoss"),s=O(t,"predictions","huberLoss"),o=null;e!=null&&(o=O(e,"weights","huberLoss")),Be(a.shape,s.shape,"Error in huberLoss: ");var l=be(i),u=Kt(ge(s,a)),c=lo(u,l),h=ge(u,c),d=fe(J(be(.5),Ye(c)),J(l,h));return ri(d,o,r)}var jO=U({huberLoss_:YO});function KO(n,t,e,i,r){i===void 0&&(i=1e-7),r===void 0&&(r=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=O(n,"labels","logLoss"),s=O(t,"predictions","logLoss"),o=null;e!=null&&(o=O(e,"weights","logLoss")),Be(a.shape,s.shape,"Error in logLoss: ");var l=be(1),u=be(i),c=vt(J(a,er(fe(s,u)))),h=J(ge(l,a),er(fe(ge(l,s),u))),d=ge(c,h);return ri(d,o,r)}var $O=U({logLoss_:KO});function XO(n,t,e,i){i===void 0&&(i=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var r=O(n,"labels","meanSquaredError"),a=O(t,"predictions","meanSquaredError"),s=null;e!=null&&(s=O(e,"weights","meanSquaredError")),Be(r.shape,a.shape,"Error in meanSquaredError: ");var o=fo(r,a);return ri(o,s,i)}var JO=U({meanSquaredError_:XO});function ZO(n,t){var e=O(n,"labels","sigmoidCrossEntropyWithLogits"),i=O(t,"logits","sigmoidCrossEntropyWithLogits");Be(e.shape,i.shape,"Error in sigmoidCrossEntropyWithLogits: ");var r=Ka(i),a=J(i,e),s=lh(bn(vt(Kt(i))));return fe(ge(r,a),s)}function QO(n,t,e,i,r){i===void 0&&(i=0),r===void 0&&(r=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=O(n,"multiClassLabels","sigmoidCrossEntropy"),s=O(t,"logits","sigmoidCrossEntropy"),o=null;if(e!=null&&(o=O(e,"weights","sigmoidCrossEntropy")),Be(a.shape,s.shape,"Error in sigmoidCrossEntropy: "),i>0){var l=be(i),u=be(1),c=be(.5);a=fe(J(a,ge(u,l)),J(c,l))}var h=ZO(a,s);return ri(h,o,r)}var eE=U({sigmoidCrossEntropy_:QO});function tE(n,t,e){if(e===void 0&&(e=-1),e===-1&&(e=t.rank-1),e!==t.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet "+("supported. Labels / logits was rank "+t.rank+" ")+("and dim was "+e));var i=zn(function(r,a,s){var o=!0,l=ch(a,[e],o),u=ge(ue(a,"float32"),l);s([r,u]);var c=vt(J(u,r)),h=Ae(c,[e]),d=function(p,f){var m=f[0],g=f[1],v=rn(p.shape,[e]);return[J(V(p,v),ge(ue(m,"float32"),bn(g))),J(V(p,v),ge(bn(g),ue(m,"float32")))]};return{value:h,gradFunc:d}});return i(n,t)}function nE(n,t,e,i,r){i===void 0&&(i=0),r===void 0&&(r=I.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=O(n,"onehotLabels","softmaxCrossEntropy"),s=O(t,"logits","softmaxCrossEntropy"),o=null;if(e!=null&&(o=O(e,"weights","softmaxCrossEntropy")),Be(a.shape,s.shape,"Error in softmaxCrossEntropy: "),i>0){var l=be(i),u=be(1),c=be(a.shape[1]);a=fe(J(a,ge(u,l)),Ie(l,c))}var h=tE(a,s);return ri(h,o,r)}var iE=U({softmaxCrossEntropy_:nE});var rE={fft:ho,ifft:$a,rfft:po,irfft:Ih},aE={hammingWindow:nO,hannWindow:Pv,frame:_v,stft:sO},sE={flipLeftRight:cO,resizeNearestNeighbor:Yv,resizeBilinear:Gv,rotateWithOffset:dO,cropAndResize:lO,nonMaxSuppression:fO,nonMaxSuppressionAsync:LO,nonMaxSuppressionWithScore:AO,nonMaxSuppressionWithScoreAsync:NO,nonMaxSuppressionPadded:CO,nonMaxSuppressionPaddedAsync:OO},oE={bandPart:FO,gramSchmidt:UO,qr:zO},lE={absoluteDifference:MO,computeWeightedLoss:ri,cosineDistance:VO,hingeLoss:GO,huberLoss:jO,logLoss:$O,meanSquaredError:JO,sigmoidCrossEntropy:eE,softmaxCrossEntropy:iE};var Ii=function(n){Zn(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.minimize=function(e,i,r){i===void 0&&(i=!1);var a=this.computeGradients(e,r),s=a.value,o=a.grads;if(r!=null){var l=r.map(function(u){return{name:u.name,tensor:o[u.name]}});this.applyGradients(l)}else this.applyGradients(o);return Mt(o),i?s:(s.dispose(),null)},Object.defineProperty(t.prototype,"iterations",{get:function(){return this.iterations_==null&&(this.iterations_=0),this.iterations_},enumerable:!0,configurable:!0}),t.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},t.prototype.computeGradients=function(e,i){return ev(e,i)},t.prototype.dispose=function(){this.iterations_!=null&&Mt(this.iterations_)},t.prototype.saveIterations=function(){return de(this,void 0,void 0,function(){return pe(this,function(e){return this.iterations_==null&&(this.iterations_=0),[2,{name:"iter",tensor:be(this.iterations_,"int32")}]})})},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){return pe(this,function(e){throw new Error("getWeights() is not implemented for this optimizer yet.")})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){return pe(this,function(i){throw new Error("setWeights() is not implemented for this optimizer class "+(""+this.getClassName()))})})},t.prototype.extractIterations=function(e){return de(this,void 0,void 0,function(){var i;return pe(this,function(r){switch(r.label){case 0:return i=this,[4,e[0].tensor.data()];case 1:return i.iterations_=r.sent()[0],[2,e.slice(1)]}})})},t}(vg);Object.defineProperty(Ii,Symbol.hasInstance,{value:function(n){return n.minimize!=null&&n.computeGradients!=null&&n.applyGradients!=null}});var Ch=function(n){Zn(t,n);function t(e,i,r){r===void 0&&(r=null);var a=n.call(this)||this;return a.learningRate=e,a.rho=i,a.epsilon=r,a.accumulatedGrads=[],a.accumulatedUpdates=[],r==null&&(a.epsilon=z.backend.epsilon()),a}return t.prototype.applyGradients=function(e){var i=this,r=Array.isArray(e)?e.map(function(a){return a.name}):Object.keys(e);r.forEach(function(a,s){var o=z.registeredVariables[a],l=!1;i.accumulatedGrads[s]==null&&(i.accumulatedGrads[s]={originalName:a+"/accum_grad",variable:mt(function(){return Ee(o).variable(l)})}),i.accumulatedUpdates[s]==null&&(i.accumulatedUpdates[s]={originalName:a+"/accum_var",variable:mt(function(){return Ee(o).variable(l)})});var u=Array.isArray(e)?e[s].tensor:e[a];if(u==null)return;var c=i.accumulatedGrads[s].variable,h=i.accumulatedUpdates[s].variable;mt(function(){var d=fe(J(c,i.rho),J(Ye(u),1-i.rho)),p=J(Ie(Vt(fe(h,i.epsilon)),Vt(fe(c,i.epsilon))),u),f=fe(J(h,i.rho),J(Ye(p),1-i.rho));c.assign(d),h.assign(f);var m=fe(J(p,-i.learningRate),o);o.assign(m)})}),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedUpdates!=null&&(Mt(this.accumulatedGrads.map(function(e){return e.variable})),Mt(this.accumulatedUpdates.map(function(e){return e.variable})))},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){var e;return pe(this,function(i){switch(i.label){case 0:return e=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[i.sent()].concat(e.map(function(r){return{name:r.originalName,tensor:r.variable}}))]}})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){var i,r;return pe(this,function(a){switch(a.label){case 0:return[4,this.extractIterations(e)];case 1:return e=a.sent(),i=e.length/2,r=!1,this.accumulatedGrads=e.slice(0,i).map(function(s){return{originalName:s.name,variable:s.tensor.variable(r)}}),this.accumulatedUpdates=e.slice(i,i*2).map(function(s){return{originalName:s.name,variable:s.tensor.variable(r)}}),[2]}})})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},t.fromConfig=function(e,i){return new e(i.learningRate,i.rho,i.epsilon)},t.className="Adadelta",t}(Ii);wi(Ch);var Rh=function(n){Zn(t,n);function t(e,i){i===void 0&&(i=.1);var r=n.call(this)||this;return r.learningRate=e,r.initialAccumulatorValue=i,r.accumulatedGrads=[],r}return t.prototype.applyGradients=function(e){var i=this,r=Array.isArray(e)?e.map(function(a){return a.name}):Object.keys(e);r.forEach(function(a,s){var o=z.registeredVariables[a];if(i.accumulatedGrads[s]==null){var l=!1;i.accumulatedGrads[s]={originalName:a+"/accumulator",variable:mt(function(){return sh(o.shape,i.initialAccumulatorValue).variable(l)})}}var u=Array.isArray(e)?e[s].tensor:e[a];if(u==null)return;var c=i.accumulatedGrads[s].variable;mt(function(){var h=fe(c,Ye(u));c.assign(h);var d=fe(J(Ie(u,Vt(fe(h,z.backend.epsilon()))),-i.learningRate),o);o.assign(d)})}),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedGrads!=null&&Mt(this.accumulatedGrads.map(function(e){return e.variable}))},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){return pe(this,function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulatedGrads.map(function(i){return{name:i.originalName,tensor:i.variable}}))]}})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){var i;return pe(this,function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),i=!1,this.accumulatedGrads=e.map(function(a){return{originalName:a.name,variable:a.tensor.variable(i)}}),[2]}})})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},t.fromConfig=function(e,i){return new e(i.learningRate,i.initialAccumulatorValue)},t.className="Adagrad",t}(Ii);wi(Rh);var Oh=function(n){Zn(t,n);function t(e,i,r,a){a===void 0&&(a=null);var s=n.call(this)||this;return s.learningRate=e,s.beta1=i,s.beta2=r,s.epsilon=a,s.accumulatedFirstMoment=[],s.accumulatedSecondMoment=[],mt(function(){s.accBeta1=be(i).variable(),s.accBeta2=be(r).variable()}),a==null&&(s.epsilon=z.backend.epsilon()),s}return t.prototype.applyGradients=function(e){var i=this,r=Array.isArray(e)?e.map(function(a){return a.name}):Object.keys(e);mt(function(){var a=ge(1,i.accBeta1),s=ge(1,i.accBeta2);r.forEach(function(o,l){var u=z.registeredVariables[o],c=!1;i.accumulatedFirstMoment[l]==null&&(i.accumulatedFirstMoment[l]={originalName:o+"/m",variable:mt(function(){return Ee(u).variable(c)})}),i.accumulatedSecondMoment[l]==null&&(i.accumulatedSecondMoment[l]={originalName:o+"/v",variable:mt(function(){return Ee(u).variable(c)})});var h=Array.isArray(e)?e[l].tensor:e[o];if(h==null)return;var d=i.accumulatedFirstMoment[l].variable,p=i.accumulatedSecondMoment[l].variable,f=fe(J(d,i.beta1),J(h,1-i.beta1)),m=fe(J(p,i.beta2),J(Ye(h),1-i.beta2)),g=Ie(f,a),v=Ie(m,s);d.assign(f),p.assign(m);var b=fe(J(Ie(g,fe(Vt(v),i.epsilon)),-i.learningRate),u);u.assign(b)}),i.accBeta1.assign(J(i.accBeta1,i.beta1)),i.accBeta2.assign(J(i.accBeta2,i.beta2))}),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&Mt(this.accumulatedFirstMoment.map(function(e){return e.variable})),this.accumulatedSecondMoment!=null&&Mt(this.accumulatedSecondMoment.map(function(e){return e.variable}))},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){var e;return pe(this,function(i){switch(i.label){case 0:return e=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[i.sent()].concat(e.map(function(r){return{name:r.originalName,tensor:r.variable}}))]}})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){var i,r,a=this;return pe(this,function(s){switch(s.label){case 0:return[4,this.extractIterations(e)];case 1:return e=s.sent(),mt(function(){a.accBeta1.assign(ni(a.beta1,a.iterations_+1)),a.accBeta2.assign(ni(a.beta2,a.iterations_+1))}),i=e.length/2,r=!1,this.accumulatedFirstMoment=e.slice(0,i).map(function(o){return{originalName:o.name,variable:o.tensor.variable(r)}}),this.accumulatedSecondMoment=e.slice(i,i*2).map(function(o){return{originalName:o.name,variable:o.tensor.variable(r)}}),[2]}})})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},t.fromConfig=function(e,i){return new e(i.learningRate,i.beta1,i.beta2,i.epsilon)},t.className="Adam",t}(Ii);wi(Oh);var Eh=function(n){Zn(t,n);function t(e,i,r,a,s){a===void 0&&(a=null),s===void 0&&(s=0);var o=n.call(this)||this;return o.learningRate=e,o.beta1=i,o.beta2=r,o.epsilon=a,o.decay=s,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],mt(function(){o.iteration=be(0).variable(),o.accBeta1=be(i).variable()}),a==null&&(o.epsilon=z.backend.epsilon()),o}return t.prototype.applyGradients=function(e){var i=this,r=Array.isArray(e)?e.map(function(a){return a.name}):Object.keys(e);mt(function(){var a=ge(1,i.accBeta1),s=Ie(-i.learningRate,fe(J(i.iteration,i.decay),1));r.forEach(function(o,l){var u=z.registeredVariables[o],c=!1;i.accumulatedFirstMoment[l]==null&&(i.accumulatedFirstMoment[l]={originalName:o+"/m",variable:Ee(u).variable(c)}),i.accumulatedWeightedInfNorm[l]==null&&(i.accumulatedWeightedInfNorm[l]={originalName:o+"/v",variable:Ee(u).variable(c)});var h=Array.isArray(e)?e[l].tensor:e[o];if(h==null)return;var d=i.accumulatedFirstMoment[l].variable,p=i.accumulatedWeightedInfNorm[l].variable,f=fe(J(d,i.beta1),J(h,1-i.beta1)),m=J(p,i.beta2),g=Kt(h),v=jr(m,g);d.assign(f),p.assign(v);var b=fe(J(Ie(s,a),Ie(f,fe(v,i.epsilon))),u);u.assign(b)}),i.iteration.assign(fe(i.iteration,1)),i.accBeta1.assign(J(i.accBeta1,i.beta1))}),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&Mt(this.accumulatedFirstMoment.map(function(e){return e.variable})),this.accumulatedWeightedInfNorm!=null&&Mt(this.accumulatedWeightedInfNorm.map(function(e){return e.variable}))},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){return pe(this,function(e){throw new Error("getWeights() is not implemented for Adamax yet.")})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){return pe(this,function(i){throw new Error("setWeights() is not implemented for Adamax yet.")})})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},t.fromConfig=function(e,i){return new e(i.learningRate,i.beta1,i.beta2,i.epsilon,i.decay)},t.className="Adamax",t}(Ii);wi(Eh);var Lo=function(n){Zn(t,n);function t(e){var i=n.call(this)||this;return i.learningRate=e,i.setLearningRate(e),i}return t.prototype.applyGradients=function(e){var i=this,r=Array.isArray(e)?e.map(function(a){return a.name}):Object.keys(e);r.forEach(function(a,s){var o=Array.isArray(e)?e[s].tensor:e[a];if(o==null)return;var l=z.registeredVariables[a];mt(function(){var u=fe(J(i.c,o),l);l.assign(u)})}),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,this.c!=null&&this.c.dispose(),this.c=wg(be(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){return pe(this,function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){return pe(this,function(i){switch(i.label){case 0:return[4,this.extractIterations(e)];case 1:if(e=i.sent(),e.length!==0)throw new Error("SGD optimizer does not have settable weights.");return[2]}})})},t.prototype.getConfig=function(){return{learningRate:this.learningRate}},t.fromConfig=function(e,i){return new e(i.learningRate)},t.className="SGD",t}(Ii);wi(Lo);var Dh=function(n){Zn(t,n);function t(e,i,r){r===void 0&&(r=!1);var a=n.call(this,e)||this;return a.learningRate=e,a.momentum=i,a.useNesterov=r,a.accumulations=[],a.m=be(a.momentum),a}return t.prototype.applyGradients=function(e){var i=this,r=Array.isArray(e)?e.map(function(a){return a.name}):Object.keys(e);r.forEach(function(a,s){var o=z.registeredVariables[a];if(i.accumulations[s]==null){var l=!1;i.accumulations[s]={originalName:a+"/momentum",variable:mt(function(){return Ee(o).variable(l)})}}var u=i.accumulations[s].variable,c=Array.isArray(e)?e[s].tensor:e[a];if(c==null)return;mt(function(){var h,d=fe(J(i.m,u),c);i.useNesterov?h=fe(J(i.c,fe(c,J(d,i.m))),o):h=fe(J(i.c,d),o),u.assign(d),o.assign(h)})}),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),this.accumulations!=null&&Mt(this.accumulations.map(function(e){return e.variable}))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){return pe(this,function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulations.map(function(i){return{name:i.originalName,tensor:i.variable}}))]}})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){var i;return pe(this,function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),i=!1,this.accumulations=e.map(function(a){return{originalName:a.name,variable:a.tensor.variable(i)}}),[2]}})})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},t.fromConfig=function(e,i){return new e(i.learningRate,i.momentum,i.useNesterov)},t.className="Momentum",t}(Lo);wi(Dh);var kh=function(n){Zn(t,n);function t(e,i,r,a,s){i===void 0&&(i=.9),r===void 0&&(r=0),a===void 0&&(a=null),s===void 0&&(s=!1);var o=n.call(this)||this;if(o.learningRate=e,o.decay=i,o.momentum=r,o.epsilon=a,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=s,a==null&&(o.epsilon=z.backend.epsilon()),e==null)throw new Error("learningRate for RMSPropOptimizer must be defined.");return o}return t.prototype.applyGradients=function(e){var i=this,r=Array.isArray(e)?e.map(function(a){return a.name}):Object.keys(e);r.forEach(function(a,s){var o=z.registeredVariables[a],l=!1;i.accumulatedMeanSquares[s]==null&&(i.accumulatedMeanSquares[s]={originalName:a+"/rms",variable:mt(function(){return Ee(o).variable(l)})}),i.accumulatedMoments[s]==null&&(i.accumulatedMoments[s]={originalName:a+"/momentum",variable:mt(function(){return Ee(o).variable(l)})}),i.accumulatedMeanGrads[s]==null&&i.centered&&(i.accumulatedMeanGrads[s]={originalName:a+"/mg",variable:mt(function(){return Ee(o).variable(l)})});var u=Array.isArray(e)?e[s].tensor:e[a];if(u==null)return;var c=i.accumulatedMeanSquares[s].variable,h=i.accumulatedMoments[s].variable;mt(function(){var d=fe(J(c,i.decay),J(Ye(u),1-i.decay));if(i.centered){var p=i.accumulatedMeanGrads[s].variable,f=fe(J(p,i.decay),J(u,1-i.decay)),m=Ie(J(u,i.learningRate),Vt(ge(d,fe(Ye(f),i.epsilon)))),g=fe(J(h,i.momentum),m);c.assign(d),p.assign(f),h.assign(g);var v=ge(o,g);o.assign(v)}else{var b=fe(J(c,i.decay),J(Ye(u),1-i.decay)),g=fe(J(h,i.momentum),Ie(J(u,i.learningRate),Vt(fe(b,i.epsilon))));c.assign(b),h.assign(g);var v=ge(o,g);o.assign(v)}})}),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedMeanSquares!=null&&Mt(this.accumulatedMeanSquares.map(function(e){return e.variable})),this.accumulatedMeanGrads!=null&&this.centered&&Mt(this.accumulatedMeanGrads.map(function(e){return e.variable})),this.accumulatedMoments!=null&&Mt(this.accumulatedMoments.map(function(e){return e.variable}))},t.prototype.getWeights=function(){return de(this,void 0,void 0,function(){var e;return pe(this,function(i){switch(i.label){case 0:return e=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&e.push.apply(e,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[i.sent()].concat(e.map(function(r){return{name:r.originalName,tensor:r.variable}}))]}})})},t.prototype.setWeights=function(e){return de(this,void 0,void 0,function(){var i,r;return pe(this,function(a){switch(a.label){case 0:return[4,this.extractIterations(e)];case 1:return e=a.sent(),i=this.centered?e.length/3:e.length/2,r=!1,this.accumulatedMeanSquares=e.slice(0,i).map(function(s){return{originalName:s.name,variable:s.tensor.variable(r)}}),this.accumulatedMoments=e.slice(i,i*2).map(function(s){return{originalName:s.name,variable:s.tensor.variable(r)}}),this.centered&&(this.accumulatedMeanGrads=e.slice(i*2,i*3).map(function(s){return{originalName:s.name,variable:s.tensor.variable(r)}})),[2]}})})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},t.fromConfig=function(e,i){return new e(i.learningRate,i.decay,i.momentum,i.epsilon,i.centered)},t.className="RMSProp",t}(Ii);wi(kh);var or=function(){function n(){}return n.sgd=function(t){return new Lo(t)},n.momentum=function(t,e,i){return i===void 0&&(i=!1),new Dh(t,e,i)},n.rmsprop=function(t,e,i,r,a){return e===void 0&&(e=.9),i===void 0&&(i=0),r===void 0&&(r=null),a===void 0&&(a=!1),new kh(t,e,i,r,a)},n.adam=function(t,e,i,r){return t===void 0&&(t=.001),e===void 0&&(e=.9),i===void 0&&(i=.999),r===void 0&&(r=null),new Oh(t,e,i,r)},n.adadelta=function(t,e,i){return t===void 0&&(t=.001),e===void 0&&(e=.95),i===void 0&&(i=null),new Ch(t,e,i)},n.adamax=function(t,e,i,r,a){return t===void 0&&(t=.002),e===void 0&&(e=.9),i===void 0&&(i=.999),r===void 0&&(r=null),a===void 0&&(a=0),new Eh(t,e,i,r,a)},n.adagrad=function(t,e){return e===void 0&&(e=.1),new Rh(t,e)},n}();var uE={sgd:or.sgd,momentum:or.momentum,adadelta:or.adadelta,adagrad:or.adagrad,rmsprop:or.rmsprop,adamax:or.adamax,adam:or.adam};var cE=function(){return typeof requestAnimationFrame!="undefined"?requestAnimationFrame:typeof setImmediate!="undefined"?setImmediate:function(n){return n()}}();function hE(){return new Promise(function(n){return cE(function(){return n()})})}function dE(n,t,e){var i=e*(typeof n=="number"?n:n[0]),r=t*(typeof n=="number"?n:n[1]);return[i,r]}function pE(n,t,e,i){i===void 0&&(i=!0);var r=[];if(i)r=r.concat(t.slice(0)),r.push(n[0]/e),r=r.concat(n.slice(1));else{r=r.concat(n[0]);for(var a=t.length,s=0;s<a;++s)r=r.concat([n[s+1]/t[s],t[s]]);r=r.concat(n.slice(a+1))}return r}function fE(n,t,e){e===void 0&&(e=!0);var i=[];if(e){i.push(t);for(var r=t+1;r<n;++r)r<=2*t?(i.push(r),i.push(r-(t+1))):i.push(r)}else{for(var a=[],s=[],r=1;r<n;++r)r>=t*2+1||r%2===1?s.push(r):a.push(r);i.push.apply(i,a),i.push(0),i.push.apply(i,s)}return i}function mE(n,t,e,i){i===void 0&&(i=!0);var r=[];i?r.push(n[0]/e):r.push(n[0]*e);for(var a=1;a<n.length;++a)a<=t.length?i?r.push(t[a-1]*n[a]):r.push(n[a]/t[a-1]):r.push(n[a]);return r}function gE(n,t){for(var e=[0],i=0;i<t;++i)e.push(n[i][0]);return e}function vE(n,t,e){for(var i=n.slice(0,1),r=0;r<e;++r)i.push(n[r+1]-t[r][0]-t[r][1]);return i}var Kv=1.7580993408473768,$v=1.0507009873554805;var yE=.3275911,bE=.254829592,wE=-.284496736,SE=1.421413741,LE=-1.453152027,IE=1.061405429;function AE(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];He().getBool("IS_TEST")||console.warn.apply(console,n)}function TE(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];He().getBool("IS_TEST")||console.log.apply(console,n)}function NE(n,t){if(n.length!==t.length)throw new Error("Cannot merge real and imag arrays of different lengths. real:"+(n.length+", imag: "+t.length+"."));for(var e=new Float32Array(n.length*2),i=0;i<e.length;i+=2)e[i]=n[i/2],e[i+1]=t[i/2];return e}function xE(n){for(var t=new Float32Array(n.length/2),e=new Float32Array(n.length/2),i=0;i<n.length;i+=2)t[i/2]=n[i],e[i/2]=n[i+1];return{real:t,imag:e}}function CE(n){for(var t=Math.ceil(n.length/4),e=new Float32Array(t),i=new Float32Array(t),r=0;r<n.length;r+=4)e[Math.floor(r/4)]=n[r],i[Math.floor(r/4)]=n[r+1];return{real:e,imag:i}}function RE(n){for(var t=Math.floor(n.length/4),e=new Float32Array(t),i=new Float32Array(t),r=2;r<n.length;r+=4)e[Math.floor(r/4)]=n[r],i[Math.floor(r/4)]=n[r+1];return{real:e,imag:i}}function OE(n,t){var e=n[t*2],i=n[t*2+1];return{real:e,imag:i}}function EE(n,t,e,i){n[i*2]=t,n[i*2+1]=e}function DE(n,t){for(var e=new Float32Array(n/2),i=new Float32Array(n/2),r=0;r<Math.ceil(n/2);r++){var a=(t?2:-2)*Math.PI*(r/n);e[r]=Math.cos(a),i[r]=Math.sin(a)}return{real:e,imag:i}}function kE(n,t,e){var i=(e?2:-2)*Math.PI*(n/t),r=Math.cos(i),a=Math.sin(i);return{real:r,imag:a}}function FE(n,t,e){if(t==="complex64"){if(n.dtype==="complex64")return n.clone();var i=ti(n.shape),r=ue(n,"float32"),a=e.complex(r,i);return i.dispose(),r.dispose(),a}if(!Am(n.dtype,t))return z.makeTensorFromDataId(n.dataId,n.shape,t);if(n.dtype==="complex64"){var s=e.real(n),a=ue(s,t);return s.dispose(),a}if(t==="int32")return e.int(n);if(t==="bool"){var o=be(0,n.dtype),a=e.notEqual(n,o);return o.dispose(),a}else throw new Error("Error in Cast: failed to cast "+n.dtype+" to "+t)}function WE(n,t){return z.makeTensorFromDataId(n.dataId,t,n.dtype)}function UE(n,t,e){var i=(t-n)/(e-1),r=Ur(e,"float32");r[0]=n;for(var a=1;a<r.length;a++)r[a]=r[a-1]+i;return Xr(r,"float32")}var BE={__proto__:null,slice_util:gg,segment_util:BN,castTensor:FE,reshapeTensor:WE,linspaceImpl:UE,upcastType:Vs,axesAreInnerMostDims:Zc,combineLocations:Ig,computeOutAndReduceShapes:Ag,expandShapeToKeepDim:rn,assertAxesAreInnerMostDims:p1,getAxesPermutation:an,getUndoAxesPermutation:Ks,getInnerMostAxes:Un,getBroadcastDims:wN,getReductionAxes:gt,assertAndGetBroadcastShape:et,assertParamsConsistent:Fg,computeOutShape:Wg,computeDilation2DInfo:I1,computePool2DInfo:Vr,computePool3DInfo:Ha,computeConv2DInfo:Bn,computeConv3DInfo:Ma,computeDefaultPad:eh,tupleValuesAreOne:Si,eitherStridesOrDilationsAreOne:Ht,convertConv2DDataFormat:_a,getFusedDyActivation:yo,getFusedBiasGradient:bo,applyActivation:wo,shouldFuse:So,PARALLELIZE_THRESHOLD:oh,computeOptimalWindowSize:FN,getImageCenter:dE,getReshaped:pE,getPermuted:fE,getReshapedPermuted:mE,getSliceBeginCoords:gE,getSliceSize:vE,prepareAndValidate:ig,validateUpdateShape:Gc,validateInput:Yc,calculateShapes:rg,SELU_SCALEALPHA:Kv,SELU_SCALE:$v,ERF_P:yE,ERF_A1:bE,ERF_A2:wE,ERF_A3:SE,ERF_A4:LE,ERF_A5:IE,warn:AE,log:TE,mergeRealAndImagArrays:NE,splitRealAndImagArrays:xE,complexWithEvenIndex:CE,complexWithOddIndex:RE,getComplexWithIndex:OE,assignToTypedArray:EE,exponents:DE,exponent:kE,prepareSplitSize:pv};function zE(n,t,e){var i=new Array(n.rank).fill(0),r=n.shape.slice();return t.map(function(a){var s=r.slice();s[e]=a;var o=ze(n,i,s);return i[e]+=a,o})}function PE(n,t){for(var e=new Array(n.rank),i=0;i<e.length;i++)e[i]=n.shape[i]*t[i];for(var r=Wn(e,n.dtype),i=0;i<r.values.length;++i){for(var a=r.indexToLoc(i),s=new Array(n.rank),o=0;o<s.length;o++)s[o]=a[o]%n.shape[o];var l=n.locToIndex(s);r.values[i]=n.values[l]}return r.toTensor()}function _E(n,t,e,i,r){for(var a=t[t.length-1],s=[n.length/a,a],o=s[0],l=s[1],u=Bs(e,o*i),c=Bs("int32",o*i),h=0;h<o;h++){for(var d=h*l,p=n.subarray(d,d+l),f=[],m=0;m<p.length;m++)f.push({value:p[m],index:m});f.sort(function(S,L){return L.value-S.value});for(var g=h*i,v=u.subarray(g,g+i),b=c.subarray(g,g+i),m=0;m<i;m++)v[m]=f[m].value,b[m]=f[m].index}var w=t.slice();return w[w.length-1]=i,[vi(u,w,e),vi(c,w,"int32")]}var ME={__proto__:null,nonMaxSuppressionV3Impl:Mv,nonMaxSuppressionV4Impl:Hv,nonMaxSuppressionV5Impl:Vv,split:zE,tile:PE,topkImpl:_E,whereImpl:yv};var HE={kernelName:kl,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(n,Zr(ue(e,"float32"),-1))}}}};var VE={kernelName:Fl,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){var i=Ye(ue(e,"float32")),r=Vt(ge(be(1),i));return vt(Ie(n,r))}}}};var qE={kernelName:Wl,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){var i=Vt(ge(Ye(ue(e,"float32")),1));return Ie(n,i)}}}};var GE={kernelName:Fs,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=et(e.shape,i.shape),a=function(){var o=n,l=gt(e.shape,r);return l.length>0&&(o=Ae(o,l)),V(o,e.shape)},s=function(){var o=n,l=gt(i.shape,r);return l.length>0&&(o=Ae(o,l)),V(o,i.shape)};return{a,b:s}}};var YE={kernelName:Ul,saveAllInputs:!0,gradFunc:function(n,t){var e={};return t.forEach(function(i,r){e[r]=function(){return n.clone()}}),e}};var jE={kernelName:Bl,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ee(e)}}}};var KE={kernelName:zl,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ee(e)}}}};var $E={kernelName:Pl,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,Vt(ge(be(1),Ye(ue(e,"float32")))))}}}};var XE={kernelName:_l,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){var i=Vt(fe(be(1),Ye(ue(e,"float32"))));return Ie(n,i)}}}};var JE={kernelName:Vl,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=et(e.shape,i.shape),a=function(){var o=fe(Ye(e),Ye(i)),l=J(n,Ie(i,o)),u=gt(e.shape,r);return u.length>0&&(l=Ae(l,u)),V(l,e.shape)},s=function(){var o=fe(Ye(e),Ye(i)),l=vt(J(n,Ie(e,o))),u=gt(i.shape,r);return u.length>0&&(l=Ae(l,u)),V(l,i.shape)};return{a,b:s}}};var ZE={kernelName:Ml,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,fe(Ye(ue(e,"float32")),1))}}}};var QE={kernelName:Hl,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,ge(be(1),Ye(ue(e,"float32"))))}}}};function eD(n,t,e,i,r,a,s){r===void 0&&(r=[1,1,1]);var o=O(n,"dy","avgPool3dBackprop"),l=O(t,"input","avgPool3dBackprop"),u=o,c=l,h=!1;l.rank===4&&(h=!0,u=V(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]]),c=V(l,[1,l.shape[0],l.shape[1],l.shape[2],l.shape[3]])),E(u.rank===5,function(){return"Error in avgPool3dBackprop: dy must be rank 5 but got rank "+(u.rank+".")}),E(c.rank===5,function(){return"Error in avgPool3dBackprop: input must be rank 5 but got rank "+(c.rank+".")}),E(Ht(i,r),function(){return"Error in avgPool3dBackprop: Either strides or dilations "+("must be 1. Got strides "+i+" and dilations '"+r+"'")}),s!=null&&E(rt(a),function(){return"Error in maxPool3dBackprop: pad must be an integer when "+("using, dimRoundingMode "+s+" but got pad "+a+".")});var d=function(g){var v=Ha(c.shape,e,i,r,a,s);return g.avgPool3dBackprop(u,c,v)},p={dy:u,input:c},f={filterSize:e,strides:i,dilations:r,pad:a,dimRoundingMode:s},m=z.runKernelFunc(d,p,null,If,f);return h?V(m,[m.shape[1],m.shape[2],m.shape[3],m.shape[4]]):m}var tD=U({avgPool3dBackprop_:eD});var nD={kernelName:Gl,inputsToSave:["x"],gradFunc:function(n,t,e){var i=t[0],r=e,a=r.filterSize,s=r.strides,o=r.dilations,l=r.pad,u=r.dimRoundingMode,c=o??[1,1,1];return{x:function(){return tD(n,i,a,s,c,l,u)}}}};function iD(n,t,e,i,r){var a=O(n,"dy","avgPoolBackprop"),s=O(t,"input","avgPoolBackprop");E(s.rank===a.rank,function(){return"Rank of input ("+s.rank+") does not match rank of dy ("+a.rank+")"});var o=s,l=a,u=!1;s.rank===3&&(u=!0,o=V(s,[1,s.shape[0],s.shape[1],s.shape[2]]),l=V(a,[1,a.shape[0],a.shape[1],a.shape[2]])),E(l.rank===4,function(){return"Error in avgPoolBackprop: dy must be rank 4 but got rank "+(l.rank+".")}),E(o.rank===4,function(){return"Error in avgPoolBackprop: input must be rank 4 but got rank "+(o.rank+".")});var c=function(f){var m=Vr(o.shape,e,i,1,r);return f.avgPoolBackprop(l,o,m)},h={dy:l,input:o},d={filterSize:e,strides:i,pad:r},p=z.runKernelFunc(c,h,null,Lf,d);return u?V(p,[p.shape[1],p.shape[2],p.shape[3]]):p}var rD=U({avgPoolBackprop_:iD});var aD={kernelName:ql,inputsToSave:["x"],gradFunc:function(n,t,e){var i=t[0],r=e,a=r.filterSize,s=r.strides,o=r.pad;return{x:function(){return rD(n,i,a,s,o)}}}};var sD={kernelName:Yl,inputsToSave:["a","b"],gradFunc:function(n,t,e){var i=t,r=i[0],a=i[1],s=e,o=s.transposeA,l=s.transposeB;return!o&&!l?{a:function(){return We(n,a,!1,!0)},b:function(){return We(r,n,!0,!1)}}:!o&&l?{a:function(){return We(n,a,!1,!1)},b:function(){return We(n,r,!0,!1)}}:o&&!l?{a:function(){return We(a,n,!1,!0)},b:function(){return We(r,n,!1,!1)}}:{a:function(){return We(a,n,!0,!0)},b:function(){return We(n,r,!0,!0)}}}};var oD={kernelName:jl,gradFunc:function(n,t,e){var i=e,r=i.blockShape,a=i.crops;return{x:function(){return co(n,r,a)}}}};var lD={kernelName:Kl,gradFunc:function(n,t,e){for(var i=e,r=i.inputShape,a=i.shape,s=Array.from(a),o=r.length-1;o>=0;o--)if(r[o]===a[o])s[o]=1;else if(r[o]!==1)throw new Error("broadcastTo(): ["+r+"] cannot be broadcast to ["+a+"].");for(var l=[],o=0;o<s.length;o++)s[o]>1&&l.push(o);return{x:function(){return Ae(n,l,!0)}}}};var uD={kernelName:Ws,gradFunc:function(n){return{x:function(){return n.clone()}}}};var cD={kernelName:$l,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var hD={kernelName:Xl,inputsToSave:["x"],gradFunc:function(n,t,e){var i=t[0],r=e,a=r.clipValueMin,s=r.clipValueMax;return{x:function(){return yn(nr(Zi(i,a),Qi(i,s)),n,Ee(n))}}}};var dD={kernelName:Jl,saveAllInputs:!0,gradFunc:function(n,t,e){var i=t.map(function(l){return l.shape}),r=e.axis,a=Qe(r,t[0].shape)[0],s=i.map(function(l){return l[a]}),o=Jr(n,s,a);return o.map(function(l){return function(){return l}})}};var pD={kernelName:Zl,inputsToSave:["x","filter"],gradFunc:function(n,t,e){var i=t,r=i[0],a=i[1],s=e,o=s.dilations,l=s.strides,u=s.pad,c=s.dataFormat;return E(Si(o),function(){return"Error in gradient of conv2D: dilation rates greater than 1 "+("are not yet supported in gradients. Got dilations '"+o+"'")}),{x:function(){return nh(r.shape,n,a,l,u,c)},filter:function(){return Nh(r,n,a.shape,l,u,c)}}}};var fD={kernelName:Ql,inputsToSave:["dy","filter"],gradFunc:function(n,t,e){var i=t,r=i[0],a=i[1],s=e,o=s.strides,l=s.pad,u=s.dataFormat,c=s.dimRoundingMode;return{dy:function(){return Gr(n,a,o,l,u,1,c)},filter:function(){return Nh(n,r,a.shape,o,l,u,c)}}}};function mD(n,t,e,i,r){var a=n;n.rank===4&&(a=V(n,[1,n.shape[0],n.shape[1],n.shape[2],n.shape[3]]));var s=t;s.rank===4&&(s=V(t,[1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]])),E(a.rank===5,function(){return"Error in conv3dDerFilter: input must be rank 5, but got shape "+(a.shape+".")}),E(s.rank===5,function(){return"Error in conv3dDerFilter: dy must be rank 5, but got shape "+(s.shape+".")}),E(e.length===5,function(){return"Error in conv3dDerFilter: filterShape must be length 5, but got "+(e+".")}),E(a.shape[4]===e[3],function(){return"Error in conv3dDerFilter: depth of input "+a.shape[4]+") must "+("match input depth in filter ("+e[3]+".")}),E(s.shape[4]===e[4],function(){return"Error in conv3dDerFilter: depth of dy ("+s.shape[4]+") must "+("match output depth for filter ("+e[4]+").")});var o=function(c){var h=1,d=Ma(a.shape,e,i,h,r);return c.conv3dDerFilter(a,s,d)},l={x:a,y:s},u={strides:i,pad:r};return z.runKernelFunc(o,l,null,Nf,u)}var gD=U({conv3DBackpropFilter_:mD});var vD={kernelName:eu,inputsToSave:["x","filter"],gradFunc:function(n,t,e){var i=e,r=i.dilations,a=i.strides,s=i.pad;E(Si(r),function(){return"Error in gradient of conv3D: dilation rates greater than 1 are "+("not yet supported in gradients. Got dilations '"+r+"'")});var o=t[0],l=t[1];return{x:function(){return _g(o.shape,n,l,a,s)},filter:function(){return gD(o,n,l.shape,a,s)}}}};var yD={kernelName:tu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(vt(Sh(ue(e,"float32"))),n)}}}};var bD={kernelName:nu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(Lh(ue(e,"float32")),n)}}}};var wD={kernelName:iu,inputsToSave:["x"],gradFunc:function(n,t,e){var i=t[0],r=e,a=r.axis,s=r.exclusive,o=r.reverse;return{x:function(){var l=an([a],i.rank),u=rh(n,a,s,!o);return l!=null&&(u=ut(u,l)),u}}}};var SD={kernelName:ru,inputsToSave:["x","filter"],gradFunc:function(n,t,e){var i=e,r=i.dilations,a=i.strides,s=i.pad,o=i.dimRoundingMode,l=r??[1,1];E(Si(l),function(){return"Error in gradient of depthwiseConv2dNative: dilation rates greater than 1 are not yet supported. Got dilations "+("'"+l+"'")});var u=t,c=u[0],h=u[1];E(c.rank===4,function(){return"Error in gradient of depthwiseConv2dNative: input must be "+("rank 4, but got rank "+c.rank+".")}),E(h.rank===4,function(){return"Error in gradient of depthwiseConv2dNative: filter must be "+("rank 4, but got rank "+h.rank+".")}),E(c.shape[3]===h.shape[2],function(){return"Error in gradient of depthwiseConv2d: number of input "+("channels ("+c.shape[3]+") must match the inChannels dimension ")+("in filter "+h.shape[2]+".")}),E(Ht(a,l),function(){return"Error in gradient of depthwiseConv2d: Either strides or "+("dilations must be 1. Got strides "+a+" and dilations ")+("'"+l+"'.")}),o!=null&&E(rt(s),function(){return"Error in depthwiseConv2d: pad must be an integer when using, "+("dimRoundingMode "+o+" but got pad "+s+".")});var d=Bn(c.shape,h.shape,a,l,s,o,!0);return{x:function(){return zv(c.shape,n,h,d)},filter:function(){return Bv(c,n,h.shape,d)}}}};var LD={kernelName:au,inputsToSave:["x","filter"],gradFunc:function(n,t,e){var i=t,r=i[0],a=i[1],s={x:r,filter:a,dy:n},o={x:r,filter:a,dy:n};return{x:function(){return z.runKernel(kf,s,e)},filter:function(){return z.runKernel(Ff,o,e)}}}};var ID={kernelName:su,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=et(e.shape,i.shape),a=function(){var o=Ie(n,ue(i,"float32")),l=gt(e.shape,r);return l.length>0?V(Ae(o,l),e.shape):o},s=function(){var o=J(n,ue(e,"float32")),l=gt(i.shape,r);l.length>0&&(o=V(Ae(o,l),i.shape));var u=Ye(i);return vt(Ie(o,ue(u,"float32")))};return{a,b:s}}};var AD={kernelName:ou,outputsToSave:[!0],gradFunc:function(n,t){var e=t[0],i=function(a){return a.eluDer(n,e)},r={dy:n,y:e};return{x:function(){return z.runKernelFunc(i,r,null,Wf)}}}};var TD={kernelName:lu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0],i=J(bn(vt(Ye(e))),2/Math.sqrt(Math.PI));return{x:function(){return J(n,i)}}}};var ND={kernelName:uu,outputsToSave:[!0],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(n,e)}}}};var xD={kernelName:cu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(n,bn(e))}}}};var CD={kernelName:hu,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var RD={kernelName:du,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=et(e.shape,i.shape),a=function(){var o=Ie(n,ue(i,"float32")),l=gt(e.shape,r);return l.length>0?V(Ae(o,l),e.shape):o},s=function(){var o=J(n,ue(e,"float32")),l=gt(i.shape,r);l.length>0&&(o=V(Ae(o,l),i.shape));var u=Ye(i);return vt(Ie(o,ue(u,"float32")))};return{a,b:s}}};var OD={kernelName:pu,inputsToSave:["x","mean","variance","scale"],gradFunc:function(n,t,e){var i=e.varianceEpsilon,r=t[0],a=t[1],s=t[2],o=t[3],l=o??be(1),u=gt(a.shape,r.shape),c=[];if(a.rank===1){for(var h=0;h<r.shape.length-1;++h)c.push(r.shape[h]);c.push(1)}var d=ge(r,a),p=J(n,l),f=wh(fe(s,be(i))),m=J(J(J(f,f),f),be(-.5)),g=function(){return a.rank===1?V(J(J(n,Yr(V(f,[1,1,1,a.shape[0]]),c)),l),r.shape):V(J(J(n,f),l),r.shape)},v=function(){var L=J(J(f,be(-1)),p);return a.rank===1&&(L=Ae(L,u)),V(L,a.shape)},b=function(){var L=J(J(m,d),p);return a.rank===1&&(L=Ae(L,u)),V(L,a.shape)},w=function(){var L=J(d,f),N=J(n,L);return a.rank===1&&(N=Ae(N,u)),V(N,a.shape)},S=function(){var L=n;return a.rank===1&&(L=Ae(L,u)),V(L,a.shape)};return{x:g,mean:v,variance:b,scale:w,offset:S}}};var ED={kernelName:fu,inputsToSave:["x","indices"],gradFunc:function(n,t,e){var i=t[0],r=t[1],a=e.axis,s=Qe(a,i.shape)[0],o=function(){var l=i.shape,u=r.size,c=l.slice(0,s),h=c.length,d=l.slice(a,l.length).slice(1),p=d.length,f=Xv(0,h),m=Xv(h+1,h+1+p),g=Jv([c,[u],d]),v=V(n,g),b=V(r,[u]),w=Jv([[h],f,m]),S=ut(v,w),L=Ah(S,b,i.shape[s]),N=Ks(w);return L=ut(L,N),L};return{x:o,indices:function(){return r}}}};function Xv(n,t){for(var e=[],i=n;i<t;++i)e.push(i);return e}function Jv(n){for(var t=[],e=0;e<n.length;++e)for(var i=0;i<n[e].length;++i)t.push(n[e][i]);return t}var DD={kernelName:mu,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1];return{a:function(){return Ee(e)},b:function(){return Ee(i)}}}};var kD={kernelName:gu,gradFunc:function(n){return{x:function(){return ue(n,"float32")}}}};var FD={kernelName:vu,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var WD={kernelName:yu,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var UD={kernelName:bu,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var BD={kernelName:Su,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,fe(e,1))}}}};var zD={kernelName:wu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,ue(e,"float32"))}}}};var PD={kernelName:Lu,inputsToSave:[],outputsToSave:[!0],gradFunc:function(n,t,e){var i=t[0],r=e.axis;return{logits:function(){var a=!0,s=bn(i);return ge(n,J(Ae(n,r,a),s))}}}};function _D(n,t,e,i,r,a,s){i===void 0&&(i=5),r===void 0&&(r=1),a===void 0&&(a=1),s===void 0&&(s=.5);var o=function(c){return c.LRNGrad(e,n,t,i,r,a,s)},l={x:n,y:t,dy:e},u={depthRadius:i,bias:r,alpha:a,beta:s};return z.runKernelFunc(o,l,null,Xf,u)}var MD=U({localResponseNormalizationBackprop_:_D});var HD={kernelName:Iu,inputsToSave:["x"],outputsToSave:[!0],gradFunc:function(n,t,e){var i=t,r=i[0],a=i[1],s=e,o=s.depthRadius,l=s.bias,u=s.alpha,c=s.beta;return{x:function(){return MD(r,a,n,o,l,u,c)}}}};function Zv(n,t,e,i,r){return t.rank<e.rank&&(t=V(t,rn(t.shape,i))),n.rank<e.rank&&(n=V(n,rn(n.shape,i))),{x:function(){var a=J(n,ue(Ga(e,t),n.dtype));return r==null?a:ut(a,r)}}}var Qv={kernelName:Au,inputsToSave:["x"],outputsToSave:[!0],gradFunc:function(n,t,e){var i=e,r=i.reductionIndices,a=t[0],s=t[1],o=Qe(r,a.shape),l=an(o,a.rank),u=Zv(n,s,a,o,l);return{x:function(){var c=u.x();return l!=null&&(c=ut(c)),c}}}};var VD={kernelName:Tu,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=function(){return J(n,ue(Zi(e,i),"float32"))},a=function(){return J(n,ue(ro(e,i),"float32"))};return{a:r,b:a}}};function qD(n,t,e,i,r,a,s,o){a===void 0&&(a=[1,1,1]);var l=O(n,"dy","maxPool3dBackprop"),u=O(t,"input","maxPool3dBackprop"),c=O(e,"output","maxPool3dBackprop"),h=l,d=u,p=c,f=!1;u.rank===4&&(f=!0,h=V(l,[1,l.shape[0],l.shape[1],l.shape[2],l.shape[3]]),d=V(u,[1,u.shape[0],u.shape[1],u.shape[2],u.shape[3]]),p=V(c,[1,c.shape[0],c.shape[1],c.shape[2],c.shape[3]])),E(h.rank===5,function(){return"Error in maxPool3dBackprop: dy must be rank 5 but got rank "+(h.rank+".")}),E(d.rank===5,function(){return"Error in maxPool3dBackprop: input must be rank 5 but got rank "+(d.rank+".")}),E(p.rank===5,function(){return"Error in maxPool3dBackprop: output must be rank 5 but got rank "+(p.rank+".")}),E(Ht(r,a),function(){return"Error in maxPool3dBackprop: Either strides or dilations "+("must be 1. Got strides "+r+" and dilations '"+a+"'")}),o!=null&&E(rt(s),function(){return"Error in maxPool3dBackprop: pad must be an integer when "+("using, dimRoundingMode "+o+" but got pad "+s+".")});var m=function(w){var S=Ha(d.shape,i,r,a,s,o);return w.maxPool3dBackprop(h,d,p,S)},g={dy:h,input:d,output:p},v={filterSize:i,strides:r,dilations:a,pad:s,dimRoundingMode:o},b=z.runKernelFunc(m,g,null,Zf,v);return f?V(b,[b.shape[1],b.shape[2],b.shape[3],b.shape[4]]):b}var GD=U({maxPool3dBackprop_:qD});var YD={kernelName:xu,inputsToSave:["x"],outputsToSave:[!0],gradFunc:function(n,t,e){var i=t,r=i[0],a=i[1],s=e,o=s.filterSize,l=s.strides,u=s.dilations,c=s.pad,h=s.dimRoundingMode,d=u??[1,1,1];return{x:function(){return GD(n,r,a,o,l,d,c,h)}}}};function jD(n,t,e,i,r,a,s){var o=O(n,"dy","maxPoolBackprop"),l=O(t,"input","maxPoolBackprop"),u=O(e,"output","maxPoolBackprop");E(l.rank===o.rank,function(){return"Rank of input ("+l.rank+") does not match rank of dy "+("("+o.rank+")")}),E(o.rank===4,function(){return"Error in maxPoolBackprop: dy must be rank 4 but got rank "+(o.rank+".")}),E(l.rank===4,function(){return"Error in maxPoolBackprop: input must be rank 4 but got rank "+(l.rank+".")}),s!=null&&E(rt(a),function(){return"Error in maxPoolBackprop: pad must be an integer when using, "+("dimRoundingMode "+s+" but got pad "+a+".")});var c=function(p){var f=Vr(l.shape,i,r,1,a,s);return p.maxPoolBackprop(o,l,u,f)},h={dy:o,input:l,output:u},d={filterSize:i,strides:r,pad:a,dimRoundingMode:s};return z.runKernelFunc(c,h,null,Jf,d)}var KD=U({maxPoolBackprop_:jD});var $D={kernelName:Nu,inputsToSave:["x"],outputsToSave:[!0],gradFunc:function(n,t,e){var i=t,r=i[0],a=i[1],s=e,o=s.filterSize,l=s.strides,u=s.pad;return{x:function(){return KD(n,r,a,o,l,u)}}}};var XD={kernelName:Cu,inputsToSave:["x"],outputsToSave:[!0],gradFunc:function(n,t,e){var i=e,r=i.axis,a=t[0],s=t[1],o=Qe(r,a.shape),l=an(o,a.rank),u=Zv(n,s,a,o,l);return{x:function(){var c=u.x();return l!=null&&(c=ut(c)),c}}}};var JD={kernelName:Ru,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=function(){return J(n,ue(Qi(e,i),"float32"))},a=function(){return J(n,ue(Li(e,i),"float32"))};return{a:r,b:a}}};var ZD={kernelName:Ou,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=et(e.shape,i.shape),a=function(){var o=gt(e.shape,r);return o.length>0?V(Ae(n,o),e.shape):n},s=function(){var o=J(n,vt(to(Ie(e,i)))),l=gt(i.shape,r);return l.length>0?V(Ae(o,l),i.shape):o};return{a,b:s}}};var QD={kernelName:Eu,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=et(e.shape,i.shape),a=function(){var o=J(n,ue(i,"float32")),l=gt(e.shape,r);return l.length>0?V(Ae(o,l),e.shape):o},s=function(){var o=J(n,ue(e,"float32")),l=gt(i.shape,r);return l.length>0?V(Ae(o,l),i.shape):o};return{a,b:s}}};var ek={kernelName:Du,gradFunc:function(n){return{x:function(){return vt(n)}}}};var tk={kernelName:Fu,inputsToSave:["indices"],gradFunc:function(n,t){var e=t[0];return{indices:function(){return ti(e.shape,"float32")}}}};var nk={kernelName:ku,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var ey={kernelName:Wu,inputsToSave:["x"],gradFunc:function(n,t,e){var i=t[0],r=e.paddings,a=r.map(function(s){return s[0]});return{x:function(){return ze(n,a,i.shape)}}}};var ik={kernelName:Uu,inputsToSave:["a","b"],outputsToSave:[!0],gradFunc:function(n,t){var e=t[0],i=t[1],r=t[2],a=e,s=i,o=et(a.shape,s.shape),l=function(){var c=ue(s,"float32"),h=J(n,J(c,ni(a,ge(c,be(1))))),d=gt(a.shape,o);return d.length>0&&(h=Ae(h,d)),V(h,a.shape)},u=function(){var c=Li(a,0),h=yn(c,er(a),Ee(a)),d=J(n,J(r,h)),p=gt(s.shape,o);return p.length>0&&(d=Ae(d,p)),V(d,s.shape)};return{a:l,b:u}}};var rk={kernelName:Bu,inputsToSave:["x","alpha"],gradFunc:function(n,t){var e=t[0],i=t[1],r=Li(e,0);return{x:function(){return yn(r,n,J(n,i))},alpha:function(){var a=yn(r,Ee(n),J(n,e)),s=gt(i.shape,n.shape);return s.length>0&&(a=Ae(a,s)),V(a,i.shape)}}}};var ak={kernelName:zu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,vt(Ye(e)))}}}};var sk={kernelName:Vu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0],i=J(Qi(e,6),Zr(e));return{x:function(){return J(n,ue(i,"float32"))}}}};var ok={kernelName:Pu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(n,ue(Zr(e),"float32"))}}}};var lk={kernelName:_u,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return V(n,e.shape)}}}};var uk={kernelName:Hu,inputsToSave:["images"],gradFunc:function(n,t,e){var i=t[0],r=function(o){var l=e.alignCorners;return o.resizeBilinearBackprop(n,i,l)},a={images:i},s=function(){return z.runKernelFunc(r,a,null,lm,e)};return{images:s}}};var ck={kernelName:Mu,inputsToSave:["images"],gradFunc:function(n,t,e){var i=t[0],r=function(o){var l=e.alignCorners;return o.resizeNearestNeighborBackprop(n,i,l)},a={images:i},s=function(){return z.runKernelFunc(r,a,null,om,e)};return{images:s}}};var hk={kernelName:qu,gradFunc:function(n,t,e){var i=e.dims,r=Qe(i,n.shape);return{x:function(){return ii(n,r)}}}};var dk={kernelName:Gu,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var pk={kernelName:Yu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return vt(Ie(n,J(ni(e,1.5),2)))}}}};var fk={kernelName:ju,inputsToSave:["condition"],gradFunc:function(n,t){var e=t[0];return{condition:function(){return ue(Ee(e),"float32")},t:function(){return J(n,ue(e,n.dtype))},e:function(){return J(n,ue(so(e),n.dtype))}}}};var mk={kernelName:Ku,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){var i=Li(e,be(0)),r=be(Kv),a=be($v),s=J(n,a),o=J(J(n,r),bn(ue(e,"float32")));return yn(i,s,o)}}}};var gk={kernelName:Qu,outputsToSave:[!0],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(n,J(e,ge(be(1),e)))}}}};var vk={kernelName:Zu,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var yk={kernelName:Xu,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(eo(ue(e,"float32")),n)}}}};var bk={kernelName:Ju,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(ih(ue(e,"float32")),n)}}}};var wk={kernelName:$u,inputsToSave:["x"],gradFunc:function(n,t,e){for(var i=t[0],r=e,a=r.begin,s=r.size,o=i.shape,l=jc(i,a,s),u=l[0],c=l[1],h=[],d=0;d<n.rank;d++)h.push([u[d],o[d]-u[d]-c[d]]);return{x:function(){return ir(n,h)}}}};var Sk={kernelName:ac,outputsToSave:[!0],gradFunc:function(n,t,e){var i=t[0],r=e.dim,a=!0,s=J(n,i);return{logits:function(){return ge(s,J(Ae(s,[r],a),i))}}}};var Lk={kernelName:ec,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(n,Ji(e))}}}};var ty={kernelName:ic,gradFunc:function(n,t,e){var i=e,r=i.blockShape,a=i.paddings;return{x:function(){return Js(n,r,a)}}}};var ny={kernelName:rc,gradFunc:function(n,t,e){var i=e.axis;return{x:function(){return Rt(n,i)}}}};var Ik={kernelName:tc,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,J(Vt(ue(e,"float32")),2))}}}};var Ak={kernelName:cm,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(n,J(ue(e,"float32"),2))}}}};var Tk={kernelName:sc,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=be(2),a=function(){return J(n,J(r,ge(e,i)))},s=function(){return J(n,J(r,ge(i,e)))};return{a,b:s}}};var Nk={kernelName:mc,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var xk={kernelName:oc,inputsToSave:["a","b"],gradFunc:function(n,t){var e=t[0],i=t[1],r=et(e.shape,i.shape),a=function(){var o=n,l=gt(e.shape,r);return l.length>0&&(o=Ae(o,l)),V(o,e.shape)},s=function(){var o=n,l=gt(i.shape,r);return l.length>0&&(o=Ae(o,l)),V(vt(o),i.shape)};return{a,b:s}}};var Ck={kernelName:nc,inputsToSave:["x"],gradFunc:function(n,t,e){var i=t[0],r=i.shape.slice(),a=e.axis,s=Qe(a,i.shape);s.forEach(function(u){r[u]=1});var o=V(n,r),l=J(o,Kr(i.shape,"float32"));return{x:function(){return l}}}};var Rk={kernelName:lc,inputsToSave:["x"],gradFunc:function(n,t){var e=t[0];return{x:function(){return Ie(n,Ye(eo(e)))}}}};var Ok={kernelName:uc,outputsToSave:[!0],gradFunc:function(n,t){var e=t[0];return{x:function(){return J(ge(be(1),Ye(e)),n)}}}};var Ek={kernelName:cc,inputsToSave:["x"],gradFunc:function(n,t,e){var i=t[0],r=e.reps,a=function(){var s=Ee(i);if(i.rank===1)for(var o=0;o<r[0];++o)s=fe(s,ze(n,[o*i.shape[0]],[i.shape[0]]));else if(i.rank===2)for(var o=0;o<r[0];++o)for(var l=0;l<r[1];++l)s=fe(s,ze(n,[o*i.shape[0],l*i.shape[1]],[i.shape[0],i.shape[1]]));else if(i.rank===3)for(var o=0;o<r[0];++o)for(var l=0;l<r[1];++l)for(var u=0;u<r[2];++u)s=fe(s,ze(n,[o*i.shape[0],l*i.shape[1],u*i.shape[2]],[i.shape[0],i.shape[1],i.shape[2]]));else if(i.rank===4)for(var o=0;o<r[0];++o)for(var l=0;l<r[1];++l)for(var u=0;u<r[2];++u)for(var c=0;c<r[3];++c)s=fe(s,ze(n,[o*i.shape[0],l*i.shape[1],u*i.shape[2],c*i.shape[3]],[i.shape[0],i.shape[1],i.shape[2],i.shape[3]]));else throw new Error("Gradient for tile operation is not implemented for rank-"+(i.rank+" tensors yet."));return s};return{x:a}}};var Dk={kernelName:hc,gradFunc:function(n,t,e){var i=e,r=i.perm,a=Ks(r);return{x:function(){return ut(n,a)}}}};var kk={kernelName:dc,gradFunc:function(n,t,e){var i=e,r=i.axis;return{value:function(){return sr(n,r)}}}};var Wk={kernelName:pc,inputsToSave:["segmentIds"],gradFunc:function(n,t){var e=t[0],i=function(){return Fk(n,e)};return{x:i}}};function Fk(n,t){for(var e=jr(t,Ee(t)),i=no(n,e),r=Zi(t,be(0,"int32")),a=i.rank-r.rank,s=0;s<a;++s)r=wn(r,s+1);r=nr(r,Kr(i.shape,"bool"));var o=Ee(i);return yn(r,i,o)}var Uk={kernelName:fc,gradFunc:function(n){return{x:function(){return Ee(n)}}}};var Bk=[HE,VE,qE,GE,YE,jE,KE,$E,XE,JE,ZE,QE,nD,aD,sD,oD,lD,uD,cD,hD,dD,fD,pD,vD,yD,bD,wD,SD,LD,ID,AD,TD,ND,xD,RD,CD,OD,ED,DD,kD,FD,WD,UD,BD,zD,PD,HD,Qv,Qv,VD,YD,$D,XD,JD,ZD,QD,ek,tk,nk,ey,ey,ik,rk,ak,sk,ok,lk,uk,ck,hk,dk,pk,fk,mk,gk,vk,yk,bk,wk,Sk,Lk,ty,ty,ny,ny,Ik,Tk,Ak,Nk,xk,Ck,Rk,Ok,Ek,Dk,kk,Wk,Uk];for(var Fh=0,iy=Bk;Fh<iy.length;Fh++){var zk=iy[Fh];vm(zk)}Y.prototype.abs=function(){return this.throwIfDisposed(),Kt(this)};Y.prototype.acos=function(){return this.throwIfDisposed(),Sg(this)};Y.prototype.acosh=function(){return this.throwIfDisposed(),Lg(this)};Y.prototype.addStrict=function(n){return this.throwIfDisposed(),Nv(this,n)};Y.prototype.add=function(n){return this.throwIfDisposed(),fe(this,n)};Y.prototype.all=function(n,t){return this.throwIfDisposed(),Tg(this,n,t)};Y.prototype.any=function(n,t){return this.throwIfDisposed(),Ng(this,n,t)};Y.prototype.argMax=function(n){return this.throwIfDisposed(),xg(this,n)};Y.prototype.argMin=function(n){return this.throwIfDisposed(),Cg(this,n)};Y.prototype.asScalar=function(){return this.throwIfDisposed(),E(this.size===1,function(){return"The array must have only 1 element."}),V(this,[])};Y.prototype.asType=function(n){return this.throwIfDisposed(),ue(this,n)};Y.prototype.as1D=function(){return this.throwIfDisposed(),V(this,[this.size])};Y.prototype.as2D=function(n,t){return this.throwIfDisposed(),V(this,[n,t])};Y.prototype.as3D=function(n,t,e){return this.throwIfDisposed(),V(this,[n,t,e])};Y.prototype.as4D=function(n,t,e,i){return this.throwIfDisposed(),V(this,[n,t,e,i])};Y.prototype.as5D=function(n,t,e,i,r){return this.throwIfDisposed(),V(this,[n,t,e,i,r])};Y.prototype.asin=function(){return this.throwIfDisposed(),Rg(this)};Y.prototype.asinh=function(){return this.throwIfDisposed(),Og(this)};Y.prototype.atan=function(){return this.throwIfDisposed(),Eg(this)};Y.prototype.atan2=function(n){return this.throwIfDisposed(),Dg(this,n)};Y.prototype.atanh=function(){return this.throwIfDisposed(),kg(this)};Y.prototype.avgPool=function(n,t,e,i){return this.throwIfDisposed(),th(this,n,t,e,i)};Y.prototype.batchToSpaceND=function(n,t){return this.throwIfDisposed(),Js(this,n,t)};Y.prototype.batchNorm=function(n,t,e,i,r){return this.throwIfDisposed(),Va(this,n,t,e,i,r)};Y.prototype.broadcastTo=function(n){return this.throwIfDisposed(),Qs(this,n)};Y.prototype.cast=function(n){return this.throwIfDisposed(),ue(this,n)};Y.prototype.ceil=function(){return this.throwIfDisposed(),Ug(this)};Y.prototype.clipByValue=function(n,t){return this.throwIfDisposed(),Bg(this,n,t)};Y.prototype.concat=function(n,t){return this.throwIfDisposed(),n instanceof Y&&(n=[n]),Rt([this].concat(n),t)};Y.prototype.conv1d=function(n,t,e,i,r,a){return this.throwIfDisposed(),zg(this,n,t,e,i,r,a)};Y.prototype.conv2dTranspose=function(n,t,e,i,r){return this.throwIfDisposed(),Pg(this,n,t,e,i,r)};Y.prototype.conv2d=function(n,t,e,i,r,a){return this.throwIfDisposed(),Gr(this,n,t,e,i,r,a)};Y.prototype.cos=function(){return this.throwIfDisposed(),eo(this)};Y.prototype.cosh=function(){return this.throwIfDisposed(),ih(this)};Y.prototype.cumsum=function(n,t,e){return this.throwIfDisposed(),rh(this,n,t,e)};Y.prototype.depthToSpace=function(n,t){return this.throwIfDisposed(),Mg(this,n,t)};Y.prototype.depthwiseConv2D=function(n,t,e,i,r,a){return At("depthwiseConv2D is deprecated, use depthwiseConv2d instead"),this.throwIfDisposed(),qa(this,n,t,e,i,r,a)};Y.prototype.depthwiseConv2d=function(n,t,e,i,r,a){return this.throwIfDisposed(),qa(this,n,t,e,i,r,a)};Y.prototype.dilation2d=function(n,t,e,i,r){return this.throwIfDisposed(),Hg(this,n,t,e,i,r)};Y.prototype.divNoNan=function(n){return this.throwIfDisposed(),Vg(this,n)};Y.prototype.divStrict=function(n){return this.throwIfDisposed(),xv(this,n)};Y.prototype.div=function(n){return this.throwIfDisposed(),Ie(this,n)};Y.prototype.dot=function(n){return this.throwIfDisposed(),qg(this,n)};Y.prototype.elu=function(){return this.throwIfDisposed(),ah(this)};Y.prototype.equalStrict=function(n){return this.throwIfDisposed(),wv(this,n)};Y.prototype.equal=function(n){return this.throwIfDisposed(),Ga(this,n)};Y.prototype.erf=function(){return this.throwIfDisposed(),Gg(this)};Y.prototype.exp=function(){return this.throwIfDisposed(),bn(this)};Y.prototype.expandDims=function(n){return this.throwIfDisposed(),wn(this,n)};Y.prototype.expm1=function(){return this.throwIfDisposed(),Yg(this)};Y.prototype.fft=function(){return this.throwIfDisposed(),ho(this)};Y.prototype.flatten=function(){return this.throwIfDisposed(),V(this,[this.size])};Y.prototype.floor=function(){return this.throwIfDisposed(),to(this)};Y.prototype.floorDiv=function(n){return this.throwIfDisposed(),Jc(this,n)};Y.prototype.gather=function(n,t){return this.throwIfDisposed(),no(this,n,t)};Y.prototype.greaterEqualStrict=function(n){return this.throwIfDisposed(),Sv(this,n)};Y.prototype.greaterEqual=function(n){return this.throwIfDisposed(),Zi(this,n)};Y.prototype.greaterStrict=function(n){return this.throwIfDisposed(),Lv(this,n)};Y.prototype.greater=function(n){return this.throwIfDisposed(),Li(this,n)};Y.prototype.ifft=function(){return this.throwIfDisposed(),$a(this)};Y.prototype.irfft=function(){return this.throwIfDisposed(),Ih(this)};Y.prototype.isFinite=function(){return this.throwIfDisposed(),$g(this)};Y.prototype.isInf=function(){return this.throwIfDisposed(),Xg(this)};Y.prototype.isNaN=function(){return this.throwIfDisposed(),Jg(this)};Y.prototype.leakyRelu=function(n){return this.throwIfDisposed(),Zg(this,n)};Y.prototype.lessEqualStrict=function(n){return this.throwIfDisposed(),Iv(this,n)};Y.prototype.lessEqual=function(n){return this.throwIfDisposed(),Qi(this,n)};Y.prototype.lessStrict=function(n){return this.throwIfDisposed(),Av(this,n)};Y.prototype.less=function(n){return this.throwIfDisposed(),ro(this,n)};Y.prototype.localResponseNormalization=function(n,t,e,i){return this.throwIfDisposed(),Qg(this,n,t,e,i)};Y.prototype.logSigmoid=function(){return this.throwIfDisposed(),tv(this)};Y.prototype.logSoftmax=function(n){return this.throwIfDisposed(),nv(this,n)};Y.prototype.logSumExp=function(n,t){return this.throwIfDisposed(),ch(this,n,t)};Y.prototype.log=function(){return this.throwIfDisposed(),er(this)};Y.prototype.log1p=function(){return this.throwIfDisposed(),lh(this)};Y.prototype.logicalAnd=function(n){return this.throwIfDisposed(),nr(this,n)};Y.prototype.logicalNot=function(){return this.throwIfDisposed(),so(this)};Y.prototype.logicalOr=function(n){return this.throwIfDisposed(),hh(this,n)};Y.prototype.logicalXor=function(n){return this.throwIfDisposed(),iv(this,n)};Y.prototype.matMul=function(n,t,e){return this.throwIfDisposed(),We(this,n,t,e)};Y.prototype.maxPool=function(n,t,e,i){return this.throwIfDisposed(),dh(this,n,t,e,i)};Y.prototype.max=function(n,t){return this.throwIfDisposed(),tr(this,n,t)};Y.prototype.maximumStrict=function(n){return this.throwIfDisposed(),Cv(this,n)};Y.prototype.maximum=function(n){return this.throwIfDisposed(),jr(this,n)};Y.prototype.mean=function(n,t){return this.throwIfDisposed(),Ya(this,n,t)};Y.prototype.min=function(n,t){return this.throwIfDisposed(),oo(this,n,t)};Y.prototype.minimumStrict=function(n){return this.throwIfDisposed(),Rv(this,n)};Y.prototype.minimum=function(n){return this.throwIfDisposed(),lo(this,n)};Y.prototype.modStrict=function(n){return this.throwIfDisposed(),Ov(this,n)};Y.prototype.mod=function(n){return this.throwIfDisposed(),ph(this,n)};Y.prototype.mulStrict=function(n){return this.throwIfDisposed(),Ev(this,n)};Y.prototype.mul=function(n){return this.throwIfDisposed(),J(this,n)};Y.prototype.neg=function(){return this.throwIfDisposed(),vt(this)};Y.prototype.norm=function(n,t,e){return this.throwIfDisposed(),vo(this,n,t,e)};Y.prototype.notEqualStrict=function(n){return this.throwIfDisposed(),Tv(this,n)};Y.prototype.notEqual=function(n){return this.throwIfDisposed(),uo(this,n)};Y.prototype.oneHot=function(n,t,e){return t===void 0&&(t=1),e===void 0&&(e=0),this.throwIfDisposed(),Ys(this,n,t,e)};Y.prototype.onesLike=function(){return this.throwIfDisposed(),fh(this)};Y.prototype.pad=function(n,t){return this.throwIfDisposed(),ir(this,n,t)};Y.prototype.pool=function(n,t,e,i,r){return this.throwIfDisposed(),rv(this,n,t,e,i,r)};Y.prototype.powStrict=function(n){return this.throwIfDisposed(),Dv(this,n)};Y.prototype.pow=function(n){return this.throwIfDisposed(),ni(this,n)};Y.prototype.prelu=function(n){return this.throwIfDisposed(),mh(this,n)};Y.prototype.prod=function(n,t){return this.throwIfDisposed(),av(this,n,t)};Y.prototype.reciprocal=function(){return this.throwIfDisposed(),ov(this)};Y.prototype.relu=function(){return this.throwIfDisposed(),Ka(this)};Y.prototype.relu6=function(){return this.throwIfDisposed(),bh(this)};Y.prototype.reshapeAs=function(n){return this.throwIfDisposed(),V(this,n.shape)};Y.prototype.reshape=function(n){return this.throwIfDisposed(),V(this,n)};Y.prototype.resizeBilinear=function(n,t){return this.throwIfDisposed(),Gv(this,n,t)};Y.prototype.resizeNearestNeighbor=function(n,t){return this.throwIfDisposed(),Yv(this,n,t)};Y.prototype.reverse=function(n){return this.throwIfDisposed(),ii(this,n)};Y.prototype.rfft=function(){return this.throwIfDisposed(),po(this)};Y.prototype.round=function(){return this.throwIfDisposed(),lv(this)};Y.prototype.rsqrt=function(){return this.throwIfDisposed(),wh(this)};Y.prototype.selu=function(){return this.throwIfDisposed(),uv(this)};Y.prototype.separableConv2d=function(n,t,e,i,r,a){return this.throwIfDisposed(),cv(this,n,t,e,i,r,a)};Y.prototype.sigmoid=function(){return this.throwIfDisposed(),Ji(this)};Y.prototype.sign=function(){return this.throwIfDisposed(),hv(this)};Y.prototype.sin=function(){return this.throwIfDisposed(),Sh(this)};Y.prototype.sinh=function(){return this.throwIfDisposed(),Lh(this)};Y.prototype.slice=function(n,t){return this.throwIfDisposed(),ze(this,n,t)};Y.prototype.softmax=function(n){return this.throwIfDisposed(),dv(this,n)};Y.prototype.softplus=function(){return this.throwIfDisposed(),uh(this)};Y.prototype.spaceToBatchND=function(n,t){return this.throwIfDisposed(),co(this,n,t)};Y.prototype.split=function(n,t){return this.throwIfDisposed(),Jr(this,n,t)};Y.prototype.sqrt=function(){return this.throwIfDisposed(),Vt(this)};Y.prototype.square=function(){return this.throwIfDisposed(),Ye(this)};Y.prototype.squaredDifference=function(n){return this.throwIfDisposed(),fo(this,n)};Y.prototype.squaredDifferenceStrict=function(n){return this.throwIfDisposed(),kv(this,n)};Y.prototype.squeeze=function(n){return this.throwIfDisposed(),mo(this,n)};Y.prototype.stack=function(n,t){this.throwIfDisposed();var e=n instanceof Y?[this,n]:[this].concat(n);return sr(e,t)};Y.prototype.step=function(n){return this.throwIfDisposed(),Zr(this,n)};Y.prototype.stridedSlice=function(n,t,e,i,r,a,s,o){return this.throwIfDisposed(),fv(this,n,t,e,i,r,a,s,o)};Y.prototype.subStrict=function(n){return this.throwIfDisposed(),Fv(this,n)};Y.prototype.sub=function(n){return this.throwIfDisposed(),ge(this,n)};Y.prototype.sum=function(n,t){return this.throwIfDisposed(),Ae(this,n,t)};Y.prototype.tan=function(){return this.throwIfDisposed(),mv(this)};Y.prototype.tanh=function(){return this.throwIfDisposed(),Xs(this)};Y.prototype.tile=function(n){return this.throwIfDisposed(),Yr(this,n)};Y.prototype.toBool=function(){return this.throwIfDisposed(),ue(this,"bool")};Y.prototype.toFloat=function(){return this.throwIfDisposed(),ue(this,"float32")};Y.prototype.toInt=function(){return this.throwIfDisposed(),ue(this,"int32")};Y.prototype.topk=function(n,t){return this.throwIfDisposed(),gv(this,n,t)};Y.prototype.transpose=function(n){return this.throwIfDisposed(),ut(this,n)};Y.prototype.unique=function(n){return this.throwIfDisposed(),vv(this,n)};Y.prototype.unsortedSegmentSum=function(n,t){return this.throwIfDisposed(),Ah(this,n,t)};Y.prototype.unstack=function(n){return this.throwIfDisposed(),go(this,n)};Y.prototype.where=function(n,t){return this.throwIfDisposed(),yn(n,this,t)};Y.prototype.zerosLike=function(){return this.throwIfDisposed(),Ee(this)};I.Abs=kl;I.Acos=Fl;I.Acosh=Wl;I.AdadeltaOptimizer=Ch;I.AdagradOptimizer=Rh;I.AdamOptimizer=Oh;I.AdamaxOptimizer=Eh;I.Add=Fs;I.AddN=Ul;I.All=wf;I.Any=Sf;I.ArgMax=Bl;I.ArgMin=zl;I.Asin=Pl;I.Asinh=_l;I.Atan=Ml;I.Atan2=Vl;I.Atanh=Hl;I.AvgPool=ql;I.AvgPool3D=Gl;I.AvgPool3DBackprop=If;I.AvgPoolBackprop=Lf;I.BatchMatMul=Yl;I.BatchToSpaceND=jl;I.BroadcastTo=Kl;I.Cast=Ws;I.Ceil=$l;I.ClipByValue=Xl;I.Complex=Af;I.Concat=Jl;I.Conv2D=Zl;I.Conv2DBackpropFilter=Tf;I.Conv2DBackpropInput=Ql;I.Conv3D=eu;I.Conv3DBackpropFilterV2=Nf;I.Conv3DBackpropInputV2=xf;I.Cos=tu;I.Cosh=nu;I.CropAndResize=Cf;I.Cumsum=iu;I.DataStorage=x2;I.DepthToSpace=Rf;I.DepthwiseConv2dNative=ru;I.DepthwiseConv2dNativeBackpropFilter=Of;I.DepthwiseConv2dNativeBackpropInput=Ef;I.Diag=Df;I.Dilation2D=au;I.Dilation2DBackpropFilter=Ff;I.Dilation2DBackpropInput=kf;I.Div=su;I.Elu=ou;I.EluGrad=Wf;I.Environment=vf;I.Equal=Uf;I.Erf=lu;I.Exp=uu;I.Expm1=cu;I.FFT=Bf;I.Fill=zf;I.FlipLeftRight=Pf;I.Floor=hu;I.FloorDiv=du;I.FromPixels=gc;I.FusedBatchNorm=pu;I.FusedConv2D=yc;I.FusedDepthwiseConv2D=bc;I.GatherNd=_f;I.GatherV2=fu;I.Greater=Mf;I.GreaterEqual=mu;I.IFFT=Hf;I.Identity=gu;I.Imag=Vf;I.IsFinite=vu;I.IsInf=yu;I.IsNan=bu;I.KernelBackend=mf;I.LRN=Iu;I.LRNBackprop=Xf;I.Less=qf;I.LessEqual=Gf;I.LinSpace=Yf;I.Log=wu;I.Log1p=Su;I.LogSoftmax=Lu;I.LogicalAnd=jf;I.LogicalNot=Kf;I.LogicalOr=$f;I.Max=Au;I.MaxPool=Nu;I.MaxPool3D=xu;I.MaxPool3DBackprop=Zf;I.MaxPoolBackprop=Jf;I.MaxPoolWithArgmax=Qf;I.Maximum=Tu;I.Mean=k2;I.Min=Cu;I.Minimum=Ru;I.Mod=Ou;I.MomentumOptimizer=Dh;I.Multiply=Eu;I.Negate=Du;I.NonMaxSuppressionV3=tm;I.NonMaxSuppressionV4=nm;I.NonMaxSuppressionV5=im;I.NotEqual=em;I.OP_SCOPE_SUFFIX=Pm;I.OneHot=Fu;I.OnesLike=ku;I.Optimizer=Ii;I.PadV2=Wu;I.Pool=F2;I.Pow=Uu;I.Prelu=Bu;I.Prod=rm;I.RMSPropOptimizer=kh;I.Range=am;I.Real=sm;I.Reciprocal=zu;I.Relu=Pu;I.Relu6=Vu;I.Reshape=_u;I.ResizeBilinear=Hu;I.ResizeBilinearGrad=lm;I.ResizeNearestNeighbor=Mu;I.ResizeNearestNeighborGrad=om;I.Reverse=qu;I.RotateWithOffset=mm;I.Round=Gu;I.Rsqrt=Yu;I.SGDOptimizer=Lo;I.ScatterNd=um;I.SelectV2=ju;I.Selu=Ku;I.Sigmoid=Qu;I.Sign=Zu;I.Sin=Xu;I.Sinh=Ju;I.Slice=$u;I.Softmax=ac;I.Softplus=ec;I.SpaceToBatchND=ic;I.SparseToDense=hm;I.SplitV=rc;I.Sqrt=tc;I.Square=cm;I.SquaredDifference=sc;I.Step=mc;I.StridedSlice=dm;I.Sub=oc;I.Sum=nc;I.Tan=lc;I.Tanh=uc;I.Tensor=Y;I.TensorBuffer=Hs;I.Tile=cc;I.TopK=pm;I.Transpose=hc;I.Unique=fm;I.Unpack=dc;I.UnsortedSegmentSum=pc;I.Variable=Ba;I.ZerosLike=fc;I._FusedMatMul=vc;I.abs=Kt;I.acos=Sg;I.acosh=Lg;I.add=fe;I.addN=d1;I.addStrict=Nv;I.all=Tg;I.any=Ng;I.argMax=xg;I.argMin=Cg;I.asin=Rg;I.asinh=Og;I.atan=Eg;I.atan2=Dg;I.atanh=kg;I.avgPool=th;I.avgPool3d=O1;I.backend=n1;I.backend_util=BE;I.basicLSTMCell=U1;I.batchNorm=Va;I.batchNorm2d=M1;I.batchNorm3d=V1;I.batchNorm4d=G1;I.batchToSpaceND=Js;I.booleanMaskAsync=fR;I.broadcastTo=Qs;I.browser=NT;I.buffer=Wn;I.cast=ue;I.ceil=Ug;I.clipByValue=Bg;I.clone=$i;I.complex=mi;I.concat=Rt;I.concat1d=X1;I.concat2d=Z1;I.concat3d=eN;I.concat4d=nN;I.conv1d=zg;I.conv2d=Gr;I.conv2dTranspose=Pg;I.conv3d=lN;I.conv3dTranspose=hN;I.copyRegisteredKernels=B2;I.cos=eo;I.cosh=ih;I.cosineWindow=Th;I.cumsum=rh;I.customGrad=zn;I.deprecationWarn=At;I.depthToSpace=Mg;I.depthwiseConv2d=qa;I.device_util=bA;I.diag=yN;I.dilation2d=Hg;I.disableDeprecationWarnings=VT;I.dispose=Mt;I.disposeVariables=qT;I.div=Ie;I.divNoNan=Vg;I.divStrict=xv;I.dot=qg;I.dropout=HR;I.elu=ah;I.enableDebugMode=HT;I.enableProdMode=MT;I.enclosingPowerOfTwo=Uv;I.engine=GT;I.env=He;I.equal=Ga;I.equalStrict=wv;I.erf=Gg;I.exp=bn;I.expandDims=wn;I.expm1=Yg;I.eye=jg;I.fft=ho;I.fill=sh;I.findBackend=QT;I.findBackendFactory=e1;I.floor=to;I.floorDiv=Jc;I.fused=eO;I.gather=no;I.gatherND=PR;I.gather_util=xT;I.getBackend=JT;I.getGradient=Lc;I.getKernel=Sc;I.getKernelsForBackend=Us;I.grad=QN;I.grads=ex;I.greater=Li;I.greaterEqual=Zi;I.greaterEqualStrict=Sv;I.greaterStrict=Lv;I.ifft=$a;I.imag=io;I.image=sE;I.inTopKAsync=qR;I.io=mT;I.irfft=Ih;I.isFinite=$g;I.isInf=Xg;I.isNaN=Jg;I.keep=wg;I.kernel_impls=ME;I.leakyRelu=Zg;I.less=ro;I.lessEqual=Qi;I.lessEqualStrict=Iv;I.lessStrict=Av;I.linalg=oE;I.linspace=$N;I.localResponseNormalization=Qg;I.log=er;I.log1p=lh;I.logSigmoid=tv;I.logSoftmax=nv;I.logSumExp=ch;I.logicalAnd=nr;I.logicalNot=so;I.logicalOr=hh;I.logicalXor=iv;I.losses=lE;I.matMul=We;I.math=LT;I.max=tr;I.maxPool=dh;I.maxPool3d=vx;I.maxPoolWithArgmax=bx;I.maximum=jr;I.maximumStrict=Cv;I.mean=Ya;I.memory=YT;I.min=oo;I.minimum=lo;I.minimumStrict=Rv;I.mod=ph;I.modStrict=Ov;I.moments=Nx;I.movingAverage=DR;I.mul=J;I.mulStrict=Ev;I.multiRNNCell=Cx;I.multinomial=Ox;I.neg=vt;I.nextFrame=hE;I.norm=vo;I.notEqual=uo;I.notEqualStrict=Tv;I.oneHot=Ys;I.ones=Kr;I.onesLike=fh;I.op=U;I.outerProduct=Wx;I.pad=ir;I.pad1d=zx;I.pad2d=_x;I.pad3d=Hx;I.pad4d=qx;I.pool=rv;I.pow=ni;I.powStrict=Dv;I.prelu=mh;I.print=$m;I.prod=av;I.profile=jT;I.rand=Qx;I.randomGamma=cC;I.randomNormal=dC;I.randomUniform=sv;I.range=yh;I.ready=XT;I.real=ja;I.reciprocal=ov;I.registerBackend=t1;I.registerGradient=vm;I.registerKernel=gm;I.relu=Ka;I.relu6=bh;I.removeBackend=ZT;I.reshape=V;I.reverse=ii;I.reverse1d=bC;I.reverse2d=SC;I.reverse3d=IC;I.reverse4d=TC;I.rfft=po;I.round=lv;I.rsqrt=wh;I.scalar=be;I.scatterND=FR;I.scatter_util=CT;I.selu=uv;I.separableConv2d=cv;I.serialization=ET;I.setBackend=$T;I.setPlatform=i1;I.setdiff1dAsync=EC;I.sigmoid=Ji;I.sign=hv;I.signal=aE;I.sin=Sh;I.sinh=Lh;I.slice=ze;I.slice1d=UC;I.slice2d=zC;I.slice3d=_C;I.slice4d=HC;I.slice_util=gg;I.softmax=dv;I.softplus=uh;I.spaceToBatchND=co;I.sparseToDense=BR;I.spectral=rE;I.split=Jr;I.sqrt=Vt;I.square=Ye;I.squaredDifference=fo;I.squaredDifferenceStrict=kv;I.squeeze=mo;I.stack=sr;I.step=Zr;I.stridedSlice=fv;I.sub=ge;I.subStrict=Fv;I.sum=Ae;I.sumOutType=cA;I.tan=mv;I.tanh=Xs;I.tensor=vi;I.tensor1d=Xr;I.tensor2d=Xa;I.tensor3d=ng;I.tensor4d=nR;I.tensor5d=iR;I.tensor6d=rR;I.tensor_util=pA;I.test_util=PT;I.tidy=mt;I.tile=Yr;I.time=KT;I.topk=gv;I.train=uE;I.transpose=ut;I.truncatedNormal=oR;I.unique=vv;I.unregisterGradient=U2;I.unregisterKernel=W2;I.unsortedSegmentSum=Ah;I.unstack=go;I.upcastType=Vs;I.util=Q2;I.valueAndGrad=tx;I.valueAndGrads=nx;I.variable=hR;I.variableGrads=ev;I.version_core=_T;I.where=yn;I.whereAsync=bv;I.zeros=ti;I.zerosLike=Ee});var Ow=Le(Xe=>{"use strict";Object.defineProperty(Xe,"__esModule",{value:!0});var y=lr();var Wh=function(n,t){return Wh=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var r in i)i.hasOwnProperty(r)&&(e[r]=i[r])},Wh(n,t)};function Q(n,t){Wh(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var $t=function(){return $t=Object.assign||function(t){for(var e,i=1,r=arguments.length;i<r;i++){e=arguments[i];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t},$t.apply(this,arguments)};function Pk(n,t){var e={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&t.indexOf(i)<0&&(e[i]=n[i]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(n);r<i.length;r++)t.indexOf(i[r])<0&&(e[i[r]]=n[i[r]]);return e}function Se(n,t,e,i){return new(e||(e=Promise))(function(r,a){function s(u){try{l(i.next(u))}catch(c){a(c)}}function o(u){try{l(i.throw(u))}catch(c){a(c)}}function l(u){u.done?r(u.value):new e(function(c){c(u.value)}).then(s,o)}l((i=i.apply(n,t||[])).next())})}function ve(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,r,a,s;return s={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(u){return function(c){return l([u,c])}}function l(u){if(i)throw new TypeError("Generator is already executing.");for(;e;)try{if(i=1,r&&(a=u[0]&2?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;(r=0,a)&&(u=[u[0]&2,a.value]);switch(u[0]){case 0:case 1:a=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,r=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){e.label=u[1];break}if(u[0]===6&&e.label<a[1]){e.label=a[1],a=u;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(u);break}a[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(n,e)}catch(c){u=[6,c],r=0}finally{i=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}var Uh;function yt(){return Uh==null&&(Uh=y.backend().epsilon()),Uh}function Sn(){return"channelsLast"}var Ai=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return Object.setPrototypeOf(i,t.prototype),i}return t}(Error),Pn=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return Object.setPrototypeOf(i,t.prototype),i}return t}(Error),M=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return Object.setPrototypeOf(i,t.prototype),i}return t}(Error),Te=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return Object.setPrototypeOf(i,t.prototype),i}return t}(Error),_k=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return Object.setPrototypeOf(i,t.prototype),i}return t}(Error),dV=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return Object.setPrototypeOf(i,t.prototype),i}return t}(Error);function ur(n,t){if(Array.isArray(n)){for(var e=[],i=0;i<t;i++)e=e.concat(n);return e}else{var e=new Array(t);return e.fill(n),e}}function _n(n,t){if(!n)throw new _k(t)}function ry(n,t){for(var e=0,i=0,r=n;i<r.length;i++){var a=r[i];a===t&&e++}return e}function qt(n){return n.length===1?n[0]:n}function Je(n){return Array.isArray(n)?n:[n]}function ai(n){var t=n.replace(/(.)([A-Z][a-z0-9]+)/g,"$1_$2"),e=t.replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase();return e[0]!=="_"?e:"private"+e}function cr(n){return n.length<=1||n.indexOf("_")===-1?n:n.replace(/[_]+(\w|$)/g,function(t,e){return e.toUpperCase()})}var pn={};function Bh(n){if(n==null)return null;var t={};return t.className=n.getClassName(),t.config=n.getConfig(),t}function zh(n){if(n==null||typeof n!="object")return;if(Array.isArray(n))n.forEach(function(s){return zh(s)});else for(var t=Object.keys(n),e=0,i=t;e<i.length;e++){var r=i[e],a=n[r];a!=null&&typeof a=="object"&&(!Array.isArray(a)&&a.type==="ndarray"&&typeof a.value=="number"?n[r]=a.value:zh(a))}}function Ja(n,t,e,i,r){var a,s,o;if(t===void 0&&(t={}),e===void 0&&(e={}),i===void 0&&(i="object"),r===void 0&&(r=!1),typeof n=="string"){var l=n,u=void 0;if(l in e)u=e[l];else if(l in pn)u=pn[l];else if(u=t[l],u==null)throw new M("Unknown "+i+": "+n+`. This may be due to one of the following reasons:
|
|
`+("1. The "+i+" is defined in Python, in which ")+`case it needs to be ported to TensorFlow.js or your JavaScript code.
|
|
`+("2. The custom "+i+" is defined in JavaScript, ")+"but is not registered properly with tf.serialization.registerClass().");return u}else{var c=n;if(c.className==null||c.config==null)throw new M(i+": Improper config format: "+(JSON.stringify(c)+`.
|
|
`)+"'className' and 'config' must set.");var h=c.className,d=void 0,p=void 0;if(h in e?(a=e[h],d=a[0],p=a[1]):h in pn?(s=pn.className,d=s[0],p=s[1]):h in t&&(o=t[h],d=o[0],p=o[1]),d==null)throw new M("Unknown "+i+": "+h+`. This may be due to one of the following reasons:
|
|
`+("1. The "+i+" is defined in Python, in which ")+`case it needs to be ported to TensorFlow.js or your JavaScript code.
|
|
`+("2. The custom "+i+" is defined in JavaScript, ")+"but is not registered properly with tf.serialization.registerClass().");if(p!=null){for(var f={},m=0,g=Object.keys(pn);m<g.length;m++){var v=g[m];f[v]=pn[v]}for(var b=0,w=Object.keys(e);b<w.length;b++){var v=w[b];f[v]=e[v]}var S=c.config;S.customObjects=f;for(var L=$t({},pn),N=0,C=Object.keys(e);N<C.length;N++){var v=C[N];pn[v]=e[v]}zh(c.config);var R=p(d,c.config,e,r);return pn=$t({},L),R}else{for(var L=$t({},pn),D=0,k=Object.keys(e);D<k.length;D++){var v=k[D];pn[v]=e[v]}var R=new d(c.config);return pn=$t({},L),R}}}function Mk(n,t){return n<t?-1:n>t?1:0}function Io(n,t){return-1*Mk(n,t)}function Ti(n){if(n==null)return n;for(var t=[],e=0,i=n;e<i.length;e++){var r=i[e];t.indexOf(r)===-1&&t.push(r)}return t}function Hk(n){if(n==null)throw new M("Invalid value in obj: "+JSON.stringify(n));for(var t in n)if(n.hasOwnProperty(t))return!1;return!0}function ea(n,t,e){if(e==null)return;if(n.indexOf(e)<0)throw new M(e+" is not a valid "+t+". Valid values are "+n+" or null/undefined.")}function Ph(n,t,e,i){return e===void 0&&(e=0),i===void 0&&(i=Infinity),_n(e>=0),_n(i>=e),Array.isArray(n)&&n.length>=e&&n.length<=i&&n.every(function(r){return typeof r===t})}function Tt(n,t){Array.isArray(n)?(y.util.assert(n.length>0,function(){return t+" is unexpectedly an empty array."}),n.forEach(function(e,i){return Tt(e,"element "+(i+1)+" of "+t)})):y.util.assert(Number.isInteger(n)&&n>0,function(){return"Expected "+t+" to be a positive integer, but got "+(ay(n)+".")})}function ay(n){return n===null?"null":Array.isArray(n)?"["+n.map(function(t){return ay(t)}).join(",")+"]":typeof n=="string"?'"'+n+'"':""+n}function Vk(n,t){var e=y.util.now(),i,r=function(){for(var a=[],s=0;s<arguments.length;s++)a[s]=arguments[s];var o=y.util.now();return o-e<t||(e=o,i=n.apply(void 0,a)),i};return r}function sy(n){return n==="relu"?"relu":n==="linear"?"linear":n==="elu"?"elu":null}function _h(n,t){return y.tidy(function(){return y.sqrt(y.sum(y.mul(n,n),t,!0))})}var Za=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.getConfig=function(){return{}},t}(y.serialization.Serializable),oy=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return i.defaultMaxValue=2,i.defaultAxis=0,i.maxValue=e.maxValue!=null?e.maxValue:i.defaultMaxValue,i.axis=e.axis!=null?e.axis:i.defaultAxis,i}return t.prototype.apply=function(e){var i=this;return y.tidy(function(){var r=_h(e,i.axis),a=y.clipByValue(r,0,i.maxValue);return y.mul(e,y.div(a,y.add(yt(),r)))})},t.prototype.getConfig=function(){return{maxValue:this.maxValue,axis:this.axis}},t.className="MaxNorm",t}(Za);y.serialization.registerClass(oy);var ly=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return i.defaultAxis=0,i.axis=e.axis!=null?e.axis:i.defaultAxis,i}return t.prototype.apply=function(e){var i=this;return y.tidy(function(){return y.div(e,y.add(yt(),_h(e,i.axis)))})},t.prototype.getConfig=function(){return{axis:this.axis}},t.className="UnitNorm",t}(Za);y.serialization.registerClass(ly);var uy=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return y.relu(e)},t.className="NonNeg",t}(Za);y.serialization.registerClass(uy);var cy=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return i.defaultMinValue=0,i.defaultMaxValue=1,i.defaultRate=1,i.defaultAxis=0,i.minValue=e.minValue!=null?e.minValue:i.defaultMinValue,i.maxValue=e.maxValue!=null?e.maxValue:i.defaultMaxValue,i.rate=e.rate!=null?e.rate:i.defaultRate,i.axis=e.axis!=null?e.axis:i.defaultAxis,i}return t.prototype.apply=function(e){var i=this;return y.tidy(function(){var r=_h(e,i.axis),a=y.add(y.mul(i.rate,y.clipByValue(r,i.minValue,i.maxValue)),y.mul(1-i.rate,r));return y.mul(e,y.div(a,y.add(yt(),r)))})},t.prototype.getConfig=function(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}},t.className="MinMaxNorm",t}(Za);y.serialization.registerClass(cy);var hy={maxNorm:"MaxNorm",minMaxNorm:"MinMaxNorm",nonNeg:"NonNeg",unitNorm:"UnitNorm"};function bt(n){return Bh(n)}function dy(n,t){return t===void 0&&(t={}),Ja(n,y.serialization.SerializationMap.getMap().classNameMap,t,"constraint")}function wt(n){if(n==null)return null;if(typeof n=="string"){var t=n in hy?hy[n]:n,e={className:t,config:{}};return dy(e)}else return n instanceof Za?n:dy(n)}function qk(n){return new oy(n)}function Gk(n){return new ly(n)}function Yk(){return new uy}function jk(n){return new cy(n)}var Kk={__proto__:null,maxNorm:qk,unitNorm:Gk,nonNeg:Yk,minMaxNorm:jk};var $k=["channelsFirst","channelsLast"],Xk=["valid","same","causal"],Jk=["max","avg"],Zk=["sum","mul","concat","ave"];var ta=new Map;function ht(n){ea($k,"DataFormat",n)}function sn(n){ea(Xk,"PaddingMode",n)}function py(n){ea(Jk,"PoolMode",n)}var Qa=[],fy="/";function hr(n,t){Qa.push(n);try{var e=t();return Qa.pop(),e}catch(i){throw Qa.pop(),i}}function Qk(){return Qa.length===0?"":Qa.join(fy)+fy}function gy(n){if(!my(n))throw new Error("Not a valid tensor name: '"+n+"'");return Qk()+n}function vy(n){if(!my(n))throw new Error("Not a valid tensor name: '"+n+"'");ta.has(n)||ta.set(n,0);var t=ta.get(n);if(ta.set(n,ta.get(n)+1),t>0){var e=n+"_"+t;return ta.set(e,1),e}else return n}var e3=new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);function my(n){return!!n.match(e3)}function t3(n){return n===parseInt(n.toString(),10)}function Ni(n,t,e){t==null&&(t=0),e==null&&(e=n.length);for(var i=1,r=t;r<e;++r)i*=n[r];return i}function yy(n){return n=Array.isArray(n)?new Float32Array(n):n,y.tensor1d(n)}function na(n){return y.min(yy(n)).dataSync()[0]}function xi(n){return y.max(yy(n)).dataSync()[0]}function Ln(n,t){if(t<n)throw new M("end ("+t+") < begin ("+n+") is forbidden.");for(var e=[],i=n;i<t;++i)e.push(i);return e}function es(n,t){return n.asType(t)}function ts(n,t){t===void 0&&(t=-1);var e=n.shape.slice();return t<0&&(t=e.length+t+1),e.splice(t,0,1),n.reshape(e)}function n3(n,t){return y.tidy(function(){if(n.shape.length!==2)throw new M("repeat() expects a rank-2 tensor, but received a "+("rank-"+n.shape.length+" tensor."));var e=ts(n,1);return Mh(e,[1,t,1])})}function i3(n){var t=[Ni(n.shape)];return n.reshape(t)}function r3(n){if(n.rank<=1)throw new M("batchFlatten requires a minimum rank of 2. Got rank: "+n.rank+".");var t=[n.shape[0],Ni(n.shape,1)];return n.reshape(t)}function dr(n,t,e){return y.tidy(function(){switch(n.rank){case 1:return y.slice1d(n,t,e);case 2:return y.slice2d(n,[t,0],[e,n.shape[1]]);case 3:return y.slice3d(n,[t,0,0],[e,n.shape[1],n.shape[2]]);case 4:return y.slice4d(n,[t,0,0,0],[e,n.shape[1],n.shape[2],n.shape[3]]);case 5:return y.slice(n,[t,0,0,0,0],[e,n.shape[1],n.shape[2],n.shape[3],n.shape[4]]);case 6:return y.slice(n,[t,0,0,0,0,0],[e,n.shape[1],n.shape[2],n.shape[3],n.shape[4],n.shape[5]]);default:throw new M("sliceAlongFirstAxis() received an unsupported tensor rank: "+(""+n.rank))}})}function Hh(n,t,e){return y.tidy(function(){switch(n.rank){case 1:return y.slice1d(n,t,e);case 2:return y.slice2d(n,[0,t],[n.shape[0],e]);case 3:return y.slice3d(n,[0,0,t],[n.shape[0],n.shape[1],e]);case 4:return y.slice4d(n,[0,0,0,t],[n.shape[0],n.shape[1],n.shape[2],e]);default:throw new M("sliceAlongLastAxis() received an unsupported tensor rank: "+(""+n.rank))}})}function Ao(n,t,e,i){return y.tidy(function(){switch(n.rank){case 1:return y.slice1d(n,t,e);case 2:switch(i){case 1:return dr(n,t,e);case 2:return Hh(n,t,e);default:throw new M("The axis is not within the rank of the tensor "+(""+i))}case 3:switch(i){case 1:return dr(n,t,e);case 2:return y.slice3d(n,[0,t,0],[n.shape[0],e,n.shape[2]]);case 3:return Hh(n,t,e);default:throw new M("The axis is not within the rank of the tensor "+(""+i))}case 4:switch(i){case 1:return dr(n,t,e);case 2:return y.slice4d(n,[0,t,0,0],[n.shape[0],e,n.shape[2],n.shape[3]]);case 3:return y.slice4d(n,[0,0,t,0],[n.shape[0],n.shape[1],e,n.shape[3]]);case 4:return Hh(n,t,e);default:throw new M("The axis is not within the rank of the tensor "+(""+i))}default:throw new M("sliceAlongLastAxis() received an unsupported tensor rank: "+(""+n.rank))}})}function Vh(n,t){t===void 0&&(t=-1);var e;return t<0&&(e=n[0].rank,e!==0?t=e:t=0),t===n[0].rank&&(t=-1),y.concat(n,t)}function by(n,t){switch(n.rank){case 1:return y.concat1d([n,t]);case 2:return y.concat2d([n,t],0);case 3:return y.concat3d([n,t],0);case 4:return y.concat4d([n,t],0);default:throw new M("concatAlongFirstAxis() received an unsupported "+("tensor rank: "+n.rank))}}function Mh(n,t){if(Array.isArray(t)||(t=[t]),n.rank!==t.length)throw new M("The length of input n ("+t.length+") does not match "+("the number of dimensions in input x ("+n.rank+")"));return y.tile(n,t)}function To(n,t,e,i,r){return t===void 0&&(t=0),e===void 0&&(e=1),y.randomNormal(n,t,e,i,r)}function Mn(n,t,e,i){if(n.rank<2||t.rank<2)throw new Te("dot requires both inputs to be rank >= 2"+(" but got x shape = "+n.shape+" and y shape = "+t.shape));if(t.rank>=3){var r=n.shape.slice(-1)[0],a=t.shape.slice(-2)[0];if(r!==a)throw new Te("If rank y >= 3, then the second last dim"+(" of y must equal the last dim of x but got x shape = "+n.shape+" and ")+(" y shape = "+t.shape))}if(n.rank===2&&t.rank===2){var s=!1,o=!1;return y.fused.matMul({a:n,b:t,transposeA:s,transposeB:o,bias:i?qh(n.rank,i,Sn()):null,activation:e})}else{var l=n.shape.slice(),u=l.pop();n=n.reshape([-1,u]);var c=t.shape.slice(),h=c.pop(),a=c.pop(),d=c.concat([h]),p=Array.from({length:t.rank},function(b,w){return w===0?t.rank-2:w<=t.rank-2?w-1:w});t=t.transpose(p).reshape([a,-1]);var f=l.concat(d),s=!1,o=!1;return y.fused.matMul({a:n,b:t,transposeA:s,transposeB:o,bias:i?qh(n.rank,i,Sn()):null,activation:e}).reshape(f)}}function wy(n,t,e){return y.tidy(function(){return Array.isArray(t)?t=y.tensor1d(t,"int32"):t=t.toInt(),y.gather(n,t,e)})}function ns(n){return y.mul(n,n)}function qh(n,t,e){var i=t.shape;if(t.rank!==1&&t.rank!==n)throw new M("Unexpected bias dimensions: "+t.rank+("; expected it to be 1 or "+n));if(n===5){if(e==="channelsFirst")return i.length===1?t.reshape([1,i[0],1,1,1]):t.reshape([1,i[3],i[0],i[1],i[2]]);if(e==="channelsLast")return i.length===1?t.reshape([1,1,1,1,i[0]]):t.reshape([1].concat(i))}else if(n===4){if(e==="channelsFirst")return i.length===1?t.reshape([1,i[0],1,1]):t.reshape([1,i[2],i[0],i[1]]);if(e==="channelsLast")return i.length===1?t.reshape([1,1,1,i[0]]):t.reshape([1].concat(i))}else if(n===3){if(e==="channelsFirst")return i.length===1?t.reshape([1,i[0],1]):t.reshape([1,i[1],i[0]]);if(e==="channelsLast")return i.length===1?t.reshape([1,1,i[0]]):t.reshape([1].concat(i))}else if(n<3)return t;throw new M("Unsupported input rank by biasAdd: "+t.rank)}function Hn(n,t,e){return y.tidy(function(){return e==null&&(e=Sn()),ht(e),n.add(qh(n.rank,t,e))})}function a3(n,t){if(t===void 0&&(t=1),t!==1)throw new Te("Support for alpha values other than 1 ("+t+") is not implemented yet.");return y.elu(n)}function s3(n){return y.tidy(function(){return y.div(n,y.abs(n).add(1))})}function Sy(n,t,e,i){return y.tidy(function(){return y.dropout(n,t,e,i)})}function o3(n){return y.tidy(function(){var t=y.add(.5,y.mul(.2,n));return y.clipByValue(t,0,1)})}function is(n,t,e){return e===void 0&&(e=!1),e?n():t()}var l3=["fanIn","fanOut","fanAvg"],u3=["normal","uniform","truncatedNormal"];function c3(n){ea(l3,"FanMode",n)}function h3(n){ea(u3,"Distribution",n)}var fn=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.fromConfigUsesCustomObjects=function(){return!1},t.prototype.getConfig=function(){return{}},t}(y.serialization.Serializable),Ly=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e,i){return y.zeros(e,i)},t.className="Zeros",t}(fn);y.serialization.registerClass(Ly);var Gh=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e,i){return y.ones(e,i)},t.className="Ones",t}(fn);y.serialization.registerClass(Gh);var Iy=function(n){Q(t,n);function t(e){var i=n.call(this)||this;if(typeof e!="object")throw new M("Expected argument of type ConstantConfig but got "+e);if(e.value===void 0)throw new M("config must have value set but got "+e);return i.value=e.value,i}return t.prototype.apply=function(e,i){var r=this;return y.tidy(function(){return y.mul(y.scalar(r.value),y.ones(e,i))})},t.prototype.getConfig=function(){return{value:this.value}},t.className="Constant",t}(fn);y.serialization.registerClass(Iy);var Ay=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return i.DEFAULT_MINVAL=-.05,i.DEFAULT_MAXVAL=.05,i.minval=e.minval||i.DEFAULT_MINVAL,i.maxval=e.maxval||i.DEFAULT_MAXVAL,i.seed=e.seed,i}return t.prototype.apply=function(e,i){return y.randomUniform(e,this.minval,this.maxval,i)},t.prototype.getConfig=function(){return{minval:this.minval,maxval:this.maxval,seed:this.seed}},t.className="RandomUniform",t}(fn);y.serialization.registerClass(Ay);var Ty=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return i.DEFAULT_MEAN=0,i.DEFAULT_STDDEV=.05,i.mean=e.mean||i.DEFAULT_MEAN,i.stddev=e.stddev||i.DEFAULT_STDDEV,i.seed=e.seed,i}return t.prototype.apply=function(e,i){if(i=i||"float32",i!=="float32"&&i!=="int32")throw new Te("randomNormal does not support dType "+i+".");return To(e,this.mean,this.stddev,i,this.seed)},t.prototype.getConfig=function(){return{mean:this.mean,stddev:this.stddev,seed:this.seed}},t.className="RandomNormal",t}(fn);y.serialization.registerClass(Ty);var Ny=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return i.DEFAULT_MEAN=0,i.DEFAULT_STDDEV=.05,i.mean=e.mean||i.DEFAULT_MEAN,i.stddev=e.stddev||i.DEFAULT_STDDEV,i.seed=e.seed,i}return t.prototype.apply=function(e,i){if(i=i||"float32",i!=="float32"&&i!=="int32")throw new Te("truncatedNormal does not support dType "+i+".");return y.truncatedNormal(e,this.mean,this.stddev,i,this.seed)},t.prototype.getConfig=function(){return{mean:this.mean,stddev:this.stddev,seed:this.seed}},t.className="TruncatedNormal",t}(fn);y.serialization.registerClass(Ny);var xy=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return i.gain=e.gain!=null?e.gain:1,i}return t.prototype.apply=function(e,i){var r=this;return y.tidy(function(){if(e.length!==2||e[0]!==e[1])throw new M("Identity matrix initializer can only be used for 2D square matrices.");return y.mul(r.gain,y.eye(e[0]))})},t.prototype.getConfig=function(){return{gain:this.gain}},t.className="Identity",t}(fn);y.serialization.registerClass(xy);function d3(n,t){t===void 0&&(t="channelsLast");var e,i;if(ht(t),n.length===2)e=n[0],i=n[1];else if([3,4,5].indexOf(n.length)!==-1){if(t==="channelsFirst"){var r=Ni(n,2);e=n[1]*r,i=n[0]*r}else if(t==="channelsLast"){var r=Ni(n,0,n.length-2);e=n[n.length-2]*r,i=n[n.length-1]*r}}else{var a=Ni(n);e=Math.sqrt(a),i=Math.sqrt(a)}return[e,i]}var Xt=function(n){Q(t,n);function t(e){var i=n.call(this)||this;if(e.scale<0)throw new M("scale must be a positive float. Got: "+e.scale);return i.scale=e.scale==null?1:e.scale,i.mode=e.mode==null?"fanIn":e.mode,c3(i.mode),i.distribution=e.distribution==null?"normal":e.distribution,h3(i.distribution),i.seed=e.seed,i}return t.prototype.apply=function(e,i){var r=d3(e),a=r[0],s=r[1],o=this.scale;if(this.mode==="fanIn"?o/=Math.max(1,a):this.mode==="fanOut"?o/=Math.max(1,s):o/=Math.max(1,(a+s)/2),this.distribution==="normal"){var l=Math.sqrt(o);if(i=i||"float32",i!=="float32"&&i!=="int32")throw new Te(this.getClassName()+" does not support dType "+i+".");return y.truncatedNormal(e,0,l,i,this.seed)}else{var u=Math.sqrt(3*o);return y.randomUniform(e,-u,u,i)}},t.prototype.getConfig=function(){return{scale:this.scale,mode:this.mode,distribution:this.distribution,seed:this.seed}},t.className="VarianceScaling",t}(fn);y.serialization.registerClass(Xt);var Yh=function(n){Q(t,n);function t(e){return n.call(this,{scale:1,mode:"fanAvg",distribution:"uniform",seed:e==null?null:e.seed})||this}return t.prototype.getClassName=function(){return Xt.className},t.className="GlorotUniform",t}(Xt);y.serialization.registerClass(Yh);var jh=function(n){Q(t,n);function t(e){return n.call(this,{scale:1,mode:"fanAvg",distribution:"normal",seed:e==null?null:e.seed})||this}return t.prototype.getClassName=function(){return Xt.className},t.className="GlorotNormal",t}(Xt);y.serialization.registerClass(jh);var Kh=function(n){Q(t,n);function t(e){return n.call(this,{scale:2,mode:"fanIn",distribution:"normal",seed:e==null?null:e.seed})||this}return t.prototype.getClassName=function(){return Xt.className},t.className="HeNormal",t}(Xt);y.serialization.registerClass(Kh);var $h=function(n){Q(t,n);function t(e){return n.call(this,{scale:2,mode:"fanIn",distribution:"uniform",seed:e==null?null:e.seed})||this}return t.prototype.getClassName=function(){return Xt.className},t.className="HeUniform",t}(Xt);y.serialization.registerClass($h);var Xh=function(n){Q(t,n);function t(e){return n.call(this,{scale:1,mode:"fanIn",distribution:"normal",seed:e==null?null:e.seed})||this}return t.prototype.getClassName=function(){return Xt.className},t.className="LeCunNormal",t}(Xt);y.serialization.registerClass(Xh);var Jh=function(n){Q(t,n);function t(e){return n.call(this,{scale:1,mode:"fanIn",distribution:"uniform",seed:e==null?null:e.seed})||this}return t.prototype.getClassName=function(){return Xt.className},t.className="LeCunNormal",t}(Xt);y.serialization.registerClass(Jh);var Cy=function(n){Q(t,n);function t(e){var i=n.call(this)||this;if(i.DEFAULT_GAIN=1,i.gain=e.gain==null?i.DEFAULT_GAIN:e.gain,i.seed=e.seed,i.seed!=null)throw new Te("Random seed is not implemented for Orthogonal Initializer yet.");return i}return t.prototype.apply=function(e,i){var r=this;return y.tidy(function(){if(e.length<2)throw new Te("Shape must be at least 2D.");e[0]*e[1]>2e3&&console.warn("Orthogonal initializer is being called on a matrix with more "+("than 2000 ("+e[0]*e[1]+") elements: ")+"Slowness may result.");var a=e[0]>e[1]?[e[1],e[0]]:e,s=To(a,0,1,"float32"),o=y.linalg.gramSchmidt(s);return e[0]>e[1]&&(o=o.transpose()),y.mul(r.gain,o)})},t.prototype.getConfig=function(){return{gain:this.gain,seed:this.seed}},t.className="Orthogonal",t}(fn);y.serialization.registerClass(Cy);var Ry={constant:"Constant",glorotNormal:"GlorotNormal",glorotUniform:"GlorotUniform",heNormal:"HeNormal",heUniform:"HeUniform",identity:"Identity",leCunNormal:"LeCunNormal",leCunUniform:"LeCunUniform",ones:"Ones",orthogonal:"Orthogonal",randomNormal:"RandomNormal",randomUniform:"RandomUniform",truncatedNormal:"TruncatedNormal",varianceScaling:"VarianceScaling",zeros:"Zeros"};function Oy(n,t){return t===void 0&&(t={}),Ja(n,y.serialization.SerializationMap.getMap().classNameMap,t,"initializer")}function st(n){return Bh(n)}function tt(n){if(typeof n=="string"){var t=n in Ry?Ry[n]:n;if(t==="GlorotNormal")return new jh;if(t==="GlorotUniform")return new Yh;if(t==="HeNormal")return new Kh;if(t==="HeUniform")return new $h;if(t==="LeCunNormal")return new Xh;if(t==="LeCunUniform")return new Jh;var e={};return e.className=t,e.config={},Oy(e)}else return n instanceof fn?n:Oy(n)}function p3(){return new Ly}function f3(){return new Gh}function m3(n){return new Iy(n)}function g3(n){return new Ay(n)}function v3(n){return new Ty(n)}function y3(n){return new Ny(n)}function b3(n){return new xy(n)}function w3(n){return new Xt(n)}function S3(n){return new Yh(n)}function L3(n){return new jh(n)}function I3(n){return new Kh(n)}function A3(n){return new $h(n)}function T3(n){return new Xh(n)}function N3(n){return new Jh(n)}function x3(n){return new Cy(n)}var C3={__proto__:null,zeros:p3,ones:f3,constant:m3,randomUniform:g3,randomNormal:v3,truncatedNormal:y3,identity:b3,varianceScaling:w3,glorotUniform:S3,glorotNormal:L3,heNormal:I3,heUniform:A3,leCunNormal:T3,leCunUniform:N3,orthogonal:x3};var R3=0;function Ey(){return R3++}var No={};function xo(n){return n===void 0&&(n=""),n in No||(No[n]=0),No[n]+=1,n+No[n].toString()}function Zh(n){return Array.isArray(n)&&Array.isArray(n[0])}function Co(n){return n.length===0?[]:Array.isArray(n[0])?n:[n]}function xe(n){var t;if(Array.isArray(n)){if(n.length!==1)throw new M("Expected Tensor length to be 1; got "+n.length);t=n[0]}else t=n;return t}function je(n){if(Array.isArray(n)&&Array.isArray(n[0])){if(n.length===1)return n=n,n[0];throw new M("Expected exactly 1 Shape; got "+n.length)}else return n}function Ro(n){for(var t=0,e=0,i=n;e<i.length;e++){var r=i[e];r.shape.length===0?t+=1:t+=r.shape.reduce(function(a,s){return a*s})}return t}var Dy="Variable",ky=function(){function n(t,e,i,r,a){e===void 0&&(e="float32"),i===void 0&&(i=Dy),r===void 0&&(r=!0),a===void 0&&(a=null),this.dtype=e??"float32",this.shape=t.shape,this.id=Ey(),i=i??Dy,this.originalName=gy(i),this.name=vy(this.originalName),this.trainable_=r,this.constraint=a,this.val=y.variable(t,this.trainable_,this.name,this.dtype)}return n.prototype.read=function(){return this.assertNotDisposed(),this.val},n.prototype.write=function(t){return this.assertNotDisposed(),O3(this.val,t),this.val.id!==t.id&&(this.val.assign(t),this.constraint!=null&&this.val.assign(this.constraint.apply(this.val))),this},n.prototype.dispose=function(){this.assertNotDisposed(),this.val.dispose()},n.prototype.assertNotDisposed=function(){if(this.val.isDisposed)throw new Error("LayersVariable "+this.name+" is already disposed.")},Object.defineProperty(n.prototype,"trainable",{get:function(){return this.trainable_},set:function(t){this.trainable_=t,this.val.trainable=t},enumerable:!0,configurable:!0}),n}();function O3(n,t){if(n.shape.toString()!==t.shape.toString())throw new Error("Shape mismatch: "+JSON.stringify(n.shape)+" vs. "+JSON.stringify(t.shape))}function Qh(n){return n.map(function(t){return t.read()})}function ed(n){n.forEach(function(t){var e=t[0];e.write(t[1])})}var Nt=function(){function n(t){this.dtype=t.dtype,this.shape=t.shape,t.shape!=null?this.ndim=t.shape.length:this.ndim=t.ndim,this.maxNDim=t.maxNDim,this.minNDim=t.minNDim,this.axes=t.axes||{}}return n}(),In=function(){function n(t,e,i,r,a,s,o){this.dtype=t,this.shape=e,this.sourceLayer=i,this.inputs=r,this.callArgs=a,this.outputTensorIndex=o,this.id=Ey(),s!=null&&(this.originalName=gy(s),this.name=vy(this.originalName)),this.rank=e.length}return n}(),E3=0,Oo=function(){function n(t,e){this.callArgs=e,this.id=E3++,this.outboundLayer=t.outboundLayer,this.inboundLayers=t.inboundLayers,this.nodeIndices=t.nodeIndices,this.tensorIndices=t.tensorIndices,this.inputTensors=t.inputTensors,this.outputTensors=t.outputTensors,this.inputMasks=t.inputMasks,this.outputMasks=t.outputMasks,this.inputShapes=t.inputShapes,this.outputShapes=t.outputShapes;for(var i=0,r=t.inboundLayers;i<r.length;i++){var a=r[i];a!=null&&a.outboundNodes.push(this)}t.outboundLayer.inboundNodes.push(this)}return n.prototype.getConfig=function(){for(var t=[],e=0,i=this.inboundLayers;e<i.length;e++){var r=i[e];r!=null?t.push(r.name):t.push(null)}return{outboundLayer:this.outboundLayer?this.outboundLayer.name:null,inboundLayers:t,nodeIndices:this.nodeIndices,tensorIndices:this.tensorIndices}},n}(),D3=0,De=function(n){Q(t,n);function t(e){e===void 0&&(e={});var i=n.call(this)||this;i._callHook=null,i._addedWeightNames=[],i._stateful=!1,i.id=D3++,i.activityRegularizer=null,i.inputSpec=null,i.supportsMasking=!1,i._trainableWeights=[],i._nonTrainableWeights=[],i._losses=[],i._updates=[],i._built=!1,i.inboundNodes=[],i.outboundNodes=[];var r=e.name;if(!r){var a=i.getClassName();r=ai(a)+"_"+xo(a)}if(i.name=r,i.trainable_=e.trainable==null?!0:e.trainable,e.inputShape!=null||e.batchInputShape!=null){var s=void 0;if(e.batchInputShape!=null)s=e.batchInputShape;else if(e.inputShape!=null){var o=null;e.batchSize!=null&&(o=e.batchSize),s=[o].concat(e.inputShape)}i.batchInputShape=s;var l=e.dtype;l==null&&(l=e.inputDType),l==null&&(l="float32"),i.dtype=l}return e.weights!=null?i.initialWeights=e.weights:i.initialWeights=null,i._refCount=null,i.fastWeightInitDuringBuild=!1,i}return t.nodeKey=function(e,i){return e.name+"_ib-"+i.toString()},t.prototype.getNodeAtIndex=function(e,i){if(this.inboundNodes.length===0)throw new Pn("The layer has never been called "+("and thus has no defined "+i+"."));if(this.inboundNodes.length<=e)throw new M("Asked to get "+i+" at node "+e+", "+("but the layer has only "+this.inboundNodes.length+" inbound nodes."));return this.inboundNodes[e]},t.prototype.getInputAt=function(e){return qt(this.getNodeAtIndex(e,"input").inputTensors)},t.prototype.getOutputAt=function(e){return qt(this.getNodeAtIndex(e,"output").outputTensors)},Object.defineProperty(t.prototype,"input",{get:function(){if(this.inboundNodes.length>1)throw new Ai("Layer "+this.name+' has multiple inbound nodes, hence the notion of "layer input" is ill-defined. Use `getInputAt(nodeIndex)` instead.');if(this.inboundNodes.length===0)throw new Ai("Layer "+this.name+" is not connected, no input to return.");return qt(this.getNodeAtIndex(0,"input").inputTensors)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"output",{get:function(){if(this.inboundNodes.length===0)throw new Ai("Layer "+this.name+" has no inbound nodes.");if(this.inboundNodes.length>1)throw new Ai("Layer "+this.name+' has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `getOutputAt(nodeIndex)` instead.');return qt(this.getNodeAtIndex(0,"output").outputTensors)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"losses",{get:function(){return this._losses},enumerable:!0,configurable:!0}),t.prototype.calculateLosses=function(){return this.losses.map(function(e){return e()})},Object.defineProperty(t.prototype,"updates",{get:function(){return this._updates},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"built",{get:function(){return this._built},set:function(e){this._built=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"trainable",{get:function(){return this.trainable_},set:function(e){this._trainableWeights.forEach(function(i){return i.trainable=e}),this.trainable_=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"trainableWeights",{get:function(){return this.trainable_?this._trainableWeights.filter(function(e){return e.trainable}):[]},set:function(e){this._trainableWeights=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){return this.trainable?this._trainableWeights.filter(function(e){return!e.trainable}).concat(this._nonTrainableWeights):this._trainableWeights.concat(this._nonTrainableWeights)},set:function(e){this._nonTrainableWeights=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"weights",{get:function(){return this.trainableWeights.concat(this.nonTrainableWeights)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stateful",{get:function(){return this._stateful},enumerable:!0,configurable:!0}),t.prototype.resetStates=function(){if(!this.stateful)throw new Error("Cannot call the resetStates() method of a non-stateful Layer object.")},t.prototype.assertInputCompatibility=function(e){if(e=Je(e),this.inputSpec==null||this.inputSpec.length===0)return;var i=Je(this.inputSpec);if(e.length!==i.length)throw new M("Layer "+this.name+" expects "+i.length+" inputs, "+("but it received "+e.length+" input tensors. ")+("Input received: "+e));for(var r=0;r<e.length;r++){var a=e[r],s=i[r];if(s==null)continue;var o=a.rank;if(s.ndim!=null&&o!==s.ndim)throw new M("Input "+r+" is incompatible with layer "+this.name+": "+("expected ndim="+s.ndim+", found ndim="+o));if(s.maxNDim!=null&&o>s.maxNDim)throw new M("Input "+r+" is incompatible with layer "+this.name+(": expected max_ndim="+s.maxNDim+", found ndim="+o));if(s.minNDim!=null&&o<s.minNDim)throw new M("Input "+r+" is incompatible with layer "+this.name+(": expected min_ndim="+s.minNDim+", found ndim="+o+"."));if(s.dtype!=null&&a.dtype!==s.dtype)throw new M("Input "+r+" is incompatible with layer "+this.name+" "+(": expected dtype="+s.dtype+", found dtype="+a.dtype+"."));if(s.axes){var l=a.shape;for(var u in s.axes){var c=Number(u),h=s.axes[u],d=c>=0?l[c]:l[l.length+c];if(h!=null&&[h,null].indexOf(d)===-1)throw new M("Input "+r+" is incompatible with layer "+(this.name+": expected axis "+c+" of input shape to ")+("have value "+h+" but got shape "+l+"."))}}if(s.shape!=null)for(var p=0;p<s.shape.length;++p){var f=s.shape[p],m=a.shape[p];if(f!=null&&m!=null&&f!==m)throw new M("Input "+r+" is incompatible with layer "+(this.name+": expected shape="+s.shape+", ")+("found shape="+a.shape+"."))}}},t.prototype.call=function(e,i){return e},t.prototype.invokeCallHook=function(e,i){this._callHook!=null&&this._callHook(e,i)},t.prototype.setCallHook=function(e){this._callHook=e},t.prototype.clearCallHook=function(){this._callHook=null},t.prototype.apply=function(e,i){var r=this;i=i||{},this.assertNotDisposed();for(var a=Je(e),s=!0,o=0,l=a;o<l.length;o++){var u=l[o];if(!(u instanceof In)){s=!1;break}}for(var c=!0,h=0,d=a;h<d.length;h++){var u=d[h];if(u instanceof In){c=!1;break}}if(s===c)throw new M("Arguments to apply() must be all SymbolicTensors or all Tensors");return hr(this.name,function(){if(!r.built){r.assertInputCompatibility(e);for(var p=[],f=0,m=Je(e);f<m.length;f++){var g=m[f];p.push(g.shape)}r.build(qt(p)),r.built=!0,r.initialWeights&&r.setWeights(r.initialWeights),r._refCount===null&&c&&(r._refCount=1)}if(r.assertInputCompatibility(e),c){for(var v=r.call(e,i),b=Je(v),w=[],S=0,L=b;S<L.length;S++){var N=L[S];a.indexOf(N)!==-1&&(N=N.clone()),w.push(N)}if(v=qt(w),r.activityRegularizer!=null)throw new Te("Layer invocation in the presence of activity regularizer(s) is not supported yet.");return v}else{var C=k3(e),R=r.computeOutputShape(C),v=void 0,D=F3(e);if(r.warnOnIncompatibleInputShape(Array.isArray(e)?C[0]:C),R!=null&&R.length>0&&Array.isArray(R[0])?v=R.map(function(W,F){return new In(D,W,r,Je(e),i,r.name,F)}):v=new In(D,R,r,Je(e),i,r.name),r.addInboundNode(e,v,null,null,C,R,i),r._refCount++,r.activityRegularizer!=null)throw new Te("Layer invocation in the presence of activity regularizer(s) is not supported yet.");return v}})},t.prototype.warnOnIncompatibleInputShape=function(e){if(this.batchInputShape==null)return;if(e.length!==this.batchInputShape.length)console.warn("The rank of the input tensor provided (shape: "+(JSON.stringify(e)+") does not match that of the ")+("batchInputShape ("+JSON.stringify(this.batchInputShape)+") ")+("of the layer "+this.name));else{var i=!1;this.batchInputShape.forEach(function(r,a){r!=null&&e[a]!=null&&e[a]!==r&&(i=!0)}),i&&console.warn("The shape of the input tensor "+("("+JSON.stringify(e)+") does not ")+("match the expectation of layer "+this.name+": ")+(""+JSON.stringify(this.batchInputShape)))}},Object.defineProperty(t.prototype,"outputShape",{get:function(){if(this.inboundNodes==null||this.inboundNodes.length===0)throw new Ai("The layer "+this.name+" has never been called and thus has no defined output shape.");for(var e=[],i=0,r=this.inboundNodes;i<r.length;i++){var a=r[i],s=JSON.stringify(a.outputShapes);e.indexOf(s)===-1&&e.push(s)}if(e.length===1){var o=this.inboundNodes[0].outputShapes;return Array.isArray(o)&&Array.isArray(o[0])&&o.length===1?o[0]:o}else throw new Ai("The layer "+this.name+' has multiple inbound nodes with different output shapes. Hence the notion of "output shape" is ill-defined for the layer.')},enumerable:!0,configurable:!0}),t.prototype.countParams=function(){if(!this.built)throw new Pn("You tried to call countParams() on "+this.name+", but the layer is not built yet. Build it first by calling build(batchInputShape).");return Ro(this.weights)},t.prototype.build=function(e){this.built=!0},t.prototype.getWeights=function(e){return e===void 0&&(e=!1),Qh(e?this.trainableWeights:this.weights)},t.prototype.setWeights=function(e){var i=this;y.tidy(function(){var r=i.weights;if(r.length!==e.length)throw new M('You called setWeights(weights) on layer "'+i.name+'" '+("with a weight list of length "+e.length+", ")+("but the layer was expecting "+r.length+" weights. ")+("Provided weights: "+e+"..."));if(r.length===0)return;for(var a=[],s=Qh(r),o=0;o<s.length;++o){var l=s[o],u=r[o],c=e[o];if(!y.util.arraysEqual(l.shape,c.shape))throw new M("Layer weight shape "+l.shape+" "+("not compatible with provided weight shape "+c.shape));a.push([u,c])}ed(a)})},t.prototype.addWeight=function(e,i,r,a,s,o,l){if(this._addedWeightNames.indexOf(e)!==-1)throw new M("Duplicate weight name "+e+" for layer "+this.name);this._addedWeightNames.push(e),r==null&&(r="float32"),this.fastWeightInitDuringBuild&&(a=tt("zeros"));var u=a.apply(i,r),c=new ky(u,r,e,o,l);return u.dispose(),s!=null&&this.addLoss(function(){return s.apply(c.read())}),o==null&&(o=!0),o?this._trainableWeights.push(c):this._nonTrainableWeights.push(c),c},t.prototype.setFastWeightInitDuringBuild=function(e){this.fastWeightInitDuringBuild=e},t.prototype.addLoss=function(e){var i;if(e==null||Array.isArray(e)&&e.length===0)return;e=Je(e),this._losses!==void 0&&this._losses!==null&&(i=this.losses).push.apply(i,e)},t.prototype.computeOutputShape=function(e){return e},t.prototype.computeMask=function(e,i){var r=this;if(!this.supportsMasking){if(i!=null)if(Array.isArray(i))i.forEach(function(a){if(a!=null)throw new TypeError("Layer "+r.name+" does not support masking, but was passed an inputMask.")});else throw new TypeError("Layer "+this.name+" does not support masking, but was passed an inputMask.");return null}return i},t.prototype.addInboundNode=function(e,i,r,a,s,o,l){l===void 0&&(l=null);var u=Je(e);i=Je(i),r=Je(r),a=Je(a),s=Co(s),o=Co(o);for(var c=[],h=[],d=[],p=0,f=u;p<f.length;p++){var m=f[p];c.push(m.sourceLayer),h.push(m.nodeIndex),d.push(m.tensorIndex)}new Oo({outboundLayer:this,inboundLayers:c,nodeIndices:h,tensorIndices:d,inputTensors:u,outputTensors:i,inputMasks:r,outputMasks:a,inputShapes:s,outputShapes:o},l);for(var g=0;g<i.length;g++)i[g].sourceLayer=this,i[g].nodeIndex=this.inboundNodes.length-1,i[g].tensorIndex=g},t.prototype.getConfig=function(){var e={name:this.name,trainable:this.trainable};return this.batchInputShape!=null&&(e.batchInputShape=this.batchInputShape),this.dtype!=null&&(e.dtype=this.dtype),e},t.prototype.disposeWeights=function(){return this.weights.forEach(function(e){return e.dispose()}),this.weights.length},t.prototype.assertNotDisposed=function(){if(this._refCount===0)throw new Error("Layer '"+this.name+"' is already disposed.")},t.prototype.dispose=function(){if(!this.built)throw new Error("Cannot dispose Layer "+this.name+" because it has not been built yet.");if(this._refCount===null)throw new Error("Cannot dispose Layer "+this.name+" because it has not been used yet.");this.assertNotDisposed();var e=0;return--this._refCount===0&&(e=this.disposeWeights()),{refCountAfterDispose:this._refCount,numDisposedVariables:e}},t}(y.serialization.Serializable);function k3(n){n=Je(n);for(var t=[],e=0,i=n;e<i.length;e++){var r=i[e];t.push(r.shape)}return qt(t)}function F3(n){return"float32"}function Fy(n,t,e){if((t==null||e!=null&&e>0)&&(t=n.sourceLayer,e=n.nodeIndex),t.inboundNodes.length===0)return[n];var i=t.inboundNodes[e];if(i.inboundLayers.length===0)return i.inputTensors;for(var r=[],a=0;a<i.inboundLayers.length;a++)for(var s=i.inputTensors[a],o=i.inboundLayers[a],l=i.nodeIndices[a],u=Fy(s,o,l),c=0,h=u;c<h.length;c++){var d=h[c];r.indexOf(d)===-1&&r.push(d)}return r}var rs=function(n){Q(t,n);function t(e){var i=n.call(this,{dtype:e.dtype,name:e.name!=null?e.name:xo("input").toString()})||this;if(e.batchSize==null&&(e.batchSize=null),e.sparse==null&&(e.sparse=!1),i.trainable=!1,i.built=!0,i.sparse=e.sparse,e.inputShape!=null&&e.batchInputShape!=null)throw new M("Only provide the inputShape OR batchInputShape argument to inputLayer, not both at the same time.");var r=e.batchInputShape;if(r==null){if(e.inputShape==null)throw new M("An InputLayer should be passed either a `batchInputShape` or an `inputShape`.");r=[e.batchSize].concat(e.inputShape)}else if(e.batchSize!=null)throw new M("Cannot specify batchSize if batchInputShape is specified when creating an InputLayer.");var a=e.dtype||"float32";i.batchInputShape=r,i.dtype=a,i.inputSpec=[{shape:r}];var s=new In(i.dtype,i.batchInputShape,i,[],{},i.name);return s.nodeIndex=0,s.tensorIndex=0,new Oo({outboundLayer:i,inboundLayers:[],nodeIndices:[],tensorIndices:[],inputTensors:[s],outputTensors:[s],inputMasks:[null],outputMasks:[null],inputShapes:[r],outputShapes:[r]}),i}return t.prototype.apply=function(e,i){throw new M("Cannot pass any input to an "+("InputLayer's apply() method. InputLayer name: "+this.name))},t.prototype.dispose=function(){return{refCountAfterDispose:this._refCount,numDisposedVariables:0}},t.prototype.getConfig=function(){return{batchInputShape:this.batchInputShape,dtype:this.dtype,sparse:this.sparse,name:this.name}},t.className="InputLayer",t}(De);y.serialization.registerClass(rs);function Wy(n){if(n.batchShape==null&&n.shape==null)throw new Error("Please provide to Input either a `shape` or a `batchShape` argument. Note that `shape` does not include the batch dimension.");if(n.batchShape!=null&&n.shape!=null)throw new M("Please provide either a `shape` or `batchShape` argument to Input, but not both.");var t=n.batchShape;n.shape!=null&&t==null&&(t=[null].concat(n.shape));var e=n.dtype;e==null&&(e="float32");var i=new rs({batchInputShape:t,name:n.name,dtype:e,sparse:n.sparse}),r=i.inboundNodes[0].outputTensors;return r[0]}function Ci(n){return Se(this,void 0,void 0,function(){var t,e,i,r,a,s,o,l;return ve(this,function(u){switch(u.label){case 0:if(n==null)return[2];t=[],e=[],i=[];for(r in n)a=n[r],typeof a!="number"&&(s=a,t.push(s.data()),e.push(r),i.push(s));return t.length>0?[4,Promise.all(t)]:[3,2];case 1:for(o=u.sent(),l=0;l<o.length;++l)n[e[l]]=o[l][0];y.dispose(i),u.label=2;case 2:return[2]}})})}function Uy(n){if(n==null)return;for(var t in n){var e=n[t];typeof e!="number"&&e.dispose()}}var By;(function(n){n[n.SILENT=0]="SILENT",n[n.VERBOSE=1]="VERBOSE"})(By||(By={}));var W3=125,ia=function(){function n(){this.validationData=null}return n.prototype.setParams=function(t){this.params=t},n.prototype.onEpochBegin=function(t,e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return[2]})})},n.prototype.onEpochEnd=function(t,e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return[2]})})},n.prototype.onBatchBegin=function(t,e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return[2]})})},n.prototype.onBatchEnd=function(t,e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return[2]})})},n.prototype.onTrainBegin=function(t){return Se(this,void 0,void 0,function(){return ve(this,function(e){return[2]})})},n.prototype.onTrainEnd=function(t){return Se(this,void 0,void 0,function(){return ve(this,function(e){return[2]})})},n.prototype.setModel=function(t){},n}(),zy=function(){function n(t,e){e===void 0&&(e=10),t==null&&(t=[]),this.callbacks=t,this.queueLength=e}return n.prototype.append=function(t){this.callbacks.push(t)},n.prototype.setParams=function(t){for(var e=0,i=this.callbacks;e<i.length;e++){var r=i[e];r.setParams(t)}},n.prototype.setModel=function(t){for(var e=0,i=this.callbacks;e<i.length;e++){var r=i[e];r.setModel(t)}},n.prototype.onEpochBegin=function(t,e){return Se(this,void 0,void 0,function(){var i,r,a;return ve(this,function(s){switch(s.label){case 0:e==null&&(e={}),i=0,r=this.callbacks,s.label=1;case 1:return i<r.length?(a=r[i],[4,a.onEpochBegin(t,e)]):[3,4];case 2:s.sent(),s.label=3;case 3:return i++,[3,1];case 4:return[2]}})})},n.prototype.onEpochEnd=function(t,e){return Se(this,void 0,void 0,function(){var i,r,a;return ve(this,function(s){switch(s.label){case 0:e==null&&(e={}),i=0,r=this.callbacks,s.label=1;case 1:return i<r.length?(a=r[i],[4,a.onEpochEnd(t,e)]):[3,4];case 2:s.sent(),s.label=3;case 3:return i++,[3,1];case 4:return[2]}})})},n.prototype.onBatchBegin=function(t,e){return Se(this,void 0,void 0,function(){var i,r,a;return ve(this,function(s){switch(s.label){case 0:e==null&&(e={}),i=0,r=this.callbacks,s.label=1;case 1:return i<r.length?(a=r[i],[4,a.onBatchBegin(t,e)]):[3,4];case 2:s.sent(),s.label=3;case 3:return i++,[3,1];case 4:return[2]}})})},n.prototype.onBatchEnd=function(t,e){return Se(this,void 0,void 0,function(){var i,r,a;return ve(this,function(s){switch(s.label){case 0:e==null&&(e={}),i=0,r=this.callbacks,s.label=1;case 1:return i<r.length?(a=r[i],[4,a.onBatchEnd(t,e)]):[3,4];case 2:s.sent(),s.label=3;case 3:return i++,[3,1];case 4:return[2]}})})},n.prototype.onTrainBegin=function(t){return Se(this,void 0,void 0,function(){var e,i,r;return ve(this,function(a){switch(a.label){case 0:t==null&&(t={}),e=0,i=this.callbacks,a.label=1;case 1:return e<i.length?(r=i[e],[4,r.onTrainBegin(t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return e++,[3,1];case 4:return[2]}})})},n.prototype.onTrainEnd=function(t){return Se(this,void 0,void 0,function(){var e,i,r;return ve(this,function(a){switch(a.label){case 0:t==null&&(t={}),e=0,i=this.callbacks,a.label=1;case 1:return e<i.length?(r=i[e],[4,r.onTrainEnd(t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return e++,[3,1];case 4:return[2]}})})},n}(),U3=function(n){Q(t,n);function t(){return n.call(this)||this}return t.prototype.onEpochBegin=function(e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return this.seen=0,this.totals={},[2]})})},t.prototype.onBatchEnd=function(e,i){return Se(this,void 0,void 0,function(){var r,a,s,o,l=this;return ve(this,function(u){i==null&&(i={}),r=i.size==null?0:i.size,this.seen+=r,a=function(c){var h=i[c];if(typeof h=="number")s.totals.hasOwnProperty(c)||(s.totals[c]=0),s.totals[c]=s.totals[c]+h*r;else{var d=void 0;c in s.totals?d=s.totals[c]:s.totals[c]=0;var p=y.tidy(function(){return y.add(l.totals[c],y.mul(h,r))});s.totals[c]=p,d!=null&&d.dispose()}},s=this;for(o in i)a(o);return[2]})})},t.prototype.onEpochEnd=function(e,i){return Se(this,void 0,void 0,function(){var r,a,s,o,l,u=this;return ve(this,function(c){if(i!=null)for(r=function(h){if(a.totals[h]==null)return"continue";typeof a.totals[h]=="number"?i[h]=a.totals[h]/a.seen:y.tidy(function(){var d=y.mul(y.div(1,u.seen),u.totals[h]);i[h]=d,u.totals[h].dispose(),y.keep(i[h])})},a=this,s=0,o=this.params.metrics;s<o.length;s++)l=o[s],r(l);return[2]})})},t}(ia),Py=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.onTrainBegin=function(e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return this.epoch=[],this.history={},[2]})})},t.prototype.onEpochEnd=function(e,i){return Se(this,void 0,void 0,function(){var r;return ve(this,function(a){i==null&&(i={}),this.epoch.push(e);for(r in i)this.history[r]==null&&(this.history[r]=[]),this.history[r].push(i[r]);return[2]})})},t.prototype.syncData=function(){return Se(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u,c,h;return ve(this,function(d){switch(d.label){case 0:e=[],i=[],r=[];for(a in this.history)for(s=this.history[a],o=0;o<s.length;++o)typeof s[o]!="number"&&(l=s[o],e.push(l.data()),i.push(a),r.push(o));return[4,Promise.all(e)];case 1:for(u=d.sent(),c=0;c<u.length;++c)h=this.history[i[c]][r[c]],h.dispose(),this.history[i[c]][r[c]]=u[c][0];return[2]}})})},t}(ia),_y=function(n){Q(t,n);function t(e,i){var r=n.call(this)||this;if(r.currentEpoch=0,r.yieldEvery=i||"auto",r.yieldEvery==="auto"&&(r.yieldEvery=W3),r.yieldEvery==="never"&&e.onYield!=null)throw new Error("yieldEvery is `never` but you provided an `onYield` callback. Either change `yieldEvery` or remove the callback");return y.util.isNumber(r.yieldEvery)&&(r.maybeWait=Vk(r.maybeWait.bind(r),r.yieldEvery)),r.trainBegin=e.onTrainBegin,r.trainEnd=e.onTrainEnd,r.epochBegin=e.onEpochBegin,r.epochEnd=e.onEpochEnd,r.batchBegin=e.onBatchBegin,r.batchEnd=e.onBatchEnd,r.yield=e.onYield,r}return t.prototype.maybeWait=function(e,i,r){return Se(this,void 0,void 0,function(){var a;return ve(this,function(s){switch(s.label){case 0:return a=[],this.yield!=null?[4,Ci(r)]:[3,2];case 1:s.sent(),a.push(this.yield(e,i,r)),s.label=2;case 2:return a.push(y.nextFrame()),[4,Promise.all(a)];case 3:return s.sent(),[2]}})})},t.prototype.onEpochBegin=function(e,i){return Se(this,void 0,void 0,function(){return ve(this,function(r){switch(r.label){case 0:return this.currentEpoch=e,this.epochBegin!=null?[4,Ci(i)]:[3,3];case 1:return r.sent(),[4,this.epochBegin(e,i)];case 2:r.sent(),r.label=3;case 3:return[2]}})})},t.prototype.onEpochEnd=function(e,i){return Se(this,void 0,void 0,function(){var r;return ve(this,function(a){switch(a.label){case 0:return r=[],this.epochEnd!=null?[4,Ci(i)]:[3,2];case 1:a.sent(),r.push(this.epochEnd(e,i)),a.label=2;case 2:return this.yieldEvery==="epoch"&&r.push(y.nextFrame()),[4,Promise.all(r)];case 3:return a.sent(),[2]}})})},t.prototype.onBatchBegin=function(e,i){return Se(this,void 0,void 0,function(){return ve(this,function(r){switch(r.label){case 0:return this.batchBegin!=null?[4,Ci(i)]:[3,3];case 1:return r.sent(),[4,this.batchBegin(e,i)];case 2:r.sent(),r.label=3;case 3:return[2]}})})},t.prototype.onBatchEnd=function(e,i){return Se(this,void 0,void 0,function(){var r;return ve(this,function(a){switch(a.label){case 0:return r=[],this.batchEnd!=null?[4,Ci(i)]:[3,2];case 1:a.sent(),r.push(this.batchEnd(e,i)),a.label=2;case 2:return this.yieldEvery==="batch"?r.push(y.nextFrame()):y.util.isNumber(this.yieldEvery)&&r.push(this.maybeWait(this.currentEpoch,e,i)),[4,Promise.all(r)];case 3:return a.sent(),[2]}})})},t.prototype.onTrainBegin=function(e){return Se(this,void 0,void 0,function(){return ve(this,function(i){switch(i.label){case 0:return this.trainBegin!=null?[4,Ci(e)]:[3,3];case 1:return i.sent(),[4,this.trainBegin(e)];case 2:i.sent(),i.label=3;case 3:return[2]}})})},t.prototype.onTrainEnd=function(e){return Se(this,void 0,void 0,function(){return ve(this,function(i){switch(i.label){case 0:return this.trainEnd!=null?[4,Ci(e)]:[3,3];case 1:return i.sent(),[4,this.trainEnd(e)];case 2:i.sent(),i.label=3;case 3:return[2]}})})},t}(ia);function My(n,t){if(n==null&&(n={}),n instanceof ia)return[n];if(Array.isArray(n)&&n[0]instanceof ia)return n;var e=Je(n);return e.map(function(i){return new _y(i,t)})}var Hy=function(){function n(){}return n.registerCallbackConstructor=function(t,e){y.util.assert(t>=0&&Number.isInteger(t),function(){return"Verbosity level is expected to be an integer >= 0, "+("but got "+t)}),n.checkForDuplicate(e),n.constructors[t]==null&&(n.constructors[t]=[]),n.constructors[t].push(e)},n.checkForDuplicate=function(t){for(var e in n.constructors){var i=n.constructors[+e];i.forEach(function(r){if(r===t)throw new M("Duplicate callback constructor.")})}},n.clear=function(){n.constructors={}},n.createCallbacks=function(t){var e=[];for(var i in n.constructors){var r=+i;t>=r&&e.push.apply(e,n.constructors[r])}return e.map(function(a){return new a})},n.constructors={},n}();function Vy(n,t,e,i,r,a,s,o,l){var u=new Py,c=[new U3].concat(Hy.createCallbacks(t));n!=null&&c.push.apply(c,n),c.push(u);var h=new zy(c);return h.setParams({epochs:e,initialEpoch:i,samples:r,steps:a,batchSize:s,verbose:t,doValidation:o,metrics:l}),{callbackList:h,history:u}}function An(n,t,e){return t===void 0&&(t={}),e===void 0&&(e=!1),Ja(n,y.serialization.SerializationMap.getMap().classNameMap,t,"layer",e)}function Eo(n,t){return y.tidy(function(){n.dtype!=="float32"&&(n=n.asType("float32"));var e=y.sum(ns(n),t,!0),i=y.fill(e.shape,yt()),r=y.sqrt(y.maximum(e,i));return y.div(n,r)})}function pr(n,t){return y.tidy(function(){return y.mean(ns(y.sub(t,n)),-1)})}function Do(n,t){return y.tidy(function(){return y.mean(y.abs(y.sub(t,n)),-1)})}function ra(n,t){return y.tidy(function(){var e=y.sub(n,t),i=y.clipByValue(y.abs(n),yt(),Number.MAX_VALUE),r=y.abs(y.div(e,i));return y.mul(100,y.mean(r,-1))})}function B3(n,t){return y.tidy(function(){var e=y.clipByValue(t,yt(),Number.MAX_VALUE),i=y.log(y.add(1,e)),r=y.clipByValue(n,yt(),Number.MAX_VALUE),a=y.log(y.add(1,r));return y.mean(ns(y.sub(i,a)),-1)})}function z3(n,t){return y.tidy(function(){var e=y.maximum(0,y.sub(1,y.mul(n,t)));return y.mean(ns(e),-1)})}function P3(n,t){return y.tidy(function(){var e=y.maximum(0,y.sub(1,y.mul(n,t)));return y.mean(e,-1)})}function _3(n,t){return y.tidy(function(){var e=y.sum(y.mul(n,t),-1),i=y.max(y.mul(y.sub(1,n),t),-1);return y.maximum(0,y.add(1,y.sub(i,e)))})}function M3(n,t){return y.tidy(function(){var e=Math.log(2),i=y.sub(t,n),r=y.sub(y.add(i,y.softplus(y.mul(-2,i))),e);return y.mean(r,-1)})}function as(n,t,e){return e===void 0&&(e=!1),y.tidy(function(){if(e)t=y.softmax(t);else{var i=y.sum(t,t.shape.length-1,!0);t=y.div(t,i)}return t=y.clipByValue(t,yt(),1-yt()),y.neg(y.sum(y.mul(n.toFloat(),y.log(t)),t.shape.length-1))})}function ko(n,t,e){return e===void 0&&(e=!1),y.tidy(function(){var i=y.floor(i3(n)).toInt();t=y.clipByValue(t,yt(),1-yt());var r=t.shape,a=y.oneHot(i,r[r.length-1]).reshape(r);return as(a,t,e)})}function H3(n,t){if(!y.util.arraysEqual(n.shape,t.shape))throw new M("logits and labels must have the same shape, but got shapes "+(JSON.stringify(n.shape)+" and "+JSON.stringify(t.shape)));return y.tidy(function(){var e=t.relu(),i=t.abs().neg();return e.sub(t.mul(n)).add(i.exp().log1p())})}function Fo(n,t){return y.tidy(function(){var e;return e=y.clipByValue(t,yt(),1-yt()),e=y.log(y.div(e,y.sub(1,e))),y.mean(H3(n,e),-1)})}function V3(n,t){return y.tidy(function(){var e=y.clipByValue(n,yt(),1),i=y.clipByValue(t,yt(),1);return y.sum(y.mul(n,y.log(y.div(e,i))),-1)})}function q3(n,t){return y.tidy(function(){var e=y.log(y.add(yt(),t));return y.mean(y.sub(t,y.mul(n,e)),-1)})}function td(n,t){return y.tidy(function(){var e=Eo(n,-1),i=Eo(t,-1),r=y.mul(e,i);return y.neg(y.sum(r,-1))})}var Wo={meanSquaredError:pr,meanAbsoluteError:Do,meanAbsolutePercentageError:ra,meanSquaredLogarithmicError:B3,squaredHinge:z3,hinge:P3,categoricalHinge:_3,logcosh:M3,categoricalCrossentropy:as,sparseCategoricalCrossentropy:ko,binaryCrossentropy:Fo,kullbackLeiblerDivergence:V3,poisson:q3,cosineProximity:td};function nd(n){if(typeof n=="string"){if(n in Wo)return Wo[n];var t="Unknown loss "+n;throw n.toLowerCase().includes("softmaxcrossentropy")&&(t="Unknown loss "+n+'. Use "categoricalCrossentropy" as the string name for tf.losses.softmaxCrossEntropy'),new M(t)}else return n}function id(n,t){return y.tidy(function(){var e=y.mul(.5,y.onesLike(t)),i=es(y.greater(t,e),n.dtype);return y.mean(y.equal(n,i),-1)})}function rd(n,t){return y.tidy(function(){return es(y.equal(y.argMax(n,-1),y.argMax(t,-1)),"float32")})}function qy(n,t){return y.tidy(function(){return y.logicalAnd(n.equal(1),t.equal(1)).sum().cast("float32")})}function G3(n,t){return y.tidy(function(){return y.logicalAnd(n.equal(1),t.equal(0)).sum().cast("float32")})}function Y3(n,t){return y.tidy(function(){return y.logicalAnd(n.equal(0),t.equal(1)).sum().cast("float32")})}function Gy(n,t){return y.tidy(function(){var e=qy(n,t),i=Y3(n,t),r=e.add(i);return y.where(y.greater(r,0),e.div(r),0).cast("float32")})}function j3(n,t){return y.tidy(function(){var e=qy(n,t),i=G3(n,t),r=e.add(i);return y.where(y.greater(r,0),e.div(r),0).cast("float32")})}function Yy(n,t){return Fo(n,t)}function jy(n,t){return n.rank===t.rank&&(n=n.squeeze([n.rank-1])),t=t.argMax(-1),t.dtype!==n.dtype&&(t=t.asType(n.dtype)),y.equal(n,t).asType("float32")}var K3=pr,$3=pr,X3=Do,J3=Do,Z3=ra,Q3=ra,ad=as,e4=td,Ky=ko,Uo={binaryAccuracy:id,categoricalAccuracy:rd,precision:Gy,categoricalCrossentropy:ad,sparseCategoricalCrossentropy:Ky,mse:K3,MSE:$3,mae:X3,MAE:J3,mape:Z3,MAPE:Q3,cosine:e4};function t4(n){if(typeof n=="string"&&n in Uo)return Uo[n];if(typeof n!="string"&&n!=null)return n;throw new M("Unknown metric "+n)}function Bo(n){if(_n(n!==null,"Unknown LossOrMetricFn "+n),typeof n=="string")return n;for(var t=void 0,e=0,i=Object.keys(Wo);e<i.length;e++){var r=i[e];if(Wo[r]===n){t=r;break}}if(t!==void 0)return t;for(var a=0,s=Object.keys(Uo);a<s.length;a++){var r=s[a];if(Uo[r]===n){t=r;break}}return t!==void 0?t:n.name}function n4(n){var t={Adagrad:function(){return y.train.adagrad(.01)},Adadelta:function(){return y.train.adadelta(1,.95,yt())},Adam:function(){return y.train.adam(.001,.9,.999,yt())},Adamax:function(){return y.train.adamax(.002,.9,.999,yt(),0)},RMSProp:function(){return y.train.rmsprop(.001,.9,0,yt())},SGD:function(){return y.train.sgd(.01)}};if(t.adagrad=t.Adagrad,t.adadelta=t.Adadelta,t.adam=t.Adam,t.adamax=t.Adamax,t.rmsprop=t.RMSProp,t.sgd=t.SGD,n in t)return t[n]();throw new M("Unknown Optimizer "+n)}var $y=1*1024*1024;function Xy(n,t,e){if(e===void 0&&(e=!1),n==null||typeof n!="object"||Object.getPrototypeOf(n)!==Object.prototype||!sd(n))throw new Error("User-defined metadata is expected to be a JSON object, but is not.");if(e){var i=JSON.stringify(n);i.length>$y&&console.warn('User-defined metadata of model "'+t+'" is too large in '+("size (length="+i.length+" when serialized). It is not ")+"recommended to store such large objects in user-defined metadata. Please make sure its serialized length is <= "+($y+"."))}}function sd(n){if(n===null)return!0;if(typeof n=="object")if(Object.getPrototypeOf(n)===Object.prototype){for(var t=Object.keys(n),e=0,i=t;e<i.length;e++){var r=i[e];if(typeof r!="string")return!1;if(!sd(n[r]))return!1}return!0}else if(Array.isArray(n)){for(var a=0,s=n;a<s.length;a++){var o=s[a];if(!sd(o))return!1}return!0}else return!1;else{var l=typeof n;return l==="string"||l==="number"||l==="boolean"}}function o4(n,t,e,i){i===void 0&&(i=console.log);var r=r4(n),a=["Layer (type)","Output shape","Param #"];r?(t=t||65,e=e||[.45,.85,1]):(t=t||98,e=e||[.33,.55,.67,1]),e[e.length-1]<=1&&(e=e.map(function(d){return Math.floor(t*d)}));var s;if(!r){a.push("Receives inputs"),s=[];for(var o in n.nodesByDepth)s.push.apply(s,n.nodesByDepth[o])}i("_".repeat(t)),zo(a,e,i),i("=".repeat(t));for(var l=n.layers,u=0;u<l.length;++u)r?a4(l[u],e,i):s4(l[u],e,s,i),i((u===l.length-1?"=":"_").repeat(t));n.checkTrainableWeightsConsistency();var c=i4(n),h=Ro(n.nonTrainableWeights);i("Total params: "+(c+h)),i("Trainable params: "+c),i("Non-trainable params: "+h),i("_".repeat(t))}function i4(n){var t;return n.collectedTrainableWeights!=null?t=Ro(n.collectedTrainableWeights):t=Ro(n.trainableWeights),t}function r4(n){var t=!0,e=[],i=[];for(var r in n.nodesByDepth)e.push(n.nodesByDepth[r]);for(var a=0,s=e;a<s.length;a++){var o=s[a];if(o.length>1||o.length===1&&o[0].inboundLayers.length>1){t=!1;break}i.push.apply(i,o)}if(t)for(var l=0,u=n.layers;l<u.length;l++){for(var c=u[l],h=!1,d=0,p=c.inboundNodes;d<p.length;d++){var f=p[d];if(i.indexOf(f)!==-1)if(h){t=!1;break}else h=!0}if(!t)break}return t}function zo(n,t,e){e===void 0&&(e=console.log);for(var i="",r=0;r<n.length;++r)r>0&&(i=i.slice(0,i.length-1)+" "),i+=n[r],i=i.slice(0,t[r]),i+=" ".repeat(t[r]-i.length);e(i)}function a4(n,t,e){var i;try{i=JSON.stringify(n.outputShape)}catch(o){i="multiple"}var r=n.name,a=n.getClassName(),s=[r+" ("+a+")",i,n.countParams().toString()];zo(s,t,e)}function s4(n,t,e,i){var r;try{r=JSON.stringify(n.outputShape)}catch(v){r="multiple"}for(var a=[],s=0,o=n.inboundNodes;s<o.length;s++){var l=o[s];if(e!=null&&e.length>0&&e.indexOf(l)===-1)continue;for(var u=0;u<l.inboundLayers.length;++u){var c=l.inboundLayers[u].name,h=l.nodeIndices[u],d=l.tensorIndices[u];a.push(c+"["+h+"]["+d+"]")}}var p=n.name,f=n.getClassName(),m=a.length===0?"":a[0],g=[p+" ("+f+")",r,n.countParams().toString(),m];zo(g,t,i);for(var u=1;u<a.length;++u)zo(["","","",a[u]],t,i)}function Jy(n,t,e){return(n==="inboundNodes"||n==="outputLayers"||n==="inputLayers")&&t===0&&typeof e=="string"}function ss(n,t){if(n===null)return null;if(typeof n=="string")return cr(n);if(typeof n=="number"||typeof n=="boolean")return n;if(n instanceof Array){for(var e=[],i=n.length,r=0;r<i;++r){var a=n[r];Jy(t,r,a)?e.push(a):e.push(ss(a,t))}return e}else{for(var s={},o=0,l=Object.keys(n);o<l.length;o++){var u=l[o],c=n[u];if(u==="name"&&typeof c=="string")s[u]=c;else{var h=cr(u);s[h]=ss(c,h)}}return s}}function od(n,t){if(n==null)return null;if(typeof n=="string")return ai(n);if(typeof n=="number"||typeof n=="boolean")return n;if(n instanceof Array){for(var e=[],i=n.length,r=0;r<i;++r){var a=n[r];Jy(t,r,a)?e.push(a):e.push(od(a,t))}return e}else{for(var s={},o=0,l=Object.keys(n);o<l.length;o++){var u=l[o],c=n[u],h=ai(u);(u==="name"||u==="className")&&typeof c=="string"?s[h]=c:s[h]=od(c,u)}return s}}var ld="2.6.0";function l4(n,t){if(n.dtype==null||n.dtype===t.dtype)return t;try{return y.cast(t,n.dtype)}catch(e){throw new M("The dtype of the feed ("+t.dtype+") can not be cast to the dtype "+("of the key '"+n.name+"' ("+n.dtype+")."))}}var aa=function(){function n(t){if(this.id2Value={},this.id2Mask={},this.name2Id={},t instanceof n)for(var e in t.id2Value)this.id2Value[e]=t.id2Value[e],e in t.id2Mask&&(this.id2Mask[e]=t.id2Mask[e]);else{if(t==null)return;for(var i=0,r=t;i<r.length;i++){var a=r[i];this.add(a.key,a.value)}}}return n.prototype.add=function(t,e,i){if(this.id2Value[t.id]==null)this.id2Value[t.id]=l4(t,e),this.name2Id[t.name]=t.id,i!=null&&(this.id2Mask[t.id]=i);else throw new M("Duplicate key: name="+t.name+", id="+t.id);return this},n.prototype.addFeed=function(t){this.add(t.key,t.value)},n.prototype.hasKey=function(t){return this.id2Value[t.id]!=null},n.prototype.names=function(){return Object.keys(this.name2Id)},n.prototype.getValue=function(t){if(t instanceof In){if(this.id2Value[t.id]==null)throw new M("Nonexistent key: "+t.name);return this.id2Value[t.id]}else{var e=this.name2Id[t];if(e==null)throw new M("Feed dict has no SymbolicTensor name: "+t);return this.id2Value[e]}},n.prototype.getMask=function(t){if(t instanceof In){if(this.id2Value[t.id]==null)throw new M("Nonexistent key: "+t.name);return this.id2Mask[t.id]}else{var e=this.name2Id[t];if(e==null)throw new M("Feed dict has no SymbolicTensor name: "+t);return this.id2Mask[e]}},n.prototype.disposeMasks=function(){this.id2Mask!=null&&y.dispose(this.id2Mask)},n}(),ud={},Zy={};function os(n,t,e,i){for(var r=e==null?!1:e.training,a=Array.isArray(n),s=a?n:[n],o=s.map(function(X){return X.name}),l=[],u=t.names(),c=0,h=o;c<h.length;c++){var d=h[c];u.indexOf(d)!==-1?l.push(t.getValue(d)):l.push(null)}i!=null&&(i.maxNumTensors=-Infinity,i.minNumTensors=Infinity);var p=o.join(",")+"|"+t.names().join(","),f,m;if(ud[p]==null){var g=u4(s,t);f=g.sorted,m=g.recipientCounts,ud[p]=f,Zy[p]=m}f=ud[p],m={},r||Object.assign(m,Zy[p]);for(var v=new aa(t),b=0;b<f.length;++b){if(i!=null){var w=y.memory().numTensors;w>i.maxNumTensors&&(i.maxNumTensors=w),w<i.minNumTensors&&(i.minNumTensors=w)}var S=f[b],L=S.sourceLayer;if(L instanceof rs)continue;for(var N=[],C=[],R=[],D=!1,k=0,W=S.inputs;k<W.length;k++){var F=W[k],P=v.getValue(F),H=v.getMask(F);N.push(P),C.push(H),H!=null&&(D=!0),r||(m[F.name]--,m[F.name]===0&&!t.hasKey(F)&&o.indexOf(F.name)===-1&&!P.isDisposed&&F.sourceLayer.stateful!==!0&&R.push(P))}D&&(e=e||{},e.mask=C[0]);var _=Je(L.apply(N,e)),j=null;L.supportsMasking&&(j=L.computeMask(N,C));for(var K=c4(S),q=Array.isArray(K)?K:[K],G=0;G<q.length;++G){v.hasKey(q[G])||v.add(q[G],_[G],Array.isArray(j)?j[0]:j);var Z=o.indexOf(q[G].name);Z!==-1&&(l[Z]=_[G])}r||y.dispose(R)}return v.disposeMasks(),a?l:l[0]}function u4(n,t){y.util.assert(n!=null&&n.length>0,function(){return"Expected at least one fetch, got none"});var e=[],i={};if(n.length===1){var r=Qy(n[0],t);e=r.sorted,i=r.recipientMap}else for(var a=new Set,s=0,o=n;s<o.length;s++){for(var l=o[s],u=Qy(l,t),c=u.sorted,h=u.recipientMap,d=0,p=c;d<p.length;d++){var f=p[d];a.has(f.name)||(e.push(f),a.add(f.name))}var m=function(v){i[v]==null&&(i[v]=new Set),h[v].forEach(function(b){return i[v].add(b)})};for(var g in h)m(g)}return{sorted:e,recipientCounts:h4(i)}}function h4(n){var t={};for(var e in n)t[e]=n[e].size;return t}function Qy(n,t){for(var e=new Set,i=[],r={},a=0,s=t.names();a<s.length;a++){var o=s[a];e.add(o)}var l=[],u=[];for(l.push(n);l.length>0;){var c=l[l.length-1];if(e.has(c.name)){l.pop();continue}var h=u[u.length-1]===l.length-1;if(c.inputs.length===0||h)l.pop(),i.push(c),e.add(c.name),h&&u.pop();else{u.push(l.length-1);for(var d=0,p=c.inputs;d<p.length;d++){var f=p[d];if(r[f.name]==null&&(r[f.name]=new Set),r[f.name].add(c.name),e.has(f.name))continue;l.push(f)}}}return{sorted:i,recipientMap:r}}function c4(n){var t;if(n.sourceLayer.inboundNodes.length===1)t=n.sourceLayer.output;else{for(var e=null,i=0;i<n.sourceLayer.inboundNodes.length;++i)for(var r=0,a=n.sourceLayer.inboundNodes[i].outputTensors;r<a.length;r++){var s=a[r];if(s.id===n.id){e=i;break}}t=n.sourceLayer.getOutputAt(e)}return t}var d4=function(n){Q(t,n);function t(e){var i=n.call(this,{})||this;if(i.containerNodes=new Set,i.name=e.name,i.name==null){var r=i.getClassName().toLowerCase();i.name=xo(r)}if(i.supportsMasking=!1,i.trainable_=!0,Array.isArray(e.inputs)?i.inputs=e.inputs.slice():i.inputs=[e.inputs],Array.isArray(e.outputs)?i.outputs=e.outputs.slice():i.outputs=[e.outputs],Ti(i.inputs).length!==i.inputs.length)throw new M("The list of inputs passed to the model is redundant. All inputs should only appear once. Found: "+(""+i.inputs.map(function(Ce){return Ce.name})));Ti(i.outputs).length!==i.outputs.length&&console.warn("The list of outputs passed to the model is redundant. All outputs should only appear once. Found: "+(""+i.outputs.map(function(Ce){return Ce.name}))),i.inputLayers=[],i.inputLayersNodeIndices=[],i.inputLayersTensorIndices=[],i.outputLayers=[],i.outputLayersNodeIndices=[],i.outputLayersTensorIndices=[],i.layers=[],i.internalContainerRefs=[];for(var a=0,s=i.outputs;a<s.length;a++){var o=s[a],l=o.sourceLayer,u=o.nodeIndex,c=o.tensorIndex;i.outputLayers.push(l),i.outputLayersNodeIndices.push(u),i.outputLayersTensorIndices.push(c)}for(var h=0,d=i.inputs;h<d.length;h++){var o=d[h],l=o.sourceLayer,u=o.nodeIndex,c=o.tensorIndex;_n(u===0,"input layer has >1 nodes"),_n(c===0,"input layer has >1 tensors"),i.inputLayers.push(l),i.inputLayersNodeIndices.push(u),i.inputLayersTensorIndices.push(c)}i.inputNames=[],i.outputNames=[],i.feedInputShapes=[],i.feedInputNames=[],i.feedOutputNames=[];for(var p=0;p<i.inputLayers.length;p++){var l=i.inputLayers[p];if(!(l instanceof rs))throw new TypeError("Input layers to a LayersModel must be InputLayer objects. "+("Received inputs: "+e.inputs+". ")+("Input "+p+" (0-based) originates ")+("from layer type "+l.getClassName()+"."));i.inputNames.push(l.name),i.feedInputShapes.push(l.batchInputShape),i.feedInputNames.push(l.name)}for(var f=0,m=i.outputLayers;f<m.length;f++){var l=m[f];i.outputNames.push(l.name)}i.internalInputShapes=i.inputs.map(function(Ce){return Ce.shape}),i.internalOutputShapes=i.outputs.map(function(Ce){return Ce.shape});for(var g={},v={},b={},w={},S={},L=[],N=function(Ce,Wt,ft,it,cn,Os){(it==null||cn==null||Os==null)&&(it=Ce.sourceLayer,cn=Ce.nodeIndex,Os=Ce.tensorIndex);var _t=it.inboundNodes[cn];if(ft.indexOf(_t)!==-1)throw new Pn("The tensor "+Ce.name+' at layer "'+it.name+'" is part of a cycle.');if(Wt.indexOf(_t)!==-1)return;i.containerNodes.add(t.nodeKey(it,cn)),it.id in S||(S[it.id]=Object.keys(S).length),ft.indexOf(_t)===-1&&ft.push(_t);for(var a2=_t.inboundLayers.length,Or=0;Or<a2;Or++){var s2=_t.inputTensors[Or],o2=_t.inboundLayers[Or],l2=_t.nodeIndices[Or],u2=_t.tensorIndices[Or];N(s2,Wt,ft,o2,l2,u2)}for(Wt.push(_t);ft.indexOf(_t)>=0;)ft.splice(ft.indexOf(_t),1);L.push(_t)},C=[],R=[],D=0,k=i.outputs;D<k.length;D++){var o=k[D];N(o,C,R)}for(var W=L.slice().reverse(),F=0,P=W;F<P.length;F++){var H=P[F];v[H.id]=H,H.id in g||(g[H.id]=0);var _=g[H.id],j=b[H.outboundLayer.id]==null?0:b[H.outboundLayer.id];_=Math.max(_,j),b[H.outboundLayer.id]=_,w[H.outboundLayer.id]=H.outboundLayer,g[H.id]=_;for(var p=0;p<H.inboundLayers.length;p++){var K=H.inboundLayers[p],u=H.nodeIndices[p],q=K.inboundNodes[u],G=g[q.id]==null?0:g[q.id];g[q.id]=Math.max(_+1,G),v[q.id]=q}}var Z={};for(var X in g){var _=g[X];_ in Z||(Z[_]=[]),Z[_].push(v[X])}var ee={};for(var ne in b){var _=b[ne];_ in ee||(ee[_]=[]),ee[_].push(w[ne])}var ie=Object.keys(ee).map(function(Ce){return parseInt(Ce,10)}).sort(Io);i.layers=[];for(var te=0,re=ie;te<re.length;te++){var _=re[te],le=ee[_];le.sort(function(Wt,ft){var it=S[Wt.id],cn=S[ft.id];return it<cn?-1:it>cn?1:0});for(var he=0,ye=le;he<ye.length;he++){var l=ye[he];l instanceof t&&i.internalContainerRefs.push(l),i.layers.push(l)}}i.layersByDepth=ee,ie=Object.keys(Z).map(function(Ce){return parseInt(Ce,10)}).sort(Io);for(var Oe=i.inputs.slice(),Fe=[],_e=0,Me=ie;_e<Me.length;_e++)for(var _=Me[_e],dt=0,Lt=Z[_];dt<Lt.length;dt++){var H=Lt[dt],l=H.outboundLayer;if(l!=null){for(var Ge=0,Ue=H.inputTensors;Ge<Ue.length;Ge++){var o=Ue[Ge];if(Oe.indexOf(o)===-1)throw new Pn("Graph disconnected: cannot obtain value for tensor "+o+(' at layer "'+l.name+'". ')+"The following previous layers were accessed without "+("issue: "+Fe))}for(var me=0,Ft=H.outputTensors;me<Ft.length;me++){var o=Ft[me];Oe.push(o)}Fe.push(l.name)}}i.nodesByDepth=Z;for(var lt=i.layers.map(function(Ce){return Ce.name}),pt=function(Ce){var Wt=lt.filter(function(ft){return ft===Ce}).length;if(Wt!==1)throw new Pn('The name "'+Ce+'" is used '+Wt+" times in the model. All layer names should be unique. Layer names: "+JSON.stringify(lt))},En=0,Et=lt;En<Et.length;En++){var It=Et[En];pt(It)}return i.outboundNodes=[],i.inboundNodes=[],new Oo({outboundLayer:i,inboundLayers:[],nodeIndices:[],tensorIndices:[],inputTensors:i.inputs,outputTensors:i.outputs,inputMasks:i.inputs.map(function(Ce){return null}),outputMasks:i.outputs.map(function(Ce){return null}),inputShapes:i.inputs.map(function(Ce){return Ce.shape}),outputShapes:i.outputs.map(function(Ce){return Ce.shape})}),i.built=!0,i._refCount=1,i}return t.prototype.assertNotDisposed=function(){if(this._refCount===0)throw new Error("Container '"+this.name+"' is already disposed.")},t.prototype.dispose=function(){this.assertNotDisposed();var e={refCountAfterDispose:null,numDisposedVariables:0};if(--this._refCount===0){for(var i=0,r=this.layers;i<r.length;i++){var a=r[i];e.numDisposedVariables+=a.dispose().numDisposedVariables}for(var s=0,o=this.internalContainerRefs;s<o.length;s++){var l=o[s];e.numDisposedVariables+=l.dispose().numDisposedVariables}}return e.refCountAfterDispose=this._refCount,e},Object.defineProperty(t.prototype,"trainable",{get:function(){return this.trainable_},set:function(e){this.layers.forEach(function(i){i._trainableWeights.forEach(function(r){return r.trainable=e})}),this.trainable_=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"trainableWeights",{get:function(){if(this._trainableWeights.length>0)throw new M("Container instance unexpectedly contains _trainableWeights.The trainable weights of a Container are a union of the trainable weights of its consituent Layers. Its own _trainableWeights must remain an empty Array.");if(!this.trainable)return[];for(var e=[],i=0,r=this.layers;i<r.length;i++){var a=r[i];e=e.concat(a.trainableWeights)}return e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){for(var e=[],i=0,r=this.layers;i<r.length;i++){var a=r[i];e.push.apply(e,a.nonTrainableWeights)}if(!this.trainable){for(var s=[],o=0,l=this.layers;o<l.length;o++){var a=l[o];s.push.apply(s,a.trainableWeights)}return s.concat(e)}return e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"weights",{get:function(){return this.trainableWeights.concat(this.nonTrainableWeights)},enumerable:!0,configurable:!0}),t.prototype.loadWeights=function(e,i){i===void 0&&(i=!0);for(var r={},a=0,s=0,o=this.layers;s<o.length;s++)for(var l=o[s],u=0,c=l.weights;u<c.length;u++){var h=c[u];if(r[h.originalName]!=null)throw new M("Duplicate weight name: "+h.originalName);r[h.originalName]=h,a++}var d=[];for(var p in e){var f=p;if(r[p]==null){var m=p.split("/"),g=m.slice(0,-2).concat([m[m.length-1]]);f=g.join("/")}if(r[f]!=null)d.push([r[f],e[p]]);else if(i)throw new M("Provided weight data has no target variable: "+p);delete r[f]}if(i){var v=[];for(var b in r)v.push(b);if(v.length>0)throw new M(v.length+" of "+a+" weights are not set: "+(""+v))}ed(d)},t.prototype.updatedConfig=function(){var e=this.getConfig(),i={};return i.className=this.getClassName(),i.config=e,i.kerasVersion="tfjs-layers "+ld,i.backend="TensorFlow.js",i},t.prototype.toJSON=function(e,i){i===void 0&&(i=!0);var r=od(this.updatedConfig());return i?JSON.stringify(r):r},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){e=Je(e);for(var a=new aa,s=0;s<r.inputs.length;++s)a.add(r.inputs[s],e[s]);return os(r.outputs,a,i)})},t.prototype.computeMask=function(e,i){var r=this;return y.tidy(function(){e=Je(e);var a;return i==null?a=ur(null,e.length):a=Je(i),r.runInternalGraph(e,a)[1]})},t.prototype.computeOutputShape=function(e){var i=Co(e);if(i.length!==this.inputLayers.length)throw new M("Invalid inputShape argument "+e+": "+("model has "+this.inputLayers.length+" tensor inputs."));for(var r={},a=0;a<i.length;a++){var s=this.inputLayers[a],o=i[a],l=s.name+"_0_0";r[l]=o}var u=Object.keys(this.nodesByDepth).map(function(P){return parseInt(P,10)}).sort(Io);if(u.length>1)for(var c=0,h=u;c<h.length;c++)for(var d=h[c],p=this.nodesByDepth[d],f=0,m=p;f<m.length;f++){var g=m[f],s=g.outboundLayer;if(this.inputLayers.map(function(H){return H.id}).indexOf(s.id)!==-1)continue;for(var v=[],b=0;b<g.inboundLayers.length;b++){var w=g.inboundLayers[b],S=g.nodeIndices[b],L=g.tensorIndices[b],l=w.name+"_"+S+"_"+L,N=r[l];v.push(N)}for(var C=s.computeOutputShape(qt(v)),R=Co(C),D=s.inboundNodes.indexOf(g),b=0;b<R.length;b++){var l=s.name+"_"+D+"_"+b;r[l]=R[b]}}for(var k=[],W=[],a=0;a<this.outputLayers.length;a++){var s=this.outputLayers[a],D=this.outputLayersNodeIndices[a],L=this.outputLayersTensorIndices[a],l=s.name+"_"+D+"_"+L;W.push(l)}for(var a=0;a<W.length;a++){var F=W[a];_n(F in r),k.push(r[F])}return qt(k)},t.prototype.runInternalGraph=function(e,i){i==null&&(i=ur(null,e.length));for(var r={},a=0;a<this.inputs.length;++a){var s=this.inputs[a],o=e[a],l=i[a];r[s.id]=[o,l]}for(var u=Object.keys(this.nodesByDepth).map(function(ee){return parseInt(ee,10)}).sort(Io),c=0,h=u;c<h.length;c++)for(var d=h[c],p=this.nodesByDepth[d],f=0,m=p;f<m.length;f++){for(var g=m[f],v=g.outboundLayer,b=g.inputTensors,w=g.outputTensors,S=new Array,L=0,N=b;L<N.length;L++){var s=N[L];s.id in r&&S.push(r[s.id])}if(S.length===b.length){var C={},R=void 0,D=void 0,k=void 0,W=void 0;if(g.callArgs!=null&&(C=g.callArgs),S.length===1){var F=S[0],P=F[0],H=F[1];C.mask==null&&(C.mask=H),k=Je(v.call(P,C)),W=Je(v.computeMask(P,H)),R=[P],D=[H]}else R=S.map(function(ee){return ee[0]}),D=S.map(function(ee){return ee[1]}),C.mask==null&&(C.mask=D),k=Je(v.call(R,C)),W=Je(v.computeMask(R,D));if(v.activityRegularizer)throw new Te("LayersModel invocation with concrete Tensor value(s) in the presence of activity regularizer(s) is not supported yet.");for(var a=0;a<w.length;++a){var s=w[a],o=k[a],l=W[a];r[s.id]=[o,l]}}}for(var _=[],j=[],K=[],q=0,G=this.outputs;q<G.length;q++){var s=G[q];_n(s.id in r,"Could not compute output "+s.name+" : "+s.id);var Z=r[s.id],X=Z[0],l=Z[1];K.push(X.shape),_.push(X),j.push(l)}return[_,j,K]},t.prototype.buildNodeConversionMap=function(e){for(var i={},r,a=0,s=this.layers;a<s.length;a++){var o=s[a];r=o instanceof t?1:0;for(var l=0;l<o.inboundNodes.length;l++){var u=t.nodeKey(o,l);this.containerNodes.has(u)&&(i[u]=r,r+=1)}}return i},t.prototype.getLayer=function(e,i){if(i!=null){if(this.layers.length<=i)throw new M("Was asked to retrieve layer at index "+i+", but model only "+("has "+this.layers.length+" layer(s)."));return this.layers[i]}else if(e==null)throw new M("Provide either a layer name or layer index");for(var r=0,a=this.layers;r<a.length;r++){var s=a[r];if(s.name===e)return s}throw new M("No such layer: "+e)},t.prototype.calculateLosses=function(){var e=this;return y.tidy(function(){for(var i=[],r=0,a=e.layers;r<a.length;r++)for(var s=a[r],o=0;o<s.inboundNodes.length;++o){var l=t.nodeKey(s,o);e.containerNodes.has(l)&&i.push.apply(i,s.calculateLosses())}return i})},t.prototype.getConfig=function(){for(var e={name:this.name},i=this.buildNodeConversionMap(this.layers),r=[],a=0,s=this.layers;a<s.length;a++){for(var o=s[a],l=o.getClassName(),u=o.getConfig(),c=[],h=0;h<o.inboundNodes.length;h++){var d=o.inboundNodes[h],p=t.nodeKey(o,h),f={};if(this.containerNodes.has(p)){if(d.callArgs)try{JSON.stringify(d.callArgs),f=d.callArgs}catch(D){console.warn("Layer "+o.name+" was passed non-serializable keyword arguments: "+(d.callArgs+". They will not be included ")+"in the serialized model (and thus will be missing at deserialization time)."),f={}}if(d.inboundLayers.length>0){for(var m=[],g=0;g<d.inboundLayers.length;g++){var v=d.inboundLayers[g],b=d.nodeIndices[g],w=d.tensorIndices[g],S=t.nodeKey(v,b),L=i[S];L==null&&(L=0),m.push([v.name,L,w,f])}c.push(m)}}}var N={};N.name=o.name,N.className=l,N.config=u,N.inboundNodes=c,r.push(N)}e.layers=r;for(var C=[],g=0;g<this.inputLayers.length;g++){var o=this.inputLayers[g],b=this.inputLayersNodeIndices[g],p=t.nodeKey(o,b);if(!this.containerNodes.has(p))continue;var L=i[p];L==null&&(L=0);var w=this.inputLayersTensorIndices[g];C.push([o.name,L,w])}e.inputLayers=C;for(var R=[],g=0;g<this.outputLayers.length;g++){var o=this.outputLayers[g],b=this.outputLayersNodeIndices[g],p=t.nodeKey(o,b);if(!this.containerNodes.has(p))continue;var L=i[p];L==null&&(L=0);var w=this.outputLayersTensorIndices[g];R.push([o.name,L,w])}return e.outputLayers=R,e},t.fromConfig=function(e,i,r,a){a===void 0&&(a=!1);var s={},o={};function l(G,Z){G.name in o?o[G.name].push(Z):o[G.name]=[Z]}function u(G,Z){for(var X=[],ee,ne=0,ie=Z;ne<ie.length;ne++){var te=ie[ne],re=te[0],le=te[1],he=te[2];if(ee=te[3]==null?{}:te[3],!(re in s)){l(G,Z);return}var ye=s[re];if(ye.inboundNodes.length<=le){l(G,Z);return}var Oe=ye.inboundNodes[le];X.push(Oe.outputTensors[he])}X.length>0&&G.apply(qt(X),ee)}function c(G){var Z=G.name,X=An(G,i.customObjects!=null?i.customObjects:{});X.setFastWeightInitDuringBuild(a),s[Z]=X;var ee=G.inboundNodes;ee.forEach(function(ne){if(!(ne instanceof Array))throw new M("Corrupted configuration, expected array for nodeData: "+ne);l(X,ne)})}for(var h=i.name,d=i.layers,p=0,f=d;p<f.length;p++){var m=f[p];c(m)}for(;!Hk(o);)for(var g=0,v=d;g<v.length;g++){var m=v[g],b=s[m.name];if(b.name in o){var w=o[b.name];delete o[b.name];for(var S=0,L=w;S<L.length;S++){var N=L[S];u(b,N)}}}for(var C=[],R=[],D=i.inputLayers,k=0,W=D;k<W.length;k++){var m=W[k],F=m[0],P=m[1],H=m[2];_n(F in s);var b=s[F],_=b.inboundNodes[P].outputTensors;C.push(_[H])}for(var j=i.outputLayers,K=0,q=j;K<q.length;K++){var m=q[K],F=m[0],P=m[1],H=m[2];_n(F in s);var b=s[F],_=b.inboundNodes[P].outputTensors;R.push(_[H])}return new e({inputs:C,outputs:R,name:h})},Object.defineProperty(t.prototype,"stateful",{get:function(){if(this._stateful)throw new M("Container instance unexpectedly has _stateful = true. The statefulness of a Container is determined by the Layers it contains. Its _stateful property must remain the default false.");for(var e=0,i=this.layers;e<i.length;e++){var r=i[e];if(r.stateful)return!0}return!1},enumerable:!0,configurable:!0}),t.prototype.resetStates=function(){var e=this;y.tidy(function(){e.layers.forEach(function(i){i.stateful&&i.resetStates()})})},t}(De);function p4(n,t,e){var i=t.length;if(n==null||Array.isArray(n)&&n.length===0)return t.map(function(a){return null});if(i===1)return Array.isArray(n)&&n.length===1?n:typeof n=="object"&&t[0]in n?[n[t[0]]]:[n];if(Array.isArray(n)){if(n.length!==i)throw new Error("Provided "+e+" is an array of "+n.length+" "+("element(s), but the model has "+i+" outputs. ")+"Make sure a set of weights is provided for each model output.");return n}else if(typeof n=="object"&&Object.keys(n).length>0&&typeof n[Object.keys(n)[0]]=="object"){var r=[];return t.forEach(function(a){a in n?r.push(n[a]):r.push(null)}),r}else throw new Error("The model has multiple ("+i+") outputs, "+("so "+e+" must be either an array with ")+(i+" elements or an object with "+t+" keys. ")+("Provided "+e+" not understood: "+JSON.stringify(n)))}function eb(n,t){return p4(n,t,"classWeight")}function tb(n,t,e,i){return Se(this,void 0,void 0,function(){var r,a,s,o,l;return ve(this,function(u){switch(u.label){case 0:if(t!=null||i!=null)throw new Error("Support sampleWeight is not implemented yet");return e!=null?(r=y.tidy(function(){if(n.shape.length===1)return n.clone();if(n.shape.length===2)if(n.shape[1]>1){var c=1;return n.argMax(c)}else{if(n.shape[1]===1)return n.reshape([n.shape[0]]);throw new Error("Encountered unexpected last-dimension size ("+n.shape[1]+") during handling of class weights. The size is expected to be >= 1.")}else throw new Error("Unexpected rank of target (y) tensor ("+n.rank+") during handling of class weights. The rank is expected to be 1 or 2.")}),o=(s=Array).from,[4,r.data()]):[3,2];case 1:return a=o.apply(s,[u.sent()]),y.dispose(r),l=[],a.forEach(function(c){if(e[c]==null)throw new Error("classWeight must contain all classes in the training data. "+("The class "+c+" exists in the data but not in ")+"classWeight");l.push(e[c])}),[2,y.tensor1d(l,"float32")];case 2:return[2,null]}})})}function f4(n,t){return y.mul(n,t)}var m4=32;function ib(n,t){var e,i,r=t;e=r.xs,i=r.ys,y.util.assert(e!=null&&i!=null,function(){return"A Dataset iterator for fitDataset() is expected to generate objects of the form `{xs: xVal, ys: yVal}`, where the two values may be `tf.Tensor`, an array of Tensors, or a map of string to Tensor. The provided Dataset instead generates "+(""+t)});var a=nb("input",n.inputNames,e),s=nb("output",n.outputNames,i),o=a[0].shape[0];y.util.assert(a.length===n.inputs.length,function(){return"LayersModel has "+n.inputs.length+" inputs, but the dataset "+("provides "+a.length+" inputs. (Expected input keys: ")+(JSON.stringify(n.inputNames)+")")}),y.util.assert(s.length===n.outputs.length,function(){return"LayersModel has "+n.outputs.length+" outputs, but the dataset "+("provides "+s.length+" outputs. (Expected output keys: ")+(JSON.stringify(n.outputNames)+")")});for(var l=function(d){y.util.assert(a[d].shape[0]===o,function(){return"Batch size mismatch: input "+(n.inputNames[d]+" has "+a[d].shape[0]+"; ")+("expected "+o+" based on input "+n.inputNames[0]+".")})},u=0;u<a.length;u++)l(u);for(var c=function(d){y.util.assert(s[d].shape[0]===o,function(){return"Batch size mismatch: output "+(n.outputNames[d]+" has "+s[d].shape[0]+"; ")+("expected "+o+" based on input "+n.inputNames[0]+".")})},h=0;h<s.length;h++)c(h);return{xs:a,ys:s}}function nb(n,t,e){if(e instanceof y.Tensor)return[e];if(Array.isArray(e))return y.util.assert(e.length===t.length,function(){return"Received an array of "+e.length+" Tensors, but expected "+t.length+" to match the "+n+" keys "+t+"."}),e;for(var i=[],r=0,a=t;r<a.length;r++){var s=a[r];if(e[s]==null)throw new M("The feature data generated by the dataset lacks the required "+(n+" key '"+s+"'."));i.push(e[s])}return i}function g4(n){if(n.length===3)throw new Te("Validation with sample weights is not implemented yet.");return{xs:n[0],ys:n[1]}}function y4(n,t,e){return Se(this,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h,d,p,f,m,g,v,b,w,S,L,N,C,R,D,k,W,F,P,H,_,j,F,K,q,G,Z,F;return ve(this,function(X){switch(X.label){case 0:if(i=e.batchesPerEpoch!=null,y.util.assert(n.optimizer!=null,function(){return"You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig)."}),y.util.assert(e!=null,function(){return"For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call."}),y.util.assert(e.epochs!=null&&e.epochs>0&&Number.isInteger(e.epochs),function(){return"For fitDataset(), config.epochs is expected to be a positive "+("integer, but got "+e.epochs)}),y.util.assert(!i||e.batchesPerEpoch>0&&Number.isInteger(e.batchesPerEpoch),function(){return"For fitDataset(), config.batchesPerEpoch is expected to be a "+("positive integer if specified, but got "+e.batchesPerEpoch)}),y.util.assert(e.validationSplit==null,function(){return"`validationSplit` is not supported by `fitDataset()`. Use validationData instead."}),n.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");n.isTraining=!0,X.label=1;case 1:return X.trys.push([1,,26,27]),r=e.validationData!=null,a=void 0,s=void 0,r&&(rb(e.validationData)?y.util.assert(e.validationBatches==null||e.validationBatches>0&&Number.isInteger(e.validationBatches),function(){return"For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, "+("but got "+e.validationBatches)}):(o=g4(e.validationData),a=o.xs,s=o.ys)),l=n.makeTrainFunction(),u=n.getDedupedMetricsNames(),c=void 0,r?c=u.slice().concat(u.map(function(ee){return"val_"+ee})):c=u.slice(),h=My(e.callbacks,e.yieldEvery),d=e.verbose==null?1:e.verbose,p=Vy(h,d,e.epochs,null,null,v4(t,e),null,r,c),f=p.callbackList,m=p.history,f.setModel(n),n.history=m,[4,f.onTrainBegin()];case 2:return X.sent(),n.stopTraining_=!1,g=e.initialEpoch==null?0:e.initialEpoch,[4,t.iterator()];case 3:v=X.sent(),X.label=4;case 4:return g<e.epochs?(b={},[4,f.onEpochBegin(g)]):[3,23];case 5:return X.sent(),w=0,S=0,i?[3,7]:[4,t.iterator()];case 6:v=X.sent(),X.label=7;case 7:return(i?w<e.batchesPerEpoch:!0)?[4,v.next()]:[3,21];case 8:return L=X.sent(),i&&L.done?(console.warn("You provided `batchesPerEpoch` as "+(e.batchesPerEpoch+", ")+"but your dataset iterator ran out of data after "+(w+" batches; ")+"interrupting training. Make sure that your dataset can generate at least `batchesPerEpoch * epochs` batches (in this case, "+(e.batchesPerEpoch*e.epochs+" batches). ")+"You may need to use the repeat() function when building your dataset."),[3,21]):L.value!=null?(N=ib(n,L.value),C=N.xs,R=N.ys,D={},D.batch=S,D.size=C[0].shape[0],[4,f.onBatchBegin(S,D)]):[3,15];case 9:if(X.sent(),k=[],!(e.classWeight!=null))return[3,13];W=eb(e.classWeight,n.outputNames),F=0,X.label=10;case 10:return F<W.length?(H=(P=k).push,[4,tb(R[F],null,W[F])]):[3,13];case 11:H.apply(P,[X.sent()]),X.label=12;case 12:return++F,[3,10];case 13:for(_=C.concat(R).concat(k),j=l(_),y.dispose(_),F=0;F<u.length;++F)K=u[F],q=j[F],D[K]=q,y.keep(q);return[4,f.onBatchEnd(S,D)];case 14:X.sent(),Uy(D),S++,w++,X.label=15;case 15:return(i?w>=e.batchesPerEpoch:L.done)?r?(G=void 0,rb(e.validationData)?(Z=Je,[4,n.evaluateDataset(e.validationData,{batches:e.validationBatches})]):[3,17]):[3,19]:[3,20];case 16:return G=Z.apply(void 0,[X.sent()]),[3,18];case 17:G=Je(n.evaluate(a,s,{batchSize:e.validationBatchSize==null?m4:e.validationBatchSize,verbose:0})),X.label=18;case 18:for(F=0;F<n.metricsNames.length;++F)b["val_"+n.metricsNames[F]]=G[F];X.label=19;case 19:return[3,21];case 20:return n.stopTraining_?[3,21]:[3,7];case 21:return[4,f.onEpochEnd(g,b)];case 22:return X.sent(),g++,n.stopTraining_?[3,23]:[3,4];case 23:return[4,f.onTrainEnd()];case 24:return X.sent(),[4,n.history.syncData()];case 25:return X.sent(),[2,n.history];case 26:return n.isTraining=!1,[7];case 27:return[2]}})})}function v4(n,t){var e=null;return t.batchesPerEpoch!=null?e=t.batchesPerEpoch:Number.isFinite(n.size)&&(e=n.size),e}function rb(n){return typeof n.iterator=="function"}function b4(n){return typeof n.next=="function"}function w4(n,t,e){return Se(this,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h,d,p;return ve(this,function(f){switch(f.label){case 0:if(e=e||{},i=e.batches!=null,r=n.testFunction,a=[],e.verbose>0)throw new Te("Verbose mode is not implemented yet.");return y.util.assert(!i||e.batches>0&&Number.isInteger(e.batches),function(){return"Test loop expects `batches` to be a positive integer, but "+("received "+JSON.stringify(e.batches))}),b4(t)?(o=t,[3,3]):[3,1];case 1:return[4,t.iterator()];case 2:o=f.sent(),f.label=3;case 3:s=o,l=0,u=0,c=function(){var m;return ve(this,function(g){switch(g.label){case 0:return[4,s.next()];case 1:return m=g.sent(),a=y.tidy(function(){if(m.value){var v=ib(n,m.value),b=v.xs,w=v.ys,S=b.concat(w),L=y.tidy(function(){return r(S)});if(y.dispose(S),u===0)for(var N=0;N<L.length;++N)a.push(y.scalar(0));for(var C=S[0].shape[0],R=function(D){var k=L[D],W=a[D];a[D]=y.tidy(function(){return y.add(a[D],y.mul(C,k))}),u>0&&y.dispose(W)},N=0;N<L.length;++N)R(N);y.dispose(L),l+=C,++u}return a}),m.done?(i&&console.warn("Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least `batches` "+("batches (in this case, "+e.batches+" batches). ")+"You may need to use the repeat() function when building your dataset."),[2,"break"]):[2]}})},f.label=4;case 4:return(i?u<e.batches:!0)?[5,c()]:[3,6];case 5:return h=f.sent(),h==="break"?[3,6]:[3,4];case 6:for(d=0;d<a.length;++d)p=a[d],a[d]=y.div(a[d],l),y.dispose(p);return[2,qt(a)]}})})}function cd(n){y.util.assert(n>0&&Number.isInteger(n),function(){return"batchSize is required to be a positive integer, but got "+n})}function ls(n,t,e){return n==null?[null]:Array.isArray(n)?n.map(function(i){return dr(i,t,e-t)}):dr(n,t,e-t)}function hd(n,t){return y.tidy(function(){return n==null?null:Array.isArray(n)?n.map(function(e){return hd(e,t)}):wy(n,t.dtype==="int32"?t:t.toInt())})}function dd(n,t){for(var e=[],i=0,r=null;i<n;)r=i+t,r>=n&&(r=n),e.push([i,r]),i=r;return e}function S4(n,t,e,i,r,a,s,o,l,u,c,h,d,p,f){return Se(this,void 0,void 0,function(){var m,g,v,b,w,S,L,N,C;return ve(this,function(R){switch(R.label){case 0:if(r==null&&(r=32),a==null&&(a=1),c==null&&(c=!0),d==null&&(d=0),m=!1,l!=null&&u!=null&&(m=!0),f!=null&&(m=!0,p==null))throw new M("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");return g=n.checkNumSamples(e,r,p,"steps_per_epoch"),g!=null&&(v=Ln(0,g)),s==null&&(s=1),b=Vy(o,s,a,d,g,p,r,m,h),w=b.callbackList,S=b.history,w.setModel(n),n.history=S,[4,w.onTrainBegin()];case 1:R.sent(),n.stopTraining_=!1,L=function(D){var k,W,F,P,H,_;return ve(this,function(j){switch(j.label){case 0:return[4,w.onEpochBegin(D)];case 1:if(j.sent(),k={},!(p!=null))return[3,2];throw new Te("stepsPerEpoch mode is not implemented yet.");case 2:if(c==="batch")throw new Te("batch shuffling is not implemneted yet");c&&y.util.shuffle(v),W=y.tensor1d(v),F=dd(g,r),P=function(K){var q;return ve(this,function(G){switch(G.label){case 0:return q={},[4,w.onBatchBegin(K,q)];case 1:return G.sent(),y.tidy(function(){var Z=F[K][0],X=F[K][1],ee=dr(W,Z,X-Z);q.batch=K,q.size=X-Z;for(var ne=hd(e,ee),ie=t(ne),te=0;te<i.length;++te){var re=i[te],le=ie[te];q[re]=le,y.keep(le)}if(K===F.length-1&&m)for(var he=n.testLoop(l,u,r),te=0;te<i.length;++te){var re=i[te],le=he[te];y.keep(le),k["val_"+re]=le}}),[4,w.onBatchEnd(K,q)];case 2:return G.sent(),Uy(q),n.stopTraining_?[2,"break"]:[2]}})},H=0,j.label=3;case 3:return H<F.length?[5,P(H)]:[3,6];case 4:if(_=j.sent(),_==="break")return[3,6];j.label=5;case 5:return++H,[3,3];case 6:W.dispose(),j.label=7;case 7:return[4,w.onEpochEnd(D,k)];case 8:return j.sent(),n.stopTraining_?[2,"break"]:[2]}})},N=d,R.label=2;case 2:return N<a?[5,L(N)]:[3,5];case 3:if(C=R.sent(),C==="break")return[3,5];R.label=4;case 4:return++N,[3,2];case 5:return[4,w.onTrainEnd()];case 6:return R.sent(),[4,n.history.syncData()];case 7:return R.sent(),[2,n.history]}})})}function L4(n,t,e,i){return i===void 0&&(i={}),Se(this,void 0,void 0,function(){var r,a,s,o,l,u,c,h,d,p,f,m,g,v,b,w,S,L,N,C,R,D,k;return ve(this,function(W){switch(W.label){case 0:if(n.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");n.isTraining=!0,W.label=1;case 1:return W.trys.push([1,,7,8]),h=i.batchSize==null?32:i.batchSize,cd(h),d=!1,[4,n.standardizeUserData(t,e,i.sampleWeight,i.classWeight,d,h)];case 2:if(p=W.sent(),r=p[0],a=p[1],c=p[2],f=!1,m=void 0,!(i.validationData!=null&&i.validationData.length>0))return[3,4];if(f=!0,i.validationData.length===2)s=i.validationData[0],o=i.validationData[1];else throw i.validationData.length===3?new Te("validationData including sample weights is not supported yet."):new M("When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; "+(i.validationData+" is invalid."));return g=!0,[4,n.standardizeUserData(s,o,null,null,g,h)];case 3:return v=W.sent(),l=v[0],u=v[1],m=l.concat(u),[3,5];case 4:i.validationSplit!=null&&i.validationSplit>0&&i.validationSplit<1?(f=!0,b=Math.floor(r[0].shape[0]*(1-i.validationSplit)),w=r[0].shape[0],l=ls(r,b,w),r=ls(r,0,b),u=ls(a,b,w),a=ls(a,0,b),m=l.concat(u)):i.validationSteps!=null&&(f=!0),W.label=5;case 5:return S=r.concat(a).concat(c),n.checkTrainableWeightsConsistency(),L=n.makeTrainFunction(),N=n.getDedupedMetricsNames(),C=void 0,R=void 0,f?(n.makeTestFunction(),C=n.testFunction,R=N.slice().concat(N.map(function(F){return"val_"+F}))):(C=null,m=[],R=N.slice()),D=My(i.callbacks,i.yieldEvery),[4,S4(n,L,S,N,h,i.epochs,i.verbose,D,C,m,i.shuffle,R,i.initialEpoch,null,null)];case 6:return k=W.sent(),[2,k];case 7:return n.isTraining=!1,fr(r,t),fr(a,e),fr(l,s),fr(u,o),c!=null&&y.dispose(c),[7];case 8:return[2]}})})}function ab(n){var t=[];n instanceof y.Tensor&&(n=[n]);for(var e=0;e<n.length;++e){var i=n[e];if(i.rank===1)t.push(ts(i,1));else{if(i.rank===0)throw new Error("Expected tensor to be at least 1D, but received a 0D tensor (scalar).");t.push(i)}}return t}function fr(n,t){if(n==null)return;var e=[];if(t instanceof y.Tensor)e.push(t.id);else if(Array.isArray(t))t.forEach(function(l){return e.push(l.id)});else if(t!=null)for(var i in t){var r=t[i];e.push(r.id)}var a=[];if(n instanceof y.Tensor)e.indexOf(n.id)===-1&&a.push(n);else if(Array.isArray(n))n.forEach(function(l){e.indexOf(l.id)===-1&&a.push(l)});else if(n!=null)for(var s in n){var o=n[s];e.indexOf(o.id)===-1&&a.push(o)}a.forEach(function(l){l.isDisposed||l.dispose()})}function I4(n){return n instanceof y.Tensor}function pd(n){return Array.isArray(n)}function sb(n){return!I4(n)&&!pd(n)}function ob(n,t,e,i,r){if(i===void 0&&(i=!0),r===void 0&&(r=""),t==null||t.length===0){if(n!=null){var a=!1;if(pd(n)&&n.length>0)a=!0;else if(sb(n)){for(var s in n)if(n.hasOwnProperty(s)){a=!0;break}}else a=!0;if(a)throw new M("Error when checking model "+r+" expected no data, "+("but got "+n))}return[]}if(n==null)return t.map(function(g){return null});var o;if(sb(n)){n=n,o=[];for(var l=0,u=t;l<u.length;l++){var c=u[l];if(n[c]==null)throw new M('No data provided for "'+c+'". Need data for each key in: '+(""+t));o.push(n[c])}}else if(pd(n)){if(n=n,n.length!==t.length)throw new M("Error when checking model "+r+": the Array of Tensors that you are passing to your model is not the size the "+("model expected. Expected to see "+t.length+" Tensor(s), but ")+("instead got the following list of Tensor(s): "+n));o=n}else{if(n=n,t.length>1)throw new M("The model "+r+" expects "+t.length+" Tensor(s), "+("but only received one Tensor. Found: Tensor with shape "+n.shape));o=[n]}if(o=ab(o),e!=null)for(var h=0;h<t.length;++h){if(e[h]==null)continue;var d=o[h];if(d.shape.length!==e[h].length)throw new M("Error when checking "+r+": expected "+t[h]+" "+("to have "+e[h].length+" dimension(s). but got array with ")+("shape "+d.shape));for(var p=0;p<e[h].length;++p){if(p===0&&!i)continue;var f=d.shape[p],m=e[h][p];if(m!=null&&m>=0&&f!==m)throw new M("Error when checking "+r+": expected "+t[h]+" "+("to have shape ["+e[h]+"], but got array with shape ")+("["+d.shape+"]."))}}return o}function A4(n,t,e){var i=Ti(n.map(function(a){return a.shape[0]}));i.sort();var r=Ti(t.map(function(a){return a.shape[0]}));if(r.sort(),i.length>1)throw new M("All input Tensors (x) should have the same number of samples. Got array shapes: "+(""+JSON.stringify(n.map(function(a){return a.shape}))));if(r.length>1)throw new M("All target Tensors (y) should have the same number of samples. Got array shapes: "+(""+JSON.stringify(t.map(function(a){return a.shape}))));if(i.length>0&&r.length>0&&!y.util.arraysEqual(i,r))throw new M("Input Tensors should have the same number of samples as target "+("Tensors. Found "+i[0]+" input sample(s) and "+r[0]+" target ")+"sample(s).")}function T4(n,t,e){for(var i=[pr,Fo,as],r=0;r<n.length;++r){var a=n[r],s=t[r],o=e[r];if(s==null)continue;if(s===as&&a.shape[a.shape.length-1]===1)throw new M("You are passing a target array of shape "+a.shape+" while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].");if(i.indexOf(s)!==-1)for(var l=a.shape.slice(1),u=o.slice(1),c=0;c<l.length;++c){var h=l[c],d=u[c];if(d!=null&&h!==d)throw new M("A target Tensor with shape "+a.shape+" was passed for an "+("output of shape "+o+", while using a loss function that ")+"expects targets to have the same shape as the output.")}}}function lb(n,t,e,i,r){i===void 0&&(i=!0),r===void 0&&(r="");var a;if(Array.isArray(n)){if(n.length!==t.length)throw new M("Error when checking model "+r+": the Array of Tensors that you are passing to your model is not the size the "+("the model expected. Expected to see "+t.length+" Tensor(s),")+(" but instead got "+n.length+" Tensors(s)."));a=n}else{if(t.length>1)throw new M("The model expects "+t.length+" "+r+" Tensors, but only received one Tensor. Found: array with shape "+(JSON.stringify(n.shape)+"."));a=[n]}if(e!=null)for(var s=0;s<t.length;++s){if(e[s]==null)continue;var o=a[s];if(o.shape.length!==e[s].length)throw new M("Error when checking "+r+": expected "+t[s]+" "+("to have "+e[s].length+" dimension(s), but got array with ")+("shape "+JSON.stringify(o.shape)));for(var l=0;l<e[s].length;++l){if(l===0&&!i)continue;var u=o.shape[l],c=e[s][l];if(c!=null&&c!==u)throw new M("Error when checking "+r+": expected "+(t[s]+" to have shape "+JSON.stringify(e[s])+" but ")+("got array with shape "+JSON.stringify(o.shape)+"."))}}}function N4(n,t){if(n==null||Array.isArray(n)&&n.length===0)return t.map(function(l){return[]});var e;if(typeof n=="string"||typeof n=="function")e=[n];else if(Array.isArray(n)||typeof n=="object")e=n;else throw new TypeError("Type of metrics argument not understood. Expected an string,"+("function, Array, or Object, found: "+n));if(Array.isArray(e))return t.map(function(l){return e});for(var i=[],r=0,a=t;r<a.length;r++){var s=a[r],o=e.hasOwnProperty(s)?e[s]:[];Array.isArray(o)||(o=[o]),i.push(o)}return i}var x4="layers-model",Ri=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.isTraining=!1,i}return t.prototype.summary=function(e,i,r){if(r===void 0&&(r=console.log),!this.built)throw new M("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data).");o4(this,e,i,r)},t.prototype.compile=function(e){var i=this;if(e.loss==null&&(e.loss=[]),this.loss=e.loss,typeof e.optimizer=="string")this.optimizer_=n4(e.optimizer),this.isOptimizerOwned=!0;else{if(!(e.optimizer instanceof y.Optimizer))throw new M("User-defined optimizer must be an instance of tf.Optimizer.");this.optimizer_=e.optimizer,this.isOptimizerOwned=!1}var r=[];if(!Array.isArray(e.loss)&&typeof e.loss!="string"&&typeof e.loss!="function"){e.loss=e.loss;for(var a in e.loss)if(this.outputNames.indexOf(a)===-1)throw new M('Unknown entry in loss dictionary: "'+a+'". '+("Only expected the following keys: "+this.outputNames));for(var s=0,o=this.outputNames;s<o.length;s++){var l=o[s];e.loss[l]==null&&console.warn('Output "'+l+'" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data '+("to be passed to "+l+" during training")),r.push(nd(e.loss[l]))}}else if(Array.isArray(e.loss)){if(e.loss.length!==this.outputs.length)throw new M("When passing an Array as loss, it should have one entry per "+("model output. The model has "+this.outputs.length+" output(s), ")+("but you passed loss="+e.loss+"."));var u=e.loss;r=u.map(function(v){return nd(v)})}else{var c=nd(e.loss);this.outputs.forEach(function(v){r.push(c)})}this.lossFunctions=r,this.feedOutputNames=[],this.feedOutputShapes=[],this.feedLossFns=[];for(var h=0;h<this.outputs.length;++h){var d=this.internalOutputShapes[h],p=this.outputNames[h];this.feedOutputNames.push(p),this.feedOutputShapes.push(d),this.feedLossFns.push(this.lossFunctions[h])}var f=[];this.metrics=e.metrics,this.metricsNames=["loss"],this.metricsTensors=[],hr("loss",function(){for(var v=0;v<i.outputs.length;++v){if(f.indexOf(v)!==-1)continue;var b=i.lossFunctions[v];i.outputs.length>1&&(i.metricsTensors.push([b,v]),i.metricsNames.push(i.outputNames[v]+"_loss"))}});var m=N4(e.metrics,this.outputNames),g=function(v,b,w){i.outputNames.length>1&&(b=i.outputNames[v]+"_"+b),i.metricsNames.push(b),i.metricsTensors.push([w,v])};hr("metric",function(){for(var v=function(w){if(f.indexOf(w)!==-1)return"continue";var S=m[w],L=function(N){for(var C="",R,D,k,W=function(_){if(typeof _=="string"&&["accuracy","acc","crossentropy","ce"].indexOf(_)!==-1){var j=i.internalOutputShapes[w];j[j.length-1]===1||i.lossFunctions[w]===Fo?["accuracy","acc"].indexOf(_)!==-1?D=id:["crossentropy","ce"].indexOf(_)!==-1&&(D=Yy):i.lossFunctions[w]===ko?["accuracy","acc"].indexOf(_)!==-1?D=jy:["crossentropy","ce"].indexOf(_)!==-1&&(D=Ky):["accuracy","acc"].indexOf(_)!==-1?D=rd:["crossentropy","ce"].indexOf(_)!==-1&&(D=ad);var K=void 0;["accuracy","acc"].indexOf(_)!==-1?K="acc":["crossentropy","ce"].indexOf(_)!==-1&&(K="ce"),k=D,R=C+K}else{var q=t4(_);k=q,R=C+Bo(_)}var G;hr(R,function(){G=k}),g(w,R,G)},F=0,P=N;F<P.length;F++){var H=P[F];W(H)}};L(S)},b=0;b<i.outputs.length;++b)v(b)}),this.collectedTrainableWeights=this.trainableWeights},t.prototype.checkTrainableWeightsConsistency=function(){if(this.collectedTrainableWeights==null)return;this.trainableWeights.length!==this.collectedTrainableWeights.length&&console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?")},t.prototype.evaluate=function(e,i,r){r===void 0&&(r={});var a=r.batchSize==null?32:r.batchSize;cd(a);var s=!0,o=this.standardizeUserDataXY(e,i,s,a);try{var l=o[0].concat(o[1]);this.makeTestFunction();var u=this.testFunction,c=this.testLoop(u,l,a,r.verbose,r.steps);return qt(c)}finally{fr(o[0],e),fr(o[1],i)}},t.prototype.evaluateDataset=function(e,i){return Se(this,void 0,void 0,function(){return ve(this,function(r){return this.makeTestFunction(),[2,w4(this,e,i)]})})},t.prototype.checkNumSamples=function(e,i,r,a){a===void 0&&(a="steps");var s;if(r!=null){if(s=null,i!=null)throw new M("If "+a+" is set, batchSize must be null or undefined."+("Got batchSize = "+i))}else if(e!=null)Array.isArray(e)?s=e[0].shape[0]:s=e.shape[0];else throw new M("Either the input data should have a defined shape, or "+(a+" shoud be specified."));return s},t.prototype.execute=function(e,i){if(Array.isArray(i)&&i.length===0)throw new M("`outputs` is an empty Array, which is not allowed.");var r=Array.isArray(i),a=r?i:[i],s=this.retrieveSymbolicTensors(a),o=new aa;if(e instanceof y.Tensor&&(e=[e]),Array.isArray(e)){if(e.length!==this.inputs.length)throw new M("The number of inputs provided ("+e.length+") does not match the number of inputs of this model "+("("+this.inputs.length+")."));for(var l=0;l<this.inputs.length;++l)o.add(this.inputs[l],e[l])}else for(var u=0,c=this.inputs;u<c.length;u++){var h=c[u],d=e[h.name];if(d==null)throw new M("No value is provided for the model's input "+h.name);o.add(h,d)}var p=os(s,o);return r?p:p[0]},t.prototype.retrieveSymbolicTensors=function(e){for(var i=ur(null,e.length),r=e.length,a=0,s=this.layers;a<s.length;a++){for(var o=s[a],l=Array.isArray(o.output)?o.output:[o.output],u=l.map(function(p){return p.name}),c=0;c<e.length;++c){var h=u.indexOf(e[c]);if(h!==-1&&(i[c]=l[h],r--),r===0)break}if(r===0)break}if(r>0){var d=[];throw i.forEach(function(p,f){p==null&&d.push(e[f])}),new M("Cannot find SymbolicTensors for output name(s): "+(""+JSON.stringify(d)))}return i},t.prototype.predictLoop=function(e,i,r){var a=this;return i===void 0&&(i=32),r===void 0&&(r=!1),y.tidy(function(){var s=a.checkNumSamples(e);if(r)throw new Te("Verbose predictLoop() is not implemented yet.");for(var o=dd(s,i),l=a.outputs.map(function(h){return[]}),u=function(h){var d=y.tidy(function(){var p=o[h][0],f=o[h][1],m=ls(e,p,f),g=[];if(Array.isArray(m))for(var v=0;v<m.length;++v)g.push({key:a.inputs[v],value:m[v]});else g.push({key:a.inputs[0],value:m});var b=new aa(g);return os(a.outputs,b)});d.forEach(function(p,f){return l[f].push(p)})},c=0;c<o.length;++c)u(c);return qt(l.map(function(h){return y.concat(h,0)}))})},t.prototype.predict=function(e,i){i===void 0&&(i={});var r=ab(e);lb(r,this.inputNames,this.feedInputShapes,!1);try{var a=i.batchSize==null?32:i.batchSize;return cd(a),this.predictLoop(r,a)}finally{fr(r,e)}},t.prototype.predictOnBatch=function(e){lb(e,this.inputNames,this.feedInputShapes,!0);var i=(Array.isArray(e)?e[0]:e).shape[0];return this.predictLoop(e,i)},t.prototype.standardizeUserDataXY=function(e,i,r,a){if(this.optimizer_==null)throw new Pn("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).");for(var s=[],o=0;o<this.feedOutputShapes.length;++o){var l=this.feedOutputShapes[o],u=this.feedLossFns[o];u===ko?s.push(l.slice(0,l.length-1).concat([1])):s.push(l)}if(e=ob(e,this.feedInputNames,this.feedInputShapes,!1,"input"),i=ob(i,this.feedOutputNames,s,!1,"target"),A4(e,i),T4(i,this.feedLossFns,this.feedOutputShapes),this.stateful&&a!=null&&a>0&&e[0].shape[0]%a!==0)throw new M("In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size "+(a+". Found: "+e[0].shape[0]+" sample(s)."));return[e,i]},t.prototype.standardizeUserData=function(e,i,r,a,s,o){return s===void 0&&(s=!0),Se(this,void 0,void 0,function(){var l,u,c,h,d,p,f,m;return ve(this,function(g){switch(g.label){case 0:if(l=this.standardizeUserDataXY(e,i,s,o),u=l[0],c=l[1],r!=null)throw new Error("sample weight is not supported yet.");if(h=null,!(a!=null))return[3,4];d=eb(a,this.outputNames),h=[],p=0,g.label=1;case 1:return p<d.length?(m=(f=h).push,[4,tb(c[p],null,d[p])]):[3,4];case 2:m.apply(f,[g.sent()]),g.label=3;case 3:return++p,[3,1];case 4:return[2,[u,c,h]]}})})},t.prototype.testLoop=function(e,i,r,a,s){var o=this;return a===void 0&&(a=0),y.tidy(function(){var l=o.checkNumSamples(i,r,s,"steps"),u=[];if(a>0)throw new Te("Verbose mode is not implemented yet.");if(s!=null)throw new Te("steps mode in testLoop() is not implemented yet");for(var c=dd(l,r),h=y.tensor1d(Ln(0,l)),d=0;d<c.length;++d){var p=c[d][0],f=c[d][1],m=dr(h,p,f-p),g=hd(i,m),v=e(g);if(d===0)for(var b=0;b<v.length;++b)u.push(y.scalar(0));for(var b=0;b<v.length;++b){var w=v[b];u[b]=y.add(u[b],y.mul(f-p,w))}}for(var b=0;b<u.length;++b)u[b]=y.div(u[b],l);return u})},t.prototype.getDedupedMetricsNames=function(){for(var e=this.metricsNames,i=[],r=0;r<e.length;++r){var a=e[r],s=a;if(ry(e,a)>1){var o=ry(e.slice(0,r),a);s+="_"+o}i.push(s)}return i},t.prototype.makeTrainFunction=function(){var e=this;return function(i){var r=[],a=i.slice(0,e.inputs.length),s=i.slice(e.inputs.length,e.inputs.length+e.outputs.length),o=i.slice(e.inputs.length+e.outputs.length,e.inputs.length+e.outputs.length*2),l=[],u=function(){for(var p=[],f=0;f<e.inputs.length;++f)p.push({key:e.inputs[f],value:a[f]});for(var m=new aa(p),g=os(e.outputs,m,{training:!0}),v,f=0;f<e.lossFunctions.length;++f){var b=e.lossFunctions[f],w=b(s[f],g[f]);o[f]!=null&&(w=f4(w,o[f]));var S=y.mean(w);r.push(S),f===0?v=w:v=y.add(v,w)}for(var f=0;f<e.metricsTensors.length;++f){var L=void 0;if(e.outputs.length>1&&f<e.outputs.length)L=r[f];else{var N=e.metricsTensors[f][0],C=e.metricsTensors[f][1];L=y.mean(N(s[C],g[C]))}y.keep(L),l.push(L)}return v=y.mean(v),e.calculateLosses().forEach(function(R){v=y.add(v,R)}),v},c=e.collectedTrainableWeights.map(function(p){return p.read()}),h=!0,d=e.optimizer_.minimize(u,h,c);return[d].concat(l)}},t.prototype.makeTestFunction=function(){var e=this;this.testFunction=function(i){return y.tidy(function(){for(var r=[],a,s=i.slice(0,e.inputs.length),o=i.slice(e.inputs.length,e.inputs.length+e.outputs.length),l=[],u=0;u<e.inputs.length;++u)l.push({key:e.inputs[u],value:s[u]});for(var c=new aa(l),h=os(e.outputs,c),u=0;u<e.lossFunctions.length;++u){var d=e.lossFunctions[u],p=y.mean(d(o[u],h[u]));u===0?a=p:a=y.add(a,p),r.push(a)}for(var u=0;u<e.metricsTensors.length;++u){var f=e.metricsTensors[u][0],m=e.metricsTensors[u][1],g=y.mean(f(o[m],h[m]));r.push(g)}return r})}},t.prototype.fit=function(e,i,r){return r===void 0&&(r={}),Se(this,void 0,void 0,function(){return ve(this,function(a){return[2,L4(this,e,i,r)]})})},t.prototype.fitDataset=function(e,i){return Se(this,void 0,void 0,function(){return ve(this,function(r){return[2,y4(this,e,i)]})})},t.prototype.trainOnBatch=function(e,i){return Se(this,void 0,void 0,function(){var r,a,s,o,l,u,c,h,d,p;return ve(this,function(f){switch(f.label){case 0:return[4,this.standardizeUserData(e,i)];case 1:r=f.sent(),a=r[0],s=r[1],o=this.makeTrainFunction(),l=o(a.concat(s)),u=[],c=0,h=l,f.label=2;case 2:return c<h.length?(d=h[c],[4,d.data()]):[3,5];case 3:p=f.sent(),u.push(p[0]),f.label=4;case 4:return c++,[3,2];case 5:return y.dispose(l),[2,qt(u)]}})})},t.prototype.getNamedWeights=function(e){for(var i=[],r=e!=null&&e.trainableOnly,a=r?this.trainableWeights:this.weights,s=this.getWeights(r),o=0;o<a.length;++o){if(r&&!a[o].trainable)continue;i.push({name:a[o].originalName,tensor:s[o]})}return i},Object.defineProperty(t.prototype,"stopTraining",{get:function(){return this.stopTraining_},set:function(e){this.stopTraining_=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"optimizer",{get:function(){return this.optimizer_},set:function(e){this.optimizer_!==e&&(this.optimizer_=e,this.isOptimizerOwned=!1)},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){var e=n.prototype.dispose.call(this);if(e.refCountAfterDispose===0&&this.optimizer!=null&&this.isOptimizerOwned){var i=y.memory().numTensors;this.optimizer_.dispose(),e.numDisposedVariables+=i-y.memory().numTensors}return e},t.prototype.getLossIdentifiers=function(){var e;if(typeof this.loss=="string")e=ai(this.loss);else if(Array.isArray(this.loss)){for(var i=0,r=this.loss;i<r.length;i++){var a=r[i];if(typeof a!="string")throw new Error("Serialization of non-string loss is not supported.")}e=this.loss.map(function(h){return ai(h)})}else{var s=Object.keys(this.loss);e={};for(var o=this.loss,l=0,u=s;l<u.length;l++){var c=u[l];if(typeof o[c]=="string")e[c]=ai(o[c]);else throw new Error("Serialization of non-string loss is not supported.")}}return e},t.prototype.getMetricIdentifiers=function(){if(typeof this.metrics=="string"||typeof this.metrics=="function")return[ai(Bo(this.metrics))];if(Array.isArray(this.metrics))return this.metrics.map(function(r){return ai(Bo(r))});var e={};for(var i in this.metrics)e[i]=ai(Bo(this.metrics[i]));return e},t.prototype.getTrainingConfig=function(){return{loss:this.getLossIdentifiers(),metrics:this.getMetricIdentifiers(),optimizer_config:{class_name:this.optimizer.getClassName(),config:this.optimizer.getConfig()}}},t.prototype.loadTrainingConfig=function(e){if(e.weighted_metrics!=null)throw new Error("Loading weight_metrics is not supported yet.");if(e.loss_weights!=null)throw new Error("Loading loss_weights is not supported yet.");if(e.sample_weight_mode!=null)throw new Error("Loading sample_weight_mode is not supported yet.");var i=ss(e.optimizer_config),r=An(i),a;if(typeof e.loss=="string")a=cr(e.loss);else if(Array.isArray(e.loss))a=e.loss.map(function(l){return cr(l)});else if(e.loss!=null){a={};for(var s in e.loss)a[s]=cr(e.loss[s])}var o;if(Array.isArray(e.metrics))o=e.metrics.map(function(l){return cr(l)});else if(e.metrics!=null){o={};for(var s in e.metrics)o[s]=cr(e.metrics[s])}this.compile({loss:a,metrics:o,optimizer:r})},t.prototype.save=function(e,i){return Se(this,void 0,void 0,function(){var r,a,s,o,l,u,c,h,d,p,f,m,g,v,b;return ve(this,function(w){switch(w.label){case 0:if(typeof e=="string"){if(r=y.io.getSaveHandlers(e),r.length===0)throw new M("Cannot find any save handlers for URL '"+e+"'");if(r.length>1)throw new M("Found more than one ("+r.length+") save handlers for "+("URL '"+e+"'"));e=r[0]}if(e.save==null)throw new M("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");return[4,y.io.encodeWeights(this.getNamedWeights(i))];case 1:return a=w.sent(),s=!1,o=null,l=this.toJSON(o,s),u={modelTopology:l,format:x4,generatedBy:"TensorFlow.js tfjs-layers v"+ld,convertedBy:null},c=i==null?!1:i.includeOptimizer,c&&this.optimizer!=null?(u.trainingConfig=this.getTrainingConfig(),h="optimizer",g=(m=y.io).encodeWeights,[4,this.optimizer.getWeights()]):[3,4];case 2:return[4,g.apply(m,[w.sent(),h])];case 3:d=w.sent(),p=d.data,f=d.specs,(b=a.specs).push.apply(b,f),a.data=y.io.concatenateArrayBuffers([a.data,p]),w.label=4;case 4:return this.userDefinedMetadata!=null&&(v=!0,Xy(this.userDefinedMetadata,this.name,v),u.userDefinedMetadata=this.userDefinedMetadata),u.weightData=a.data,u.weightSpecs=a.specs,[2,e.save(u)]}})})},t.prototype.setUserDefinedMetadata=function(e){Xy(e,this.name),this.userDefinedMetadata=e},t.prototype.getUserDefinedMetadata=function(){return this.userDefinedMetadata},t.className="Model",t}(d4);y.serialization.registerClass(Ri);var C4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.className="Functional",t}(Ri);y.serialization.registerClass(C4);function R4(n,t){return Se(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u;return ve(this,function(c){switch(c.label){case 0:return"modelTopology"in n||(n={modelTopology:n}),n=n,e=n.modelTopology,e.model_config!=null&&(e=e.model_config),i=ss(e),r=An(i,t),n.weightsManifest!=null?[4,y.io.loadWeights(n.weightsManifest,n.pathPrefix,r.weights.map(function(h){return h.originalName}))]:[3,2];case 1:for(a=c.sent(),s={},o=0,l=r.weights;o<l.length;o++)u=l[o],s[u.originalName]=a[u.originalName];r.loadWeights(s),y.dispose(a),c.label=2;case 2:return[2,r]}})})}function E4(n,t){return Se(this,void 0,void 0,function(){var e;return ve(this,function(i){if(t==null&&(t={}),typeof n=="string"){if(e=y.io.getLoadHandlers(n,t),e.length===0)e.push(y.io.browserHTTPRequest(n,t));else if(e.length>1)throw new M("Found more than one ("+e.length+") load handlers for "+("URL '"+n+"'"));n=e[0]}return[2,O4(n,void 0,t)]})})}function O4(n,t,e){return Se(this,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h;return ve(this,function(d){switch(d.label){case 0:if(e==null&&(e={}),n.load==null)throw new M("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");return[4,n.load()];case 1:if(i=d.sent(),r=i.modelTopology,r.model_config!=null&&(r=r.model_config),a=e.strict==null?!0:e.strict,s=i.weightData!=null&&i.weightSpecs!=null&&a,o=An(ss(r),t,s),l=i.trainingConfig,l!=null&&o.loadTrainingConfig(l),i.userDefinedMetadata!=null&&o.setUserDefinedMetadata(i.userDefinedMetadata),!(i.weightData!=null))return[3,4];if(i.weightSpecs==null)throw new M("LayersModel artifacts contains weight data, but not weight specs. Therefore loading of weights cannot proceed.");return u=D4(i.weightData,i.weightSpecs),c=u.modelWeights,h=u.optimizerWeights,o.loadWeights(c,a),o.optimizer!=null&&h.length>0?[4,o.optimizer.setWeights(h)]:[3,3];case 2:d.sent(),d.label=3;case 3:y.dispose(c),y.dispose(h.map(function(p){return p.tensor})),d.label=4;case 4:return[2,o]}})})}function D4(n,t){var e=y.io.decodeWeights(n,t),i={},r=[];return t.forEach(function(a){a.group==="optimizer"?r.push({name:a.name,tensor:e[a.name]}):i[a.name]=e[a.name]}),{modelWeights:i,optimizerWeights:r}}var fd=function(n){Q(t,n);function t(e){var i=n.call(this,{inputs:[],outputs:[]})||this;if(e=e||{},i.trainable=!0,i.built=!1,i.name=e.name!=null?e.name:xo("sequential_"),e.layers!=null)for(var r=0,a=e.layers;r<a.length;r++){var s=a[r];i.add(s)}return i}return t.prototype.checkShape=function(e){var i=e.inboundNodes[0].outputTensors[0].shape;if(i.some(function(r){return r<0}))throw new M("Negative dimension size caused by adding layer "+(e.name+" with input shape [")+(e.inboundNodes[0].inputTensors[0].shape+"]"))},t.prototype.add=function(e){var i=e instanceof t||e instanceof Ri,r;if(i){if(r=e,r.outputs.length!==1)throw new M("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");if(r.inputs.length!==1)throw new M("All layers in a Sequential model should have a single input tensor. For multi-input layers, use the functional API.")}if(this.outputs.length===0){if(e.inboundNodes.length===0){if(e.batchInputShape==null)throw new M("The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument.");var a=Wy({batchShape:e.batchInputShape,dtype:e.dtype,name:e.name+"_input"});e.apply(a)}if(i)this.outputs=r.outputs,this.inputs=r.inputs;else{if(e.inboundNodes.length!==1)throw new M("A layer added to a Sequential model must not already be "+("connected somewhere else. LayersModel received layer "+e.name+" ")+("which has "+e.inboundNodes.length+" pre-existing inbound ")+"connections.");if(e.inboundNodes[0].outputTensors.length!==1)throw new M("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");this.checkShape(e),this.outputs=[e.inboundNodes[0].outputTensors[0]],this.inputs=Fy(this.outputs[0])}this.inboundNodes=[],new Oo({outboundLayer:this,inboundLayers:[],nodeIndices:[],tensorIndices:[],inputTensors:this.inputs,outputTensors:this.outputs,inputMasks:ur(null,this.inputs.length),outputMasks:[null],inputShapes:this.inputs.map(function(o){return o.shape}),outputShapes:this.outputs[0].shape})}else{var s=e.apply(this.outputs[0]);if(Array.isArray(s))throw new TypeError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");this.checkShape(e),this.outputs=[s],this.inboundNodes[0].outputTensors=this.outputs,this.inboundNodes[0].outputShapes=[this.outputs[0].shape]}this.layers.push(e),this.built=!1},t.prototype.pop=function(){if(this.layers.length===0)throw new TypeError("There are no layers in the model.");if(this.layers.pop(),this.layers.length===0)this.outputs=[],this.inboundNodes=[],this.outboundNodes=[];else{var e=this.layers.length-1;this.layers[e].outboundNodes=[],this.outputs=[this.layers[e].output],this.inboundNodes[0].outputTensors=this.outputs,this.inboundNodes[0].outputShapes=[this.outputs[0].shape]}},t.prototype.call=function(e,i){return this.model==null&&this.build(),this.model.call(e,i)},t.prototype.build=function(e){if(je(e),this.inputs.length===0||this.outputs.length===0)throw new TypeError("Sequential model cannot be built: model is empty. Add some layers first.");this.model=new Ri({inputs:this.inputs,outputs:this.outputs[0],name:this.name+"_model"}),this.model.trainable=this.trainable,this.supportsMasking=this.model.supportsMasking,this.inputLayers=this.model.inputLayers,this.inputLayersNodeIndices=this.model.inputLayersNodeIndices,this.inputLayersTensorIndices=this.model.inputLayersTensorIndices,this.outputLayers=this.model.outputLayers,this.outputLayersNodeIndices=this.model.outputLayersNodeIndices,this.outputLayersTensorIndices=this.model.outputLayersTensorIndices,this.nodesByDepth=this.model.nodesByDepth,this.containerNodes=this.model.containerNodes,this.outputNames=this.model.outputNames,this.inputNames=this.model.inputNames,this.built=!0},t.prototype.countParams=function(){return this.built||this.build(),n.prototype.countParams.call(this)},t.prototype.summary=function(e,i,r){r===void 0&&(r=console.log),this.built||this.build(),n.prototype.summary.call(this,e,i,r)},t.prototype.setWeights=function(e){this.model==null&&this.build(),this.model.setWeights(e)},t.prototype.evaluate=function(e,i,r){if(r===void 0&&(r={}),!this.built)throw new Pn("The model needs to be compiled before being used.");return this.model.evaluate(e,i,r)},t.prototype.evaluateDataset=function(e,i){return Se(this,void 0,void 0,function(){return ve(this,function(r){if(!this.built)throw new Pn("The model needs to be compiled before being used.");return[2,this.model.evaluateDataset(e,i)]})})},t.prototype.predict=function(e,i){return i===void 0&&(i={}),this.model==null&&this.build(),this.model.predict(e,i)},t.prototype.predictOnBatch=function(e){return this.model==null&&this.build(),this.model.predictOnBatch(e)},t.prototype.compile=function(e){this.build(),this.model.compile(e),this.optimizer_=this.model.optimizer,this.isOptimizerOwned=this.model.isOptimizerOwned,this.loss=this.model.loss,this.metrics=this.model.metrics,this.metricsTensors=this.model.metricsTensors,this.metricsNames=this.model.metricsNames},Object.defineProperty(t.prototype,"optimizer",{get:function(){return this.model==null?void 0:this.model.optimizer},set:function(e){this.model.optimizer=e},enumerable:!0,configurable:!0}),t.prototype.fit=function(e,i,r){return r===void 0&&(r={}),Se(this,void 0,void 0,function(){return ve(this,function(a){if(!this.built)throw new Pn("The model needs to be compiled before being used.");return[2,this.model.fit(e,i,r)]})})},t.prototype.fitDataset=function(e,i){return Se(this,void 0,void 0,function(){return ve(this,function(r){if(!this.built)throw new Pn("The model needs to be compiled before being used.");return[2,this.model.fitDataset(e,i)]})})},t.prototype.trainOnBatch=function(e,i){return Se(this,void 0,void 0,function(){return ve(this,function(r){return[2,this.model.trainOnBatch(e,i)]})})},t.fromConfig=function(e,i,r,a){a===void 0&&(a=!1);var s,o={};if(i instanceof Array){if(!(i[0].className!=null)||i[0].className==="Merge")throw new M("Legacy serialization format not supported yet.");s=i}else y.util.assert(i.layers!=null,function(){return"When the config data for a Sequential model is not an Array, it must be an Object that contains the 'layers' field."}),s=i.layers,delete i.layers,o=i;var l=new e(o);if(!(l instanceof t))throw new Te("Sequential.fromConfig called on non-Sequential input: "+l);for(var u=0,c=s;u<c.length;u++){var h=c[u],d=void 0,p=An(h,d,a);a&&p.setFastWeightInitDuringBuild(!0),l.add(p)}return l},Object.defineProperty(t.prototype,"stopTraining",{get:function(){if(this.model==null)throw new M("Cannot get the stopTraining property of a sequential model before it is compiled.");return this.model.stopTraining},set:function(e){if(this.model==null)throw new M("Cannot set the stopTraining property of a sequential model before it is compiled.");this.model.stopTraining=e},enumerable:!0,configurable:!0}),t.prototype.getConfig=function(){for(var e=[],i=0,r=this.layers;i<r.length;i++){var a=r[i],s={};s.className=a.getClassName(),s.config=a.getConfig(),e.push(s)}return{name:this.name,layers:e}},t.className="Sequential",t}(Ri);y.serialization.registerClass(fd);function k4(n){return new Ri(n)}function F4(n){return new fd(n)}function W4(n,t){return t==null&&(t={}),E4(n,t)}function ub(n){return Wy(n)}function U4(n,t){Hy.registerCallbackConstructor(n,t)}var Jt=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.getConfig=function(){return{}},t}(y.serialization.Serializable),B4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e,i){return i===void 0&&(i=1),a3(e,i)},t.className="elu",t}(Jt);y.serialization.registerClass(B4);var z4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return y.selu(e)},t.className="selu",t}(Jt);y.serialization.registerClass(z4);var P4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return y.relu(e)},t.className="relu",t}(Jt);y.serialization.registerClass(P4);var _4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return y.tidy(function(){return y.minimum(6,y.relu(e))})},t.className="relu6",t}(Jt);y.serialization.registerClass(_4);var M4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return e},t.className="linear",t}(Jt);y.serialization.registerClass(M4);var H4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return y.sigmoid(e)},t.className="sigmoid",t}(Jt);y.serialization.registerClass(H4);var V4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return o3(e)},t.className="hardSigmoid",t}(Jt);y.serialization.registerClass(V4);var q4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return y.softplus(e)},t.className="softplus",t}(Jt);y.serialization.registerClass(q4);var G4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return s3(e)},t.className="softsign",t}(Jt);y.serialization.registerClass(G4);var Y4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e){return y.tanh(e)},t.className="tanh",t}(Jt);y.serialization.registerClass(Y4);var cb=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e,i){return i===void 0&&(i=-1),y.softmax(e,i)},t.className="softmax",t}(Jt);y.serialization.registerClass(cb);var j4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e,i){return i===void 0&&(i=-1),y.logSoftmax(e,i)},t.className="logSoftmax",t}(Jt);y.serialization.registerClass(j4);var K4=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.apply=function(e,i){return i===void 0&&(i=1),y.tidy(function(){return y.sigmoid(e.mul(i)).mul(e)})},t.className="swish",t}(Jt);y.serialization.registerClass(K4);function Oi(n){return n.getClassName()}function md(n,t){return t===void 0&&(t={}),Ja(n,y.serialization.SerializationMap.getMap().classNameMap,t,"activation")}function Ei(n){if(n==null){var t={};return t.className="linear",t.config={},md(t)}if(typeof n=="string"){var t={};return t.className=n,t.config={},md(t)}else return n instanceof Jt?n:md(n)}function gd(n){if(n!=null&&typeof n!="object")throw new Error("Argument to L1L2 regularizer's constructor is expected to be an "+("object, but received: "+n))}var hb=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t}(y.serialization.Serializable),Po=function(n){Q(t,n);function t(e){var i=n.call(this)||this;return gd(e),i.l1=e==null||e.l1==null?.01:e.l1,i.l2=e==null||e.l2==null?.01:e.l2,i.hasL1=i.l1!==0,i.hasL2=i.l2!==0,i}return t.prototype.apply=function(e){var i=this;return y.tidy(function(){var r=y.zeros([1]);return i.hasL1&&(r=y.add(r,y.sum(y.mul(i.l1,y.abs(e))))),i.hasL2&&(r=y.add(r,y.sum(y.mul(i.l2,ns(e))))),r.asScalar()})},t.prototype.getConfig=function(){return{l1:this.l1,l2:this.l2}},t.fromConfig=function(e,i){return new e({l1:i.l1,l2:i.l2})},t.className="L1L2",t}(hb);y.serialization.registerClass(Po);function $4(n){return gd(n),new Po({l1:n!=null?n.l1:null,l2:0})}function X4(n){return gd(n),new Po({l2:n!=null?n.l2:null,l1:0})}var db={l1l2:"L1L2"};function Ke(n){return Bh(n)}function pb(n,t){return t===void 0&&(t={}),Ja(n,y.serialization.SerializationMap.getMap().classNameMap,t,"regularizer")}function nt(n){if(n==null)return null;if(typeof n=="string"){var t=n in db?db[n]:n,e={className:t,config:{}};return pb(e)}else return n instanceof hb?n:pb(n)}var fb=function(n){Q(t,n);function t(e){var i=n.call(this,e??{})||this;return i.supportsMasking=!0,e!=null&&(i.maxValue=e.maxValue),i}return t.prototype.call=function(e,i){e=xe(e);var r=y.relu(e);return this.maxValue!=null&&(r=y.clipByValue(r,0,this.maxValue)),r},t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e={maxValue:this.maxValue},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="ReLU",t}(De);y.serialization.registerClass(fb);var mb=function(n){Q(t,n);function t(e){var i=n.call(this,e??{})||this;return i.DEFAULT_ALPHA=.3,e==null&&(e={}),i.alpha=e.alpha==null?i.DEFAULT_ALPHA:e.alpha,i}return t.prototype.call=function(e,i){var r=xe(e);return y.leakyRelu(r,this.alpha)},t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e={alpha:this.alpha},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="LeakyReLU",t}(De);y.serialization.registerClass(mb);var gb=function(n){Q(t,n);function t(e){var i=n.call(this,e??{})||this;if(i.DEFAULT_ALPHA_INITIALIZER="zeros",e==null&&(e={}),i.supportsMasking=!0,i.alphaInitializer=tt(e.alphaInitializer||i.DEFAULT_ALPHA_INITIALIZER),i.alphaRegularizer=nt(e.alphaRegularizer),i.alphaConstraint=wt(e.alphaConstraint),e.sharedAxes==null)i.sharedAxes=null;else if(Array.isArray(e.sharedAxes))i.sharedAxes=e.sharedAxes;else if(typeof e.sharedAxes=="number")i.sharedAxes=[e.sharedAxes];else throw new M("Expected sharedAxes to be a number or an array of numbers, "+("but got "+e.sharedAxes));return i}return t.prototype.build=function(e){e=je(e);var i=e.slice(1);if(this.sharedAxes!=null)for(var r=0,a=this.sharedAxes;r<a.length;r++){var s=a[r];i[s-1]=1}this.alpha=this.addWeight("alpha",i,"float32",this.alphaInitializer,this.alphaRegularizer,!0,this.alphaConstraint);var o={};if(this.sharedAxes!=null)for(var s=1;s<e.length;++s)o[s]=e[s];this.inputSpec=[new Nt({ndim:e.length,axes:o})],this.built=!0},t.prototype.call=function(e,i){return e=xe(e),y.prelu(e,this.alpha.read())},t.prototype.getConfig=function(){var e={alphaInitializer:st(this.alphaInitializer),alphaRegularizer:Ke(this.alphaRegularizer),alphaConstraint:bt(this.alphaConstraint),sharedAxes:this.sharedAxes},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="PReLU",t}(De);y.serialization.registerClass(gb);var vb=function(n){Q(t,n);function t(e){var i=n.call(this,e??{})||this;if(i.DEFAULT_ALPHA=1,e==null&&(e={}),e.alpha!=null&&e.alpha!==i.DEFAULT_ALPHA)throw new Te("Non-default alpha value ("+e.alpha+") is not supported by the ELU layer yet.");return i.alpha=e.alpha==null?i.DEFAULT_ALPHA:e.alpha,i}return t.prototype.call=function(e,i){var r=xe(e);return y.elu(r)},t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e={alpha:this.alpha},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="ELU",t}(De);y.serialization.registerClass(vb);var yb=function(n){Q(t,n);function t(e){var i=n.call(this,e??{})||this;return i.DEFAULT_THETA=1,e==null&&(e={}),i.theta=e.theta==null?i.DEFAULT_THETA:e.theta,i}return t.prototype.call=function(e,i){var r=xe(e);return r.mul(es(r.greater(this.theta),"float32"))},t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e={theta:this.theta},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="ThresholdedReLU",t}(De);y.serialization.registerClass(yb);var bb=function(n){Q(t,n);function t(e){var i=n.call(this,e??{})||this;return i.DEFAULT_AXIS=1,e==null&&(e={}),i.softmax=new cb().apply,i.axis=e.axis==null?i.DEFAULT_AXIS:e.axis,i}return t.prototype.call=function(e,i){var r=xe(e);return this.softmax(r,this.axis)},t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e={axis:this.axis},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Softmax",t}(De);y.serialization.registerClass(bb);function sa(n,t,e){if(typeof n=="number")return ur(n,t);if(n.length!==t)throw new M("The "+e+" argument must be an integer or tuple of "+t+" integers."+(" Received: "+n.length+" elements."));for(var i=0;i<t;++i){var r=n[i];if(!t3(r))throw new M("The "+e+" argument must be an integer or tuple of "+t+(" integers. Received: "+JSON.stringify(n)+" including a")+(" non-integer number "+r))}return n}function Tn(n,t,e,i,r){if(r===void 0&&(r=1),n==null)return n;var a=t+(t-1)*(r-1),s;return e==="same"?s=n:s=n-a+1,Math.floor((s+i-1)/i)}function _o(n,t,e,i){if(n==null)return null;if(i==="valid")n=n*t+xi([e-t,0]);else if(i==="same")n=n*t;else throw new M("Unsupport padding mode: "+i+".");return n}function vd(n,t){return y.tidy(function(){return ht(t),t==="channelsFirst"?y.transpose(n,[0,2,3,1]):n})}function wb(n,t){return y.tidy(function(){return ht(t),t==="channelsFirst"?y.transpose(n,[0,2,3,4,1]):n})}function J4(n,t,e,i,r,a,s){return i===void 0&&(i=1),r===void 0&&(r="valid"),s===void 0&&(s=1),y.tidy(function(){if(a==null&&(a=Sn()),ht(a),n.shape.length!==3)throw new M("The input of a conv1dWithBias operation should be 3, but is "+(n.shape.length+" instead."));if(t.shape.length!==3)throw new M("The kernel for a conv1dWithBias operation should be 3, but is "+(t.shape.length+" instead"));if(e!=null&&e.shape.length!==1)throw new M("The bias for a conv1dWithBias operation should be 1, but is "+(t.shape.length+" instead"));if(a==="channelsFirst"&&(n=y.transpose(n,[0,2,1])),r==="causal")throw new Te("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");var o=y.conv1d(n,t,i,r==="same"?"same":"valid","NWC",s);return e!=null&&(o=Hn(o,e)),o})}function Sb(n,t,e,i,r,a,s,o){return i===void 0&&(i=[1,1]),r===void 0&&(r="valid"),o===void 0&&(o=null),y.tidy(function(){if(a==null&&(a=Sn()),ht(a),n.rank!==3&&n.rank!==4)throw new M("conv2dWithBiasActivation expects input to be of rank 3 or 4, "+("but received "+n.rank+"."));if(t.rank!==3&&t.rank!==4)throw new M("conv2dWithBiasActivation expects kernel to be of rank 3 or 4, "+("but received "+n.rank+"."));var l=vd(n,a);if(r==="causal")throw new Te("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");return l=y.fused.conv2d({x:l,filter:t,strides:i,pad:r==="same"?"same":"valid",dilations:s,dataFormat:"NHWC",bias:e,activation:o}),a==="channelsFirst"&&(l=y.transpose(l,[0,3,1,2])),l})}function Z4(n,t,e,i,r,a,s){return i===void 0&&(i=[1,1,1]),r===void 0&&(r="valid"),y.tidy(function(){if(a==null&&(a=Sn()),ht(a),n.rank!==4&&n.rank!==5)throw new M("conv3dWithBias expects input to be of rank 4 or 5, but received "+(n.rank+"."));if(t.rank!==4&&t.rank!==5)throw new M("conv3dWithBias expects kernel to be of rank 4 or 5, but received "+(n.rank+"."));var o=wb(n,a);if(r==="causal")throw new Te("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet.");return o=y.conv3d(o,t,i,r==="same"?"same":"valid","NDHWC",s),e!=null&&(o=Hn(o,e)),a==="channelsFirst"&&(o=y.transpose(o,[0,4,1,2,3])),o})}var Lb=function(n){Q(t,n);function t(e,i){var r=n.call(this,i)||this;if(r.bias=null,r.DEFAULT_KERNEL_INITIALIZER="glorotNormal",r.DEFAULT_BIAS_INITIALIZER="zeros",t.verifyArgs(i),r.rank=e,Tt(r.rank,"rank"),r.rank!==1&&r.rank!==2&&r.rank!==3)throw new Te("Convolution layer for rank other than 1, 2, or 3 ("+r.rank+") is not implemented yet.");if(r.kernelSize=sa(i.kernelSize,e,"kernelSize"),r.strides=sa(i.strides==null?1:i.strides,e,"strides"),r.padding=i.padding==null?"valid":i.padding,sn(r.padding),r.dataFormat=i.dataFormat==null?"channelsLast":i.dataFormat,ht(r.dataFormat),r.activation=Ei(i.activation),r.useBias=i.useBias==null?!0:i.useBias,r.biasInitializer=tt(i.biasInitializer||r.DEFAULT_BIAS_INITIALIZER),r.biasConstraint=wt(i.biasConstraint),r.biasRegularizer=nt(i.biasRegularizer),r.activityRegularizer=nt(i.activityRegularizer),r.dilationRate=sa(i.dilationRate==null?1:i.dilationRate,e,"dilationRate"),r.rank===1&&Array.isArray(r.dilationRate)&&r.dilationRate.length!==1)throw new M("dilationRate must be a number or an array of a single number for 1D convolution, but received "+(""+JSON.stringify(r.dilationRate)));if(r.rank===2){if(typeof r.dilationRate=="number")r.dilationRate=[r.dilationRate,r.dilationRate];else if(r.dilationRate.length!==2)throw new M("dilationRate must be a number or array of two numbers for 2D "+("convolution, but received "+JSON.stringify(r.dilationRate)))}else if(r.rank===3){if(typeof r.dilationRate=="number")r.dilationRate=[r.dilationRate,r.dilationRate,r.dilationRate];else if(r.dilationRate.length!==3)throw new M("dilationRate must be a number or array of three numbers for 3D "+("convolution, but received "+JSON.stringify(r.dilationRate)))}return r}return t.verifyArgs=function(e){if(_n("kernelSize"in e,"required key 'kernelSize' not in config"),typeof e.kernelSize!="number"&&!Ph(e.kernelSize,"number",1,3))throw new M("BaseConv expects config.kernelSize to be number or number[] with "+("length 1, 2, or 3, but received "+JSON.stringify(e.kernelSize)+"."))},t.prototype.getConfig=function(){var e={kernelSize:this.kernelSize,strides:this.strides,padding:this.padding,dataFormat:this.dataFormat,dilationRate:this.dilationRate,activation:Oi(this.activation),useBias:this.useBias,biasInitializer:st(this.biasInitializer),biasRegularizer:Ke(this.biasRegularizer),activityRegularizer:Ke(this.activityRegularizer),biasConstraint:bt(this.biasConstraint)},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t}(De),Mo=function(n){Q(t,n);function t(e,i){var r=n.call(this,e,i)||this;return r.kernel=null,t.verifyArgs(i),r.filters=i.filters,Tt(r.filters,"filters"),r.kernelInitializer=tt(i.kernelInitializer||r.DEFAULT_KERNEL_INITIALIZER),r.kernelConstraint=wt(i.kernelConstraint),r.kernelRegularizer=nt(i.kernelRegularizer),r}return t.prototype.build=function(e){var i;e=je(e);var r=this.dataFormat==="channelsFirst"?1:e.length-1;if(e[r]==null)throw new M("The channel dimension of the input should be defined. "+("Found "+e[r]));var a=e[r],s=this.kernelSize.concat([a,this.filters]);this.kernel=this.addWeight("kernel",s,null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[{ndim:this.rank+2,axes:(i={},i[r]=a,i)}],this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){e=xe(e);var a,s=r.bias==null?null:r.bias.read(),o=sy(r.activation.getClassName());if(o!=null&&r.rank===2)a=Sb(e,r.kernel.read(),s,r.strides,r.padding,r.dataFormat,r.dilationRate,o);else{if(r.rank===1)a=J4(e,r.kernel.read(),s,r.strides[0],r.padding,r.dataFormat,r.dilationRate[0]);else if(r.rank===2)a=Sb(e,r.kernel.read(),s,r.strides,r.padding,r.dataFormat,r.dilationRate);else if(r.rank===3)a=Z4(e,r.kernel.read(),s,r.strides,r.padding,r.dataFormat,r.dilationRate);else throw new Te("convolutions greater than 3D are not implemented yet.");r.activation!=null&&(a=r.activation.apply(a))}return a})},t.prototype.computeOutputShape=function(e){e=je(e);for(var i=[],r=this.dataFormat==="channelsLast"?e.slice(1,e.length-1):e.slice(2),a=0;a<r.length;++a){var s=Tn(r[a],this.kernelSize[a],this.padding,this.strides[a],typeof this.dilationRate=="number"?this.dilationRate:this.dilationRate[a]);i.push(s)}var o=[e[0]];return this.dataFormat==="channelsLast"?(o=o.concat(i),o.push(this.filters)):(o.push(this.filters),o=o.concat(i)),o},t.prototype.getConfig=function(){var e={filters:this.filters,kernelInitializer:st(this.kernelInitializer),kernelRegularizer:Ke(this.kernelRegularizer),kernelConstraint:bt(this.kernelConstraint)},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.verifyArgs=function(e){if(!("filters"in e)||typeof e.filters!="number"||e.filters<1)throw new M("Convolution layer expected config.filters to be a 'number' > 0 "+("but got "+JSON.stringify(e.filters)))},t}(Lb),yd=function(n){Q(t,n);function t(e){var i=n.call(this,2,e)||this;return t.verifyArgs(e),i}return t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this);return delete e.rank,e},t.verifyArgs=function(e){if(typeof e.kernelSize!="number"&&!Ph(e.kernelSize,"number",1,2))throw new M("Conv2D expects config.kernelSize to be number or number[] with "+("length 1 or 2, but received "+JSON.stringify(e.kernelSize)+"."))},t.className="Conv2D",t}(Mo);y.serialization.registerClass(yd);var Ib=function(n){Q(t,n);function t(e){var i=n.call(this,3,e)||this;return t.verifyArgs(e),i}return t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this);return delete e.rank,e},t.verifyArgs=function(e){if(typeof e.kernelSize!="number"&&!(Array.isArray(e.kernelSize)&&(e.kernelSize.length===1||e.kernelSize.length===3)))throw new M("Conv3D expects config.kernelSize to be number or"+(" [number, number, number], but received "+JSON.stringify(e.kernelSize)+"."))},t.className="Conv3D",t}(Mo);y.serialization.registerClass(Ib);var Ab=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;if(i.inputSpec=[new Nt({ndim:4})],i.padding!=="same"&&i.padding!=="valid")throw new M("Conv2DTranspose currently supports only padding modes 'same' "+("and 'valid', but received padding mode "+i.padding));return i}return t.prototype.build=function(e){var i;if(e=je(e),e.length!==4)throw new M("Input should have rank 4; Received input shape: "+JSON.stringify(e));var r=this.dataFormat==="channelsFirst"?1:e.length-1;if(e[r]==null)throw new M("The channel dimension of the inputs should be defined. Found `None`.");var a=e[r],s=this.kernelSize.concat([this.filters,a]);this.kernel=this.addWeight("kernel",s,"float32",this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[new Nt({ndim:4,axes:(i={},i[r]=a,i)})],this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=xe(e);if(a.shape.length!==4)throw new M("Conv2DTranspose.call() expects input tensor to be rank-4, but "+("received a tensor of rank-"+a.shape.length));var s=a.shape,o=s[0],l,u;r.dataFormat==="channelsFirst"?(l=2,u=3):(l=1,u=2);var c=s[l],h=s[u],d=r.kernelSize[0],p=r.kernelSize[1],f=r.strides[0],m=r.strides[1],g=_o(c,f,d,r.padding),v=_o(h,m,p,r.padding),b=[o,g,v,r.filters];r.dataFormat!=="channelsLast"&&(a=y.transpose(a,[0,2,3,1]));var w=y.conv2dTranspose(a,r.kernel.read(),b,r.strides,r.padding);return r.dataFormat!=="channelsLast"&&(w=y.transpose(w,[0,3,1,2])),r.bias!=null&&(w=Hn(w,r.bias.read(),r.dataFormat)),r.activation!=null&&(w=r.activation.apply(w)),w})},t.prototype.computeOutputShape=function(e){e=je(e);var i=e.slice(),r,a,s;this.dataFormat==="channelsFirst"?(r=1,a=2,s=3):(r=3,a=1,s=2);var o=this.kernelSize[0],l=this.kernelSize[1],u=this.strides[0],c=this.strides[1];return i[r]=this.filters,i[a]=_o(i[a],u,o,this.padding),i[s]=_o(i[s],c,l,this.padding),i},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this);return delete e.dilationRate,e},t.className="Conv2DTranspose",t}(yd);y.serialization.registerClass(Ab);var Q4=function(n){Q(t,n);function t(e,i){var r=n.call(this,e,i)||this;if(r.DEFAULT_DEPTHWISE_INITIALIZER="glorotUniform",r.DEFAULT_POINTWISE_INITIALIZER="glorotUniform",r.depthwiseKernel=null,r.pointwiseKernel=null,i.filters==null)throw new M("The `filters` configuration field is required by SeparableConv, but is unspecified.");if(i.kernelInitializer!=null||i.kernelRegularizer!=null||i.kernelConstraint!=null)throw new M("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead.");if(i.padding!=null&&i.padding!=="same"&&i.padding!=="valid")throw new M("SeparableConv"+r.rank+"D supports only padding modes: "+("'same' and 'valid', but received "+JSON.stringify(i.padding)));return r.depthMultiplier=i.depthMultiplier==null?1:i.depthMultiplier,r.depthwiseInitializer=tt(i.depthwiseInitializer||r.DEFAULT_DEPTHWISE_INITIALIZER),r.depthwiseRegularizer=nt(i.depthwiseRegularizer),r.depthwiseConstraint=wt(i.depthwiseConstraint),r.pointwiseInitializer=tt(i.depthwiseInitializer||r.DEFAULT_POINTWISE_INITIALIZER),r.pointwiseRegularizer=nt(i.pointwiseRegularizer),r.pointwiseConstraint=wt(i.pointwiseConstraint),r}return t.prototype.build=function(e){var i;if(e=je(e),e.length<this.rank+2)throw new M("Inputs to SeparableConv"+this.rank+"D should have rank "+(this.rank+2+", but received input shape: ")+(""+JSON.stringify(e)));var r=this.dataFormat==="channelsFirst"?1:e.length-1;if(e[r]==null||e[r]<0)throw new M("The channel dimension of the inputs should be defined, "+("but found "+JSON.stringify(e[r])));for(var a=e[r],s=this.kernelSize.concat([a,this.depthMultiplier]),o=[],l=0;l<this.rank;++l)o.push(1);o.push(a*this.depthMultiplier,this.filters);var u=!0;this.depthwiseKernel=this.addWeight("depthwise_kernel",s,"float32",this.depthwiseInitializer,this.depthwiseRegularizer,u,this.depthwiseConstraint),this.pointwiseKernel=this.addWeight("pointwise_kernel",o,"float32",this.pointwiseInitializer,this.pointwiseRegularizer,u,this.pointwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,u,this.biasConstraint):this.bias=null,this.inputSpec=[new Nt({ndim:this.rank+2,axes:(i={},i[r]=a,i)})],this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){e=xe(e);var a;if(r.rank===1)throw new Te("1D separable convolution is not implemented yet.");return r.rank===2&&(r.dataFormat==="channelsFirst"&&(e=y.transpose(e,[0,2,3,1])),a=y.separableConv2d(e,r.depthwiseKernel.read(),r.pointwiseKernel.read(),r.strides,r.padding,r.dilationRate,"NHWC")),r.useBias&&(a=Hn(a,r.bias.read(),r.dataFormat)),r.activation!=null&&(a=r.activation.apply(a)),r.dataFormat==="channelsFirst"&&(a=y.transpose(a,[0,3,1,2])),a})},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this);return delete e.rank,delete e.kernelInitializer,delete e.kernelRegularizer,delete e.kernelConstraint,e.depthwiseInitializer=st(this.depthwiseInitializer),e.pointwiseInitializer=st(this.pointwiseInitializer),e.depthwiseRegularizer=Ke(this.depthwiseRegularizer),e.pointwiseRegularizer=Ke(this.pointwiseRegularizer),e.depthwiseConstraint=bt(this.depthwiseConstraint),e.pointwiseConstraint=bt(this.pointwiseConstraint),e},t.className="SeparableConv",t}(Mo),Tb=function(n){Q(t,n);function t(e){return n.call(this,2,e)||this}return t.className="SeparableConv2D",t}(Q4);y.serialization.registerClass(Tb);var Nb=function(n){Q(t,n);function t(e){var i=n.call(this,1,e)||this;return t.verifyArgs(e),i.inputSpec=[{ndim:3}],i}return t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this);return delete e.rank,delete e.dataFormat,e},t.verifyArgs=function(e){if(typeof e.kernelSize!="number"&&!Ph(e.kernelSize,"number",1,1))throw new M("Conv1D expects config.kernelSize to be number or number[] with "+("length 1, but received "+JSON.stringify(e.kernelSize)+"."))},t.className="Conv1D",t}(Mo);y.serialization.registerClass(Nb);var xb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return typeof e.cropping=="number"?i.cropping=[[e.cropping,e.cropping],[e.cropping,e.cropping]]:typeof e.cropping[0]=="number"?i.cropping=[[e.cropping[0],e.cropping[0]],[e.cropping[1],e.cropping[1]]]:i.cropping=e.cropping,i.dataFormat=e.dataFormat===void 0?"channelsLast":e.dataFormat,i.inputSpec=[{ndim:4}],i}return t.prototype.computeOutputShape=function(e){return this.dataFormat==="channelsFirst"?[e[0],e[1],e[2]-this.cropping[0][0]-this.cropping[0][1],e[3]-this.cropping[1][0]-this.cropping[1][1]]:[e[0],e[1]-this.cropping[0][0]-this.cropping[0][1],e[2]-this.cropping[1][0]-this.cropping[1][1],e[3]]},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){if(e=xe(e),r.dataFormat==="channelsLast"){var a=Ao(e,r.cropping[0][0],e.shape[1]-r.cropping[0][0]-r.cropping[0][1],2);return Ao(a,r.cropping[1][0],e.shape[2]-r.cropping[1][1]-r.cropping[1][0],3)}else{var a=Ao(e,r.cropping[0][0],e.shape[2]-r.cropping[0][0]-r.cropping[0][1],3);return Ao(a,r.cropping[1][0],e.shape[3]-r.cropping[1][1]-r.cropping[1][0],4)}})},t.prototype.getConfig=function(){var e={cropping:this.cropping,dataFormat:this.dataFormat},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Cropping2D",t}(De);y.serialization.registerClass(xb);var Cb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.DEFAULT_SIZE=[2,2],i.inputSpec=[{ndim:4}],i.size=e.size==null?i.DEFAULT_SIZE:e.size,i.dataFormat=e.dataFormat==null?"channelsLast":e.dataFormat,i}return t.prototype.computeOutputShape=function(e){if(this.dataFormat==="channelsFirst"){var i=e[2]==null?null:this.size[0]*e[2],r=e[3]==null?null:this.size[1]*e[3];return[e[0],e[1],i,r]}else{var i=e[1]==null?null:this.size[0]*e[1],r=e[2]==null?null:this.size[1]*e[2];return[e[0],i,r,e[3]]}},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=xe(e),s=a.shape;if(r.dataFormat==="channelsFirst"){a=y.transpose(a,[0,2,3,1]);var o=r.size[0]*s[2],l=r.size[1]*s[3],u=a.resizeNearestNeighbor([o,l]);return y.transpose(u,[0,3,1,2])}else{var o=r.size[0]*s[1],l=r.size[1]*s[2];return a.resizeNearestNeighbor([o,l])}})},t.prototype.getConfig=function(){var e={size:this.size,dataFormat:this.dataFormat},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="UpSampling2D",t}(De);y.serialization.registerClass(Cb);function eF(n,t,e,i,r,a){return e===void 0&&(e=[1,1]),i===void 0&&(i="valid"),y.tidy(function(){r==null&&(r=Sn()),ht(r);var s=vd(n,r);if(n.rank!==4)throw new M("Input for depthwiseConv2d is required to be 4-D, but is instead "+(n.rank+"-D"));if(t.rank!==4)throw new M("depthwiseKernel is required to be 4-D, but is instead "+(t.rank+"-D"));return s=y.depthwiseConv2d(s,t,e,i==="same"?"same":"valid","NHWC",a),r==="channelsFirst"&&(s=y.transpose(s,[0,3,1,2])),s})}var Rb=function(n){Q(t,n);function t(e){var i=n.call(this,2,e)||this;return i.depthwiseKernel=null,i.depthMultiplier=e.depthMultiplier==null?1:e.depthMultiplier,i.depthwiseInitializer=tt(e.depthwiseInitializer||i.DEFAULT_KERNEL_INITIALIZER),i.depthwiseConstraint=wt(e.depthwiseConstraint),i.depthwiseRegularizer=nt(e.depthwiseRegularizer),i}return t.prototype.build=function(e){if(e=je(e),e.length<4)throw new M("Inputs to DepthwiseConv2D should have rank 4. "+("Received input shape: "+JSON.stringify(e)+"."));var i=this.dataFormat==="channelsFirst"?1:3;if(e[i]==null||e[i]<0)throw new M("The channel dimension of the inputs to DepthwiseConv2D should "+("be defined, but is not ("+e[i]+")."));var r=e[i],a=[this.kernelSize[0],this.kernelSize[1],r,this.depthMultiplier];this.depthwiseKernel=this.addWeight("depthwise_kernel",a,null,this.depthwiseInitializer,this.depthwiseRegularizer,!0,this.depthwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[r*this.depthMultiplier],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){e=xe(e);var a=eF(e,r.depthwiseKernel.read(),r.strides,r.padding,r.dataFormat,null);return r.useBias&&(a=Hn(a,r.bias.read(),r.dataFormat)),r.activation!=null&&(a=r.activation.apply(a)),a})},t.prototype.computeOutputShape=function(e){e=je(e);var i=this.dataFormat==="channelsFirst"?e[2]:e[1],r=this.dataFormat==="channelsFirst"?e[3]:e[2],a=this.dataFormat==="channelsFirst"?e[1]*this.depthMultiplier:e[3]*this.depthMultiplier,s=Tn(i,this.kernelSize[0],this.padding,this.strides[0]),o=Tn(r,this.kernelSize[1],this.padding,this.strides[1]);return this.dataFormat==="channelsFirst"?[e[0],a,s,o]:[e[0],s,o,a]},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this);return e.depthMultiplier=this.depthMultiplier,e.depthwiseInitializer=st(this.depthwiseInitializer),e.depthwiseRegularizer=Ke(this.depthwiseRegularizer),e.depthwiseConstraint=bt(this.depthwiseRegularizer),e},t.className="DepthwiseConv2D",t}(Lb);y.serialization.registerClass(Rb);function Ob(n,t,e,i){if(Array.isArray(n)){if(t!=null||e!=null)throw new M("When inputs is an array, neither initialState or constants should be provided");i!=null&&(e=n.slice(n.length-i,n.length),n=n.slice(0,n.length-i)),n.length>1&&(t=n.slice(1,n.length)),n=n[0]}function r(a){return a==null||Array.isArray(a)?a:[a]}return t=r(t),e=r(e),{inputs:n,initialState:t,constants:e}}function Eb(n,t,e,i,r,a,s,o){return i===void 0&&(i=!1),s===void 0&&(s=!1),o===void 0&&(o=!1),y.tidy(function(){var l=t.shape.length;if(l<3)throw new M("Input should be at least 3D, but is "+l+"D.");var u=[1,0].concat(Ln(2,l));if(t=y.transpose(t,u),a!=null)throw new Te("The rnn() functoin of the deeplearn.js backend does not support constants yet.");s&&console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."),r!=null&&(r=r.asType("bool").asType("float32"),r.rank===l-1&&(r=y.expandDims(r,-1)),r=y.transpose(r,u)),i&&(t=y.reverse(t,0),r!=null&&(r=y.reverse(r,0)));var c=[],h,d=e,p=t.shape[0],f=y.unstack(t),m;r!=null&&(m=y.unstack(r));for(var g=function(S){var L=f[S],N=y.tidy(function(){return n(L,d)});if(r==null)h=N[0],d=N[1];else{var C=y.tidy(function(){var R=m[S],D=y.onesLike(R).sub(R),k=N[0].mul(R).add(d[0].mul(D)),W=d.map(function(F,P){return N[1][P].mul(R).add(F.mul(D))});return{output:k,newStates:W}});h=C.output,d=C.newStates}o&&c.push(h)},v=0;v<p;++v)g(v);var b;if(o){var w=1;b=y.stack(c,w)}return[h,b,d]})}var Di=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this,r;if(e.cell==null)throw new M("cell property is missing for the constructor of RNN.");if(Array.isArray(e.cell)?r=new bd({cells:e.cell}):r=e.cell,r.stateSize==null)throw new M("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state).");return i.cell=r,i.returnSequences=e.returnSequences==null?!1:e.returnSequences,i.returnState=e.returnState==null?!1:e.returnState,i.goBackwards=e.goBackwards==null?!1:e.goBackwards,i._stateful=e.stateful==null?!1:e.stateful,i.unroll=e.unroll==null?!1:e.unroll,i.supportsMasking=!0,i.inputSpec=[new Nt({ndim:3})],i.stateSpec=null,i.states_=null,i.numConstants=null,i.keptStates=[],i}return t.prototype.getStates=function(){if(this.states_==null){var e=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1;return Ln(0,e).map(function(i){return null})}else return this.states_},t.prototype.setStates=function(e){this.states_=e},t.prototype.computeOutputShape=function(e){Zh(e)&&(e=e[0]),e=e;var i=this.cell.stateSize;Array.isArray(i)||(i=[i]);var r=i[0],a;if(this.returnSequences?a=[e[0],e[1],r]:a=[e[0],r],this.returnState){for(var s=[],o=0,l=i;o<l.length;o++){var u=l[o];s.push([e[0],u])}return[a].concat(s)}else return a},t.prototype.computeMask=function(e,i){var r=this;return y.tidy(function(){Array.isArray(i)&&(i=i[0]);var a=r.returnSequences?i:null;if(r.returnState){var s=r.states.map(function(o){return null});return[a].concat(s)}else return a})},Object.defineProperty(t.prototype,"states",{get:function(){if(this.states_==null){for(var e=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1,i=[],r=0;r<e;++r)i.push(null);return i}else return this.states_},set:function(e){this.states_=e},enumerable:!0,configurable:!0}),t.prototype.build=function(e){if(this.numConstants!=null)throw new Te("Constants support is not implemented in RNN yet.");Zh(e)&&(e=e[0]),e=e;var i=this.stateful?e[0]:null,r=e.slice(2);this.inputSpec[0]=new Nt({shape:[i,null].concat(r)});var a=[e[0]].concat(e.slice(2));this.cell.build(a);var s;if(Array.isArray(this.cell.stateSize)?s=this.cell.stateSize:s=[this.cell.stateSize],this.stateSpec!=null){if(!y.util.arraysEqual(this.stateSpec.map(function(o){return o.shape[o.shape.length-1]}),s))throw new M("An initialState was passed that is not compatible with "+("cell.stateSize. Received stateSpec="+this.stateSpec+"; ")+("However cell.stateSize is "+this.cell.stateSize))}else this.stateSpec=s.map(function(o){return new Nt({shape:[null,o]})});this.stateful&&this.resetStates()},t.prototype.resetStates=function(e,i){var r=this;i===void 0&&(i=!1),y.tidy(function(){if(!r.stateful)throw new Ai("Cannot call resetStates() on an RNN Layer that is not stateful.");var a=r.inputSpec[0].shape[0];if(a==null)throw new M("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");if(r.states_==null)Array.isArray(r.cell.stateSize)?r.states_=r.cell.stateSize.map(function(c){return y.zeros([a,c])}):r.states_=[y.zeros([a,r.cell.stateSize])];else if(e==null)y.dispose(r.states_),r.keptStates!=null&&(y.dispose(r.keptStates),r.keptStates=[]),Array.isArray(r.cell.stateSize)?r.states_=r.cell.stateSize.map(function(c){return y.zeros([a,c])}):r.states_[0]=y.zeros([a,r.cell.stateSize]);else{if(Array.isArray(e)||(e=[e]),e.length!==r.states_.length)throw new M("Layer "+r.name+" expects "+r.states_.length+" state(s), "+("but it received "+e.length+" state value(s). Input ")+("received: "+e));i===!0?r.keptStates.push(r.states_.slice()):y.dispose(r.states_);for(var s=0;s<r.states_.length;++s){var o=e[s],l=Array.isArray(r.cell.stateSize)?r.cell.stateSize[s]:r.cell.stateSize,u=[a,l];if(!y.util.arraysEqual(o.shape,u))throw new M("State "+s+" is incompatible with layer "+r.name+": "+("expected shape="+u+", received shape="+o.shape));r.states_[s]=o}}r.states_=r.states_.map(function(c){return y.keep(c.clone())})})},t.prototype.apply=function(e,i){var r=i==null?null:i.initialState,a=i==null?null:i.constants;i==null&&(i={});var s=Ob(e,r,a,this.numConstants);e=s.inputs,r=s.initialState,a=s.constants;var o=[],l=[];if(r!=null){i.initialState=r,o=o.concat(r),this.stateSpec=[];for(var u=0,c=r;u<c.length;u++){var h=c[u];this.stateSpec.push(new Nt({shape:h.shape}))}l=l.concat(this.stateSpec)}a!=null&&(i.constants=a,o=o.concat(a),this.numConstants=a.length);var d=o[0]instanceof In;if(d){var p=[e].concat(o),f=this.inputSpec.concat(l),m=this.inputSpec;this.inputSpec=f;var g=n.prototype.apply.call(this,p,i);return this.inputSpec=m,g}else return n.prototype.apply.call(this,e,i)},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=i==null?null:i.mask,s=i==null?null:i.training,o=i==null?null:i.initialState;e=xe(e),o==null&&(r.stateful?o=r.states_:o=r.getInitialState(e));var l=Array.isArray(r.cell.stateSize)?r.cell.stateSize.length:1;if(o.length!==l)throw new M("RNN Layer has "+l+" state(s) but was passed "+(o.length+" initial state(s)."));r.unroll&&console.warn("Ignoring unroll = true for RNN layer, due to imperative backend.");var u={training:s},c=function(g,v){var b=r.cell.call([g].concat(v),u);return[b[0],b.slice(1)]},h=Eb(c,e,o,r.goBackwards,a,null,r.unroll,r.returnSequences),d=h[0],p=h[1],f=h[2];r.stateful&&r.resetStates(f,s);var m=r.returnSequences?p:d;return r.returnState?[m].concat(f):m})},t.prototype.getInitialState=function(e){var i=this;return y.tidy(function(){var r=y.zeros(e.shape);return r=y.sum(r,[1,2]),r=ts(r),Array.isArray(i.cell.stateSize)?i.cell.stateSize.map(function(a){return a>1?Mh(r,[1,a]):r}):i.cell.stateSize>1?[Mh(r,[1,i.cell.stateSize])]:[r]})},Object.defineProperty(t.prototype,"trainableWeights",{get:function(){return this.trainable?this.cell.trainableWeights:[]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){return this.trainable?this.cell.nonTrainableWeights:this.cell.weights},enumerable:!0,configurable:!0}),t.prototype.setFastWeightInitDuringBuild=function(e){n.prototype.setFastWeightInitDuringBuild.call(this,e),this.cell!=null&&this.cell.setFastWeightInitDuringBuild(e)},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={returnSequences:this.returnSequences,returnState:this.returnState,goBackwards:this.goBackwards,stateful:this.stateful,unroll:this.unroll};this.numConstants!=null&&(i.numConstants=this.numConstants);var r=this.cell.getConfig();return this.getClassName()===t.className&&(i.cell={className:this.cell.getClassName(),config:r}),$t({},r,e,i)},t.fromConfig=function(e,i,r){r===void 0&&(r={});var a=i.cell,s=An(a,r);return new e(Object.assign(i,{cell:s}))},t.className="RNN",t}(De);y.serialization.registerClass(Di);var oa=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t}(De),wd=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.DEFAULT_ACTIVATION="tanh",i.DEFAULT_KERNEL_INITIALIZER="glorotNormal",i.DEFAULT_RECURRENT_INITIALIZER="orthogonal",i.DEFAULT_BIAS_INITIALIZER="zeros",i.units=e.units,Tt(i.units,"units"),i.activation=Ei(e.activation==null?i.DEFAULT_ACTIVATION:e.activation),i.useBias=e.useBias==null?!0:e.useBias,i.kernelInitializer=tt(e.kernelInitializer||i.DEFAULT_KERNEL_INITIALIZER),i.recurrentInitializer=tt(e.recurrentInitializer||i.DEFAULT_RECURRENT_INITIALIZER),i.biasInitializer=tt(e.biasInitializer||i.DEFAULT_BIAS_INITIALIZER),i.kernelRegularizer=nt(e.kernelRegularizer),i.recurrentRegularizer=nt(e.recurrentRegularizer),i.biasRegularizer=nt(e.biasRegularizer),i.kernelConstraint=wt(e.kernelConstraint),i.recurrentConstraint=wt(e.recurrentConstraint),i.biasConstraint=wt(e.biasConstraint),i.dropout=na([1,xi([0,e.dropout==null?0:e.dropout])]),i.recurrentDropout=na([1,xi([0,e.recurrentDropout==null?0:e.recurrentDropout])]),i.stateSize=i.units,i.dropoutMask=null,i.recurrentDropoutMask=null,i}return t.prototype.build=function(e){e=je(e),this.kernel=this.addWeight("kernel",[e[e.length-1],this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){if(e=e,e.length!==2)throw new M("SimpleRNNCell expects 2 input Tensors, got "+e.length+".");var a=e[1];e=e[0];var s=i.training==null?!1:i.training;0<r.dropout&&r.dropout<1&&r.dropoutMask==null&&(r.dropoutMask=ki({ones:function(){return y.onesLike(e)},rate:r.dropout,training:s})),0<r.recurrentDropout&&r.recurrentDropout<1&&r.recurrentDropoutMask==null&&(r.recurrentDropoutMask=ki({ones:function(){return y.onesLike(a)},rate:r.recurrentDropout,training:s}));var o,l=r.dropoutMask,u=r.recurrentDropoutMask;l!=null?o=Mn(y.mul(e,l),r.kernel.read()):o=Mn(e,r.kernel.read()),r.bias!=null&&(o=Hn(o,r.bias.read())),u!=null&&(a=y.mul(a,u));var c=y.add(o,Mn(a,r.recurrentKernel.read()));return r.activation!=null&&(c=r.activation.apply(c)),[c,c]})},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={units:this.units,activation:Oi(this.activation),useBias:this.useBias,kernelInitializer:st(this.kernelInitializer),recurrentInitializer:st(this.recurrentInitializer),biasInitializer:st(this.biasInitializer),kernelRegularizer:Ke(this.kernelRegularizer),recurrentRegularizer:Ke(this.recurrentRegularizer),biasRegularizer:Ke(this.biasRegularizer),activityRegularizer:Ke(this.activityRegularizer),kernelConstraint:bt(this.kernelConstraint),recurrentConstraint:bt(this.recurrentConstraint),biasConstraint:bt(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout};return $t({},e,i)},t.className="SimpleRNNCell",t}(oa);y.serialization.registerClass(wd);var Db=function(n){Q(t,n);function t(e){var i=this;return e.cell=new wd(e),i=n.call(this,e)||this,i}return t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.cell.dropoutMask!=null&&(y.dispose(r.cell.dropoutMask),r.cell.dropoutMask=null),r.cell.recurrentDropoutMask!=null&&(y.dispose(r.cell.recurrentDropoutMask),r.cell.recurrentDropoutMask=null);var a=i==null?null:i.mask,s=i==null?null:i.training,o=i==null?null:i.initialState;return n.prototype.call.call(r,e,{mask:a,training:s,initialState:o})})},t.fromConfig=function(e,i){return new e(i)},t.className="SimpleRNN",t}(Di);y.serialization.registerClass(Db);var Sd=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;if(i.DEFAULT_ACTIVATION="tanh",i.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",i.DEFAULT_KERNEL_INITIALIZER="glorotNormal",i.DEFAULT_RECURRENT_INITIALIZER="orthogonal",i.DEFAULT_BIAS_INITIALIZER="zeros",e.resetAfter)throw new M("GRUCell does not support reset_after parameter set to true.");return i.units=e.units,Tt(i.units,"units"),i.activation=Ei(e.activation===void 0?i.DEFAULT_ACTIVATION:e.activation),i.recurrentActivation=Ei(e.recurrentActivation===void 0?i.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),i.useBias=e.useBias==null?!0:e.useBias,i.kernelInitializer=tt(e.kernelInitializer||i.DEFAULT_KERNEL_INITIALIZER),i.recurrentInitializer=tt(e.recurrentInitializer||i.DEFAULT_RECURRENT_INITIALIZER),i.biasInitializer=tt(e.biasInitializer||i.DEFAULT_BIAS_INITIALIZER),i.kernelRegularizer=nt(e.kernelRegularizer),i.recurrentRegularizer=nt(e.recurrentRegularizer),i.biasRegularizer=nt(e.biasRegularizer),i.kernelConstraint=wt(e.kernelConstraint),i.recurrentConstraint=wt(e.recurrentConstraint),i.biasConstraint=wt(e.biasConstraint),i.dropout=na([1,xi([0,e.dropout==null?0:e.dropout])]),i.recurrentDropout=na([1,xi([0,e.recurrentDropout==null?0:e.recurrentDropout])]),i.implementation=e.implementation,i.stateSize=i.units,i.dropoutMask=null,i.recurrentDropoutMask=null,i}return t.prototype.build=function(e){e=je(e);var i=e[e.length-1];this.kernel=this.addWeight("kernel",[i,this.units*3],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,this.units*3],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[this.units*3],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){if(e=e,e.length!==2)throw new M("GRUCell expects 2 input Tensors (inputs, h, c), got "+(e.length+"."));var a=i.training==null?!1:i.training,s=e[1];e=e[0],0<r.dropout&&r.dropout<1&&r.dropoutMask==null&&(r.dropoutMask=ki({ones:function(){return y.onesLike(e)},rate:r.dropout,training:a,count:3})),0<r.recurrentDropout&&r.recurrentDropout<1&&r.recurrentDropoutMask==null&&(r.recurrentDropoutMask=ki({ones:function(){return y.onesLike(s)},rate:r.recurrentDropout,training:a,count:3}));var o=r.dropoutMask,l=r.recurrentDropoutMask,u,c,h;0<r.dropout&&r.dropout<1&&(e=y.mul(e,o[0]));var d=Mn(e,r.kernel.read());r.useBias&&(d=Hn(d,r.bias.read())),0<r.recurrentDropout&&r.recurrentDropout<1&&(s=y.mul(s,l[0]));var p=r.recurrentKernel.read(),f=y.split(p,[2*r.units,r.units],p.rank-1),m=f[0],g=f[1],v=Mn(s,m),b=y.split(d,3,d.rank-1),w=b[0],S=b[1],L=b[2],N=y.split(v,2,v.rank-1),C=N[0],R=N[1];u=r.recurrentActivation.apply(y.add(w,C)),c=r.recurrentActivation.apply(y.add(S,R));var D=Mn(y.mul(c,s),g);h=r.activation.apply(y.add(L,D));var k=y.add(y.mul(u,s),y.mul(y.add(1,y.neg(u)),h));return[k,k]})},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={units:this.units,activation:Oi(this.activation),recurrentActivation:Oi(this.recurrentActivation),useBias:this.useBias,kernelInitializer:st(this.kernelInitializer),recurrentInitializer:st(this.recurrentInitializer),biasInitializer:st(this.biasInitializer),kernelRegularizer:Ke(this.kernelRegularizer),recurrentRegularizer:Ke(this.recurrentRegularizer),biasRegularizer:Ke(this.biasRegularizer),activityRegularizer:Ke(this.activityRegularizer),kernelConstraint:bt(this.kernelConstraint),recurrentConstraint:bt(this.recurrentConstraint),biasConstraint:bt(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation,resetAfter:!1};return $t({},e,i)},t.className="GRUCell",t}(oa);y.serialization.registerClass(Sd);var kb=function(n){Q(t,n);function t(e){var i=this;return e.implementation===0&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new Sd(e),i=n.call(this,e)||this,i}return t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.cell.dropoutMask!=null&&(y.dispose(r.cell.dropoutMask),r.cell.dropoutMask=null),r.cell.recurrentDropoutMask!=null&&(y.dispose(r.cell.recurrentDropoutMask),r.cell.recurrentDropoutMask=null);var a=i==null?null:i.mask,s=i==null?null:i.training,o=i==null?null:i.initialState;return n.prototype.call.call(r,e,{mask:a,training:s,initialState:o})})},t.fromConfig=function(e,i){return i.implmentation===0&&(i.implementation=1),new e(i)},t.className="GRU",t}(Di);y.serialization.registerClass(kb);var Ho=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.DEFAULT_ACTIVATION="tanh",i.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",i.DEFAULT_KERNEL_INITIALIZER="glorotNormal",i.DEFAULT_RECURRENT_INITIALIZER="orthogonal",i.DEFAULT_BIAS_INITIALIZER="zeros",i.units=e.units,Tt(i.units,"units"),i.activation=Ei(e.activation===void 0?i.DEFAULT_ACTIVATION:e.activation),i.recurrentActivation=Ei(e.recurrentActivation===void 0?i.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),i.useBias=e.useBias==null?!0:e.useBias,i.kernelInitializer=tt(e.kernelInitializer||i.DEFAULT_KERNEL_INITIALIZER),i.recurrentInitializer=tt(e.recurrentInitializer||i.DEFAULT_RECURRENT_INITIALIZER),i.biasInitializer=tt(e.biasInitializer||i.DEFAULT_BIAS_INITIALIZER),i.unitForgetBias=e.unitForgetBias,i.kernelRegularizer=nt(e.kernelRegularizer),i.recurrentRegularizer=nt(e.recurrentRegularizer),i.biasRegularizer=nt(e.biasRegularizer),i.kernelConstraint=wt(e.kernelConstraint),i.recurrentConstraint=wt(e.recurrentConstraint),i.biasConstraint=wt(e.biasConstraint),i.dropout=na([1,xi([0,e.dropout==null?0:e.dropout])]),i.recurrentDropout=na([1,xi([0,e.recurrentDropout==null?0:e.recurrentDropout])]),i.implementation=e.implementation,i.stateSize=[i.units,i.units],i.dropoutMask=null,i.recurrentDropoutMask=null,i}return t.prototype.build=function(e){var i;e=je(e);var r=e[e.length-1];this.kernel=this.addWeight("kernel",[r,this.units*4],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,this.units*4],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint);var a;if(this.useBias){if(this.unitForgetBias){var s=this.biasInitializer,o=this.units;a=new(i=function(l){Q(u,l);function u(){return l!==null&&l.apply(this,arguments)||this}return u.prototype.apply=function(c,h){var d=s.apply([o]),p=new Gh().apply([o]),f=s.apply([o*2]);return by(by(d,p),f)},u}(fn),i.className="CustomInit",i)}else a=this.biasInitializer;this.bias=this.addWeight("bias",[this.units*4],null,a,this.biasRegularizer,!0,this.biasConstraint)}else this.bias=null;this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=i.training==null?!1:i.training;if(e=e,e.length!==3)throw new M("LSTMCell expects 3 input Tensors (inputs, h, c), got "+(e.length+"."));var s=e[1],o=e[2];e=e[0],0<r.dropout&&r.dropout<1&&r.dropoutMask==null&&(r.dropoutMask=ki({ones:function(){return y.onesLike(e)},rate:r.dropout,training:a,count:4})),0<r.recurrentDropout&&r.recurrentDropout<1&&r.recurrentDropoutMask==null&&(r.recurrentDropoutMask=ki({ones:function(){return y.onesLike(s)},rate:r.recurrentDropout,training:a,count:4}));var l=r.dropoutMask,u=r.recurrentDropoutMask,c,h,d,p;0<r.dropout&&r.dropout<1&&(e=y.mul(e,l[0]));var f=Mn(e,r.kernel.read());0<r.recurrentDropout&&r.recurrentDropout<1&&(s=y.mul(s,u[0])),f=y.add(f,Mn(s,r.recurrentKernel.read())),r.useBias&&(f=Hn(f,r.bias.read()));var m=y.split(f,4,f.rank-1),g=m[0],v=m[1],b=m[2],w=m[3];c=r.recurrentActivation.apply(g),h=r.recurrentActivation.apply(v),d=y.add(y.mul(h,o),y.mul(c,r.activation.apply(b))),p=r.recurrentActivation.apply(w);var S=y.mul(p,r.activation.apply(d));return[S,S,d]})},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={units:this.units,activation:Oi(this.activation),recurrentActivation:Oi(this.recurrentActivation),useBias:this.useBias,kernelInitializer:st(this.kernelInitializer),recurrentInitializer:st(this.recurrentInitializer),biasInitializer:st(this.biasInitializer),unitForgetBias:this.unitForgetBias,kernelRegularizer:Ke(this.kernelRegularizer),recurrentRegularizer:Ke(this.recurrentRegularizer),biasRegularizer:Ke(this.biasRegularizer),activityRegularizer:Ke(this.activityRegularizer),kernelConstraint:bt(this.kernelConstraint),recurrentConstraint:bt(this.recurrentConstraint),biasConstraint:bt(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation};return $t({},e,i)},t.className="LSTMCell",t}(oa);y.serialization.registerClass(Ho);var Fb=function(n){Q(t,n);function t(e){var i=this;return e.implementation===0&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new Ho(e),i=n.call(this,e)||this,i}return t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.cell.dropoutMask!=null&&(y.dispose(r.cell.dropoutMask),r.cell.dropoutMask=null),r.cell.recurrentDropoutMask!=null&&(y.dispose(r.cell.recurrentDropoutMask),r.cell.recurrentDropoutMask=null);var a=i==null?null:i.mask,s=i==null?null:i.training,o=i==null?null:i.initialState;return n.prototype.call.call(r,e,{mask:a,training:s,initialState:o})})},t.fromConfig=function(e,i){return i.implmentation===0&&(i.implementation=1),new e(i)},t.className="LSTM",t}(Di);y.serialization.registerClass(Fb);var bd=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.cells=e.cells,i}return Object.defineProperty(t.prototype,"stateSize",{get:function(){for(var e=[],i=0,r=this.cells.slice().reverse();i<r.length;i++){var a=r[i];Array.isArray(a.stateSize)?e.push.apply(e,a.stateSize):e.push(a.stateSize)}return e},enumerable:!0,configurable:!0}),t.prototype.call=function(e,i){var r=this;return y.tidy(function(){e=e;for(var a=e.slice(1),s=[],o=0,l=r.cells.slice().reverse();o<l.length;o++){var u=l[o];Array.isArray(u.stateSize)?s.push(a.splice(0,u.stateSize.length)):s.push(a.splice(0,1))}s.reverse();for(var c=[],h,d=0;d<r.cells.length;++d){var u=r.cells[d];a=s[d],d===0?h=[e[0]].concat(a):h=[h[0]].concat(a),h=u.call(h,i),c.push(h.slice(1))}a=[];for(var p=0,f=c.slice().reverse();p<f.length;p++){var m=f[p];a.push.apply(a,m)}return[h[0]].concat(a)})},t.prototype.build=function(e){Zh(e)&&(e=e[0]),e=e;var i;this.cells.forEach(function(r,a){hr("RNNCell_"+a,function(){r.build(e),Array.isArray(r.stateSize)?i=r.stateSize[0]:i=r.stateSize,e=[e[0],i]})}),this.built=!0},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i=function(s){return{className:s.getClassName(),config:s.getConfig()}},r=this.cells.map(i),a={cells:r};return $t({},e,a)},t.fromConfig=function(e,i,r){r===void 0&&(r={});for(var a=[],s=0,o=i.cells;s<o.length;s++){var l=o[s];a.push(An(l,r))}return new e({cells:a})},Object.defineProperty(t.prototype,"trainableWeights",{get:function(){if(!this.trainable)return[];for(var e=[],i=0,r=this.cells;i<r.length;i++){var a=r[i];e.push.apply(e,a.trainableWeights)}return e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){for(var e=[],i=0,r=this.cells;i<r.length;i++){var a=r[i];e.push.apply(e,a.nonTrainableWeights)}if(!this.trainable){for(var s=[],o=0,l=this.cells;o<l.length;o++){var a=l[o];s.push.apply(s,a.trainableWeights)}return s.concat(e)}return e},enumerable:!0,configurable:!0}),t.prototype.getWeights=function(){for(var e=[],i=0,r=this.cells;i<r.length;i++){var a=r[i];e.push.apply(e,a.weights)}return Qh(e)},t.prototype.setWeights=function(e){for(var i=[],r=0,a=this.cells;r<a.length;r++)for(var s=a[r],o=s.weights.length,l=e.splice(o),u=0;u<s.weights.length;++u)i.push([s.weights[u],l[u]]);ed(i)},t.className="StackedRNNCells",t}(oa);y.serialization.registerClass(bd);function ki(n){var t=n.ones,e=n.rate,i=n.training,r=i===void 0?!1:i,a=n.count,s=a===void 0?1:a,o=function(){return Sy(t(),e)},l=function(){return is(o,t,r)};if(!s||s<=1)return y.keep(l().clone());var u=Array(s).fill(void 0).map(l);return u.map(function(c){return y.keep(c.clone())})}var pV=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t}(oa),tF=function(n){Q(t,n);function t(e){var i=this;if(e.unroll)throw new Te("Unrolling is not possible with convolutional RNNs.");if(Array.isArray(e.cell))throw new Te("It is not possible at the moment to stack convolutional cells.");return i=n.call(this,e)||this,i.inputSpec=[new Nt({ndim:5})],i}return t.prototype.call=function(e,i){var r=this;return y.tidy(function(){if(r.cell.dropoutMask!=null&&(y.dispose(r.cell.dropoutMask),r.cell.dropoutMask=null),r.cell.recurrentDropoutMask!=null&&(y.dispose(r.cell.recurrentDropoutMask),r.cell.recurrentDropoutMask=null),i&&i.constants)throw new M("ConvRNN2D cell does not support constants");var a=i==null?null:i.mask,s=i==null?null:i.training,o=i==null?null:i.initialState;return n.prototype.call.call(r,e,{mask:a,training:s,initialState:o})})},t.prototype.computeOutputShape=function(e){var i=this.computeSingleOutputShape(e);return this.returnSequences||(i=[i[0]].concat(i.slice(2))),this.returnState&&(i=[i].concat(Array(2).fill([e[0]].concat(i.slice(-3))))),i},t.prototype.getInitialState=function(e){var i=this;return y.tidy(function(){var r=i.cell.stateSize,a=e.shape,s=i.computeSingleOutputShape(a),o=[s[0]].concat(s.slice(2)),l=y.zeros(o);return Array.isArray(r)?Array(r.length).fill(l):[l]})},t.prototype.resetStates=function(e,i){var r=this;i===void 0&&(i=!1),y.tidy(function(){if(!r.stateful)throw new Ai("Cannot call resetStates() on an RNN Layer that is not stateful.");var a=r.inputSpec[0].shape,s=r.computeSingleOutputShape(a),o=[s[0]].concat(s.slice(2)),l=a[0];if(l==null)throw new M("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");if(r.getStates()==null)Array.isArray(r.cell.stateSize)?r.states_=r.cell.stateSize.map(function(){return y.zeros(o)}):r.states_=[y.zeros(o)];else if(e==null)y.dispose(r.states_),r.keptStates!=null&&(y.dispose(r.keptStates),r.keptStates=[]),Array.isArray(r.cell.stateSize)?r.states_=r.cell.stateSize.map(function(){return y.zeros(o)}):r.states_[0]=y.zeros(o);else{if(Array.isArray(e)||(e=[e]),e.length!==r.states_.length)throw new M("Layer "+r.name+" expects "+r.states_.length+" state(s), "+("but it received "+e.length+" state value(s). Input ")+("received: "+e));i?r.keptStates.push(r.states_.slice()):y.dispose(r.states_);for(var u=0;u<r.states_.length;++u){var c=e[u],h=o;if(!y.util.arraysEqual(c.shape,h))throw new M("State "+u+" is incompatible with layer "+r.name+": "+("expected shape="+h+", received shape="+c.shape));r.states_[u]=c}}r.states_=r.states_.map(function(d){return y.keep(d.clone())})})},t.prototype.computeSingleOutputShape=function(e){var i=this.cell,r=i.dataFormat,a=i.filters,s=i.kernelSize,o=i.padding,l=i.strides,u=i.dilationRate,c=r==="channelsFirst",h=e[c?3:2],d=e[c?4:3],p=Tn(h,s[0],o,l[0],u[0]),f=Tn(d,s[1],o,l[1],u[1]),m=e.slice(0,2).concat(c?[a,p,f]:[p,f,a]);return m},t.className="ConvRNN2D",t}(Di),Ld=function(n){Q(t,n);function t(e){var i=this,r=e.filters,a=e.kernelSize,s=e.strides,o=e.padding,l=e.dataFormat,u=e.dilationRate;return i=n.call(this,$t({},e,{units:r}))||this,i.filters=r,Tt(i.filters,"filters"),i.kernelSize=sa(a,2,"kernelSize"),i.kernelSize.forEach(function(c){return Tt(c,"kernelSize")}),i.strides=sa(s||1,2,"strides"),i.strides.forEach(function(c){return Tt(c,"strides")}),i.padding=o||"valid",sn(i.padding),i.dataFormat=l||"channelsLast",ht(i.dataFormat),i.dilationRate=sa(u||1,2,"dilationRate"),i.dilationRate.forEach(function(c){return Tt(c,"dilationRate")}),i}return t.prototype.build=function(e){var i;e=je(e);var r=this.dataFormat==="channelsFirst"?1:e.length-1;if(e[r]==null)throw new M("The channel dimension of the input should be defined. "+("Found "+e[r]));var a=e[r],s=4,o=this.kernelSize.concat([a,this.filters*s]);this.kernel=this.addWeight("kernel",o,null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint);var l=this.kernelSize.concat([this.filters,this.filters*s]);if(this.recurrentKernel=this.addWeight("recurrent_kernel",l,null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias){var u=void 0;if(this.unitForgetBias){var c=this.biasInitializer,h=this.filters;u=new(i=function(d){Q(p,d);function p(){return d!==null&&d.apply(this,arguments)||this}return p.prototype.apply=function(f,m){var g=c.apply([h]),v=y.ones([h]),b=c.apply([h*2]);return Vh([g,v,b])},p}(fn),i.className="CustomInit",i)}else u=this.biasInitializer;this.bias=this.addWeight("bias",[this.filters*s],null,u,this.biasRegularizer,!0,this.biasConstraint)}this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){if(e.length!==3)throw new M("ConvLSTM2DCell expects 3 input Tensors (inputs, h, c), got "+(e.length+"."));var a=i.training||!1,s=e[0],o=e[1],l=e[2],u=4;0<r.dropout&&r.dropout<1&&r.dropoutMask==null&&(r.dropoutMask=ki({ones:function(){return y.onesLike(s)},rate:r.dropout,training:a,count:u}));var c=r.dropoutMask,h=function(te,re,le){return!re||!re[le]?te:y.mul(re[le],te)},d=h(s,c,0),p=h(s,c,1),f=h(s,c,2),m=h(s,c,3);0<r.recurrentDropout&&r.recurrentDropout<1&&r.recurrentDropoutMask==null&&(r.recurrentDropoutMask=ki({ones:function(){return y.onesLike(o)},rate:r.recurrentDropout,training:a,count:u}));var g=r.recurrentDropoutMask,v=h(o,g,0),b=h(o,g,1),w=h(o,g,2),S=h(o,g,3),L=3,N=y.split(r.kernel.read(),u,L),C=N[0],R=N[1],D=N[2],k=N[3],W=r.useBias?y.split(r.bias.read(),u):[null,null,null,null],F=W[0],P=W[1],H=W[2],_=W[3];d=r.inputConv(d,C,F,r.padding),p=r.inputConv(p,R,P,r.padding),f=r.inputConv(f,D,H,r.padding),m=r.inputConv(m,k,_,r.padding);var j=y.split(r.recurrentKernel.read(),u,L),K=j[0],q=j[1],G=j[2],Z=j[3];v=r.recurrentConv(v,K),b=r.recurrentConv(b,q),w=r.recurrentConv(w,G),S=r.recurrentConv(S,Z);var X=r.recurrentActivation.apply(y.add(d,v)),ee=r.recurrentActivation.apply(y.add(p,b)),ne=y.add(y.mul(ee,l),y.mul(X,r.activation.apply(y.add(f,w)))),ie=y.mul(r.recurrentActivation.apply(y.add(m,S)),r.activation.apply(ne));return[ie,ie,ne]})},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i=e.units,r=Pk(e,["units"]),a={filters:this.filters,kernelSize:this.kernelSize,padding:this.padding,dataFormat:this.dataFormat,dilationRate:this.dilationRate,strides:this.strides};return $t({},r,a)},t.prototype.inputConv=function(e,i,r,a){var s=y.conv2d(e,i,this.strides,a||"valid",this.dataFormat==="channelsFirst"?"NCHW":"NHWC",this.dilationRate);return r?Hn(s,r,this.dataFormat):s},t.prototype.recurrentConv=function(e,i){var r=1;return y.conv2d(e,i,r,"same",this.dataFormat==="channelsFirst"?"NCHW":"NHWC")},t.className="ConvLSTM2DCell",t}(Ho);y.serialization.registerClass(Ld);var Wb=function(n){Q(t,n);function t(e){var i=this,r=new Ld(e);return i=n.call(this,$t({},e,{cell:r}))||this,i}return t.fromConfig=function(e,i){return new e(i)},t.className="ConvLSTM2D",t}(tF);y.serialization.registerClass(Wb);var Id=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.rate=Math.max(Math.min(e.rate,1),0),i.noiseShape=e.noiseShape,i.seed=e.seed,i.supportsMasking=!0,i}return t.prototype.getNoiseShape=function(e){if(this.noiseShape==null)return this.noiseShape;for(var i=e.shape,r=[],a=0;a<this.noiseShape.length;++a)r.push(this.noiseShape[a]==null?i[a]:this.noiseShape[a]);return r},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e);if(0<r.rate&&r.rate<1){var s=i.training==null?!1:i.training,o=r.getNoiseShape(a),l=is(function(){return Sy(a,r.rate,o,r.seed)},function(){return a},s);return l}return e})},t.prototype.getConfig=function(){var e={rate:this.rate,noiseShape:this.noiseShape,seed:this.seed},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.prototype.dispose=function(){return n.prototype.dispose.call(this)},t.className="Dropout",t}(De);y.serialization.registerClass(Id);var Ub=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.inputSpec=[{ndim:3}],i}return t.prototype.getNoiseShape=function(e){var i=e.shape;return[i[0],1,i[2]]},t.className="SpatialDropout1D",t}(Id);y.serialization.registerClass(Ub);var Bb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;if(i.activation=null,i.useBias=!0,i.kernel=null,i.bias=null,i.DEFAULT_KERNEL_INITIALIZER="glorotNormal",i.DEFAULT_BIAS_INITIALIZER="zeros",e.batchInputShape==null&&e.inputShape==null&&e.inputDim!=null){var r=null;e.batchSize!=null&&(r=e.batchSize),i.batchInputShape=[r,e.inputDim]}return i.units=e.units,Tt(i.units,"units"),i.activation=Ei(e.activation),e.useBias!=null&&(i.useBias=e.useBias),i.kernelInitializer=tt(e.kernelInitializer||i.DEFAULT_KERNEL_INITIALIZER),i.biasInitializer=tt(e.biasInitializer||i.DEFAULT_BIAS_INITIALIZER),i.kernelConstraint=wt(e.kernelConstraint),i.biasConstraint=wt(e.biasConstraint),i.kernelRegularizer=nt(e.kernelRegularizer),i.biasRegularizer=nt(e.biasRegularizer),i.activityRegularizer=nt(e.activityRegularizer),i.supportsMasking=!0,i.inputSpec=[{minNDim:2}],i}return t.prototype.build=function(e){var i;e=je(e);var r=e[e.length-1];this.kernel==null&&(this.kernel=this.addWeight("kernel",[r,this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint))),this.inputSpec=[{minNDim:2,axes:(i={},i[-1]=r,i)}],this.built=!0},t.prototype.computeOutputShape=function(e){e=je(e);var i=e.slice();return i[i.length-1]=this.units,i},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e),s=sy(r.activation.getClassName()),o;return s!=null?o=Mn(a,r.kernel.read(),s,r.bias?r.bias.read():null):(o=Mn(a,r.kernel.read()),r.bias!=null&&(o=Hn(o,r.bias.read())),r.activation!=null&&(o=r.activation.apply(o))),o})},t.prototype.getConfig=function(){var e={units:this.units,activation:Oi(this.activation),useBias:this.useBias,kernelInitializer:st(this.kernelInitializer),biasInitializer:st(this.biasInitializer),kernelRegularizer:Ke(this.kernelRegularizer),biasRegularizer:Ke(this.biasRegularizer),activityRegularizer:Ke(this.activityRegularizer),kernelConstraint:bt(this.kernelConstraint),biasConstraint:bt(this.biasConstraint)},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Dense",t}(De);y.serialization.registerClass(Bb);var zb=function(n){Q(t,n);function t(e){var i=this;return e=e||{},i=n.call(this,e)||this,i.inputSpec=[{minNDim:3}],i.dataFormat=e.dataFormat,i}return t.prototype.computeOutputShape=function(e){e=je(e);for(var i=0,r=e.slice(1);i<r.length;i++){var a=r[i];if(a==null)throw new M('The shape of the input to "Flatten" is not fully defined '+("(got "+e.slice(1)+"). Make sure to pass a complete ")+'"input_shape" or "batch_input_shape" argument to the first layer in your model.')}return[e[0],Ni(e,1)]},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e);if(r.dataFormat==="channelsFirst"&&a.rank>1){for(var s=[0],o=2;o<a.rank;++o)s.push(o);s.push(1),a=a.transpose(s)}return r3(a)})},t.prototype.getConfig=function(){var e={};this.dataFormat!=null&&(e.dataFormat=this.dataFormat);var i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Flatten",t}(De);y.serialization.registerClass(zb);var Pb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.supportsMasking=!0,i.activation=Ei(e.activation),i}return t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e);return r.activation.apply(a)})},t.prototype.getConfig=function(){var e={activation:Oi(this.activation)},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Activation",t}(De);y.serialization.registerClass(Pb);var _b=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.n=e.n,i.inputSpec=[{ndim:2}],i}return t.prototype.computeOutputShape=function(e){return[e[0],this.n,e[1]]},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){return e=xe(e),n3(e,r.n)})},t.prototype.getConfig=function(){var e={n:this.n},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="RepeatVector",t}(De);y.serialization.registerClass(_b);var Mb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;i.targetShape=e.targetShape;for(var r=0;r<i.targetShape.length;++r)i.isUnknown(i.targetShape[r])&&(i.targetShape[r]=null);return i}return t.prototype.isUnknown=function(e){return e<0||e==null},t.prototype.fixUnknownDimension=function(e,i){for(var r="Total size of new array must be unchanged.",a=i.slice(),s=1,o=null,l=0;l<a.length;++l){var u=a[l];if(this.isUnknown(u))if(o===null)o=l;else throw new M("Can only specifiy one unknown dimension.");else s*=u}var c=Ni(e);if(o!==null){if(s===0||c%s!==0)throw new M(r);a[o]=c/s}else if(c!==s)throw new M(r);return a},t.prototype.computeOutputShape=function(e){for(var i=!1,r=0;r<e.length;++r)if(this.isUnknown(e[r])){i=!0;break}return i?e.slice(0,1).concat(this.targetShape):e.slice(0,1).concat(this.fixUnknownDimension(e.slice(1),this.targetShape))},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e),s=a.shape,o=s.slice(0,1).concat(r.fixUnknownDimension(s.slice(1),r.targetShape));return a.reshape(o)})},t.prototype.getConfig=function(){var e={targetShape:this.targetShape},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Reshape",t}(De);y.serialization.registerClass(Mb);var Hb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;if(e.dims==null)throw new Error("Required configuration field `dims` is missing during Permute constructor call.");if(!Array.isArray(e.dims))throw new Error("Permute constructor requires `dims` to be an Array, but received "+(e.dims+" instead."));var r=Ln(1,e.dims.length+1);if(!y.util.arraysEqual(e.dims.slice().sort(),r))throw new Error("Invalid permutation `dims`: "+JSON.stringify(e.dims)+" `dims` must contain consecutive integers starting from 1.");return i.dims=e.dims,i.dimsIncludingBatch=[0].concat(i.dims),i.inputSpec=[new Nt({ndim:i.dims.length+1})],i}return t.prototype.computeOutputShape=function(e){e=je(e);var i=e.slice();return this.dims.forEach(function(r,a){i[a+1]=e[r]}),i},t.prototype.call=function(e,i){return y.transpose(xe(e),this.dimsIncludingBatch)},t.prototype.getConfig=function(){var e={dims:this.dims},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Permute",t}(De);y.serialization.registerClass(Hb);var Vb=function(n){Q(t,n);function t(e){var i=n.call(this,e??{})||this;return i.supportsMasking=!0,e!=null?i.maskValue=e.maskValue==null?0:e.maskValue:i.maskValue=0,i}return t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={maskValue:this.maskValue};return Object.assign(i,e),i},t.prototype.computeMask=function(e,i){var r=xe(e),a=-1;return y.any(y.notEqual(r,this.maskValue),a)},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e),s=-1,o=!0,l=y.any(y.notEqual(a,r.maskValue),s,o),u=a.mul(l.asType(a.dtype));return u})},t.className="Masking",t}(De);y.serialization.registerClass(Vb);var qb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;if(i.embeddings=null,i.DEFAULT_EMBEDDINGS_INITIALIZER="randomUniform",e.batchInputShape==null&&e.inputShape==null){var r=null;e.batchSize!=null&&(r=e.batchSize),e.inputLength==null?i.batchInputShape=[r,null]:i.batchInputShape=[r].concat(Je(e.inputLength))}return i.inputDim=e.inputDim,Tt(i.inputDim,"inputDim"),i.outputDim=e.outputDim,Tt(i.outputDim,"outputDim"),i.embeddingsInitializer=tt(e.embeddingsInitializer||i.DEFAULT_EMBEDDINGS_INITIALIZER),i.embeddingsRegularizer=nt(e.embeddingsRegularizer),i.activityRegularizer=nt(e.activityRegularizer),i.embeddingsConstraint=wt(e.embeddingsConstraint),i.maskZero=e.maskZero,i.supportsMasking=e.maskZero,i.inputLength=e.inputLength,i}return t.prototype.build=function(e){this.embeddings=this.addWeight("embeddings",[this.inputDim,this.outputDim],this.dtype,this.embeddingsInitializer,this.embeddingsRegularizer,!0,this.embeddingsConstraint),this.built=!0},t.prototype.warnOnIncompatibleInputShape=function(e){},t.prototype.computeMask=function(e,i){var r=this;return y.tidy(function(){return r.maskZero?(e=xe(e),y.notEqual(e,y.zerosLike(e))):null})},t.prototype.computeOutputShape=function(e){if(e=je(e),this.inputLength==null)return e.concat([this.outputDim]);var i=Je(this.inputLength);if(i.length!==e.length-1)throw new M('"inputLength" is '+this.inputLength+", but received "+("input shape has shape "+e));for(var r=0,a=0;a<i.length;++a){var s=i[a],o=e[a+1];if(s!=null&&o!=null&&s!==o)throw new M('"inputLength" is '+this.inputLength+", but received "+("input shape has shape "+e));s==null&&(i[r]=o),r++}return[e[0]].concat(i,[this.outputDim])},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e);a.dtype!=="int32"&&(a=es(a,"int32"));var s=wy(r.embeddings.read(),a.as1D());return s.reshape(je(r.computeOutputShape(a.shape)))})},t.prototype.getConfig=function(){var e={inputDim:this.inputDim,outputDim:this.outputDim,embeddingsInitializer:st(this.embeddingsInitializer),embeddingsRegularizer:Ke(this.embeddingsRegularizer),activityRegularizer:Ke(this.activityRegularizer),embeddingsConstraint:bt(this.embeddingsConstraint),maskZero:this.maskZero,inputLength:this.inputLength},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Embedding",t}(De);y.serialization.registerClass(qb);var mr=function(n){Q(t,n);function t(e){var i=n.call(this,e||{})||this;return i.supportsMasking=!0,i}return t.prototype.mergeFunction=function(e){throw new Te},t.prototype.computeElementwiseOpOutputShape=function(e,i){if(e==null||i==null)return null;if(e.length<i.length)return this.computeElementwiseOpOutputShape(i,e);if(i.length===0)return e;for(var r=e.slice(0,e.length-i.length),a=0;a<i.length;++a){var s=e[e.length-i.length+a],o=i[a];if(s==null||o==null||s<0||o<0)r.push(null);else if(s===1)r.push(o);else if(o===1)r.push(s);else{if(s!==o)throw new M("Operands could not be broadcast together with shapes "+JSON.stringify(e)+" "+JSON.stringify(i));r.push(s)}}return r},t.prototype.build=function(e){if(Array.isArray(e)&&!Array.isArray(e[0])&&(e=[je(e)]),e=e,e.length<2)throw new M("A merge layer should be called on an Array of at least 2 inputs."+(" Got "+e.length+" input(s)."));for(var i=[],r=0,a=e;r<a.length;r++){var s=a[r];s!=null&&s[0]!==null&&i.push(s[0])}if(i=Ti(i),i.length>1)throw new M("Can not merge tensors with different batch sizes. "+("Got tensors with shapes: "+JSON.stringify(e)+"."));for(var o=e[0]==null?null:e[0].slice(1),l=1;l<e.length;++l){var s=e[l]==null?null:e[l].slice(1);o=this.computeElementwiseOpOutputShape(o,s)}var u=e.map(function(c){return c.length});e.indexOf(null)===-1&&Ti(u).length===1?this.reshapeRequired=!1:this.reshapeRequired=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){if(e=e,r.reshapeRequired){var a=[],s=e.map(function(D){return D.rank});if(s.indexOf(null)===-1){for(var o=xi(s),l=0,u=e;l<u.length;l++){for(var c=u[l],h=c.rank,d=0;d<o-h;++d)c=ts(c,1);a.push(c)}return r.mergeFunction(a)}else{for(var p=!1,f=0,m=e;f<m.length;f++){var c=m[f],h=c.rank;if(h==null){var g=c.shape,v=g[0],b=g.slice(1).concat([v]),w=c.reshape([v].concat(Ni(g.slice(1))));w=y.transpose(w,[1,0]),w=w.reshape(b),a.push(w),p=!0}else if(h>1){var S=Ln(1,h).concat([0]);a.push(y.transpose(c,S)),p=!0}else a.push(c)}var L=r.mergeFunction(a),N=L.rank;if(p){if(N==null){var C=L.shape,R=C.length,v=C[R-1],b=[v].concat(C.slice(0,C.length-1));L=y.transpose(L.reshape([-1,v]),[1,0]).reshape(b)}else if(N>1){var S=[N-1].concat(Ln(0,N-1));L=y.transpose(L,S)}}return L}}else return r.mergeFunction(e)})},t.prototype.computeOutputShape=function(e){e=e;var i;e[0]==null?i=null:i=e[0].slice(1);for(var r=1;r<e.length;++r){var a=e[r]==null?null:e[r].slice(1);i=this.computeElementwiseOpOutputShape(i,a)}for(var s=[],o=0,l=e;o<l.length;o++){var a=l[o];a!=null&&a[0]!==null&&s.push(a[0])}return s=Ti(s),s.length===1?i=s.concat(i):i=[null].concat(i),i},t.prototype.computeMask=function(e,i){return y.tidy(function(){if(i==null)return null;if(!Array.isArray(i))throw new M("`mask` should be an Array");if(!Array.isArray(e))throw new M("`inputs` should be an Array");if(i.length!==e.length)throw new M("The Array 'inputs' and 'mask' are expected to have the same length, but have different lengths "+("("+e.length+" vs "+i.length+")"));if(i.every(function(s){return s==null}))return null;i=i.map(function(s){return s==null?s:y.expandDims(s,0)});for(var r=i[0],a=1;a<i.length-1;++a)r=y.logicalAnd(r,i[a]);return r})},t}(De),Gb=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.mergeFunction=function(e){return y.tidy(function(){for(var i=e[0].clone(),r=1;r<e.length;++r)i=y.add(i,e[r]);return i})},t.className="Add",t}(mr);y.serialization.registerClass(Gb);var Yb=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.mergeFunction=function(e){return y.tidy(function(){for(var i=e[0].clone(),r=1;r<e.length;++r)i=y.mul(i,e[r]);return i})},t.className="Multiply",t}(mr);y.serialization.registerClass(Yb);var jb=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.mergeFunction=function(e){return y.tidy(function(){for(var i=e[0].clone(),r=1;r<e.length;++r)i=y.add(i,e[r]);return y.mul(1/e.length,i)})},t.className="Average",t}(mr);y.serialization.registerClass(jb);var Kb=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.mergeFunction=function(e){return y.tidy(function(){for(var i=e[0],r=1;r<e.length;++r)i=y.maximum(i,e[r]);return i})},t.className="Maximum",t}(mr);y.serialization.registerClass(Kb);var $b=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.mergeFunction=function(e){return y.tidy(function(){for(var i=e[0],r=1;r<e.length;++r)i=y.minimum(i,e[r]);return i})},t.className="Minimum",t}(mr);y.serialization.registerClass($b);var Xb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.DEFAULT_AXIS=-1,e==null&&(e={}),i.axis=e.axis==null?i.DEFAULT_AXIS:e.axis,i.supportsMasking=!0,i.reshapeRequired=!1,i}return t.prototype.build=function(e){if(!(Array.isArray(e)&&Array.isArray(e[0]))||e.length===1)throw new M("A `Concatenate` layer should be called on a list of at least 2 inputs");e=e;for(var i=!0,r=0,a=e;r<a.length;r++){var s=a[r];if(s!=null){i=!1;break}}if(i)return;for(var o=[],l=0;l<e.length;++l){var u=e[l].slice();u.splice(this.axis,1);for(var c=!1,h=0,d=o;h<d.length;h++){var s=d[h];if(y.util.arraysEqual(s,u)){c=!0;break}}c||o.push(u)}if(o.length>1)throw new M("A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: "+JSON.stringify(e))},t.prototype.mergeFunction=function(e){var i=this;return y.tidy(function(){return Vh(e,i.axis)})},t.prototype.computeOutputShape=function(e){if(!(Array.isArray(e)&&Array.isArray(e[0])))throw new M("A `Concatenate` layer should be called on a list of inputs.");for(var i=e,r=i[0].slice(),a=this.axis<0?r.length+this.axis:this.axis,s=0,o=i.slice(1);s<o.length;s++){var l=o[s];if(r[a]==null||l[a]==null){r[a]=null;break}r[a]+=l[a]}return r},t.prototype.computeMask=function(e,i){var r=this;if(i==null)return null;if(!Array.isArray(i))throw new M("`mask` should be an array for Concatenate");if(!Array.isArray(e))throw new M("`inputs` should be an array for Concatenate");if(i.length!==e.length)throw new M("Mismatch in the length of mask ("+i.length+") "+("and the legnth of inputs ("+e.length+")"));return y.tidy(function(){var a=!0;if(i.forEach(function(u){if(u!=null){a=!1;return}}),a)return null;for(var s=[],o=0;o<e.length;++o)i[o]==null?s.push(y.onesLike(e[o]).asType("bool")):i[o].rank<e[o].rank?s.push(y.expandDims(i[o],-1)):s.push(i[o]);var l=y.concat(s,r.axis);return y.all(l,-1,!1)})},t.prototype.getConfig=function(){var e={axis:this.axis},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Concatenate",t}(mr);y.serialization.registerClass(Xb);function us(n,t){for(;n<0;)n+=t;return n}function nF(n,t,e){if(n.shape.length>3||t.shape.length>3)throw new Te("batchDot is not implemented for tensors of 4D or higher rank yet");if(y.util.assert(n.shape.length>=2,function(){return"batchDot requires the rank of x to be >= 2, "+("but got "+n.shape.length)}),y.util.assert(n.shape.length>=2,function(){return"batchDot requires the rank of y to be >= 2, "+("but got "+t.shape.length)}),typeof e=="number"&&(e=[e,e]),n.dtype==="complex64"||t.dtype==="complex64")throw new Te("batchDot is not implemented for complex64-type Tensors yet.");var i=n.shape.length,r=t.shape.length;e==null&&(e=[i-1,r-2]);var a=e;return y.tidy(function(){var s;if(i>r){s=i-r;for(var o=[],l=0;l<s;++l)o.push(1);t=t.reshape(t.shape.concat(o))}else if(r>i){s=r-i;for(var o=[],l=0;l<s;++l)o.push(1);n=n.reshape(n.shape.concat(o))}else s=0;var u;if(n.shape.length===2&&t.shape.length===2)a[0]===a[1]?u=n.mul(t).sum(a[0]):u=n.transpose([1,0]).mul(t).sum(a[1]);else{var c=a[0]!==n.shape.length-1,h=a[1]===t.shape.length-1;u=n.matMul(t,c,h)}if(s>0){var d=void 0;i>r?d=i+r-3:d=i-1;for(var p=[],l=d;l<d+s;++l)p.push(l);u=u.squeeze(p)}return u.shape.length===1&&(u=u.expandDims(1)),u})}var Jb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.axes=e.axes,i.normalize=e.normalize==null?!1:e.normalize,i.supportsMasking=!0,i.reshapeRequired=!1,i}return t.prototype.build=function(e){y.util.assert(Array.isArray(e)&&e.length===2&&Array.isArray(e[0])&&Array.isArray(e[1]),function(){return"A `Dot` layer should be called on a list of exactly 2 inputs."});var i=e[0],r=e[1];if(i.length>3||r.length>3)throw new Te("Dot layer does not support tensors of 4D or higher rank yet.");var a=this.interpretAxes(i,r);if(i[a[0]]!==r[a[1]])throw new M("Dimension incompatibility: "+(i[a[0]]+" !== "+r[a[1]]))},t.prototype.mergeFunction=function(e){if(e.length!==2)throw new M("A `Dot` layer must be called on exactly 2 inputs, "+("but received "+e.length+" input(s)."));var i=e[0],r=e[1],a;return Array.isArray(this.axes)?a=this.axes.map(function(s,o){return us(s,e[o].shape.length)}):a=[us(this.axes,i.shape.length),us(this.axes,r.shape.length)],this.normalize&&(i=Eo(i,a[0]),r=Eo(r,a[1])),nF(i,r,a)},t.prototype.interpretAxes=function(e,i){var r;return Array.isArray(this.axes)?r=this.axes:r=[us(this.axes,e.length),us(this.axes,i.length)],r},t.prototype.computeOutputShape=function(e){y.util.assert(Array.isArray(e)&&e.length===2&&Array.isArray(e[0])&&Array.isArray(e[1]),function(){return"A `Dot` layer should be called on a list of exactly 2 inputs."});var i=e[0].slice(),r=e[1].slice();if(i.length>3||r.length>3)throw new Te("Dot layer does not support tensors of 4D or higher rank yet.");var a=this.interpretAxes(i,r);i.splice(a[0],1),r.splice(a[1],1),r.splice(0,1);var s=i.concat(r);return s.length===1&&s.push(1),s},t.prototype.computeMask=function(e,i){return null},t.prototype.getConfig=function(){var e={axes:this.axes,normalize:this.normalize},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="Dot",t}(mr);y.serialization.registerClass(Jb);var Zb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.supportsMasking=!0,i.stddev=e.stddev,i}return t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={stddev:this.stddev};return Object.assign(i,e),i},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e),s=function(){return To(a.shape,0,r.stddev).add(a)},o=is(s,function(){return a},i.training||!1);return o})},t.className="GaussianNoise",t}(De);y.serialization.registerClass(Zb);var Qb=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.supportsMasking=!0,i.rate=e.rate,i}return t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={rate:this.rate};return Object.assign(i,e),i},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i);var a=xe(e);if(r.rate>0&&r.rate<1){var s=function(){var o=Math.sqrt(r.rate/(1-r.rate));return a.mul(To(a.shape,1,o))};return is(s,function(){return a},i.training||!1)}return a})},t.className="GaussianDropout",t}(De);y.serialization.registerClass(Qb);var ew=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.supportsMasking=!0,i.rate=e.rate,i.noiseShape=e.noiseShape,i}return t.prototype._getNoiseShape=function(e){return this.noiseShape||xe(e).shape},t.prototype.computeOutputShape=function(e){return e},t.prototype.getConfig=function(){var e=n.prototype.getConfig.call(this),i={rate:this.rate};return Object.assign(i,e),i},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){if(r.rate<1&&r.rate>0){var a=r._getNoiseShape(e),s=function(){var o=xe(e),l=1.6732632423543772,u=1.0507009873554805,c=-l*u,h=y.greaterEqual(y.randomUniform(a),r.rate);h=es(h,"float32");var d=Math.pow((1-r.rate)*(1+r.rate*Math.pow(c,2)),-.5),p=-d*c*r.rate,f=o.mul(h).add(h.add(-1).mul(c));return f.mul(d).add(p)};return is(s,function(){return xe(e)},i.training||!1)}return e})},t.className="AlphaDropout",t}(De);y.serialization.registerClass(ew);function cs(n,t,e,i,r,a){a===void 0&&(a=.001);var s;if(n.rank===2)s=y.batchNorm2d(n,t,e,i,r,a);else if(n.rank===3)s=y.batchNorm3d(n,t,e,i,r,a);else if(n.rank===4)s=y.batchNorm4d(n,t,e,i,r,a);else throw new Te("batchNormalization is not implemented for array of rank "+n.rank+" yet");return s}function iF(n,t,e,i,r){return r===void 0&&(r=.001),y.tidy(function(){var a=y.moments(n,i),s=a.mean,o=a.variance,l=cs(n,s,o,e,t,r);return[l,s,o]})}function rF(n,t,e,i,r){return r===void 0&&(r=.001),y.tidy(function(){for(var a=y.moments(n,i),s=a.mean,o=a.variance,l=[],u=0,c=Ln(0,n.rank);u<c.length;u++){var h=c[u];i.indexOf(h)!==-1?l.push(1):l.push(n.shape[h])}var d=s.reshape(l),p=o.reshape(l),f=t==null?null:t.reshape(l),m=e==null?null:e.reshape(l),g=cs(n,d,p,m,f,r);return[g,s,o]})}function aF(n,t,e,i,r){return r===void 0&&(r=.001),y.util.arraysEqual(i.slice().sort(),Ln(0,n.rank-1))?iF(n,t,e,i,r):rF(n,t,e,i,r)}var tw=function(n){Q(t,n);function t(e){var i=this;return e==null&&(e={}),i=n.call(this,e)||this,i.supportsMasking=!0,i.axis=e.axis==null?-1:e.axis,i.momentum=e.momentum==null?.99:e.momentum,i.epsilon=e.epsilon==null?.001:e.epsilon,i.center=e.center==null?!0:e.center,i.scale=e.scale==null?!0:e.scale,i.betaInitializer=tt(e.betaInitializer||"zeros"),i.gammaInitializer=tt(e.gammaInitializer||"ones"),i.movingMeanInitializer=tt(e.movingMeanInitializer||"zeros"),i.movingVarianceInitializer=tt(e.movingVarianceInitializer||"ones"),i.betaConstraint=wt(e.betaConstraint),i.gammaConstraint=wt(e.gammaConstraint),i.betaRegularizer=nt(e.betaRegularizer),i.gammaRegularizer=nt(e.gammaRegularizer),i}return t.prototype.build=function(e){var i;e=je(e);var r=this.axis>=0?this.axis:this.axis+e.length,a=e[r];if(a==null)throw new M("Axis "+r+" of input tensor should have a defined dimension but the layer received an input with shape "+(JSON.stringify(e)+"."));this.inputSpec=[new Nt({ndim:e.length,axes:(i={},i[r]=a,i)})];var s=[a];this.scale&&(this.gamma=this.addWeight("gamma",s,null,this.gammaInitializer,this.gammaRegularizer,!0,this.gammaConstraint)),this.center&&(this.beta=this.addWeight("beta",s,null,this.betaInitializer,this.betaRegularizer,!0,this.betaConstraint)),this.movingMean=this.addWeight("moving_mean",s,null,this.movingMeanInitializer,null,!1),this.movingVariance=this.addWeight("moving_variance",s,null,this.movingVarianceInitializer,null,!1),this.built=!0},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=i.training==null?!1:i.training,s=xe(e),o=s.shape,l=o.length,u=Ln(0,l),c=r.axis>=0?r.axis:r.axis+l;u.splice(c,1);var h=ur(1,l);h[c]=o[c];var d=u.slice();d.sort();var p=!y.util.arraysEqual(d,Ln(0,l).slice(0,l-1)),f=function(){if(p){var L=r.movingMean.read().reshape(h),N=r.movingVariance.read().reshape(h),C=r.center?r.beta.read().reshape(h):null,R=r.scale?r.gamma.read().reshape(h):null;return cs(s,L,N,C,R,r.epsilon)}else return cs(s,r.movingMean.read(),r.movingVariance.read(),r.beta==null?null:r.beta.read(),r.gamma==null?null:r.gamma.read(),r.epsilon)};if(!a)return f();var m=aF(s,r.gamma.read(),r.beta.read(),u,r.epsilon),g=m[0],v=m[1],b=m[2],w=function(L,N,C){y.tidy(function(){var R=1-C,D=L.read(),k=D.sub(N).mul(R);L.write(D.sub(k))})},S=function(){w(r.movingMean,v,r.momentum),w(r.movingVariance,b,r.momentum)};return S(),g})},t.prototype.getConfig=function(){var e={axis:this.axis,momentum:this.momentum,epsilon:this.epsilon,center:this.center,scale:this.scale,betaInitializer:st(this.betaInitializer),gammaInitializer:st(this.gammaInitializer),movingMeanInitializer:st(this.movingMeanInitializer),movingVarianceInitializer:st(this.movingVarianceInitializer),betaRegularizer:Ke(this.betaRegularizer),gammaRegularizer:Ke(this.gammaRegularizer),betaConstraint:bt(this.betaConstraint),gammaConstraint:bt(this.gammaConstraint)},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="BatchNormalization",t}(De);y.serialization.registerClass(tw);var nw=function(n){Q(t,n);function t(e){var i=this;if(e==null&&(e={}),i=n.call(this,e)||this,i.axis=e.axis==null?-1:e.axis,typeof i.axis=="number"){if(!Number.isInteger(i.axis))throw new Error("Expected axis to be an integer, but received "+i.axis)}else if(Array.isArray(i.axis))for(var r=0,a=i.axis;r<a.length;r++){var s=a[r];if(!Number.isInteger(s))throw new Error("Expected axis to be an array of integers, "+("but received "+JSON.stringify(i.axis)))}else throw new Error("Expected axis to be an integer or an array of integers, "+("but received "+JSON.stringify(i.axis)));return i.epsilon=e.epsilon==null?.001:e.epsilon,i.center=e.center==null?!0:e.center,i.scale=e.scale==null?!0:e.scale,i.betaInitializer=tt(e.betaInitializer||"zeros"),i.gammaInitializer=tt(e.gammaInitializer||"ones"),i.betaRegularizer=nt(e.betaRegularizer),i.gammaRegularizer=nt(e.gammaRegularizer),i.supportsMasking=!0,i}return t.prototype.build=function(e){e=je(e);var i=e.length;typeof this.axis=="number"&&(this.axis=[this.axis]);for(var r=0;r<this.axis.length;++r)this.axis[r]<0&&(this.axis[r]+=i);for(var a=0,s=this.axis;a<s.length;a++){var o=s[a];if(o<0||o>=i)throw new Error("Invalid axis: "+o)}if(this.axis.length!==Ti(this.axis).length)throw new Error("Found duplicate axes in: "+this.axis);var l=this.axis.map(function(c){return e[c]}),u=!0;this.scale?this.gamma=this.addWeight("gamma",l,"float32",this.gammaInitializer,this.gammaRegularizer,u):this.gamma=null,this.center?this.beta=this.addWeight("beta",l,"float32",this.betaInitializer,this.betaRegularizer,u):this.beta=null,this.built=!0},t.prototype.call=function(e,i){var r=this,a=xe(e),s=a.shape,o=s.length;return y.tidy(function(){for(var l=!0,u=y.moments(a,r.axis,l),c=u.mean,h=u.variance,d=ur(1,o),p=0,f=r.axis;p<f.length;p++){var m=f[p];d[m]=s[m]}for(var g=function(N){return N!=null&&N.shape.length!==o&&r.axis!==[o-1]?N.reshape(d):N},v=g(r.gamma.read()),b=g(r.beta.read()),w=[],S=[],L=0;L<o;++L)r.axis.indexOf(L)!==-1?(w.push(s[L]),S.push(1)):(w.push(1),S.push(s[L]));return c=c.tile(w),h=h.tile(w),v=v.tile(S),b=b.tile(S),cs(a,c,h,b,v,r.epsilon)})},t.prototype.getConfig=function(){var e={axis:this.axis,epsilon:this.epsilon,center:this.center,scale:this.scale,betaInitializer:st(this.betaInitializer),gammaInitializer:st(this.gammaInitializer),betaRegularizer:Ke(this.betaRegularizer),gammaRegularizer:Ke(this.gammaRegularizer)},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="LayerNormalization",t}(De);y.serialization.registerClass(nw);function sF(n,t,e){return y.tidy(function(){if(n.rank!==4)throw new M("temporalPadding expects input tensor to be 4-D, but received a "+(n.rank+"-D tensor."));if(t==null&&(t=[[1,1],[1,1]]),t.length!==2||t[0].length!==2||t[1].length!==2)throw new M("spatial2dPadding expects `padding` to be an Array of two Arrays, each of which is an Array of two integers.");if(e==null&&(e=Sn()),e!=="channelsLast"&&e!=="channelsFirst")throw new M("Unknown data format: "+e+". Supported data formats are 'channelsLast' and 'channelsFirst.");var i;return e==="channelsFirst"?i=[[0,0],[0,0],t[0],t[1]]:i=[[0,0],t[0],t[1],[0,0]],y.pad(n,i)})}var iw=function(n){Q(t,n);function t(e){var i=this;if(e==null&&(e={}),i=n.call(this,e)||this,i.dataFormat=e.dataFormat==null?Sn():e.dataFormat,e.padding==null)i.padding=[[1,1],[1,1]];else if(typeof e.padding=="number")i.padding=[[e.padding,e.padding],[e.padding,e.padding]];else{if(e.padding=e.padding,e.padding.length!==2)throw new M("ZeroPadding2D expects padding to be a length-2 array, but "+("received a length-"+e.padding.length+" array."));var r=void 0,a=void 0;if(typeof e.padding[0]=="number")r=[e.padding[0],e.padding[0]],a=[e.padding[1],e.padding[1]];else{if(e.padding=e.padding,e.padding[0].length!==2)throw new M("ZeroPadding2D expects height padding to be a length-2 array, "+("but received a length-"+e.padding[0].length+" array."));if(r=e.padding[0],e.padding[1].length!==2)throw new M("ZeroPadding2D expects width padding to be a length-2 array, "+("but received a length-"+e.padding[1].length+" array."));a=e.padding[1]}i.padding=[r,a]}return i.inputSpec=[new Nt({ndim:4})],i}return t.prototype.computeOutputShape=function(e){e=je(e);var i,r;return this.dataFormat==="channelsFirst"?(e[2]!=null&&e[2]>=0?i=e[2]+this.padding[0][0]+this.padding[0][1]:i=null,e[3]!=null&&e[3]>=0?r=e[3]+this.padding[1][0]+this.padding[1][1]:r=null,[e[0],e[1],i,r]):(e[1]!=null&&e[1]>=0?i=e[1]+this.padding[0][0]+this.padding[0][1]:i=null,e[2]!=null&&e[2]>=0?r=e[2]+this.padding[1][0]+this.padding[1][1]:r=null,[e[0],i,r,e[3]])},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){return sF(xe(e),r.padding,r.dataFormat)})},t.prototype.getConfig=function(){var e={padding:this.padding,dataFormat:this.dataFormat},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="ZeroPadding2D",t}(De);y.serialization.registerClass(iw);function Vo(n,t,e,i,r,a){return y.tidy(function(){ht(r),py(a),sn(i),e==null&&(e=[1,1]),i==null&&(i="valid"),r==null&&(r=Sn()),a==null&&(a="max"),n=vd(n,r);var s,o=i==="same"?"same":"valid";return a==="max"?s=y.maxPool(n,t,e,o):s=y.avgPool(n,t,e,o),r==="channelsFirst"&&(s=y.transpose(s,[0,3,1,2])),s})}function rw(n,t,e,i,r,a){return y.tidy(function(){ht(r),py(a),sn(i),e==null&&(e=[1,1,1]),i==null&&(i="valid"),r==null&&(r=Sn()),a==null&&(a="max"),n=wb(n,r);var s,o=i==="same"?"same":"valid";return a==="max"?s=y.maxPool3d(n,t,e,o):s=y.avgPool3d(n,t,e,o),r==="channelsFirst"&&(s=y.transpose(s,[0,4,1,2,3])),s})}var aw=function(n){Q(t,n);function t(e){var i=this;if(e.poolSize==null&&(e.poolSize=2),i=n.call(this,e)||this,typeof e.poolSize=="number")i.poolSize=[e.poolSize];else if(Array.isArray(e.poolSize)&&e.poolSize.length===1&&typeof e.poolSize[0]=="number")i.poolSize=e.poolSize;else throw new M("poolSize for 1D convolutional layer must be a number or an Array of a single number, but received "+(""+JSON.stringify(e.poolSize)));if(Tt(i.poolSize,"poolSize"),e.strides==null)i.strides=i.poolSize;else if(typeof e.strides=="number")i.strides=[e.strides];else if(Array.isArray(e.strides)&&e.strides.length===1&&typeof e.strides[0]=="number")i.strides=e.strides;else throw new M("strides for 1D convolutional layer must be a number or an Array of a single number, but received "+(""+JSON.stringify(e.strides)));return Tt(i.strides,"strides"),i.padding=e.padding==null?"valid":e.padding,sn(i.padding),i.inputSpec=[new Nt({ndim:3})],i}return t.prototype.computeOutputShape=function(e){e=je(e);var i=Tn(e[1],this.poolSize[0],this.padding,this.strides[0]);return[e[0],i,e[2]]},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){r.invokeCallHook(e,i),e=ts(xe(e),2);var a=r.poolingFunction(xe(e),[r.poolSize[0],1],[r.strides[0],1],r.padding,"channelsLast");return y.squeeze(a,[2])})},t.prototype.getConfig=function(){var e={poolSize:this.poolSize,padding:this.padding,strides:this.strides},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t}(De),sw=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.poolingFunction=function(e,i,r,a,s){return ht(s),sn(a),Vo(e,i,r,a,s,"max")},t.className="MaxPooling1D",t}(aw);y.serialization.registerClass(sw);var ow=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.poolingFunction=function(e,i,r,a,s){return ht(s),sn(a),Vo(e,i,r,a,s,"avg")},t.className="AveragePooling1D",t}(aw);y.serialization.registerClass(ow);var lw=function(n){Q(t,n);function t(e){var i=this;if(e.poolSize==null&&(e.poolSize=[2,2]),i=n.call(this,e)||this,i.poolSize=Array.isArray(e.poolSize)?e.poolSize:[e.poolSize,e.poolSize],e.strides==null)i.strides=i.poolSize;else if(Array.isArray(e.strides)){if(e.strides.length!==2)throw new M("If the strides property of a 2D pooling layer is an Array, it is expected to have a length of 2, but received length "+(e.strides.length+"."));i.strides=e.strides}else i.strides=[e.strides,e.strides];return Tt(i.poolSize,"poolSize"),Tt(i.strides,"strides"),i.padding=e.padding==null?"valid":e.padding,i.dataFormat=e.dataFormat==null?"channelsLast":e.dataFormat,ht(i.dataFormat),sn(i.padding),i.inputSpec=[new Nt({ndim:4})],i}return t.prototype.computeOutputShape=function(e){e=je(e);var i=this.dataFormat==="channelsFirst"?e[2]:e[1],r=this.dataFormat==="channelsFirst"?e[3]:e[2];return i=Tn(i,this.poolSize[0],this.padding,this.strides[0]),r=Tn(r,this.poolSize[1],this.padding,this.strides[1]),this.dataFormat==="channelsFirst"?[e[0],e[1],i,r]:[e[0],i,r,e[3]]},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){return r.invokeCallHook(e,i),r.poolingFunction(xe(e),r.poolSize,r.strides,r.padding,r.dataFormat)})},t.prototype.getConfig=function(){var e={poolSize:this.poolSize,padding:this.padding,strides:this.strides,dataFormat:this.dataFormat},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t}(De),uw=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.poolingFunction=function(e,i,r,a,s){return ht(s),sn(a),Vo(e,i,r,a,s,"max")},t.className="MaxPooling2D",t}(lw);y.serialization.registerClass(uw);var cw=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.poolingFunction=function(e,i,r,a,s){return ht(s),sn(a),Vo(e,i,r,a,s,"avg")},t.className="AveragePooling2D",t}(lw);y.serialization.registerClass(cw);var hw=function(n){Q(t,n);function t(e){var i=this;if(e.poolSize==null&&(e.poolSize=[2,2,2]),i=n.call(this,e)||this,i.poolSize=Array.isArray(e.poolSize)?e.poolSize:[e.poolSize,e.poolSize,e.poolSize],e.strides==null)i.strides=i.poolSize;else if(Array.isArray(e.strides)){if(e.strides.length!==3)throw new M("If the strides property of a 3D pooling layer is an Array, it is expected to have a length of 3, but received length "+(e.strides.length+"."));i.strides=e.strides}else i.strides=[e.strides,e.strides,e.strides];return Tt(i.poolSize,"poolSize"),Tt(i.strides,"strides"),i.padding=e.padding==null?"valid":e.padding,i.dataFormat=e.dataFormat==null?"channelsLast":e.dataFormat,ht(i.dataFormat),sn(i.padding),i.inputSpec=[new Nt({ndim:5})],i}return t.prototype.computeOutputShape=function(e){e=je(e);var i=this.dataFormat==="channelsFirst"?e[2]:e[1],r=this.dataFormat==="channelsFirst"?e[3]:e[2],a=this.dataFormat==="channelsFirst"?e[4]:e[3];return i=Tn(i,this.poolSize[0],this.padding,this.strides[0]),r=Tn(r,this.poolSize[1],this.padding,this.strides[1]),a=Tn(a,this.poolSize[2],this.padding,this.strides[2]),this.dataFormat==="channelsFirst"?[e[0],e[1],i,r,a]:[e[0],i,r,a,e[4]]},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){return r.invokeCallHook(e,i),r.poolingFunction(xe(e),r.poolSize,r.strides,r.padding,r.dataFormat)})},t.prototype.getConfig=function(){var e={poolSize:this.poolSize,padding:this.padding,strides:this.strides,dataFormat:this.dataFormat},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t}(De),dw=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.poolingFunction=function(e,i,r,a,s){return ht(s),sn(a),rw(e,i,r,a,s,"max")},t.className="MaxPooling3D",t}(hw);y.serialization.registerClass(dw);var pw=function(n){Q(t,n);function t(e){return n.call(this,e)||this}return t.prototype.poolingFunction=function(e,i,r,a,s){return ht(s),sn(a),rw(e,i,r,a,s,"avg")},t.className="AveragePooling3D",t}(hw);y.serialization.registerClass(pw);var fw=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.inputSpec=[new Nt({ndim:3})],i}return t.prototype.computeOutputShape=function(e){return[e[0],e[2]]},t.prototype.call=function(e,i){throw new Te},t}(De),mw=function(n){Q(t,n);function t(e){return n.call(this,e||{})||this}return t.prototype.call=function(e,i){return y.tidy(function(){var r=xe(e);return y.mean(r,1)})},t.className="GlobalAveragePooling1D",t}(fw);y.serialization.registerClass(mw);var gw=function(n){Q(t,n);function t(e){return n.call(this,e||{})||this}return t.prototype.call=function(e,i){return y.tidy(function(){var r=xe(e);return y.max(r,1)})},t.className="GlobalMaxPooling1D",t}(fw);y.serialization.registerClass(gw);var vw=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.dataFormat=e.dataFormat==null?"channelsLast":e.dataFormat,ht(i.dataFormat),i.inputSpec=[new Nt({ndim:4})],i}return t.prototype.computeOutputShape=function(e){return e=e,this.dataFormat==="channelsLast"?[e[0],e[3]]:[e[0],e[1]]},t.prototype.call=function(e,i){throw new Te},t.prototype.getConfig=function(){var e={dataFormat:this.dataFormat},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t}(De),yw=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=xe(e);return r.dataFormat==="channelsLast"?y.mean(a,[1,2]):y.mean(a,[2,3])})},t.className="GlobalAveragePooling2D",t}(vw);y.serialization.registerClass(yw);var bw=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=xe(e);return r.dataFormat==="channelsLast"?y.max(a,[1,2]):y.max(a,[2,3])})},t.className="GlobalMaxPooling2D",t}(vw);y.serialization.registerClass(bw);var ww=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.layer=e.layer,i}return t.prototype.build=function(e){this.built=!0},Object.defineProperty(t.prototype,"trainable",{get:function(){return this.layer!=null?this.layer.trainable:!1},set:function(e){this.layer!=null&&(this.layer.trainable=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"trainableWeights",{get:function(){return this.layer.trainableWeights},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){return this.layer.nonTrainableWeights},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updates",{get:function(){return this.layer._updates},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"losses",{get:function(){return this.layer.losses},enumerable:!0,configurable:!0}),t.prototype.getWeights=function(){return this.layer.getWeights()},t.prototype.setWeights=function(e){this.layer.setWeights(e)},t.prototype.getConfig=function(){var e={layer:{className:this.layer.getClassName(),config:this.layer.getConfig()}},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.prototype.setFastWeightInitDuringBuild=function(e){n.prototype.setFastWeightInitDuringBuild.call(this,e),this.layer!=null&&this.layer.setFastWeightInitDuringBuild(e)},t.fromConfig=function(e,i,r){r===void 0&&(r={});var a=i.layer,s=An(a,r);delete i.layer;var o={layer:s};return Object.assign(o,i),new e(o)},t}(De),Sw=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.supportsMasking=!0,i}return t.prototype.build=function(e){if(e=je(e),e.length<3)throw new M("TimeDistributed layer expects an input shape >= 3D, but received "+("input shape "+JSON.stringify(e)));this.inputSpec=[{shape:e}];var i=[e[0]].concat(e.slice(2));this.layer.built||(this.layer.build(i),this.layer.built=!0),n.prototype.build.call(this,e)},t.prototype.computeOutputShape=function(e){e=je(e);var i=[e[0]].concat(e.slice(2)),r=this.layer.computeOutputShape(i),a=e[1];return[r[0],a].concat(r.slice(1))},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){e=xe(e);var a=function(l,u){var c=xe(r.layer.call(l,i));return[c,[]]},s=Eb(a,e,[],!1,null,null,!1,!0),o=s[1];return o})},t.className="TimeDistributed",t}(ww);y.serialization.registerClass(Sw);function oF(n){ea(Zk,"BidirectionalMergeMode",n)}var lF="concat",Lw=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this,r=e.layer.getConfig(),a={};a.className=e.layer.getClassName(),a.config=r,i.forwardLayer=An(a),r.goBackwards=!(r.goBackwards===!0);var s={};if(s.className=e.layer.getClassName(),s.config=r,i.backwardLayer=An(s),i.forwardLayer.name="forward_"+i.forwardLayer.name,i.backwardLayer.name="backward_"+i.backwardLayer.name,i.mergeMode=e.mergeMode===void 0?lF:e.mergeMode,oF(i.mergeMode),e.weights)throw new Te("weights support is not implemented for Bidirectional layer yet.");return i._stateful=e.layer.stateful,i.returnSequences=e.layer.returnSequences,i.returnState=e.layer.returnState,i.supportsMasking=!0,i._trainable=!0,i.inputSpec=e.layer.inputSpec,i.numConstants=null,i}return Object.defineProperty(t.prototype,"trainable",{get:function(){return this._trainable},set:function(e){this._trainable=e,this.forwardLayer!=null&&(this.forwardLayer.trainable=e),this.backwardLayer!=null&&(this.backwardLayer.trainable=e)},enumerable:!0,configurable:!0}),t.prototype.getWeights=function(){return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights())},t.prototype.setWeights=function(e){var i=e.length,r=Math.floor(i/2);this.forwardLayer.setWeights(e.slice(0,r)),this.backwardLayer.setWeights(e.slice(r))},t.prototype.computeOutputShape=function(e){var i=this.forwardLayer.computeOutputShape(e);Array.isArray(i)&&Array.isArray(i[0])||(i=[i]),i=i;var r,a,s;return this.returnState&&(s=i.slice(1)),r=i[0],r=r,this.mergeMode==="concat"?(r[r.length-1]*=2,a=[r]):this.mergeMode==null?a=[r,r.slice()]:a=[r],this.returnState?this.mergeMode==null?a.concat(s).concat(s.slice()):[r].concat(s).concat(s.slice()):qt(a)},t.prototype.apply=function(e,i){var r=i==null?null:i.initialState,a=i==null?null:i.constants;i==null&&(i={});var s=Ob(e,r,a,this.numConstants);if(e=s.inputs,r=s.initialState,a=s.constants,Array.isArray(e)&&(r=e.slice(1),e=e[0]),(r==null||r.length===0)&&a==null)return n.prototype.apply.call(this,e,i);var o=[],l=[];if(r!=null){var u=r.length;if(u%2>0)throw new M("When passing `initialState` to a Bidrectional RNN, the state should be an Array containing the states of the underlying RNNs.");i.initialState=r,o.push.apply(o,r);var c=r.map(function(w){return new Nt({shape:w.shape})});this.forwardLayer.stateSpec=c.slice(0,u/2),this.backwardLayer.stateSpec=c.slice(u/2),l.push.apply(l,c)}if(a!=null)throw new Te("Support for constants in Bidirectional layers is not implemented yet.");for(var h=o[0]instanceof In,d=0,p=o;d<p.length;d++){var f=p[d];if(f instanceof In!==h)throw new M("The initial state of a Bidirectional layer cannot be specified as a mix of symbolic and non-symbolic tensors")}if(h){var m=[e].concat(o),g=this.inputSpec.concat(l),v=this.inputSpec;this.inputSpec=g;var b=n.prototype.apply.call(this,m,i);return this.inputSpec=v,b}else return n.prototype.apply.call(this,e,i)},t.prototype.call=function(e,i){var r=this;return y.tidy(function(){var a=i.initialState,s,o;if(a==null)s=r.forwardLayer.call(e,i),o=r.backwardLayer.call(e,i);else{var l=a.slice(0,a.length/2),u=a.slice(a.length/2);s=r.forwardLayer.call(e,Object.assign(i,{initialState:l})),o=r.backwardLayer.call(e,Object.assign(i,{initialState:u}))}var c;r.returnState&&(Array.isArray(s)&&(c=s.slice(1).concat(o.slice(1))),s=s[0],o=o[0]),r.returnSequences&&(o=y.reverse(o,1));var h;return r.mergeMode==="concat"?h=Vh([s,o]):r.mergeMode==="sum"?h=y.add(s,o):r.mergeMode==="ave"?h=y.mul(.5,y.add(s,o)):r.mergeMode==="mul"?h=y.mul(s,o):r.mergeMode==null&&(h=[s,o]),r.returnState?r.mergeMode==null?h.concat(c):[h].concat(c):h})},t.prototype.resetStates=function(e){this.forwardLayer.resetStates(),this.backwardLayer.resetStates()},t.prototype.build=function(e){var i=this;hr(this.forwardLayer.name,function(){i.forwardLayer.build(e)}),hr(this.backwardLayer.name,function(){i.backwardLayer.build(e)}),this.built=!0},t.prototype.computeMask=function(e,i){Array.isArray(i)&&(i=i[0]);var r;if(this.returnSequences?this.mergeMode==null?r=[i,i]:r=i:this.mergeMode==null?r=[null,null]:r=null,this.returnState){var a=this.forwardLayer.states,s=a.map(function(o){return null});return Array.isArray(r)?r.concat(s).concat(s):[r].concat(s).concat(s)}else return r},Object.defineProperty(t.prototype,"trainableWeights",{get:function(){return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights)},enumerable:!0,configurable:!0}),t.prototype.setFastWeightInitDuringBuild=function(e){n.prototype.setFastWeightInitDuringBuild.call(this,e),this.forwardLayer!=null&&this.forwardLayer.setFastWeightInitDuringBuild(e),this.backwardLayer!=null&&this.backwardLayer.setFastWeightInitDuringBuild(e)},t.prototype.getConfig=function(){var e={mergeMode:this.mergeMode},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.fromConfig=function(e,i){var r=An(i.layer);if(delete i.layer,i.numConstants!=null)throw new Te("Deserialization of a Bidirectional layer with numConstants present is not supported yet.");var a=i;return a.layer=r,new e(a)},t.className="Bidirectional",t}(ww);y.serialization.registerClass(Lw);function uF(n){return new rs(n)}function cF(n){return new vb(n)}function hF(n){return new fb(n)}function dF(n){return new mb(n)}function pF(n){return new gb(n)}function fF(n){return new bb(n)}function mF(n){return new yb(n)}function gF(n){return new Nb(n)}function vF(n){return new yd(n)}function yF(n){return new Ab(n)}function bF(n){return new Ib(n)}function wF(n){return new Tb(n)}function SF(n){return new xb(n)}function LF(n){return new Cb(n)}function IF(n){return new Rb(n)}function AF(n){return new Pb(n)}function TF(n){return new Bb(n)}function NF(n){return new Id(n)}function xF(n){return new Ub(n)}function CF(n){return new zb(n)}function RF(n){return new _b(n)}function OF(n){return new Mb(n)}function EF(n){return new Hb(n)}function DF(n){return new qb(n)}function kF(n){return new Gb(n)}function FF(n){return new jb(n)}function WF(n){return new Xb(n)}function UF(n){return new Kb(n)}function BF(n){return new $b(n)}function zF(n){return new Yb(n)}function PF(n){return new Jb(n)}function _F(n){return new tw(n)}function MF(n){return new nw(n)}function HF(n){return new iw(n)}function Ad(n){return new ow(n)}function VF(n){return Ad(n)}function qF(n){return Ad(n)}function Td(n){return new cw(n)}function GF(n){return Td(n)}function YF(n){return Td(n)}function Nd(n){return new pw(n)}function jF(n){return Nd(n)}function KF(n){return Nd(n)}function $F(n){return new mw(n)}function XF(n){return new yw(n)}function Iw(n){return new gw(n)}function Aw(n){return new bw(n)}function Tw(n){return new sw(n)}function Nw(n){return new uw(n)}function JF(n){return new dw(n)}function ZF(n){return new kb(n)}function QF(n){return new Sd(n)}function eW(n){return new Fb(n)}function tW(n){return new Ho(n)}function nW(n){return new Db(n)}function iW(n){return new wd(n)}function rW(n){return new Wb(n)}function aW(n){return new Ld(n)}function sW(n){return new Di(n)}function oW(n){return new bd(n)}function lW(n){return new Lw(n)}function uW(n){return new Sw(n)}var cW=Iw,hW=Aw,dW=Tw,pW=Nw;function fW(n){return new Zb(n)}function mW(n){return new Qb(n)}function gW(n){return new ew(n)}function vW(n){return new Vb(n)}var yW={__proto__:null,inputLayer:uF,elu:cF,reLU:hF,leakyReLU:dF,prelu:pF,softmax:fF,thresholdedReLU:mF,conv1d:gF,conv2d:vF,conv2dTranspose:yF,conv3d:bF,separableConv2d:wF,cropping2D:SF,upSampling2d:LF,depthwiseConv2d:IF,activation:AF,dense:TF,dropout:NF,spatialDropout1d:xF,flatten:CF,repeatVector:RF,reshape:OF,permute:EF,embedding:DF,add:kF,average:FF,concatenate:WF,maximum:UF,minimum:BF,multiply:zF,dot:PF,batchNormalization:_F,layerNormalization:MF,zeroPadding2d:HF,averagePooling1d:Ad,avgPool1d:VF,avgPooling1d:qF,averagePooling2d:Td,avgPool2d:GF,avgPooling2d:YF,averagePooling3d:Nd,avgPool3d:jF,avgPooling3d:KF,globalAveragePooling1d:$F,globalAveragePooling2d:XF,globalMaxPooling1d:Iw,globalMaxPooling2d:Aw,maxPooling1d:Tw,maxPooling2d:Nw,maxPooling3d:JF,gru:ZF,gruCell:QF,lstm:eW,lstmCell:tW,simpleRNN:nW,simpleRNNCell:iW,convLstm2d:rW,convLstm2dCell:aW,rnn:sW,stackedRNNCells:oW,bidirectional:lW,timeDistributed:uW,globalMaxPool1d:cW,globalMaxPool2d:hW,maxPool1d:dW,maxPool2d:pW,Layer:De,RNN:Di,RNNCell:oa,input:ub,gaussianNoise:fW,gaussianDropout:mW,alphaDropout:gW,masking:vW};function bW(n,t){return id(n,t)}function wW(n,t){return Yy(n,t)}function SW(n,t){return jy(n,t)}function LW(n,t){return rd(n,t)}function IW(n,t){return ad(n,t)}function AW(n,t){return Gy(n,t)}function TW(n,t){return j3(n,t)}function NW(n,t){return td(n,t)}function xW(n,t){return Do(n,t)}function CW(n,t){return ra(n,t)}function RW(n,t){return ra(n,t)}function OW(n,t){return ra(n,t)}function EW(n,t){return pr(n,t)}function DW(n,t){return pr(n,t)}function kW(n,t){return pr(n,t)}var FW={__proto__:null,binaryAccuracy:bW,binaryCrossentropy:wW,sparseCategoricalAccuracy:SW,categoricalAccuracy:LW,categoricalCrossentropy:IW,precision:AW,recall:TW,cosineProximity:NW,meanAbsoluteError:xW,meanAbsolutePercentageError:CW,MAPE:RW,mape:OW,meanSquaredError:EW,MSE:DW,mse:kW};var WW={__proto__:null,modelFromJSON:R4};function UW(n){return new Po(n)}function BW(n){return $4(n)}function zW(n){return X4(n)}var PW={__proto__:null,l1l2:UW,l1:BW,l2:zW};var xw=function(n){Q(t,n);function t(){var e=n!==null&&n.apply(this,arguments)||this;return e.model=null,e}return t.prototype.setModel=function(e){if(!(e instanceof Ri))throw new Error("model must be a LayersModel, not some other Container");this.model=e},t}(ia);function qo(n,t){return n<t}function Cw(n,t){return n>t}var Rw=function(n){Q(t,n);function t(e){var i=n.call(this)||this;if(e==null&&(e={}),e.restoreBestWeights)throw new Te("restoreBestWeights = True is not implemented in EarlyStopping yet.");return i.monitor=e.monitor||"val_loss",i.minDelta=Math.abs(e.minDelta||0),i.patience=e.patience||0,i.verbose=e.verbose||0,i.mode=e.mode||"auto",i.baseline=e.baseline,["auto","min","max"].indexOf(i.mode)===-1&&(console.warn("EarlyStopping mode '"+i.mode+"' is invalid. Falling back to mode 'auto'."),i.mode="auto"),i.mode==="min"?i.monitorFunc=qo:i.mode==="max"||i.monitor.indexOf("acc")!==-1?i.monitorFunc=Cw:i.monitorFunc=qo,i.monitorFunc===qo&&(i.minDelta*=-1),i}return t.prototype.onTrainBegin=function(e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return this.wait=0,this.stoppedEpoch=0,this.baseline!=null?this.best=this.baseline:this.best=this.monitorFunc===qo?Infinity:-Infinity,[2]})})},t.prototype.onEpochEnd=function(e,i){return Se(this,void 0,void 0,function(){var r;return ve(this,function(a){switch(a.label){case 0:return[4,Ci(i)];case 1:return a.sent(),r=this.getMonitorValue(i),r==null?[2]:(this.monitorFunc(r-this.minDelta,this.best)?(this.best=r,this.wait=0):(this.wait++,this.wait>=this.patience&&(this.stoppedEpoch=e,this.model.stopTraining=!0)),[2])}})})},t.prototype.onTrainEnd=function(e){return Se(this,void 0,void 0,function(){return ve(this,function(i){return this.stoppedEpoch>0&&this.verbose&&console.log("Epoch "+this.stoppedEpoch+": early stopping."),[2]})})},t.prototype.getMonitorValue=function(e){e==null&&(e={});var i=e[this.monitor];return i==null&&console.warn("Metric for EarlyStopping "+this.monitor+" is not available. "+("Available metrics are: "+Object.keys(e))),i},t}(xw);function _W(n){return new Rw(n)}var MW={earlyStopping:_W};Xe.Callback=xw;Xe.CallbackList=zy;Xe.CustomCallback=_y;Xe.EarlyStopping=Rw;Xe.History=Py;Xe.InputSpec=Nt;Xe.LayerVariable=ky;Xe.LayersModel=Ri;Xe.RNN=Di;Xe.Sequential=fd;Xe.SymbolicTensor=In;Xe.callbacks=MW;Xe.constraints=Kk;Xe.initializers=C3;Xe.input=ub;Xe.layers=yW;Xe.loadLayersModel=W4;Xe.metrics=FW;Xe.model=k4;Xe.models=WW;Xe.registerCallbackConstructor=U4;Xe.regularizers=PW;Xe.sequential=F4;Xe.version_layers=ld});var Gw=Le(gr=>{"use strict";Object.defineProperty(gr,"__esModule",{value:!0});var B=lr();var Ew=Object.assign||function(t){for(var e,i=1,r=arguments.length;i<r;i++){e=arguments[i];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t};function Vn(n,t,e,i){return new(e||(e=Promise))(function(r,a){function s(u){try{l(i.next(u))}catch(c){a(c)}}function o(u){try{l(i.throw(u))}catch(c){a(c)}}function l(u){u.done?r(u.value):new e(function(c){c(u.value)}).then(s,o)}l((i=i.apply(n,t||[])).next())})}function Nn(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,r,a,s;return s={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(u){return function(c){return l([u,c])}}function l(u){if(i)throw new TypeError("Generator is already executing.");for(;e;)try{if(i=1,r&&(a=r[u[0]&2?"return":u[0]?"throw":"next"])&&!(a=a.call(r,u[1])).done)return a;(r=0,a)&&(u=[0,a.value]);switch(u[0]){case 0:case 1:a=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,r=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){e.label=u[1];break}if(u[0]===6&&e.label<a[1]){e.label=a[1],a=u;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(u);break}a[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(n,e)}catch(c){u=[6,c],r=0}finally{i=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}var xn;(function(n){n[n.DT_INVALID=0]="DT_INVALID",n[n.DT_FLOAT=1]="DT_FLOAT",n[n.DT_DOUBLE=2]="DT_DOUBLE",n[n.DT_INT32=3]="DT_INT32",n[n.DT_UINT8=4]="DT_UINT8",n[n.DT_INT16=5]="DT_INT16",n[n.DT_INT8=6]="DT_INT8",n[n.DT_STRING=7]="DT_STRING",n[n.DT_COMPLEX64=8]="DT_COMPLEX64",n[n.DT_INT64=9]="DT_INT64",n[n.DT_BOOL=10]="DT_BOOL",n[n.DT_QINT8=11]="DT_QINT8",n[n.DT_QUINT8=12]="DT_QUINT8",n[n.DT_QINT32=13]="DT_QINT32",n[n.DT_BFLOAT16=14]="DT_BFLOAT16",n[n.DT_FLOAT_REF=101]="DT_FLOAT_REF",n[n.DT_DOUBLE_REF=102]="DT_DOUBLE_REF",n[n.DT_INT32_REF=103]="DT_INT32_REF",n[n.DT_UINT8_REF=104]="DT_UINT8_REF",n[n.DT_INT16_REF=105]="DT_INT16_REF",n[n.DT_INT8_REF=106]="DT_INT8_REF",n[n.DT_STRING_REF=107]="DT_STRING_REF",n[n.DT_COMPLEX64_REF=108]="DT_COMPLEX64_REF",n[n.DT_INT64_REF=109]="DT_INT64_REF",n[n.DT_BOOL_REF=110]="DT_BOOL_REF",n[n.DT_QINT8_REF=111]="DT_QINT8_REF",n[n.DT_QUINT8_REF=112]="DT_QUINT8_REF",n[n.DT_QINT32_REF=113]="DT_QINT32_REF",n[n.DT_BFLOAT16_REF=114]="DT_BFLOAT16_REF"})(xn||(xn={}));var Dw;(function(n){var t;(function(e){e[e.LEGACY=0]="LEGACY",e[e.V1=1]="V1",e[e.V2=2]="V2"})(t=n.CheckpointFormatVersion||(n.CheckpointFormatVersion={}))})(Dw||(Dw={}));var xd={};function HW(n,t){var e={tfOpName:n,category:"custom",inputs:[],attrs:[],customExecutor:t};xd[n]=e}function kw(n){return xd[n]}function VW(n){delete xd[n]}function A(n,t,e,i){var r=t.inputParams[n];if(r&&r.inputIndexStart!==void 0){var a=r.inputIndexStart,s=r.inputIndexEnd===0?void 0:r.inputIndexEnd===void 0?a+1:r.inputIndexEnd;if(r.type==="tensor")return Gt(t.inputNames[r.inputIndexStart],e,i);if(r.type==="tensors"){var o=t.inputNames.slice(a,s);return o.map(function(h){return Gt(h,e,i)})}var l=Gt(t.inputNames.slice(a)[0],e,i),u=l.dataSync();return r.type==="number"?u[0]:B.util.toNestedArray(l.shape,u)}var c=t.attrParams[n];return c&&c.value}function Gt(n,t,e){var i=Zt(n),r=i[0],a=i[1],s=e.currentContextIds.find(function(o){return!!t[Go(r,o)]});return s!==void 0?t[Go(r,s)][a]:void 0}function qW(n,t,e){return t[Go(n,e.currentContextId)]}function si(n,t){var e=Zt(n),i=e[0],r=e[1];return[Go(i,t&&t.currentContextId),r]}function Go(n,t){return t?n+"-"+t:n}function Zt(n){var t=n.split(":");if(t.length===1)return[n,0];var e=t[0];return[e,Number(t[t.length-1])]}function Yo(n,t,e){var i=A("pad",n,t,e);if(i==="explicit"){i=A("explicitPaddings",n,t,e);for(var r=[[0,0],[0,0],[0,0],[0,0]],a=0;a<4;a++)r[a][0]=i[a*2],r[a][1]=i[a*2+1];return r}return i}function oi(n){return n.kept?n:B.clone(n)}var GW=[{tfOpName:"Add",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AddV2",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AddN",category:"arithmetic",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}]},{tfOpName:"BiasAdd",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sub",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"RealDiv",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Div",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"DivNoNan",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"FloorDiv",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Mul",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Maximum",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}]},{tfOpName:"Minimum",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}]},{tfOpName:"Pow",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"SquaredDifference",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Mod",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"FloorMod",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}],YW={__proto__:null,json:GW};var jW=[{tfOpName:"Abs",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Acos",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Asin",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atan",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atan2",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"y",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Ceil",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ClipByValue",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"clip_value_min",name:"clipValueMin",type:"number"},{tfName:"clip_value_max",name:"clipValueMax",type:"number"}]},{tfOpName:"Complex",category:"basic_math",inputs:[{start:0,name:"real",type:"tensor"},{start:1,name:"imag",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ComplexAbs",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Cos",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Cosh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Elu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Exp",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Floor",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Log",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Imag",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"Tout",name:"outputType",type:"dtype",notSupported:!0}]},{tfOpName:"Neg",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Real",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"Tout",name:"outputType",type:"dtype",notSupported:!0}]},{tfOpName:"Prelu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"alpha",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Relu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Relu6",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"clipValueMin",name:"clipValueMin",type:"number",defaultValue:0},{tfName:"clipValueMax",name:"clipValueMax",type:"number",defaultValue:6}]},{tfOpName:"Selu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sigmoid",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sin",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sinh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sqrt",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Rsqrt",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Square",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Tan",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Tanh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sign",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Round",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Expm1",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Log1p",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Reciprocal",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Softplus",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Asinh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Acosh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atanh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Erf",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Prod",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axes",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool",notSupported:!0},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LeakyRelu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"alpha",name:"alpha",type:"number",defaultValue:.2},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}],KW={__proto__:null,json:jW};var $W=[{tfOpName:"LoopCond",category:"control",inputs:[{start:0,name:"pred",type:"tensor"}]},{tfOpName:"Switch",category:"control",inputs:[{start:0,name:"data",type:"tensor"},{start:1,name:"pred",type:"tensor"}]},{tfOpName:"Merge",category:"control",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}]},{tfOpName:"Enter",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"frame_name",name:"frameName",type:"string"},{tfName:"is_constant",name:"isConstant",type:"bool"}]},{tfOpName:"Exit",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"NextIteration",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayV3",category:"control",inputs:[{start:0,name:"size",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape",name:"elementShape",type:"shape"},{tfName:"dynamic_size",name:"dynamicSize",type:"bool"},{tfName:"clear_after_read",name:"clearAfterRead",type:"bool"},{tfName:"identical_element_shapes",name:"identicalElementShapes",type:"bool"},{tfName:"tensor_array_name",name:"name",type:"string"}]},{tfOpName:"TensorArrayWriteV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"tensor",type:"tensor"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayReadV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayGatherV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape",name:"elementShape",type:"shape"}]},{tfOpName:"TensorArrayScatterV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"tensor",type:"tensor"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"TensorArrayConcatV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape_except0",name:"elementShapeExcept0",type:"shape",notSupported:!0}]},{tfOpName:"TensorArraySplitV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"tensor",type:"tensor"},{start:2,name:"lengths",type:"number[]"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"TensorArraySizeV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"},{start:1,name:"flowIn",type:"number"}]},{tfOpName:"TensorArrayCloseV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"tensor"}]},{tfOpName:"StatelessIf",category:"control",inputs:[{start:0,name:"cond",type:"tensor"},{start:1,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"then_branch",name:"thenBranch",type:"func"},{tfName:"else_branch",name:"elseBranch",type:"func"}]},{tfOpName:"If",category:"control",inputs:[{start:0,name:"cond",type:"tensor"},{start:1,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"then_branch",name:"thenBranch",type:"func"},{tfName:"else_branch",name:"elseBranch",type:"func"}]},{tfOpName:"StatelessWhile",category:"control",inputs:[{start:0,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"cond",name:"cond",type:"func"},{tfName:"body",name:"body",type:"func"}]},{tfOpName:"While",category:"control",inputs:[{start:0,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"cond",name:"cond",type:"func"},{tfName:"body",name:"body",type:"func"}]},{tfOpName:"TensorListScatter",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListScatterV2",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"elementShape",type:"shape"},{start:3,name:"numElements",type:"number"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListGather",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"indices",type:"number[]"},{start:2,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListGetItem",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListSetItem",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"index",type:"number"},{start:2,name:"tensor",type:"tensor"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListReserve",category:"control",inputs:[{start:0,name:"elementShape",type:"shape"},{start:1,name:"numElements",type:"number"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListFromTensor",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListStack",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"},{tfName:"num_elements",name:"numElements",type:"dtype"}]},{tfOpName:"TensorListSplit",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"},{start:1,name:"elementShape",type:"shape"},{start:2,name:"lengths",type:"number[]"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListConcat",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"}],attrs:[{tfName:"element_shape",name:"elementShape",type:"shape"},{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListPopBack",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"elementShape",type:"shape"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]},{tfOpName:"TensorListPushBack",category:"control",inputs:[{start:0,name:"tensorListId",type:"tensor"},{start:1,name:"tensor",type:"tensor"}],attrs:[{tfName:"element_dtype",name:"elementDType",type:"dtype"}]}],XW={__proto__:null,json:$W};var JW=[{tfOpName:"AvgPool",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPool",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPoolWithArgmax",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"include_batch_in_index",name:"includeBatchInIndex",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AvgPool3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPool3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Conv1D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"stride",name:"stride",type:"number"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NWC"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"dilation",name:"dilation",type:"number",defaultValue:1}]},{tfOpName:"Conv2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"useCudnnOnGpu",name:"useCudnnOnGpu",type:"bool"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"_FusedConv2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"use_cudnn_on_gpu",name:"useCudnnOnGpu",type:"bool",defaultValue:!0},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]",defaultValue:[1,1,1,1]},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]},{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:1e-4}]},{tfOpName:"Conv2DBackpropInput",category:"convolution",inputs:[{start:2,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:0,name:"outputShape",type:"number[]"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]}]},{tfOpName:"DepthwiseConv2d",category:"convolution",inputs:[{start:0,name:"input",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"DepthwiseConv2dNative",category:"convolution",inputs:[{start:0,name:"input",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"FusedDepthwiseConv2dNative",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]",defaultValue:[1,1,1,1]},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]}]},{tfOpName:"Conv3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"Dilation2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"rates",name:"dilations",type:"number[]"},{tfName:"padding",name:"pad",type:"string"}]}],ZW={__proto__:null,json:JW};var QW=[{tfOpName:"Fill",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"},{start:1,name:"value",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"LinSpace",category:"creation",inputs:[{start:0,name:"start",type:"number"},{start:1,name:"stop",type:"number"},{start:2,name:"num",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"OneHot",category:"creation",inputs:[{start:0,name:"indices",type:"tensor"},{start:1,name:"depth",type:"number"},{start:2,name:"onValue",type:"number",defaultValue:1},{start:3,name:"offValue",type:"number",defaultValue:0}],attrs:[{tfName:"axis",name:"axis",type:"number",notSupported:!0},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Ones",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"OnesLike",category:"creation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"RandomUniform",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"minval",name:"minval",type:"number",defaultValue:0},{tfName:"maxval",name:"maxval",type:"number",defaultValue:1},{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"seed",name:"seed",type:"number",defaultValue:0},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0},{tfName:"T",name:"T",type:"number",notSupported:!0}]},{tfOpName:"Range",category:"creation",inputs:[{start:0,name:"start",type:"number"},{start:1,name:"stop",type:"number"},{start:2,name:"step",type:"number",defaultValue:0}],attrs:[{tfName:"Tidx",name:"dtype",type:"dtype"}]},{tfOpName:"TruncatedNormal",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"means",name:"mean",type:"number",defaultValue:0},{tfName:"stddev",name:"stdDev",type:"number",defaultValue:1},{tfName:"seed",name:"seed",type:"number"},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0},{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"T",name:"T",type:"number",notSupported:!0}]},{tfOpName:"Zeros",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"ZerosLike",category:"creation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"Multinomial",category:"creation",inputs:[{start:0,name:"logits",type:"tensor"},{start:1,name:"numSamples",type:"number"}],attrs:[{tfName:"seed",name:"seed",type:"number"},{tfName:"seed2",name:"seed2",type:"number"},{tfName:"T",name:"dtype",type:"dtype"},{tfName:"output_dtype",name:"output_dtype",type:"dtype"}]}],eU={__proto__:null,json:QW};var tU=[{tfOpName:"NonMaxSuppressionV2",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"}]},{tfOpName:"NonMaxSuppressionV3",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"}]},{tfOpName:"NonMaxSuppressionV4",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"T_threshold",name:"threshold",type:"dtype",notSupported:!0},{tfName:"pad_to_max_output_size",name:"padToMaxOutputSize",type:"bool"}]},{tfOpName:"NonMaxSuppressionV5",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"},{start:5,name:"softNmsSigma",type:"number"}]},{tfOpName:"Where",category:"dynamic",inputs:[{start:0,name:"condition",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ListDiff",category:"dynamic",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"y",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}],nU={__proto__:null,json:tU};var iU=[{tfOpName:"TopKV2",category:"evaluation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"k",type:"number"}],attrs:[{tfName:"sorted",name:"sorted",type:"bool"}]},{tfOpName:"Unique",category:"evaluation",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"UniqueV2",category:"evaluation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]}],rU={__proto__:null,json:iU};var aU=[{tfOpName:"PlaceholderWithDefault",category:"graph",inputs:[{start:0,name:"default",type:"tensor"}],attrs:[{tfName:"shape",name:"shape",type:"shape"},{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"Placeholder",category:"graph",attrs:[{tfName:"shape",name:"shape",type:"shape"},{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"Const",category:"graph"},{tfOpName:"Identity",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"IdentityN",category:"graph",inputs:[{start:0,end:0,name:"x",type:"tensors"}]},{tfOpName:"Snapshot",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Rank",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Size",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Shape",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"ShapeN",category:"graph",inputs:[{start:0,end:0,name:"x",type:"tensors"}]},{tfOpName:"Print",category:"graph",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"data",type:"tensors"}],attrs:[{tfName:"message",name:"message",type:"string"},{tfName:"first_n",name:"firstN",type:"number",notSupported:!0},{tfName:"summarize",name:"summarize",type:"number",defaultValue:3}]},{tfOpName:"NoOp",category:"graph",inputs:[]},{tfOpName:"StopGradient",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"FakeQuantWithMinMaxVars",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"min",name:"min",type:"number"},{tfName:"max",name:"max",type:"number"}]}],sU={__proto__:null,json:aU};var oU=[{tfOpName:"ResizeBilinear",category:"image",inputs:[{start:0,name:"images",type:"tensor"},{start:1,name:"size",type:"number[]"}],attrs:[{tfName:"align_corners",name:"alignCorners",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ResizeNearestNeighbor",category:"image",inputs:[{start:0,name:"images",type:"tensor"},{start:1,name:"size",type:"number[]"}],attrs:[{tfName:"align_corners",name:"alignCorners",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"CropAndResize",category:"image",inputs:[{start:0,name:"image",type:"tensor"},{start:1,name:"boxes",type:"tensor"},{start:2,name:"boxInd",type:"tensor"},{start:3,name:"cropSize",type:"number[]"}],attrs:[{tfName:"method",name:"method",type:"string"},{tfName:"extrapolation_value",name:"extrapolationValue",type:"number"}]}],lU={__proto__:null,json:oU};var uU=[{tfOpName:"Equal",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"NotEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Greater",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"GreaterEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Less",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LessEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalAnd",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalNot",category:"logical",inputs:[{start:0,name:"a",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalOr",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Select",category:"logical",inputs:[{start:0,name:"condition",type:"tensor"},{start:1,name:"a",type:"tensor"},{start:2,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"SelectV2",category:"logical",inputs:[{start:0,name:"condition",type:"tensor"},{start:1,name:"a",type:"tensor"},{start:2,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}],cU={__proto__:null,json:uU};var hU=[{tfOpName:"_FusedMatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]},{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:1e-4},{tfName:"transpose_a",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"transpose_b",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"transpose_a",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"transpose_b",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"BatchMatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"adj_x",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"adj_y",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"BatchMatMulV2",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"adj_x",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"adj_y",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Transpose",category:"matrices",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"perm",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}],dU={__proto__:null,json:hU};var pU=[{tfOpName:"FusedBatchNorm",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"FusedBatchNormV2",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"FusedBatchNormV3",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"LRN",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"depth_radius",name:"radius",type:"number",defaultValue:5},{tfName:"bias",name:"bias",type:"number",defaultValue:1},{tfName:"alpha",name:"alpha",type:"number",defaultValue:1},{tfName:"beta",name:"beta",type:"number",defaultValue:.5}]},{tfOpName:"Softmax",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"LogSoftmax",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"SparseToDense",category:"normalization",inputs:[{start:0,name:"sparseIndices",type:"tensor"},{start:1,name:"outputShape",type:"number[]"},{start:2,name:"sparseValues",type:"tensor"},{start:3,name:"defaultValue",type:"tensor"}],attrs:[{tfName:"validate_indices",name:"validateIndices",type:"bool",defaultValue:!0,notSupported:!0}]}],fU={__proto__:null,json:pU};var mU=[{tfOpName:"Max",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Mean",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Min",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Sum",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"All",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Any",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"ArgMax",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"ArgMin",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"Prod",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Cumsum",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}],attrs:[{tfName:"exclusive",name:"exclusive",type:"bool"},{tfName:"reverse",name:"reverse",type:"bool"}]}],gU={__proto__:null,json:mU};var vU=[{tfOpName:"ConcatV2",category:"slice_join",inputs:[{start:0,end:-1,name:"tensors",type:"tensors"},{start:-1,name:"axis",type:"number"}],attrs:[{tfName:"N",name:"n",type:"number",defaultValue:2}]},{tfOpName:"Concat",category:"slice_join",inputs:[{start:1,end:0,name:"tensors",type:"tensors"},{start:0,name:"axis",type:"number"}],attrs:[{tfName:"N",name:"n",type:"number",defaultValue:2}]},{tfOpName:"GatherV2",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"},{start:2,name:"axis",type:"number",defaultValue:0}]},{tfOpName:"Gather",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0},{tfName:"validate_indices",name:"validateIndices",type:"bool",notSupported:!0}]},{tfOpName:"Reverse",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"dims",type:"bool",notSupported:!0}]},{tfOpName:"ReverseV2",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}]},{tfOpName:"Slice",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"begin",type:"number[]"},{start:2,name:"size",type:"number[]"}]},{tfOpName:"StridedSlice",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"begin",type:"number[]"},{start:2,name:"end",type:"number[]"},{start:3,name:"strides",type:"number[]"}],attrs:[{tfName:"begin_mask",name:"beginMask",type:"number",defaultValue:0},{tfName:"end_mask",name:"endMask",type:"number",defaultValue:0},{tfName:"new_axis_mask",name:"newAxisMask",type:"number",defaultValue:0},{tfName:"ellipsis_mask",name:"ellipsisMask",type:"number",defaultValue:0},{tfName:"shrink_axis_mask",name:"shrinkAxisMask",type:"number",defaultValue:0}]},{tfOpName:"Pack",category:"slice_join",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0}]},{tfOpName:"Unpack",category:"slice_join",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0},{tfName:"num",name:"num",type:"number",defaultValue:0,notSupported:!0}]},{tfOpName:"Tile",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"reps",type:"number[]"}]},{tfOpName:"Split",category:"slice_join",inputs:[{start:0,name:"axis",type:"number",defaultValue:0},{start:1,name:"x",type:"tensor"}],attrs:[{tfName:"num_split",name:"numOrSizeSplits",type:"number",defaultValue:1}]},{tfOpName:"SplitV",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"numOrSizeSplits",type:"number[]"},{start:2,name:"axis",type:"number",defaultValue:0}]},{tfOpName:"ScatterNd",category:"slice_join",inputs:[{start:0,name:"indices",type:"tensor"},{start:1,name:"values",type:"tensor"},{start:2,name:"shape",type:"number[]"}]},{tfOpName:"GatherNd",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"}]},{tfOpName:"SparseToDense",category:"slice_join",inputs:[{start:0,name:"sparseIndices",type:"tensor"},{start:1,name:"outputShape",type:"number[]"},{start:2,name:"sparseValues",type:"tensor"},{start:3,name:"defaultValue",type:"tensor"}],attrs:[{tfName:"validate_indices",name:"validateIndices",type:"bool",defaultValue:!1,notSupported:!0}]}],yU={__proto__:null,json:vU};var bU=[{tfOpName:"FFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"IFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"RFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"fft_length",type:"number",notSupported:!0}]},{tfOpName:"IRFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"fft_length",type:"number",notSupported:!0}]}],wU={__proto__:null,json:bU};var SU=[{tfOpName:"Cast",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"SrcT",name:"sdtype",type:"dtype",notSupported:!0},{tfName:"DstT",name:"dtype",type:"dtype"}]},{tfOpName:"ExpandDims",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"Pad",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"padding",type:"number[]"}],attrs:[{tfName:"constant_value",name:"constantValue",type:"number",defaultValue:0}]},{tfOpName:"PadV2",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"padding",type:"number[]"},{start:2,name:"constantValue",type:"number",defaultValue:0}]},{tfOpName:"Reshape",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"shape",type:"number[]"}]},{tfOpName:"Squeeze",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"axis",tfDeprecatedName:"squeeze_dims",name:"axis",type:"number[]"}]},{tfOpName:"SpaceToBatchND",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"blockShape",type:"number[]"},{start:2,name:"paddings",type:"number[]"}]},{tfOpName:"BatchToSpaceND",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"blockShape",type:"number[]"},{start:2,name:"crops",type:"number[]"}]},{tfOpName:"DepthToSpace",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"block_size",name:"blockSize",type:"number"},{tfName:"data_format",name:"dataFormat",type:"string"}]},{tfOpName:"BroadcastTo",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"shape",type:"number[]"}],attrs:[]}],LU={__proto__:null,json:SU};var Ww=function(){function n(){var t=[YW,KW,XW,ZW,eU,nU,rU,cU,lU,sU,dU,fU,gU,yU,wU,LU],e=[].concat.apply([],t.map(function(i){return i.json}));this.opMappers=e.reduce(function(i,r){return i[r.tfOpName]=r,i},{})}return Object.defineProperty(n,"Instance",{get:function(){return this._instance||(this._instance=new this)},enumerable:!0,configurable:!0}),n.prototype.transformGraph=function(t,e){var i=this;e===void 0&&(e={});var r=t.node,a=[],s=[],o=[],l=r.reduce(function(g,v){return g[v.name]=i.mapNode(v),v.op.startsWith("Placeholder")?a.push(g[v.name]):v.op==="Const"?s.push(g[v.name]):(v.input==null||v.input.length===0)&&o.push(g[v.name]),g},{}),u=[],c=[],h={},d={};e!=null&&(h=this.mapSignatureEntries(e.inputs),d=this.mapSignatureEntries(e.outputs));var p=Object.keys(l);p.forEach(function(g){var v=l[g];v.inputNames.forEach(function(b){var w=si(b)[0];v.inputs.push(l[w]),l[w].children.push(v)})}),Object.keys(d).length===0?p.forEach(function(g){var v=l[g];v.children.length===0&&c.push(v)}):Object.keys(d).forEach(function(g){var v=si(g)[0],b=l[v];b!=null&&(b.signatureKey=d[g],c.push(b))}),Object.keys(h).length>0?Object.keys(h).forEach(function(g){var v=si(g)[0],b=l[v];b&&(b.signatureKey=h[g],u.push(b))}):u=a;var f={};t.library!=null&&t.library.function!=null&&(f=t.library.function.reduce(function(g,v){return g[v.signature.name]=i.mapFunction(v),g},{}));var m={nodes:l,inputs:u,outputs:c,weights:s,placeholders:a,signature:e,functions:f};return o.length>0&&(m.initNodes=o),m},n.prototype.mapSignatureEntries=function(t){return Object.keys(t||{}).reduce(function(e,i){return e[t[i].name]=i,e},{})},n.prototype.mapNode=function(t){var e=kw(t.op)||this.opMappers[t.op]||{};t.attr==null&&(t.attr={});var i={name:t.name,op:t.op,category:e.category,inputNames:(t.input||[]).map(function(r){return r.startsWith("^")?r.substr(1):r}),inputs:[],children:[],inputParams:{},attrParams:{},rawAttrs:t.attr};return e.inputs!=null&&(i.inputParams=e.inputs.reduce(function(r,a){return r[a.name]={type:a.type,inputIndexStart:a.start,inputIndexEnd:a.end},r},{})),e.attrs!=null&&(i.attrParams=e.attrs.reduce(function(r,a){var s=a.type,o=void 0;switch(a.type){case"string":o=Cd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Cd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"string[]":o=Ud(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Ud(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"number":o=Od(t.attr,a.tfName,a.defaultValue||0),o===void 0&&!!a.tfDeprecatedName&&(o=Od(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"number[]":o=Wd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Wd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"bool":o=Rd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Rd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"bool[]":o=zd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=zd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"shape":o=Fd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Fd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"shape[]":o=Bd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Bd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"dtype":o=Dd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Dd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"dtype[]":o=kd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=kd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"func":o=Fw(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Fw(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"tensor":case"tensors":break;default:throw new Error("Unsupported param type: "+a.type+" for op: "+t.op)}return r[a.name]={value:o,type:s},r},{})),i},n.prototype.mapFunction=function(t){var e=this,i=t.nodeDef,r=[],a=[],s={};i!=null&&(s=i.reduce(function(d,p){return d[p.name]=e.mapNode(p),p.op==="Const"&&a.push(d[p.name]),d},{}));var o=[],l=[];t.signature.inputArg.forEach(function(d){var p=si(d.name)[0],f={name:p,op:"Placeholder",inputs:[],inputNames:[],category:"graph",inputParams:{},attrParams:{dtype:{value:Ed(d.type),type:"dtype"}},children:[]};f.signatureKey=d.name,o.push(f),s[p]=f});var u=Object.keys(s);u.forEach(function(d){var p=s[d];p.inputNames.forEach(function(f){var m=si(f)[0];p.inputs.push(s[m]),s[m].children.push(p)})});var c=t.ret;t.signature.outputArg.forEach(function(d){var p=si(c[d.name]),f=p[0],m=p[1],g=s[f];g!=null&&(g.defaultOutput=m,l.push(g))});var h=this.mapArgsToSignature(t);return{nodes:s,inputs:o,outputs:l,weights:a,placeholders:r,signature:h}},n.prototype.mapArgsToSignature=function(t){var e=this;return{methodName:t.signature.name,inputs:t.signature.inputArg.reduce(function(i,r){return i[r.name]=e.mapArgToTensorInfo(r),i},{}),outputs:t.signature.outputArg.reduce(function(i,r){return i[r.name]=e.mapArgToTensorInfo(r,t.ret),i},{})}},n.prototype.mapArgToTensorInfo=function(t,e){var i=t.name;return e!=null&&(i=e[i]),{name:i,dtype:t.type}},n}();function IU(n){var t=B.env().global;if(typeof t.atob!="undefined")return t.atob(n);if(typeof Buffer!="undefined")return new Buffer(n,"base64").toString();throw new Error("Unable to decode base64 in this environment. Missing built-in atob() or Buffer()")}function Uw(n,t){var e=Array.isArray(n)?String.fromCharCode.apply(null,n):IU(n);return t?e:e.toLowerCase()}function Cd(n,t,e,i){i===void 0&&(i=!1);var r=n[t];return r!=null?Uw(r.s,i):e}function Rd(n,t,e){var i=n[t];return i?i.b:e}function Od(n,t,e){var i=n[t]||{},r=i.i!=null?i.i:i.f!=null?i.f:e;return typeof r=="number"?r:parseInt(r,10)}function Ed(n){typeof n=="string"&&(n=xn[n]);switch(n){case xn.DT_FLOAT:return"float32";case xn.DT_INT32:case xn.DT_INT64:case xn.DT_INT8:case xn.DT_UINT8:return"int32";case xn.DT_BOOL:return"bool";case xn.DT_DOUBLE:return"float32";case xn.DT_STRING:return"string";default:return null}}function Fw(n,t,e){var i=n[t];return i&&i.func?i.func.name:e}function Dd(n,t,e){var i=n[t];return i&&i.type?Ed(i.type):e}function kd(n,t,e){var i=n[t];return i&&i.list&&i.list.type?i.list.type.map(function(r){return Ed(r)}):e}function Bw(n){return n.unknownRank?void 0:n.dim!=null?n.dim.map(function(t){return typeof t.size=="number"?t.size:parseInt(t.size,10)}):[]}function Fd(n,t,e){var i=n[t];return i&&i.shape?Bw(i.shape):e}function Wd(n,t,e){var i=n[t];return i?((i.list.f&&i.list.f.length?i.list.f:i.list.i)||[]).map(function(r){return typeof r=="number"?r:parseInt(r,10)}):e}function Ud(n,t,e,i){i===void 0&&(i=!1);var r=n[t];return r&&r.list&&r.list.s?r.list.s.map(function(a){return Uw(a,i)}):e}function Bd(n,t,e){var i=n[t];return i&&i.list&&i.list.shape?i.list.shape.map(function(r){return Bw(r)}):e}function zd(n,t,e){var i=n[t];return i&&i.list&&i.list.b?i.list.b:e}var AU=function(){function n(t,e,i){var r=this;this.node=t,this.tensorMap=e,this.context=i,this.inputs=[],this.attrs={},this.inputs=t.inputNames.map(function(a){return r.getInput(a)}),t.rawAttrs!=null&&(this.attrs=Object.keys(t.rawAttrs).reduce(function(a,s){return a[s]=r.getAttr(s),a},{}))}return n.prototype.getInput=function(t){return Gt(t,this.tensorMap,this.context)},n.prototype.getAttr=function(t,e){var i=this.node.rawAttrs[t];if(i.tensor!=null)return Gt(t,this.tensorMap,this.context);if(i.i!=null||i.f!=null)return Od(this.node.rawAttrs,t,e);if(i.s!=null)return Cd(this.node.rawAttrs,t,e);if(i.b!=null)return Rd(this.node.rawAttrs,t,e);if(i.shape!=null)return Fd(this.node.rawAttrs,t,e);if(i.type!=null)return Dd(this.node.rawAttrs,t,e);if(i.list!=null){if(i.list.i!=null||i.list.f!=null)return Wd(this.node.rawAttrs,t,e);if(i.list.s!=null)return Ud(this.node.rawAttrs,t,e);if(i.list.shape!=null)return Bd(this.node.rawAttrs,t,e);if(i.list.b!=null)return zd(this.node.rawAttrs,t,e);if(i.list.type!=null)return kd(this.node.rawAttrs,t,e)}return e},n}();var TU=function(n,t,e){switch(n.op){case"BiasAdd":case"AddV2":case"Add":return[B.add(A("a",n,t,e),A("b",n,t,e))];case"AddN":return[B.addN(A("tensors",n,t,e))];case"FloorMod":case"Mod":return[B.mod(A("a",n,t,e),A("b",n,t,e))];case"Mul":return[B.mul(A("a",n,t,e),A("b",n,t,e))];case"RealDiv":case"Div":return[B.div(A("a",n,t,e),A("b",n,t,e))];case"DivNoNan":return[B.divNoNan(A("a",n,t,e),A("b",n,t,e))];case"FloorDiv":return[B.floorDiv(A("a",n,t,e),A("b",n,t,e))];case"Sub":return[B.sub(A("a",n,t,e),A("b",n,t,e))];case"Minimum":return[B.minimum(A("a",n,t,e),A("b",n,t,e))];case"Maximum":return[B.maximum(A("a",n,t,e),A("b",n,t,e))];case"Pow":return[B.pow(A("a",n,t,e),A("b",n,t,e))];case"SquaredDifference":return[B.squaredDifference(A("a",n,t,e),A("b",n,t,e))];default:throw TypeError("Node type "+n.op+" is not implemented")}};var NU=function(n,t,e){switch(n.op){case"Abs":case"ComplexAbs":return[B.abs(A("x",n,t,e))];case"Acos":return[B.acos(A("x",n,t,e))];case"Acosh":return[B.acosh(A("x",n,t,e))];case"Asin":return[B.asin(A("x",n,t,e))];case"Asinh":return[B.asinh(A("x",n,t,e))];case"Atan":return[B.atan(A("x",n,t,e))];case"Atan2":return[B.atan2(A("x",n,t,e),A("y",n,t,e))];case"Atanh":return[B.atanh(A("x",n,t,e))];case"Ceil":return[B.ceil(A("x",n,t,e))];case"Complex":return[B.complex(A("real",n,t,e),A("imag",n,t,e))];case"Cos":return[B.cos(A("x",n,t,e))];case"Cosh":return[B.cosh(A("x",n,t,e))];case"Elu":return[B.elu(A("x",n,t,e))];case"Erf":return[B.erf(A("x",n,t,e))];case"Exp":return[B.exp(A("x",n,t,e))];case"Expm1":return[B.expm1(A("x",n,t,e))];case"Floor":return[B.floor(A("x",n,t,e))];case"Log":return[B.log(A("x",n,t,e))];case"Log1p":return[B.log1p(A("x",n,t,e))];case"Imag":return[B.imag(A("x",n,t,e))];case"Neg":return[B.neg(A("x",n,t,e))];case"Reciprocal":return[B.reciprocal(A("x",n,t,e))];case"Real":return[B.real(A("x",n,t,e))];case"Relu":return[B.relu(A("x",n,t,e))];case"Round":return[B.round(A("x",n,t,e))];case"Selu":return[B.selu(A("x",n,t,e))];case"Sigmoid":return[B.sigmoid(A("x",n,t,e))];case"Sin":return[B.sin(A("x",n,t,e))];case"Sign":return[B.sign(A("x",n,t,e))];case"Sinh":return[B.sinh(A("x",n,t,e))];case"Softplus":return[B.softplus(A("x",n,t,e))];case"Sqrt":return[B.sqrt(A("x",n,t,e))];case"Square":return[B.square(A("x",n,t,e))];case"Tanh":return[B.tanh(A("x",n,t,e))];case"Tan":return[B.tan(A("x",n,t,e))];case"Relu6":case"ClipByValue":return[B.clipByValue(A("x",n,t,e),A("clipValueMin",n,t,e),A("clipValueMax",n,t,e))];case"Rsqrt":return[B.rsqrt(Gt(n.inputNames[0],t,e))];case"Prod":return[B.prod(A("x",n,t,e),A("axes",n,t,e))];case"LeakyRelu":return[B.leakyRelu(A("x",n,t,e),A("alpha",n,t,e))];case"Prelu":return[B.prelu(A("x",n,t,e),A("alpha",n,t,e))];default:throw TypeError("Node type "+n.op+" is not implemented")}};function mn(n,t,e){e===void 0&&(e=""),B.util.assert(xU(n,t),function(){return e+(" Shapes "+n+" and "+t+" must match")})}function xU(n,t){if(n.length!==t.length)return!1;for(var e=0;e<n.length;e++)if(n[e]!==-1&&t[e]!==-1&&n[e]!==t[e])return!1;return!0}var CU=function(){function n(t,e,i,r,a,s,o){this.name=t,this.dtype=e,this.maxSize=i,this.elementShape=r,this.identicalElementShapes=a,this.dynamicSize=s,this.clearAfterRead=o,this.tensors=[],this.closed_=!1,this.idTensor=B.scalar(0),B.keep(this.idTensor)}return Object.defineProperty(n.prototype,"id",{get:function(){return this.idTensor.id},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"closed",{get:function(){return this.closed_},enumerable:!0,configurable:!0}),n.prototype.clearAndClose=function(t){this.tensors.forEach(function(e){(t==null||!t.has(e.tensor.id))&&e.tensor.dispose()}),this.tensors=[],this.closed_=!0,this.idTensor.dispose()},n.prototype.size=function(){return this.tensors.length},n.prototype.read=function(t){if(this.closed_)throw new Error("TensorArray "+this.name+" has already been closed.");if(t<0||t>=this.size())throw new Error("Tried to read from index "+t+", but array size is: "+this.size());var e=this.tensors[t];if(e.cleared)throw new Error("TensorArray "+this.name+": Could not read index "+t+" twice because it was cleared after a previous read (perhaps try setting clear_after_read = false?).");return this.clearAfterRead&&(e.cleared=!0),e.read=!0,e.tensor},n.prototype.readMany=function(t){var e=this;return t.map(function(i){return e.read(i)})},n.prototype.write=function(t,e){if(this.closed_)throw new Error("TensorArray "+this.name+" has already been closed.");if(t<0||!this.dynamicSize&&t>=this.maxSize)throw new Error("Tried to write to index "+t+", but array is not resizeable and size is: "+this.maxSize);var i=this.tensors[t]||{};if(e.dtype!==this.dtype)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+t+`,
|
|
because the value dtype is `+e.dtype+", but TensorArray dtype is "+this.dtype+".");if(this.size()===0&&(this.elementShape==null||this.elementShape.length===0)&&(this.elementShape=e.shape),mn(this.elementShape,e.shape,"TensorArray "+this.name+": Could not write to TensorArray index "+t+"."),i.read)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+t+", because it has already been read.");if(i.written)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+t+", because it has already been written.");i.tensor=e,B.keep(e),i.written=!0,this.tensors[t]=i},n.prototype.writeMany=function(t,e){var i=this;if(t.length!==e.length)throw new Error("TensorArray "+this.name+": could not write multiple tensors,"+("because the index size: "+t.length+" is not the same as tensors size: "+e.length+"."));t.forEach(function(r,a){return i.write(r,e[a])})},n.prototype.gather=function(t,e){if(!!e&&e!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but gather requested dtype "+e);if(t)t=t.slice(0,this.size());else{t=[];for(var i=0;i<this.size();i++)t.push(i)}if(t.length===0)return B.tensor([],[0].concat(this.elementShape));var r=this.readMany(t);return mn(this.elementShape,r[0].shape,"TensorArray shape mismatch: "),B.stack(r,0)},n.prototype.concat=function(t){if(!!t&&t!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but concat requested dtype "+t);if(this.size()===0)return B.tensor([],[0].concat(this.elementShape));for(var e=[],i=0;i<this.size();i++)e.push(i);var r=this.readMany(e);return mn(this.elementShape,r[0].shape,"TensorArray shape mismatch: tensor array shape ("+this.elementShape+") vs first tensor shape ("+r[0].shape+")"),B.concat(r,0)},n.prototype.scatter=function(t,e){if(e.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+e.dtype);if(t.length!==e.shape[0])throw new Error("Expected len(indices) == tensor.shape[0], but saw: "+t.length+" vs. "+e.shape[0]);var i=Math.max.apply(Math,t);if(!this.dynamicSize&&i>=this.maxSize)throw new Error("Max index must be < array size ("+i+" vs. "+this.maxSize+")");this.writeMany(t,B.unstack(e,0))},n.prototype.split=function(t,e){var i=this;if(e.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+e.dtype);var r=0,a=t.map(function(c){return r+=c,r});if(r!==e.shape[0])throw new Error(`Expected sum of lengths to be equal to
|
|
tensor.shape[0], but sum of lengths is
|
|
`+r+", and tensor's shape is: "+e.shape);if(!this.dynamicSize&&t.length!==this.maxSize)throw new Error("TensorArray's size is not equal to the size of lengths ("+this.maxSize+" vs. "+t.length+"), and the TensorArray is not marked as dynamically resizeable");var s=r===0?0:e.size/r,o=[];B.tidy(function(){e=B.reshape(e,[1,r,s]);for(var c=0;c<t.length;++c){var h=c===0?0:a[c-1],d=[0,h,0],p=[1,t[c],s];o[c]=B.reshape(B.slice(e,d,p),i.elementShape)}return o});for(var l=[],u=0;u<t.length;u++)l[u]=u;this.writeMany(l,o)},n}();var jo=function(){function n(t,e,i,r){r===void 0&&(r=-1),this.tensors=t,this.elementShape=e,this.elementDtype=i,t!=null&&t.forEach(function(a){if(i!==a.dtype)throw new Error("Invalid data types; op elements "+i+", but list elements "+a.dtype);mn(e,a.shape,"TensorList shape mismatch: "),B.keep(a)}),this.idTensor=B.scalar(0),this.maxNumElements=r,B.keep(this.idTensor)}return Object.defineProperty(n.prototype,"id",{get:function(){return this.idTensor.id},enumerable:!0,configurable:!0}),n.prototype.copy=function(){return new n(this.tensors.slice(),this.elementShape,this.elementDtype)},n.prototype.clearAndClose=function(t){this.tensors.forEach(function(e){(t==null||!t.has(e.id))&&e.dispose()}),this.tensors.length=0,this.idTensor.dispose()},n.prototype.size=function(){return this.tensors.length},n.prototype.stack=function(t,e,i){var r=this;if(i===void 0&&(i=-1),e!==this.elementDtype)throw new Error("Invalid data types; op elements "+e+", but list elements "+this.elementDtype);if(i!==-1&&this.tensors.length!==i)throw new Error("Operation expected a list with "+i+" elements but got a list with "+this.tensors.length+" elements.");return mn(t,this.elementShape,"TensorList shape mismatch: "),B.tidy(function(){var a=r.tensors.map(function(s){return B.reshape(s,t)});return B.stack(a,0)})},n.prototype.popBack=function(t,e){if(e!==this.elementDtype)throw new Error("Invalid data types; op elements "+e+", but list elements "+this.elementDtype);if(this.size()===0)throw new Error("Trying to pop from an empty list.");var i=this.tensors.pop();return mn(i.shape,t,"TensorList shape mismatch: "),B.reshape(i,t)},n.prototype.pushBack=function(t){if(t.dtype!==this.elementDtype)throw new Error("Invalid data types; op elements "+t.dtype+", but list elements "+this.elementDtype);if(mn(t.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");B.keep(t),this.tensors.push(t)},n.prototype.resize=function(t){if(t<0)throw new Error("TensorListResize expects size to be non-negative. Got: "+t);if(this.maxNumElements!==-1&&t>this.maxNumElements)throw new Error("TensorListResize input size "+t+" is greater maxNumElement "+this.maxNumElements+".");this.tensors.length=t},n.prototype.getItem=function(t,e,i){if(i!==this.elementDtype)throw new Error("Invalid data types; op elements "+i+", but list elements "+this.elementDtype);if(t<0||t>this.tensors.length)throw new Error("Trying to access element "+t+" in a list with "+this.tensors.length+" elements.");if(this.tensors[t]==null)throw new Error("element at index "+t+" is null.");return mn(this.tensors[t].shape,e,"TensorList shape mismatch: "),this.tensors[t]},n.prototype.setItem=function(t,e){if(e.dtype!==this.elementDtype)throw new Error("Invalid data types; op elements "+e.dtype+", but list elements "+this.elementDtype);if(t<0||this.maxNumElements!==-1&&t>=this.maxNumElements)throw new Error("Trying to set element "+t+" in a list with max "+this.maxNumElements+" elements.");mn(this.elementShape,e.shape,"TensorList shape mismatch: "),B.keep(e),this.tensors[t]=e},n.prototype.gather=function(t,e,i){var r=this;if(e!==this.elementDtype)throw new Error("Invalid data types; op elements "+e+", but list elements "+this.elementDtype);return mn(this.elementShape,i,"TensorList shape mismatch: "),t=t.slice(0,this.size()),t.length===0?B.tensor([],[0].concat(this.elementShape)):B.tidy(function(){var a=t.map(function(s){return B.reshape(r.tensors[s],i)});return B.stack(a,0)})},n.prototype.concat=function(t,e){var i=this;if(!!t&&t!==this.elementDtype)throw new Error("TensorList dtype is "+this.elementDtype+" but concat requested dtype "+t);return mn(this.elementShape,e,"TensorList shape mismatch: "),this.size()===0?B.tensor([],[0].concat(this.elementShape)):B.tidy(function(){var r=i.tensors.map(function(a){return B.reshape(a,e)});return B.concat(r,0)})},n}();function RU(n,t,e){var i=n.dtype;if(n.shape.length<1)throw new Error("Tensor must be at least a vector, but saw shape: "+n.shape);if(n.dtype!==e)throw new Error("Invalid data types; op elements "+n.dtype+", but list elements "+e);var r=n.shape.slice(1);mn(r,t,"TensorList shape mismatch: ");var a=B.unstack(n);return new jo(a,t,i)}function OU(n,t,e){return new jo([],n,t,e)}function EU(n,t,e,i){if(t.length!==n.shape[0])throw new Error("Expected len(indices) == tensor.shape[0], but saw: "+t.length+" vs. "+n.shape[0]);var r=Math.max.apply(Math,t);if(i!=null&&i!==-1&&r>=i)throw new Error("Max index must be < array size ("+r+" vs. "+i+")");var a=new jo([],e,n.dtype,i),s=B.unstack(n,0);return t.forEach(function(o,l){a.setItem(o,s[l])}),a}function DU(n,t,e){var i=0,r=t.map(function(u){return i+=u,i});if(i!==n.shape[0])throw new Error(`Expected sum of lengths to be equal to
|
|
tensor.shape[0], but sum of lengths is
|
|
`+i+", and tensor's shape is: "+n.shape);for(var a=i===0?0:n.size/i,s=B.tidy(function(){var u=[];n=B.reshape(n,[1,i,a]);for(var c=0;c<t.length;++c){var h=c===0?0:r[c-1],d=[0,h,0],p=[1,t[c],a];u[c]=B.reshape(B.slice(n,d,p),e)}return n.dispose(),u}),o=new jo([],e,n.dtype,t.length),l=0;l<s.length;l++)o.setItem(l,s[l]);return o}var kU=void 0,FU=function(n,t,e){return Vn(kU,void 0,void 0,function(){var i,r,a,s,o,l,u,c,o,h,d,l,p,f,m,m,g,v,g,b,g,g,g,w,S,L,N,C,R,D,k,W,F,P,H,_,j,K,q,G,Z,X,ee,ne,ie,te,re,le,he,ye,Oe,Fe,_e,Me,dt,Lt,Ge,Ue,F,P,me,Ue,j,L,Ft,me,ne,ie,L,lt,me,L,pt,lt,me,q,G,L,pt,me,Ue,L,pt,lt,me,En,L,pt,me,re,me,he,L,Ue,P,me,Ue,L,Ft,me,Oe,L,Fe,me;return Nn(this,function(Et){switch(Et.label){case 0:i=n.op;switch(i){case"If":return[3,1];case"StatelessIf":return[3,1];case"While":return[3,3];case"StatelessWhile":return[3,3];case"LoopCond":return[3,9];case"Switch":return[3,10];case"Merge":return[3,12];case"Enter":return[3,13];case"Exit":return[3,14];case"NextIteration":return[3,15];case"TensorArrayV3":return[3,16];case"TensorArrayWriteV3":return[3,17];case"TensorArrayReadV3":return[3,18];case"TensorArrayGatherV3":return[3,19];case"TensorArrayScatterV3":return[3,20];case"TensorArrayConcatV3":return[3,21];case"TensorArraySplitV3":return[3,22];case"TensorArraySizeV3":return[3,23];case"TensorArrayCloseV3":return[3,24];case"TensorListSetItem":return[3,25];case"TensorListGetItem":return[3,26];case"TensorListScatterV2":return[3,27];case"TensorListScatter":return[3,27];case"TensorListReserve":return[3,28];case"TensorListGather":return[3,29];case"TensorListStack":return[3,30];case"TensorListFromTensor":return[3,31];case"TensorListConcat":return[3,32];case"TensorListPushBack":return[3,33];case"TensorListPopBack":return[3,34];case"TensorListSplit":return[3,35]}return[3,36];case 1:return r=A("thenBranch",n,t,e),a=A("elseBranch",n,t,e),s=A("cond",n,t,e),o=A("args",n,t,e),[4,s.data()];case 2:return l=Et.sent(),l[0]?[2,e.functionMap[r].executeFunctionAsync(o,e.tensorArrayMap,e.tensorListMap)]:[2,e.functionMap[a].executeFunctionAsync(o,e.tensorArrayMap,e.tensorListMap)];case 3:return u=A("body",n,t,e),c=A("cond",n,t,e),o=A("args",n,t,e),[4,e.functionMap[c].executeFunctionAsync(o,e.tensorArrayMap,e.tensorListMap)];case 4:return h=Et.sent(),d=o.map(function(It){return It.id}),[4,h[0].data()];case 5:l=Et.sent(),h.forEach(function(It){!It.kept&&d.indexOf(It.id)===-1&&It.dispose()}),p=o,f=function(){var It,Ce,Wt;return Nn(this,function(ft){switch(ft.label){case 0:return It=p,[4,e.functionMap[u].executeFunctionAsync(p,e.tensorArrayMap,e.tensorListMap)];case 1:return p=ft.sent(),Ce=p.map(function(it){return it.id}),It.forEach(function(it){!it.kept&&d.indexOf(it.id)===-1&&Ce.indexOf(it.id)===-1&&it.dispose()}),[4,e.functionMap[c].executeFunctionAsync(p,e.tensorArrayMap,e.tensorListMap)];case 2:return Wt=ft.sent(),[4,Wt[0].data()];case 3:return l=ft.sent(),Wt.forEach(function(it){!it.kept&&d.indexOf(it.id)===-1&&Ce.indexOf(it.id)===-1&&it.dispose()}),[2]}})},Et.label=6;case 6:return l[0]?[5,f()]:[3,8];case 7:return Et.sent(),[3,6];case 8:return[2,p];case 9:return m=A("pred",n,t,e),[2,[oi(m)]];case 10:return m=A("pred",n,t,e),g=A("data",n,t,e),g.kept||(g=oi(g)),[4,m.data()];case 11:return[2,Et.sent()[0]?[void 0,g]:[g,void 0]];case 12:return v=n.inputNames.find(function(It){return Gt(It,t,e)!==void 0}),v?(g=Gt(v,t,e),[2,[oi(g)]]):[2,void 0];case 13:return b=A("frameName",n,t,e),g=A("tensor",n,t,e),e.enterFrame(b),[2,[oi(g)]];case 14:return g=A("tensor",n,t,e),e.exitFrame(),[2,[oi(g)]];case 15:return g=A("tensor",n,t,e),e.nextIteration(),[2,[oi(g)]];case 16:return w=A("size",n,t,e),S=A("dtype",n,t,e),L=A("elementShape",n,t,e),N=A("dynamicSize",n,t,e),C=A("clearAfterRead",n,t,e),R=A("identicalElementShapes",n,t,e),D=A("name",n,t,e),k=new CU(D,S,w,L,R,N,C),e.addTensorArray(k),[2,[k.idTensor,B.scalar(1)]];case 17:return W=A("tensorArrayId",n,t,e),F=A("index",n,t,e),P=A("tensor",n,t,e),H=e.getTensorArray(W.id),H.write(F,P),[2,[H.idTensor]];case 18:return _=A("tensorArrayId",n,t,e),j=A("index",n,t,e),K=e.getTensorArray(_.id),[2,[K.read(j)]];case 19:return q=A("tensorArrayId",n,t,e),G=A("indices",n,t,e),Z=A("dtype",n,t,e),X=e.getTensorArray(q.id),[2,[X.gather(G,Z)]];case 20:return ee=A("tensorArrayId",n,t,e),ne=A("indices",n,t,e),ie=A("tensor",n,t,e),te=e.getTensorArray(ee.id),te.scatter(ne,ie),[2,[te.idTensor]];case 21:return re=A("tensorArrayId",n,t,e),le=e.getTensorArray(re.id),he=A("dtype",n,t,e),[2,[le.concat(he)]];case 22:return ye=A("tensorArrayId",n,t,e),Oe=A("tensor",n,t,e),Fe=A("lengths",n,t,e),_e=e.getTensorArray(ye.id),_e.split(Fe,Oe),[2,[_e.idTensor]];case 23:return Me=A("tensorArrayId",n,t,e),dt=e.getTensorArray(Me.id),[2,[B.scalar(dt.size(),"int32")]];case 24:return Lt=A("tensorArrayId",n,t,e),Ge=e.getTensorArray(Lt.id),Ge.clearAndClose(),[2,[Ge.idTensor]];case 25:return Ue=A("tensorListId",n,t,e),F=A("index",n,t,e),P=A("tensor",n,t,e),me=e.getTensorList(Ue.id),me.setItem(F,P),[2,[me.idTensor]];case 26:return Ue=A("tensorListId",n,t,e),j=A("index",n,t,e),L=A("elementShape",n,t,e),Ft=A("elementDType",n,t,e),me=e.getTensorList(Ue.id),[2,[me.getItem(j,L,Ft)]];case 27:return ne=A("indices",n,t,e),ie=A("tensor",n,t,e),L=A("elementShape",n,t,e),lt=A("numElements",n,t,e),me=EU(ie,ne,L,lt),e.addTensorList(me),[2,[me.idTensor]];case 28:return L=A("elementShape",n,t,e),pt=A("elementDType",n,t,e),lt=A("numElements",n,t,e),me=OU(L,pt,lt),e.addTensorList(me),[2,[me.idTensor]];case 29:return q=A("tensorListId",n,t,e),G=A("indices",n,t,e),L=A("elementShape",n,t,e),pt=A("elementDType",n,t,e),me=e.getTensorList(q.id),[2,[me.gather(G,pt,L)]];case 30:return Ue=A("tensorListId",n,t,e),L=A("elementShape",n,t,e),pt=A("elementDType",n,t,e),lt=A("numElements",n,t,e),me=e.getTensorList(Ue.id),[2,[me.stack(L,pt,lt)]];case 31:return En=A("tensor",n,t,e),L=A("elementShape",n,t,e),pt=A("elementDType",n,t,e),me=RU(En,L,pt),e.addTensorList(me),[2,[me.idTensor]];case 32:return re=A("tensorListId",n,t,e),me=e.getTensorList(re.id),he=A("dtype",n,t,e),L=A("elementShape",n,t,e),[2,[me.concat(he,L)]];case 33:return Ue=A("tensorListId",n,t,e),P=A("tensor",n,t,e),me=e.getTensorList(Ue.id),me.pushBack(P),[2,[me.idTensor]];case 34:return Ue=A("tensorListId",n,t,e),L=A("elementShape",n,t,e),Ft=A("elementDType",n,t,e),me=e.getTensorList(Ue.id),[2,[me.popBack(L,Ft)]];case 35:return Oe=A("tensor",n,t,e),L=A("elementShape",n,t,e),Fe=A("lengths",n,t,e),me=DU(Oe,Fe,L),e.addTensorList(me),[2,[me.idTensor]];case 36:throw TypeError("Node type "+n.op+" is not implemented")}})})};function zw(n,t,e){var i=A("fusedOps",n,t,e),r=i[0],a=i[1],s=r==="biasadd",o=a==="prelu",l=r==="fusedbatchnorm",u=A("numArgs",n,t,e);if(s){if(o&&u!==2)throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!o&&u!==1)throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd must have one extra argument: bias.")}if(l)throw new Error("FusedConv2d and DepthwiseConv2d with FusedBatchNorm is not supported.");var c=A("strides",n,t,e),h=Yo(n,t,e),d=A("dataFormat",n,t,e).toUpperCase(),p=A("dilations",n,t,e),f=A("args",n,t,e),m=f[0],g=f[1];return{stride:c,pad:h,dataFormat:d,dilations:p,biasArg:m,preluArg:g,activationFunc:a}}var WU=function(n,t,e){switch(n.op){case"Conv1D":{var i=A("stride",n,t,e),r=A("pad",n,t,e),a=A("dataFormat",n,t,e).toUpperCase(),s=A("dilation",n,t,e);return[B.conv1d(A("x",n,t,e),A("filter",n,t,e),i,r,a,s)]}case"Conv2D":{var i=A("strides",n,t,e),r=Yo(n,t,e),a=A("dataFormat",n,t,e).toUpperCase(),o=A("dilations",n,t,e);return[B.conv2d(A("x",n,t,e),A("filter",n,t,e),[i[1],i[2]],r,a,[o[1],o[2]])]}case"_FusedConv2D":{var l=zw(n,t,e),i=l.stride,r=l.pad,a=l.dataFormat,o=l.dilations,u=l.biasArg,c=l.preluArg,h=l.activationFunc;return[B.fused.conv2d({x:A("x",n,t,e),filter:A("filter",n,t,e),strides:[i[1],i[2]],pad:r,dataFormat:a,dilations:[o[1],o[2]],bias:u,activation:h,preluActivationWeights:c})]}case"FusedDepthwiseConv2dNative":{var d=zw(n,t,e),i=d.stride,r=d.pad,a=d.dataFormat,o=d.dilations,u=d.biasArg,c=d.preluArg,h=d.activationFunc;return[B.fused.depthwiseConv2d({x:A("x",n,t,e),filter:A("filter",n,t,e),strides:[i[1],i[2]],pad:r,dataFormat:a,dilations:[o[1],o[2]],bias:u,activation:h,preluActivationWeights:c})]}case"Conv2DBackpropInput":case"Conv2dTranspose":{var p=A("outputShape",n,t,e),i=A("strides",n,t,e),r=Yo(n,t,e);return[B.conv2dTranspose(A("x",n,t,e),A("filter",n,t,e),p,[i[1],i[2]],r)]}case"DepthwiseConv2dNative":case"DepthwiseConv2d":{var i=A("strides",n,t,e),r=Yo(n,t,e),o=A("dilations",n,t,e),a=A("dataFormat",n,t,e).toUpperCase();return[B.depthwiseConv2d(A("input",n,t,e),A("filter",n,t,e),[i[1],i[2]],r,a,[o[1],o[2]])]}case"Conv3D":{var i=A("strides",n,t,e),r=A("pad",n,t,e),a=A("dataFormat",n,t,e).toUpperCase(),o=A("dilations",n,t,e);return[B.conv3d(A("x",n,t,e),A("filter",n,t,e),[i[1],i[2],i[3]],r,a,[o[1],o[2],o[3]])]}case"AvgPool":{var i=A("strides",n,t,e),r=A("pad",n,t,e),f=A("kernelSize",n,t,e);return[B.avgPool(A("x",n,t,e),[f[1],f[2]],[i[1],i[2]],r)]}case"MaxPool":{var i=A("strides",n,t,e),r=A("pad",n,t,e),f=A("kernelSize",n,t,e);return[B.maxPool(A("x",n,t,e),[f[1],f[2]],[i[1],i[2]],r)]}case"MaxPoolWithArgmax":{var i=A("strides",n,t,e),r=A("pad",n,t,e),f=A("kernelSize",n,t,e),m=A("includeBatchInIndex",n,t,e),g=B.maxPoolWithArgmax(A("x",n,t,e),[f[1],f[2]],[i[1],i[2]],r,m),v=g.result,b=g.indexes;return[v,b]}case"AvgPool3D":{var i=A("strides",n,t,e),r=A("pad",n,t,e),f=A("kernelSize",n,t,e);return[B.avgPool3d(A("x",n,t,e),[f[1],f[2],f[3]],[i[1],i[2],i[3]],r)]}case"MaxPool3D":{var i=A("strides",n,t,e),r=A("pad",n,t,e),f=A("kernelSize",n,t,e);return[B.maxPool3d(A("x",n,t,e),[f[1],f[2],f[3]],[i[1],i[2],i[3]],r)]}case"Dilation2D":{var w=A("strides",n,t,e),r=A("pad",n,t,e),o=A("dilations",n,t,e),S=w[1],L=w[2],N=o[1],C=o[2];return[B.dilation2d(A("x",n,t,e),A("filter",n,t,e),[S,L],r,[N,C],"NHWC")]}default:throw TypeError("Node type "+n.op+" is not implemented")}};var UU=function(n,t,e){switch(n.op){case"Fill":{var i=A("shape",n,t,e),r=A("dtype",n,t,e),a=A("value",n,t,e);return[B.fill(i,a,r)]}case"LinSpace":{var s=A("start",n,t,e),o=A("stop",n,t,e),l=A("num",n,t,e);return[B.linspace(s,o,l)]}case"Multinomial":{var u=A("logits",n,t,e),c=A("numSamples",n,t,e),h=A("seed",n,t,e);return[B.multinomial(u,c,h)]}case"OneHot":{var d=A("indices",n,t,e),p=A("depth",n,t,e),f=A("onValue",n,t,e),m=A("offValue",n,t,e);return[B.oneHot(d,p,f,m)]}case"Ones":return[B.ones(A("shape",n,t,e),A("dtype",n,t,e))];case"OnesLike":return[B.onesLike(A("x",n,t,e))];case"RandomUniform":return[B.randomUniform(A("shape",n,t,e),A("minval",n,t,e),A("maxval",n,t,e),A("dtype",n,t,e))];case"Range":{var s=A("start",n,t,e),g=A("stop",n,t,e),v=A("step",n,t,e);return[B.range(s,g,v,A("dtype",n,t,e))]}case"TruncatedNormal":{var i=A("shape",n,t,e),b=A("mean",n,t,e),w=A("stdDev",n,t,e),h=A("seed",n,t,e);return[B.truncatedNormal(i,b,w,A("dtype",n,t,e),h)]}case"Zeros":return[B.zeros(A("shape",n,t,e),A("dtype",n,t,e))];case"ZerosLike":return[B.zerosLike(A("x",n,t,e))];default:throw TypeError("Node type "+n.op+" is not implemented")}};var BU=void 0;function Pd(n,t,e){var i=A("boxes",n,t,e),r=A("scores",n,t,e),a=A("maxOutputSize",n,t,e),s=A("iouThreshold",n,t,e),o=A("scoreThreshold",n,t,e),l=A("softNmsSigma",n,t,e);return{boxes:i,scores:r,maxOutputSize:a,iouThreshold:s,scoreThreshold:o,softNmsSigma:l}}var zU=function(n,t,e){return Vn(BU,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h,d,a,s,o,l,u,p,h,f,a,s,o,l,u,m,h;return Nn(this,function(g){switch(g.label){case 0:i=n.op;switch(i){case"NonMaxSuppressionV5":return[3,1];case"NonMaxSuppressionV4":return[3,3];case"NonMaxSuppressionV3":return[3,5];case"NonMaxSuppressionV2":return[3,5];case"Where":return[3,7];case"ListDiff":return[3,9]}return[3,10];case 1:return r=Pd(n,t,e),a=r.boxes,s=r.scores,o=r.maxOutputSize,l=r.iouThreshold,u=r.scoreThreshold,c=r.softNmsSigma,[4,B.image.nonMaxSuppressionWithScoreAsync(a,s,o,l,u,c)];case 2:return h=g.sent(),[2,[h.selectedIndices,h.selectedScores]];case 3:return d=Pd(n,t,e),a=d.boxes,s=d.scores,o=d.maxOutputSize,l=d.iouThreshold,u=d.scoreThreshold,p=A("padToMaxOutputSize",n,t,e),[4,B.image.nonMaxSuppressionPaddedAsync(a,s,o,l,u,p)];case 4:return h=g.sent(),[2,[h.selectedIndices,h.validOutputs]];case 5:return f=Pd(n,t,e),a=f.boxes,s=f.scores,o=f.maxOutputSize,l=f.iouThreshold,u=f.scoreThreshold,[4,B.image.nonMaxSuppressionAsync(a,s,o,l,u)];case 6:return[2,[g.sent()]];case 7:return m=B.cast(A("condition",n,t,e),"bool"),[4,B.whereAsync(m)];case 8:return h=[g.sent()],m.dispose(),[2,h];case 9:return[2,B.setdiff1dAsync(A("x",n,t,e),A("y",n,t,e))];case 10:throw TypeError("Node type "+n.op+" is not implemented")}})})};var PU=function(n,t,e){switch(n.op){case"TopKV2":{var i=A("x",n,t,e),r=A("k",n,t,e),a=A("sorted",n,t,e),s=B.topk(i,r,a);return[s.values,s.indices]}case"Unique":{var i=A("x",n,t,e),s=B.unique(i);return[s.values,s.indices]}case"UniqueV2":{var i=A("x",n,t,e),o=A("axis",n,t,e),s=B.unique(i,o);return[s.values,s.indices]}default:throw TypeError("Node type "+n.op+" is not implemented")}};var _U=function(n,t,e){switch(n.op){case"Const":return t[n.name];case"PlaceholderWithDefault":var i=A("default",n,t,e);return[Gt(n.name,t,e)||i];case"Placeholder":return[Gt(n.name,t,e)];case"Identity":case"StopGradient":case"FakeQuantWithMinMaxVars":{var r=A("x",n,t,e);return[oi(r)]}case"IdentityN":return A("x",n,t,e).map(function(h){return oi(h)});case"Snapshot":var a=A("x",n,t,e);return[oi(a)];case"Shape":return[B.tensor1d(A("x",n,t,e).shape,"int32")];case"ShapeN":return A("x",n,t,e).map(function(h){return B.tensor1d(h.shape)});case"Size":return[B.scalar(A("x",n,t,e).size,"int32")];case"Rank":return[B.scalar(A("x",n,t,e).rank,"int32")];case"NoOp":return[B.scalar(1)];case"Print":var s=A("x",n,t,e),o=A("data",n,t,e),l=A("message",n,t,e),u=A("summarize",n,t,e);console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."),console.log(l);for(var c=0;c<o.length;c++)console.log(Array.prototype.slice.call(o[c].dataSync()).slice(0,u));return[s];default:throw TypeError("Node type "+n.op+" is not implemented")}};var MU=function(n,t,e){switch(n.op){case"ResizeBilinear":{var i=A("images",n,t,e),r=A("size",n,t,e),a=A("alignCorners",n,t,e);return[B.image.resizeBilinear(i,[r[0],r[1]],a)]}case"ResizeNearestNeighbor":{var i=A("images",n,t,e),r=A("size",n,t,e),a=A("alignCorners",n,t,e);return[B.image.resizeNearestNeighbor(i,[r[0],r[1]],a)]}case"CropAndResize":{var s=A("image",n,t,e),o=A("boxes",n,t,e),l=A("boxInd",n,t,e),u=A("cropSize",n,t,e),c=A("method",n,t,e),h=A("extrapolationValue",n,t,e);return[B.image.cropAndResize(s,o,l,u,c,h)]}default:throw TypeError("Node type "+n.op+" is not implemented")}};var HU=function(n,t,e){switch(n.op){case"Equal":return[B.equal(A("a",n,t,e),A("b",n,t,e))];case"NotEqual":return[B.notEqual(A("a",n,t,e),A("b",n,t,e))];case"Greater":return[B.greater(A("a",n,t,e),A("b",n,t,e))];case"GreaterEqual":return[B.greaterEqual(A("a",n,t,e),A("b",n,t,e))];case"Less":return[B.less(A("a",n,t,e),A("b",n,t,e))];case"LessEqual":return[B.lessEqual(A("a",n,t,e),A("b",n,t,e))];case"LogicalAnd":return[B.logicalAnd(A("a",n,t,e),A("b",n,t,e))];case"LogicalNot":return[B.logicalNot(A("a",n,t,e))];case"LogicalOr":return[B.logicalOr(A("a",n,t,e),A("b",n,t,e))];case"Select":case"SelectV2":return[B.where(A("condition",n,t,e),A("a",n,t,e),A("b",n,t,e))];default:throw TypeError("Node type "+n.op+" is not implemented")}};var VU=function(n,t,e){switch(n.op){case"BatchMatMul":case"BatchMatMulV2":case"MatMul":return[B.matMul(A("a",n,t,e),A("b",n,t,e),A("transposeA",n,t,e),A("transposeB",n,t,e))];case"Transpose":return[B.transpose(A("x",n,t,e),A("perm",n,t,e))];case"_FusedMatMul":var i=A("fusedOps",n,t,e),r=i[0],a=i[1],s=r==="biasadd",o=a==="prelu",l=A("numArgs",n,t,e);if(s){if(o&&l!==2)throw new Error("Fused MatMul with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!o&&l!==1)throw new Error("Fused MatMul with BiasAdd must have one extra argument: bias.")}var u=A("args",n,t,e),c=u[0],h=u[1];return[B.fused.matMul({a:A("a",n,t,e),b:A("b",n,t,e),transposeA:A("transposeA",n,t,e),transposeB:A("transposeB",n,t,e),bias:c,activation:a,preluActivationWeights:h})];default:throw TypeError("Node type "+n.op+" is not implemented")}};var qU=function(n,t,e){switch(n.op){case"FusedBatchNorm":case"FusedBatchNormV2":return[B.batchNorm(A("x",n,t,e),A("mean",n,t,e),A("variance",n,t,e),A("offset",n,t,e),A("scale",n,t,e),A("epsilon",n,t,e))];case"FusedBatchNormV3":return[B.batchNorm(A("x",n,t,e),A("mean",n,t,e),A("variance",n,t,e),A("offset",n,t,e),A("scale",n,t,e),A("epsilon",n,t,e))];case"LRN":return[B.localResponseNormalization(A("x",n,t,e),A("radius",n,t,e),A("bias",n,t,e),A("alpha",n,t,e),A("beta",n,t,e))];case"Softmax":return[B.softmax(A("x",n,t,e))];case"LogSoftmax":return[B.logSoftmax(A("x",n,t,e))];case"SparseToDense":return[B.sparseToDense(A("sparseIndices",n,t,e),A("outputShape",n,t,e),A("sparseValues",n,t,e),A("defaultValue",n,t,e))];default:throw TypeError("Node type "+n.op+" is not implemented")}};var GU=function(n,t,e){switch(n.op){case"Max":{var i=A("axis",n,t,e),r=A("keepDims",n,t,e);return[B.max(A("x",n,t,e),i,r)]}case"Mean":{var i=A("axis",n,t,e),r=A("keepDims",n,t,e);return[B.mean(A("x",n,t,e),i,r)]}case"Min":{var i=A("axis",n,t,e),r=A("keepDims",n,t,e);return[B.min(A("x",n,t,e),i,r)]}case"Sum":{var i=A("axis",n,t,e),r=A("keepDims",n,t,e);return[B.sum(A("x",n,t,e),i,r)]}case"All":{var i=A("axis",n,t,e),r=A("keepDims",n,t,e);return[B.all(A("x",n,t,e),i,r)]}case"Any":{var i=A("axis",n,t,e),r=A("keepDims",n,t,e);return[B.any(A("x",n,t,e),i,r)]}case"ArgMax":{var i=A("axis",n,t,e);return[B.argMax(A("x",n,t,e),i)]}case"ArgMin":{var i=A("axis",n,t,e);return[B.argMin(A("x",n,t,e),i)]}case"Prod":{var i=A("axis",n,t,e),r=A("keepDims",n,t,e);return[B.prod(A("x",n,t,e),i,r)]}case"Cumsum":{var i=A("axis",n,t,e),a=A("exclusive",n,t,e),s=A("reverse",n,t,e);return[B.cumsum(A("x",n,t,e),i,a,s)]}default:throw TypeError("Node type "+n.op+" is not implemented")}};var YU=function(n,t,e){switch(n.op){case"ConcatV2":case"Concat":{var i=A("n",n,t,e),r=A("axis",n,t,e),a=A("tensors",n,t,e);return a=a.slice(0,i),[B.concat(a,r)]}case"GatherV2":case"Gather":{var r=A("axis",n,t,e),s=A("x",n,t,e),o=A("indices",n,t,e);return[B.gather(s,B.cast(o,"int32"),r)]}case"ReverseV2":case"Reverse":{var r=A("axis",n,t,e),s=A("x",n,t,e);return[B.reverse(s,r)]}case"Slice":{var l=A("begin",n,t,e),u=A("size",n,t,e);return[B.slice(A("x",n,t,e),l,u)]}case"StridedSlice":{var l=A("begin",n,t,e),c=A("end",n,t,e),h=A("strides",n,t,e),d=A("beginMask",n,t,e),p=A("endMask",n,t,e),f=A("ellipsisMask",n,t,e),m=A("newAxisMask",n,t,e),g=A("shrinkAxisMask",n,t,e),v=A("x",n,t,e);return[B.stridedSlice(v,l,c,h,d,p,f,m,g)]}case"Pack":return B.tidy(function(){var D=A("axis",n,t,e),k=A("tensors",n,t,e),W=k[0].shape,F=B.squeeze(k[0]).shape,P=k.map(function(H){var _=B.util.arraysEqual(H.shape,W);if(!_&&!B.util.arraysEqual(B.squeeze(H).shape,F))throw new Error("the input tensors shape does not match");return _?H:B.reshape(H,W)});return[B.stack(P,D)]});case"Unpack":{var r=A("axis",n,t,e),v=A("tensor",n,t,e);return B.unstack(v,r)}case"Tile":{var b=A("reps",n,t,e);return[B.tile(A("x",n,t,e),b)]}case"Split":case"SplitV":{var r=A("axis",n,t,e),w=A("numOrSizeSplits",n,t,e),v=A("x",n,t,e);return B.split(v,w,r)}case"ScatterNd":{var o=A("indices",n,t,e),S=A("values",n,t,e),L=A("shape",n,t,e);return[B.scatterND(o,S,L)]}case"GatherNd":{var N=A("x",n,t,e),o=A("indices",n,t,e);return[B.gatherND(N,o)]}case"SparseToDense":{var o=A("sparseIndices",n,t,e),L=A("outputShape",n,t,e),C=A("sparseValues",n,t,e),R=A("defaultValue",n,t,e);return[B.sparseToDense(o,C,L,C.dtype===R.dtype?R:B.cast(R,C.dtype))]}default:throw TypeError("Node type "+n.op+" is not implemented")}};var jU=function(n,t,e){switch(n.op){case"FFT":return[B.fft(A("x",n,t,e))];case"IFFT":return[B.ifft(A("x",n,t,e))];case"RFFT":return[B.rfft(A("x",n,t,e))];case"IRFFT":return[B.irfft(A("x",n,t,e))];default:throw TypeError("Node type "+n.op+" is not implemented")}};var KU=function(n,t,e){switch(n.op){case"Cast":return[B.cast(A("x",n,t,e),A("dtype",n,t,e))];case"ExpandDims":{var i=A("axis",n,t,e);return[B.expandDims(A("x",n,t,e),i)]}case"Squeeze":{var i=A("axis",n,t,e);return[B.squeeze(A("x",n,t,e),i)]}case"Reshape":return[B.reshape(A("x",n,t,e),A("shape",n,t,e))];case"PadV2":case"Pad":return[B.pad(A("x",n,t,e),A("padding",n,t,e),A("constantValue",n,t,e))];case"SpaceToBatchND":{var r=A("blockShape",n,t,e),a=A("paddings",n,t,e);return[B.spaceToBatchND(A("x",n,t,e),r,a)]}case"BatchToSpaceND":{var r=A("blockShape",n,t,e),s=A("crops",n,t,e);return[B.batchToSpaceND(A("x",n,t,e),r,s)]}case"DepthToSpace":{var o=A("blockSize",n,t,e),l=A("dataFormat",n,t,e).toUpperCase();return[B.depthToSpace(A("x",n,t,e),o,l)]}case"BroadcastTo":return[B.broadcastTo(A("x",n,t,e),A("shape",n,t,e))];default:throw TypeError("Node type "+n.op+" is not implemented")}};function Pw(n,t,e){var i=function(r,a,s){switch(r.category){case"arithmetic":return B.tidy(function(){return TU(r,a,s)});case"basic_math":return B.tidy(function(){return NU(r,a,s)});case"control":return FU(r,a,s);case"convolution":return B.tidy(function(){return WU(r,a,s)});case"creation":return B.tidy(function(){return UU(r,a,s)});case"dynamic":return zU(r,a,s);case"evaluation":return B.tidy(function(){return PU(r,a,s)});case"image":return B.tidy(function(){return MU(r,a,s)});case"graph":return B.tidy(function(){return _U(r,a,s)});case"logical":return B.tidy(function(){return HU(r,a,s)});case"matrices":return B.tidy(function(){return VU(r,a,s)});case"normalization":return B.tidy(function(){return qU(r,a,s)});case"reduction":return B.tidy(function(){return GU(r,a,s)});case"slice_join":return B.tidy(function(){return YU(r,a,s)});case"spectral":return B.tidy(function(){return jU(r,a,s)});case"transformation":return B.tidy(function(){return KU(r,a,s)});case"custom":var o=kw(r.op);if(o&&o.customExecutor)return o.customExecutor(new AU(r,a,s));throw TypeError("Custom op "+r.op+" is not registered.");default:throw TypeError("Unknown op '"+r.op+"'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()")}}(n,t,e);return i instanceof Promise?i.then(function(r){return[].concat(r)}):[].concat(i)}var _w=function(){function n(t,e,i,r){t===void 0&&(t={}),e===void 0&&(e={}),i===void 0&&(i={}),r===void 0&&(r={}),this.weightMap=t,this.tensorArrayMap=e,this.tensorListMap=i,this.functionMap=r,this.rootContext={id:0,frameName:"",iterationId:0},this.contexts=[this.rootContext],this.lastId=0,this.generateCurrentContextIds()}return n.prototype.newFrame=function(t,e){return{id:t,frameName:e,iterationId:0}},Object.defineProperty(n.prototype,"currentContext",{get:function(){return this.contexts},set:function(t){this.contexts!==t&&(this.contexts=t,this.generateCurrentContextIds())},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"currentContextId",{get:function(){return this._currentContextIds[0]},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"currentContextIds",{get:function(){return this._currentContextIds},enumerable:!0,configurable:!0}),n.prototype.generateCurrentContextIds=function(){for(var t=[],e=0;e<this.contexts.length-1;e++){var i=this.contexts.slice(0,this.contexts.length-e);t.push(this.contextIdforContexts(i))}t.push(""),this._currentContextIds=t},n.prototype.contextIdforContexts=function(t){return t?t.map(function(e){return e.id===0&&e.iterationId===0?"":e.frameName+"-"+e.iterationId}).join("/"):""},n.prototype.enterFrame=function(t){this.contexts&&(this.lastId++,this.contexts=this.contexts.slice(),this.contexts.push(this.newFrame(this.lastId,t)),this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)))},n.prototype.exitFrame=function(){if(this.contexts&&this.contexts.length>1)this.contexts=this.contexts.slice(),this.contexts.splice(-1),this.currentContextIds.shift();else throw new Error("Cannot exit frame, the context is empty")},n.prototype.nextIteration=function(){if(this.contexts&&this.contexts.length>0){this.contexts=this.contexts.slice(),this.lastId++;var t=Object.assign({},this.contexts[this.contexts.length-1]);t.iterationId+=1,t.id=this.lastId,this.contexts.splice(-1,1,t),this._currentContextIds.splice(0,1,this.contextIdforContexts(this.contexts))}else throw new Error("Cannot increase frame iteration, the context is empty")},n.prototype.getWeight=function(t){return this.weightMap[t]},n.prototype.addTensorArray=function(t){this.tensorArrayMap[t.id]=t},n.prototype.getTensorArray=function(t){return this.tensorArrayMap[t]},n.prototype.addTensorList=function(t){this.tensorListMap[t.id]=t},n.prototype.getTensorList=function(t){return this.tensorListMap[t]},n.prototype.dispose=function(t){for(var e in this.tensorArrayMap)this.tensorArrayMap[e].clearAndClose(t);for(var e in this.tensorListMap)this.tensorListMap[e].clearAndClose(t)},n}();function Hw(n,t,e,i){var r=new Set,a=[],s=null,o=null,l=new Set,u=Object.keys(n).map(function(p){return Zt(p)[0]}),c=[];i!=null&&(c=i.map(function(p){return Zt(p.name)[0]}));for(var h=t.slice();h.length>0;){var d=h.pop();if((Mw(d)||$U(d))&&(s==null&&(s=d,o=s.children.map(function(p){return p.name}).filter(function(p){return r.has(p)}))),r.add(d.name),e[d.name]!=null)continue;if(u.indexOf(d.name)!==-1)continue;if(c.indexOf(d.name)!==-1)continue;if(d.inputs.length===0){a.push(d.name);continue}d.inputs.forEach(function(p){if(l.has(p.name))return;l.add(p.name),h.push(p)})}return{inputs:n,outputs:t,usedNodes:r,missingInputs:a,dynamicNode:s,syncInputs:o}}function XU(n,t,e){var i=e.usedNodes,r=e.inputs,a=[],s=Object.keys(r).map(function(h){return Zt(h)[0]}).map(function(h){return n.nodes[h]}),o=n.initNodes;s.forEach(function(h){i.has(h.name)&&a.push(h)}),n.weights.forEach(function(h){i.has(h.name)&&a.push(h)}),o!=null&&o.forEach(function(h){i.has(h.name)&&a.push(h)});for(var l=new Set,u=[];a.length>0;){var c=a.pop();l.add(c.name),t[c.name]||u.push(c),c.children.forEach(function(h){!l.has(h.name)&&i.has(h.name)&&h.inputs.every(function(d){return l.has(d.name)})&&a.push(h)})}return u}var JU=["Switch","Merge","Enter","Exit","NextIteration","StatelessIf","StatelessWhile","if","While"],ZU=["NonMaxSuppressionV2","NonMaxSuppressionV3","NonMaxSuppressionV5","Where"];function Mw(n){return JU.indexOf(n.op)>=0}function $U(n){return ZU.indexOf(n.op)>=0}var Vw=function(){function n(t,e){var i=this;this.graph=t,this.parent=e,this.compiledMap=new Map,this._weightMap={},this.SEPERATOR=",",this._functions={},this._functionExecutorMap={},this._outputs=t.outputs,this._inputs=t.inputs,this._initNodes=t.initNodes,this._signature=t.signature,this._functions=t.functions,t.functions!=null&&Object.keys(t.functions).forEach(function(r){i._functionExecutorMap[r]=new n(t.functions[r],i)})}return Object.defineProperty(n.prototype,"weightIds",{get:function(){return this.parent?this.parent.weightIds:this._weightIds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"functionExecutorMap",{get:function(){return this.parent?this.parent.functionExecutorMap:this._functionExecutorMap},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"weightMap",{get:function(){return this.parent?this.parent.weightMap:this._weightMap},set:function(t){var e=Object.keys(t).map(function(i){return t[i].map(function(r){return r.id})});this._weightIds=[].concat.apply([],e),this._weightMap=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputs",{get:function(){return this._inputs.map(function(t){return{name:t.name,shape:t.attrParams.shape?t.attrParams.shape.value:void 0,dtype:t.attrParams.dtype?t.attrParams.dtype.value:void 0}})},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"outputs",{get:function(){return this._outputs.map(function(t){return{name:t.name,shape:t.attrParams.shape?t.attrParams.shape.value:void 0,dtype:t.attrParams.dtype?t.attrParams.dtype.value:void 0}})},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputNodes",{get:function(){return this._inputs.map(function(t){return t.signatureKey||t.name})},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"outputNodes",{get:function(){return this._outputs.map(function(t){var e=t.signatureKey||t.name;return t.defaultOutput?e+":"+t.defaultOutput:e})},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"functions",{get:function(){var t=this;return Object.keys(this._functions).reduce(function(e,i){return e[i]=t._functions[i].signature,e},{})},enumerable:!0,configurable:!0}),n.prototype.getCompilationKey=function(t,e){var i=t.map(function(a){return a.name}).sort(),r=e.map(function(a){return a.name}).sort();return i.join(this.SEPERATOR)+"--"+r.join(this.SEPERATOR)},n.prototype.compile=function(t,e){var i=Hw(t,e,this.weightMap,this._initNodes),r=i.missingInputs,a=i.dynamicNode,s=i.syncInputs;if(a!=null)throw new Error("This execution contains the node '"+a.name+"', which has "+("the dynamic op '"+a.op+"'. Please use ")+"model.executeAsync() instead. Alternatively, to avoid the "+("dynamic ops, specify the inputs ["+s+"]"));if(r.length>0){var o=e.map(function(u){return u.name}),l=Object.keys(t);throw new Error("Cannot compute the outputs ["+o+"] from the provided inputs "+("["+l+"]. Missing the following inputs: ["+r+"]"))}return XU(this.graph,this.weightMap,i)},n.prototype.execute=function(t,e){var i=this;t=this.mapInputs(t);var r=Object.keys(t).sort();this.checkInputs(t),this.checkInputShapeAndType(t),e=this.mapOutputs(e),this.checkOutputs(e);var a=r.map(function(d){return i.graph.nodes[Zt(d)[0]]}),s=e.map(function(d){return Zt(d)[0]}),o=s.map(function(d){return i.graph.nodes[d]});o.length===0&&(o=this._outputs);var l=this.getCompilationKey(a,o),u=this.compiledMap.get(l);u==null&&(u=this.compile(t,o),this.compiledMap.set(l,u));var c={},h={};return B.tidy(function(){var d=new _w(i.weightMap,c,h,i.functionExecutorMap),p=Ew({},i.weightMap);Object.keys(t).forEach(function(w){var S=Zt(w),L=S[0],N=S[1],C=[];C[N]=t[w],p[L]=C});for(var f=i.getFrozenTensorIds(p),m={},g=0;g<u.length;g++){var v=u[g];if(!p[v.name]){var b=Pw(v,p,d);if(b instanceof Promise)throw new Error("The execution of the op '"+v.op+"' returned a promise. Please use model.executeAsync() instead.");p[v.name]=b,i.checkTensorForDisposal(v.name,v,p,d,f,s,m)}}return i.parent==null&&d.dispose(f),e.map(function(w){return Gt(w,p,d)})})},n.prototype.getFrozenTensorIds=function(t){var e=[].concat.apply([],Object.keys(t).map(function(i){return t[i]}).map(function(i){return i.map(function(r){return r.id})}));return new Set(e)},n.prototype.checkTensorForDisposal=function(t,e,i,r,a,s,o){if(e.category==="control"||s.indexOf(t)!==-1)return;i[t].forEach(function(l){l!=null&&(o[l.id]=(o[l.id]||0)+e.children.length)}),e.inputs.forEach(function(l){if(l.category!=="control"){var u=qW(l.name,i,r);u!=null&&u.forEach(function(c){if(c&&!a.has(c.id)){var h=o[c.id];h===1?(c.dispose(),delete o[c.id]):h!=null&&o[c.id]--}})}})},n.prototype.executeAsync=function(t,e){return Vn(this,void 0,void 0,function(){return Nn(this,function(i){return[2,this._executeAsync(t,e)]})})},n.prototype._executeAsync=function(t,e,i,r,a){return i===void 0&&(i=!1),r===void 0&&(r={}),a===void 0&&(a={}),Vn(this,void 0,void 0,function(){var s,o,l,u,c,h;return Nn(this,function(d){switch(d.label){case 0:return i||(t=this.mapInputs(t),this.checkInputs(t),this.checkInputShapeAndType(t),e=this.mapOutputs(e),this.checkOutputs(e)),s=new _w(this.weightMap,r,a,this.functionExecutorMap),[4,this.executeWithControlFlow(t,s,e,i)];case 1:return o=d.sent(),l=e.map(function(p){return Gt(p,o,s)}),u=l.map(function(p){return p.id}),c=Object.keys(t).map(function(p){return t[p].id}),h=new Set(u.concat(c,this.weightIds)),Object.keys(o).forEach(function(p){var f=o[p];f.forEach(function(m){m&&!m.isDisposed&&!h.has(m.id)&&m.dispose()})}),this.parent==null&&s.dispose(h),[2,l]}})})},n.prototype.executeFunctionAsync=function(t,e,i){return Vn(this,void 0,void 0,function(){var r,a=this;return Nn(this,function(s){return r=t.reduce(function(o,l,u){return o[a.inputs[u].name]=l,o},{}),[2,this._executeAsync(r,this.outputNodes,!0,e,i)]})})},n.prototype.executeWithControlFlow=function(t,e,i,r){return Vn(this,void 0,void 0,function(){var a,s,o,l,u,c,h,d,p,f,m,g,v,b,w,S,L,N=this;return Nn(this,function(C){switch(C.label){case 0:a=Object.keys(t),s=a.map(function(R){return N.graph.nodes[Zt(R)[0]]}),o=i.map(function(R){return Zt(R)[0]}),l=o.map(function(R){return N.graph.nodes[R]}),u=Hw(t,l,this.weightMap),c=u.usedNodes,h=u.missingInputs,d=u.dynamicNode,p=u.syncInputs,f=s.concat(this.graph.weights).map(function(R){return{node:R,contexts:e.currentContext}}),m=Ew({},this.weightMap),Object.keys(t).forEach(function(R){var D=Zt(R),k=D[0],W=D[1],F=[];F[W]=t[R],m[k]=F}),g={},v=this.getFrozenTensorIds(m),b={},C.label=1;case 1:return f.length>0?(w=this.processStack(s,f,e,m,b,v,o,g,c),[4,Promise.all(w)]):[3,3];case 2:return C.sent(),[3,1];case 3:if(d==null&&!r&&console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead."),S=l.filter(function(R){return!Mw(R)&&!Gt(R.name,m,e)}).map(function(R){return R.name}),S.length>0)throw L="",d!=null&&(L="Alternatively, to avoid the dynamic ops, use model.execute() "+("and specify the inputs ["+p+"]")),new Error("Cannot compute the outputs ["+S+"] from the provided "+("inputs ["+a+"]. Consider providing the following inputs: ")+("["+h+"]. "+L));return[2,m]}})})},n.prototype.processStack=function(t,e,i,r,a,s,o,l,u){for(var c=this,h=[],d=function(){var f=e.pop();i.currentContext=f.contexts;var m="";if(f.node.op==="Enter"&&A("isConstant",f.node,r,i)&&(m=si(f.node.name,i)[0]),t.indexOf(f.node)===-1){var g=Pw(f.node,r,i);m||(m=si(f.node.name,i)[0]);var v=i.currentContext;g instanceof Promise?h.push(g.then(function(b){return r[m]=b,i.currentContext=v,c.checkTensorForDisposal(m,f.node,r,i,s,o,l),c.processChildNodes(f.node,e,i,r,a,u),b})):(r[m]=g,p.checkTensorForDisposal(m,f.node,r,i,s,o,l),p.processChildNodes(f.node,e,i,r,a,u))}else p.processChildNodes(f.node,e,i,r,a,u)},p=this;e.length>0;)d();return h},n.prototype.processChildNodes=function(t,e,i,r,a,s){t.children.forEach(function(o){var l=si(o.name,i)[0];if(a[l]||!s.has(o.name))return;o.op==="Merge"?o.inputNames.some(function(u){return!!Gt(u,r,i)})&&(a[l]=!0,e.push({contexts:i.currentContext,node:o})):o.inputNames.every(function(u){return!!Gt(u,r,i)})&&(a[l]=!0,e.push({contexts:i.currentContext,node:o}))})},n.prototype.dispose=function(){var t=this;Object.keys(this.weightMap).forEach(function(e){return t.weightMap[e].forEach(function(i){return i.dispose()})})},n.prototype.checkInputShapeAndType=function(t){var e=this;Object.keys(t).forEach(function(i){var r=t[i],a=Zt(i)[0],s=e.graph.nodes[a];if(s.attrParams.shape&&s.attrParams.shape.value){var o=s.attrParams.shape.value,l=o.length===r.shape.length&&r.shape.every(function(u,c){return o[c]===-1||o[c]===u});B.util.assert(l,function(){return"The shape of dict['"+s.name+"'] provided in "+("model.execute(dict) must be ["+o+"], but was ")+("["+r.shape+"]")})}s.attrParams.dtype&&s.attrParams.dtype.value&&B.util.assert(r.dtype===s.attrParams.dtype.value,function(){return"The dtype of dict['"+s.name+"'] provided in model.execute(dict) must be "+(s.attrParams.dtype.value+", but was "+r.dtype)})})},n.prototype.mapInputs=function(t){var e={};for(var i in t)if(this._signature!=null&&this._signature.inputs!=null&&this._signature.inputs[i]!=null){var r=this._signature.inputs[i];e[r.name]=t[i]}else e[i]=t[i];return e},n.prototype.checkInputs=function(t){var e=this,i=Object.keys(t).filter(function(r){var a=Zt(r)[0];return e.graph.nodes[a]==null});if(i.length>0)throw new Error("The dict provided in model.execute(dict) has "+("keys: ["+i+"] that are not part of graph"))},n.prototype.mapOutputs=function(t){var e=this;return t.map(function(i){if(e._signature!=null&&e._signature.outputs!=null&&e._signature.outputs[i]!=null){var r=e._signature.outputs[i];return r.name}return i},{})},n.prototype.checkOutputs=function(t){var e=this;t.forEach(function(i){var r=Zt(i)[0];if(!e.graph.nodes[r])throw new Error("The output '"+i+"' is not found in the graph")})},n}();var QU="?tfjs-format=file",eB="model.json",qw=function(){function n(t,e){e===void 0&&(e={}),this.modelUrl=t,this.loadOptions=e,this.version="n/a",e==null&&(this.loadOptions={})}return Object.defineProperty(n.prototype,"modelVersion",{get:function(){return this.version},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputNodes",{get:function(){return this.executor.inputNodes},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"outputNodes",{get:function(){return this.executor.outputNodes},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputs",{get:function(){return this.executor.inputs},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"outputs",{get:function(){return this.executor.outputs},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"weights",{get:function(){return this.executor.weightMap},enumerable:!0,configurable:!0}),n.prototype.findIOHandler=function(){var t=this.modelUrl;if(t.load!=null)this.handler=t;else if(this.loadOptions.requestInit!=null)this.handler=B.io.browserHTTPRequest(t,this.loadOptions);else{var e=B.io.getLoadHandlers(t,this.loadOptions);if(e.length===0)e.push(B.io.browserHTTPRequest(t,this.loadOptions));else if(e.length>1)throw new Error("Found more than one ("+e.length+") load handlers for "+("URL '"+[t]+"'"));this.handler=e[0]}},n.prototype.load=function(){return Vn(this,void 0,void 0,function(){var t;return Nn(this,function(e){switch(e.label){case 0:if(this.findIOHandler(),this.handler.load==null)throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");return[4,this.handler.load()];case 1:return t=e.sent(),[2,this.loadSync(t)]}})})},n.prototype.loadSync=function(t){this.artifacts=t;var e=this.artifacts.modelTopology,i={};this.artifacts.userDefinedMetadata!=null&&(i=this.artifacts.userDefinedMetadata.signature),this.version=e.versions.producer+"."+e.versions.minConsumer;var r=B.io.decodeWeights(this.artifacts.weightData,this.artifacts.weightSpecs);if(this.executor=new Vw(Ww.Instance.transformGraph(e,i)),this.executor.weightMap=this.convertTensorMapToTensorsMap(r),t.modelInitializer!=null){var a=Ww.Instance.transformGraph(t.modelInitializer);this.initializer=new Vw(a),this.initializer.weightMap=this.executor.weightMap,this.initializer.execute({},[])}return!0},n.prototype.save=function(t,e){return Vn(this,void 0,void 0,function(){var i;return Nn(this,function(r){if(typeof t=="string"){if(i=B.io.getSaveHandlers(t),i.length===0)throw new Error("Cannot find any save handlers for URL '"+t+"'");if(i.length>1)throw new Error("Found more than one ("+i.length+") save handlers for "+("URL '"+t+"'"));t=i[0]}if(t.save==null)throw new Error("GraphModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");return[2,t.save(this.artifacts)]})})},n.prototype.predict=function(t,e){return this.execute(t,this.outputNodes)},n.prototype.normalizeInputs=function(t){if(!(t instanceof B.Tensor)&&!Array.isArray(t))return t;if(t=Array.isArray(t)?t:[t],t.length!==this.inputNodes.length)throw new Error("Input tensor count mismatch,"+("the graph model has "+this.inputNodes.length+" placeholders, ")+("while there are "+t.length+" input tensors."));return this.inputNodes.reduce(function(e,i,r){return e[i]=t[r],e},{})},n.prototype.normalizeOutputs=function(t){return t=t||this.outputNodes,Array.isArray(t)?t:[t]},n.prototype.execute=function(t,e){t=this.normalizeInputs(t),e=this.normalizeOutputs(e);var i=this.executor.execute(t,e);return i.length>1?i:i[0]},n.prototype.executeAsync=function(t,e){return Vn(this,void 0,void 0,function(){var i;return Nn(this,function(r){switch(r.label){case 0:return t=this.normalizeInputs(t),e=this.normalizeOutputs(e),[4,this.executor.executeAsync(t,e)];case 1:return i=r.sent(),[2,i.length>1?i:i[0]]}})})},n.prototype.convertTensorMapToTensorsMap=function(t){return Object.keys(t).reduce(function(e,i){return e[i]=[t[i]],e},{})},n.prototype.dispose=function(){this.executor.dispose(),this.initializer&&this.initializer.dispose()},n}();function tB(n,t){return t===void 0&&(t={}),Vn(this,void 0,void 0,function(){var e;return Nn(this,function(i){switch(i.label){case 0:if(n==null)throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");return t==null&&(t={}),t.fromTFHub&&(n.load==null&&(n.endsWith("/")||(n=n+"/"),n=""+n+eB+QU)),e=new qw(n,t),[4,e.load()];case 1:return i.sent(),[2,e]}})})}var nB="2.6.0";gr.GraphModel=qw;gr.deregisterOp=VW;gr.loadGraphModel=tB;gr.registerOp=HW;gr.version_converter=nB});var h0=Le(Yt=>{"use strict";Object.defineProperty(Yt,"__esModule",{value:!0});var Ne=lr();var _d=function(n,t){return _d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var r in i)i.hasOwnProperty(r)&&(e[r]=i[r])},_d(n,t)};function Ve(n,t){_d(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function se(n,t,e,i){return new(e||(e=Promise))(function(r,a){function s(u){try{l(i.next(u))}catch(c){a(c)}}function o(u){try{l(i.throw(u))}catch(c){a(c)}}function l(u){u.done?r(u.value):new e(function(c){c(u.value)}).then(s,o)}l((i=i.apply(n,t||[])).next())})}function oe(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,r,a,s;return s={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(u){return function(c){return l([u,c])}}function l(u){if(i)throw new TypeError("Generator is already executing.");for(;e;)try{if(i=1,r&&(a=u[0]&2?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;(r=0,a)&&(u=[u[0]&2,a.value]);switch(u[0]){case 0:case 1:a=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,r=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){e.label=u[1];break}if(u[0]===6&&e.label<a[1]){e.label=a[1],a=u;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(u);break}a[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(n,e)}catch(c){u=[6,c],r=0}finally{i=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}var la=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function vr(n,t){return t={exports:{}},n(t,t.exports),t.exports}var iB=vr(function(n){(function(t,e,i){function r(l){var u=this,c=o();u.next=function(){var h=2091639*u.s0+u.c*23283064365386963e-26;return u.s0=u.s1,u.s1=u.s2,u.s2=h-(u.c=h|0)},u.c=1,u.s0=c(" "),u.s1=c(" "),u.s2=c(" "),u.s0-=c(l),u.s0<0&&(u.s0+=1),u.s1-=c(l),u.s1<0&&(u.s1+=1),u.s2-=c(l),u.s2<0&&(u.s2+=1),c=null}function a(l,u){return u.c=l.c,u.s0=l.s0,u.s1=l.s1,u.s2=l.s2,u}function s(l,u){var c=new r(l),h=u&&u.state,d=c.next;return d.int32=function(){return c.next()*4294967296|0},d.double=function(){return d()+(d()*2097152|0)*11102230246251565e-32},d.quick=d,h&&(typeof h=="object"&&a(h,c),d.state=function(){return a(c,{})}),d}function o(){var l=4022871197,u=function(c){c=c.toString();for(var h=0;h<c.length;h++){l+=c.charCodeAt(h);var d=.02519603282416938*l;l=d>>>0,d-=l,d*=l,l=d>>>0,d-=l,l+=d*4294967296}return(l>>>0)*23283064365386963e-26};return u}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.alea=s})(la,n,!1)}),rB=vr(function(n){(function(t,e,i){function r(o){var l=this,u="";l.x=0,l.y=0,l.z=0,l.w=0,l.next=function(){var h=l.x^l.x<<11;return l.x=l.y,l.y=l.z,l.z=l.w,l.w^=l.w>>>19^h^h>>>8},o===(o|0)?l.x=o:u+=o;for(var c=0;c<u.length+64;c++)l.x^=u.charCodeAt(c)|0,l.next()}function a(o,l){return l.x=o.x,l.y=o.y,l.z=o.z,l.w=o.w,l}function s(o,l){var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(typeof c=="object"&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xor128=s})(la,n,!1)}),aB=vr(function(n){(function(t,e,i){function r(o){var l=this,u="";l.next=function(){var h=l.x^l.x>>>2;return l.x=l.y,l.y=l.z,l.z=l.w,l.w=l.v,(l.d=l.d+362437|0)+(l.v=l.v^l.v<<4^(h^h<<1))|0},l.x=0,l.y=0,l.z=0,l.w=0,l.v=0,o===(o|0)?l.x=o:u+=o;for(var c=0;c<u.length+64;c++)l.x^=u.charCodeAt(c)|0,c==u.length&&(l.d=l.x<<10^l.x>>>4),l.next()}function a(o,l){return l.x=o.x,l.y=o.y,l.z=o.z,l.w=o.w,l.v=o.v,l.d=o.d,l}function s(o,l){var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(typeof c=="object"&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xorwow=s})(la,n,!1)}),sB=vr(function(n){(function(t,e,i){function r(o){var l=this;l.next=function(){var c=l.x,h=l.i,d,p;return d=c[h],d^=d>>>7,p=d^d<<24,d=c[h+1&7],p^=d^d>>>10,d=c[h+3&7],p^=d^d>>>3,d=c[h+4&7],p^=d^d<<7,d=c[h+7&7],d=d^d<<13,p^=d^d<<9,c[h]=p,l.i=h+1&7,p};function u(c,h){var d,p,f=[];if(h===(h|0))p=f[0]=h;else for(h=""+h,d=0;d<h.length;++d)f[d&7]=f[d&7]<<15^h.charCodeAt(d)+f[d+1&7]<<13;for(;f.length<8;)f.push(0);for(d=0;d<8&&f[d]===0;++d);for(d==8?p=f[7]=-1:p=f[d],c.x=f,c.i=0,d=256;d>0;--d)c.next()}u(l,o)}function a(o,l){return l.x=o.x.slice(),l.i=o.i,l}function s(o,l){o==null&&(o=+new Date);var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(c.x&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xorshift7=s})(la,n,!1)}),oB=vr(function(n){(function(t,e,i){function r(o){var l=this;l.next=function(){var c=l.w,h=l.X,d=l.i,p,f;return l.w=c=c+1640531527|0,f=h[d+34&127],p=h[d=d+1&127],f^=f<<13,p^=p<<17,f^=f>>>15,p^=p>>>12,f=h[d]=f^p,l.i=d,f+(c^c>>>16)|0};function u(c,h){var d,p,f,m,g,v=[],b=128;for(h===(h|0)?(p=h,h=null):(h=h+"\0",p=0,b=Math.max(b,h.length)),f=0,m=-32;m<b;++m)h&&(p^=h.charCodeAt((m+32)%h.length)),m===0&&(g=p),p^=p<<10,p^=p>>>15,p^=p<<4,p^=p>>>13,m>=0&&(g=g+1640531527|0,d=v[m&127]^=p+g,f=d==0?f+1:0);for(f>=128&&(v[(h&&h.length||0)&127]=-1),f=127,m=4*128;m>0;--m)p=v[f+34&127],d=v[f=f+1&127],p^=p<<13,d^=d<<17,p^=p>>>15,d^=d>>>12,v[f]=p^d;c.w=g,c.X=v,c.i=f}u(l,o)}function a(o,l){return l.i=o.i,l.w=o.w,l.X=o.X.slice(),l}function s(o,l){o==null&&(o=+new Date);var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(c.X&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.xor4096=s})(la,n,!1)}),lB=vr(function(n){(function(t,e,i){function r(o){var l=this,u="";l.next=function(){var h=l.b,d=l.c,p=l.d,f=l.a;return h=h<<25^h>>>7^d,d=d-p|0,p=p<<24^p>>>8^f,f=f-h|0,l.b=h=h<<20^h>>>12^d,l.c=d=d-p|0,l.d=p<<16^d>>>16^f,l.a=f-h|0},l.a=0,l.b=0,l.c=2654435769|0,l.d=1367130551,o===Math.floor(o)?(l.a=o/4294967296|0,l.b=o|0):u+=o;for(var c=0;c<u.length+20;c++)l.b^=u.charCodeAt(c)|0,l.next()}function a(o,l){return l.a=o.a,l.b=o.b,l.c=o.c,l.d=o.d,l}function s(o,l){var u=new r(o),c=l&&l.state,h=function(){return(u.next()>>>0)/4294967296};return h.double=function(){do var d=u.next()>>>11,p=(u.next()>>>0)/4294967296,f=(d+p)/(1<<21);while(f===0);return f},h.int32=u.next,h.quick=h,c&&(typeof c=="object"&&a(c,u),h.state=function(){return a(u,{})}),h}e&&e.exports?e.exports=s:i&&i.amd?i(function(){return s}):this.tychei=s})(la,n,!1)}),yr=vr(function(n){(function(t,e){var i=this,r=256,a=6,s=52,o="random",l=e.pow(r,a),u=e.pow(2,s),c=u*2,h=r-1,d;function p(S,L,N){var C=[];L=L==!0?{entropy:!0}:L||{};var R=v(g(L.entropy?[S,w(t)]:S??b(),3),C),D=new f(C),k=function(){for(var W=D.g(a),F=l,P=0;W<u;)W=(W+P)*r,F*=r,P=D.g(1);for(;W>=c;)W/=2,F/=2,P>>>=1;return(W+P)/F};return k.int32=function(){return D.g(4)|0},k.quick=function(){return D.g(4)/4294967296},k.double=k,v(w(D.S),t),(L.pass||N||function(W,F,P,H){return H&&(H.S&&m(H,D),W.state=function(){return m(D,{})}),P?(e[o]=W,F):W})(k,R,"global"in L?L.global:this==e,L.state)}e["seed"+o]=p;function f(S){var L,N=S.length,C=this,R=0,D=C.i=C.j=0,k=C.S=[];for(N||(S=[N++]);R<r;)k[R]=R++;for(R=0;R<r;R++)k[R]=k[D=h&D+S[R%N]+(L=k[R])],k[D]=L;(C.g=function(W){for(var F,P=0,H=C.i,_=C.j,j=C.S;W--;)F=j[H=h&H+1],P=P*r+j[h&(j[H]=j[_=h&_+F])+(j[_]=F)];return C.i=H,C.j=_,P})(r)}function m(S,L){return L.i=S.i,L.j=S.j,L.S=S.S.slice(),L}function g(S,L){var N=[],C=typeof S,R;if(L&&C=="object")for(R in S)try{N.push(g(S[R],L-1))}catch(D){}return N.length?N:C=="string"?S:S+"\0"}function v(S,L){for(var N=S+"",C,R=0;R<N.length;)L[h&R]=h&(C^=L[h&R]*19)+N.charCodeAt(R++);return w(L)}function b(){try{var S;return d&&(S=d.randomBytes)?S=S(r):(S=new Uint8Array(r),(i.crypto||i.msCrypto).getRandomValues(S)),w(S)}catch(C){var L=i.navigator,N=L&&L.plugins;return[+new Date,i,N,i.screen,w(t)]}}function w(S){return String.fromCharCode.apply(0,S)}if(v(e.random(),t),n.exports){n.exports=p;try{d=require("crypto")}catch(S){}}})([],Math)});yr.alea=iB;yr.xor128=rB;yr.xorwow=aB;yr.xorshift7=sB;yr.xor4096=oB;yr.tychei=lB;var uB=yr,Yw=uB.alea;function cB(n,t){return Ko(n,t)}function Ko(n,t,e,i){if(e===void 0&&(e=new Map),i===void 0&&(i=new Set),n==null)return null;if(i.has(n))throw new Error("Circular references are not supported.");if(e.has(n))return e.get(n);var r=t(n);if(r.recurse&&r.value!==null)throw new Error("A deep map function may not return both a value and recurse=true.");if(r.recurse)if(ua(n)){var a=Array.isArray(n)?[]:{};i.add(n);for(var s in n){var o=n[s],l=Ko(o,t,e,i);a[s]=l}return i.delete(n),a}else throw new Error("Can't recurse into non-iterable type: "+n);else return e.set(n,r.value),r.value}function hB(n,t){return t===void 0&&(t=Kw),jw(n,t)}function jw(n,t,e){e===void 0&&(e=new Set);var i=n[0];if(e.has(i))throw new Error("Circular references are not supported.");var r=t(n);if(r.recurse&&r.value!==null)throw new Error("A deep zip function may not return both a value and recurse=true.");if(r.recurse)if(ua(i)){var a=Array.isArray(i)?[]:{};e.add(i);var s=function(l){var u=n.map(function(h){return h[l]}),c=jw(u,t,e);a[l]=c};for(var o in i)s(o);return e.delete(i),a}else throw new Error("Can't recurse into non-iterable type: "+i);else return r.value}function Kw(n){return n===null?null:ua(n[0])?{value:null,recurse:!0}:{value:n,recurse:!1}}function $w(n,t){return se(this,void 0,void 0,function(){var e,i,r,a,s,o,l;return oe(this,function(u){switch(u.label){case 0:e=new Map,Ko(n,t,e),i=0,r=Array.from(e.keys()),u.label=1;case 1:return i<r.length?(a=r[i],s=e.get(a),s instanceof Promise?[4,s]:[3,3]):[3,4];case 2:o=u.sent(),e.set(a,o),u.label=3;case 3:return i++,[3,1];case 4:return l=Ko(n,t,e),[2,l]}})})}function ua(n){return n!=null&&!ArrayBuffer.isView(n)&&(Array.isArray(n)||typeof n=="object"&&!(n instanceof Ne.Tensor))}function pB(n){return n==null||dB(n)||Array.isArray(n)||typeof n=="object"&&n instanceof Ne.Tensor||Ne.util.isTypedArray(n)}function dB(n){return n===null||typeof n!="object"&&typeof n!="function"}function mB(n){return cB(n,fB)}function fB(n){return n instanceof Ne.Tensor?{value:n.clone(),recurse:!1}:ua(n)?{value:null,recurse:!0}:{value:n,recurse:!1}}var Xw=function(){function n(t){if(this.capacity=t,this.begin=0,this.end=0,t==null)throw new RangeError("Can't create a ring buffer of unknown capacity.");if(t<1)throw new RangeError("Can't create ring buffer of capacity < 1.");this.data=new Array(t),this.doubledCapacity=2*t}return n.prototype.wrap=function(t){for(;t<0;)t+=this.doubledCapacity;return t%this.doubledCapacity},n.prototype.get=function(t){if(t<0)throw new RangeError("Can't get item at a negative index.");return this.data[t%this.capacity]},n.prototype.set=function(t,e){if(t<0)throw new RangeError("Can't set item at a negative index.");this.data[t%this.capacity]=e},n.prototype.length=function(){var t=this.end-this.begin;return t<0&&(t=this.doubledCapacity+t),t},n.prototype.isFull=function(){return this.length()===this.capacity},n.prototype.isEmpty=function(){return this.length()===0},n.prototype.push=function(t){if(this.isFull())throw new RangeError("Ring buffer is full.");this.set(this.end,t),this.end=this.wrap(this.end+1)},n.prototype.pushAll=function(t){for(var e=0,i=t;e<i.length;e++){var r=i[e];this.push(r)}},n.prototype.pop=function(){if(this.isEmpty())throw new RangeError("Ring buffer is empty.");this.end=this.wrap(this.end-1);var t=this.get(this.end);return this.set(this.end,void 0),t},n.prototype.unshift=function(t){if(this.isFull())throw new RangeError("Ring buffer is full.");this.begin=this.wrap(this.begin-1),this.set(this.begin,t)},n.prototype.shift=function(){if(this.isEmpty())throw new RangeError("Ring buffer is empty.");var t=this.get(this.begin);return this.set(this.begin,void 0),this.begin=this.wrap(this.begin+1),t},n.prototype.shuffleExcise=function(t){if(this.isEmpty())throw new RangeError("Ring buffer is empty.");var e=this.wrap(this.begin+t),i=this.get(e);return this.set(e,this.pop()),i},n}();var gB=function(n){Ve(t,n);function t(){return n.call(this,t.INITIAL_CAPACITY)||this}return t.prototype.isFull=function(){return!1},t.prototype.push=function(e){n.prototype.isFull.call(this)&&this.expand(),n.prototype.push.call(this,e)},t.prototype.unshift=function(e){n.prototype.isFull.call(this)&&this.expand(),n.prototype.unshift.call(this,e)},t.prototype.expand=function(){for(var e=this.capacity*2,i=new Array(e),r=this.length(),a=0;a<r;a++)i[a]=this.get(this.wrap(this.begin+a));this.data=i,this.capacity=e,this.doubledCapacity=2*this.capacity,this.begin=0,this.end=r},t.INITIAL_CAPACITY=32,t}(Xw);function Jw(n){return new vB(n)}function Md(n){return new yB(n)}function bB(n,t){return new Zw(n,t)}function SB(n,t){return t===void 0&&(t=Fi.FAIL),new wB(n,t)}var xt=function(){function n(){}return n.prototype.toArray=function(){return se(this,void 0,void 0,function(){var t,e;return oe(this,function(i){switch(i.label){case 0:return t=[],[4,this.next()];case 1:e=i.sent(),i.label=2;case 2:return e.done?[3,4]:(t.push(e.value),[4,this.next()]);case 3:return e=i.sent(),[3,2];case 4:return[2,t]}})})},n.prototype.toArrayForTest=function(){return se(this,void 0,void 0,function(){var t,e,i;return oe(this,function(r){switch(r.label){case 0:return t=this.prefetch(100),e=[],[4,t.next()];case 1:i=r.sent(),r.label=2;case 2:return i.done?[3,4]:(e.push(i.value),[4,t.next()]);case 3:return i=r.sent(),[3,2];case 4:return[2,e]}})})},n.prototype.resolveFully=function(){return se(this,void 0,void 0,function(){var t;return oe(this,function(e){switch(e.label){case 0:return[4,this.next()];case 1:t=e.sent(),e.label=2;case 2:return t.done?[3,4]:[4,this.next()];case 3:return t=e.sent(),[3,2];case 4:return[2]}})})},n.prototype.resolveWhile=function(t){return se(this,void 0,void 0,function(){var e,i;return oe(this,function(r){switch(r.label){case 0:return[4,this.next()];case 1:e=r.sent(),i=t(e.value),r.label=2;case 2:return!e.done&&i?[4,this.next()]:[3,4];case 3:return e=r.sent(),i=t(e.value),[3,2];case 4:return[2]}})})},n.prototype.handleErrors=function(t){return new CB(this,t)},n.prototype.filter=function(t){return new NB(this,t)},n.prototype.map=function(t){return new xB(this,t)},n.prototype.mapAsync=function(t){return new Qw(this,t)},n.prototype.serialMapAsync=function(t){return new Qw(this,t).serial()},n.prototype.flatmap=function(t){return new RB(this,t)},n.prototype.forEachAsync=function(t){return se(this,void 0,void 0,function(){return oe(this,function(e){return[2,this.map(t).resolveFully()]})})},n.prototype.serialForEach=function(t){return se(this,void 0,void 0,function(){return oe(this,function(e){return[2,this.serialMapAsync(t).resolveWhile(function(i){return i===!0})]})})},n.prototype.rowMajorBatch=function(t,e){return e===void 0&&(e=!0),new TB(this,t,e)},n.prototype.columnMajorBatch=function(t,e,i){e===void 0&&(e=!0),i===void 0&&(i=Kw);var r=this.rowMajorBatch(t,e);return r.map(function(a){return hB(a,i)})},n.prototype.concatenate=function(t,e){return new Zw(Jw([this,t]),e)},n.prototype.take=function(t){return t<0||t==null?this:new AB(this,t)},n.prototype.skip=function(t){return t<0||t==null?this:new IB(this,t)},n.prototype.prefetch=function(t){return new e0(this,t)},n.prototype.shuffle=function(t,e){return new OB(this,t,e)},n.prototype.serial=function(){return new LB(this)},n}(),vB=function(n){Ve(t,n);function t(e){var i=n.call(this)||this;return i.items=e,i.trav=0,i}return t.prototype.summary=function(){return"Array of "+this.items.length+" items"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e;return oe(this,function(i){return this.trav>=this.items.length?[2,{value:null,done:!0}]:(e=this.items[this.trav],this.trav++,[2,{value:mB(e),done:!1}])})})},t}(xt),yB=function(n){Ve(t,n);function t(e){var i=n.call(this)||this;return i.nextFn=e,i}return t.prototype.summary=function(){return"Function call"},t.prototype.next=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){try{return[2,this.nextFn()]}catch(i){throw i.message="Error thrown while iterating through a dataset: "+i.message,i}return[2]})})},t}(xt),LB=function(n){Ve(t,n);function t(e){var i=n.call(this)||this;return i.upstream=e,i.lastRead=Promise.resolve({value:null,done:!1}),i}return t.prototype.summary=function(){return this.upstream.summary()+" -> Serial"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e=this;return oe(this,function(i){return this.lastRead=this.lastRead.then(function(){return e.serialNext()}),[2,this.lastRead]})})},t.prototype.serialNext=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){return[2,this.upstream.next()]})})},t}(xt),IB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.maxCount=i,r.count=0,r.lastRead=Promise.resolve({value:null,done:!1}),r}return t.prototype.summary=function(){return this.upstream.summary()+" -> Skip"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e=this;return oe(this,function(i){return this.lastRead=this.lastRead.then(function(){return e.serialNext()}),[2,this.lastRead]})})},t.prototype.serialNext=function(){return se(this,void 0,void 0,function(){var e;return oe(this,function(i){switch(i.label){case 0:return this.count++<this.maxCount?[4,this.upstream.next()]:[3,2];case 1:return e=i.sent(),e.done?[2,e]:(Ne.dispose(e.value),[3,0]);case 2:return[2,this.upstream.next()]}})})},t}(xt),AB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.maxCount=i,r.count=0,r}return t.prototype.summary=function(){return this.upstream.summary()+" -> Take"},t.prototype.next=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){return this.count++>=this.maxCount?[2,{value:null,done:!0}]:[2,this.upstream.next()]})})},t}(xt),TB=function(n){Ve(t,n);function t(e,i,r){r===void 0&&(r=!0);var a=n.call(this)||this;return a.upstream=e,a.batchSize=i,a.enableSmallLastBatch=r,a.lastRead=Promise.resolve({value:null,done:!1}),a}return t.prototype.summary=function(){return this.upstream.summary()+" -> RowMajorBatch"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e=this;return oe(this,function(i){return this.lastRead=this.lastRead.then(function(){return e.serialNext()}),[2,this.lastRead]})})},t.prototype.serialNext=function(){return se(this,void 0,void 0,function(){var e,i;return oe(this,function(r){switch(r.label){case 0:e=[],r.label=1;case 1:return e.length<this.batchSize?[4,this.upstream.next()]:[3,3];case 2:return i=r.sent(),i.done?this.enableSmallLastBatch&&e.length>0?[2,{value:e,done:!1}]:[2,{value:null,done:!0}]:(e.push(i.value),[3,1]);case 3:return[2,{value:e,done:!1}]}})})},t}(xt),NB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.predicate=i,r.lastRead=Promise.resolve({value:null,done:!1}),r}return t.prototype.summary=function(){return this.upstream.summary()+" -> Filter"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e=this;return oe(this,function(i){return this.lastRead=this.lastRead.then(function(){return e.serialNext()}),[2,this.lastRead]})})},t.prototype.serialNext=function(){return se(this,void 0,void 0,function(){var e;return oe(this,function(i){switch(i.label){case 0:return[4,this.upstream.next()];case 1:return e=i.sent(),e.done||this.predicate(e.value)?[2,e]:(Ne.dispose(e.value),[3,0]);case 2:return[2]}})})},t}(xt),xB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.transform=i,r}return t.prototype.summary=function(){return this.upstream.summary()+" -> Map"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e,i,r,a,s,o,l;return oe(this,function(u){switch(u.label){case 0:return[4,this.upstream.next()];case 1:if(e=u.sent(),e.done)return[2,{value:null,done:!0}];for(i=Ne.tensor_util.getTensorsInContainer(e.value),r=this.transform(e.value),a=Ne.tensor_util.getTensorsInContainer(r),s=0,o=i;s<o.length;s++)l=o[s],Ne.tensor_util.isTensorInList(l,a)||l.dispose();return[2,{value:r,done:!1}]}})})},t}(xt),CB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.handler=i,r.count=0,r.lastRead=Promise.resolve({value:null,done:!1}),r}return t.prototype.summary=function(){return this.upstream.summary()+" -> handleErrors"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e=this;return oe(this,function(i){return this.lastRead=this.lastRead.then(function(){return e.serialNext()}),[2,this.lastRead]})})},t.prototype.serialNext=function(){return se(this,void 0,void 0,function(){var e;return oe(this,function(i){switch(i.label){case 0:i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.upstream.next()];case 2:return[2,i.sent()];case 3:return e=i.sent(),this.handler(e)?[3,4]:[2,{value:null,done:!0}];case 4:return[3,0];case 5:return[2]}})})},t}(xt),Qw=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.transform=i,r}return t.prototype.summary=function(){return this.upstream.summary()+" -> AsyncMap"},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e,i,r,a,s,o,l;return oe(this,function(u){switch(u.label){case 0:return[4,this.upstream.next()];case 1:return e=u.sent(),e.done?[2,{value:null,done:!0}]:(i=Ne.tensor_util.getTensorsInContainer(e.value),[4,this.transform(e.value)]);case 2:for(r=u.sent(),a=Ne.tensor_util.getTensorsInContainer(r),s=0,o=i;s<o.length;s++)l=o[s],Ne.tensor_util.isTensorInList(l,a)||l.dispose();return[2,{value:r,done:!1}]}})})},t}(xt),Hd=function(n){Ve(t,n);function t(){var e=n.call(this)||this;return e.outputQueue=new gB,e.lastRead=Promise.resolve({value:null,done:!1}),e}return t.prototype.next=function(){return se(this,void 0,void 0,function(){var e=this;return oe(this,function(i){return this.lastRead=this.lastRead.then(function(){return e.serialNext()}),[2,this.lastRead]})})},t.prototype.serialNext=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){switch(e.label){case 0:return this.outputQueue.length()===0?[4,this.pump()]:[3,2];case 1:return e.sent()?[3,0]:[2,{value:null,done:!0}];case 2:return[2,{value:this.outputQueue.shift(),done:!1}]}})})},t}(xt),RB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.transform=i,r}return t.prototype.summary=function(){return this.upstream.summary()+" -> Flatmap"},t.prototype.pump=function(){return se(this,void 0,void 0,function(){var e,i,r,a,s,o,l;return oe(this,function(u){switch(u.label){case 0:return[4,this.upstream.next()];case 1:if(e=u.sent(),e.done)return[2,!1];for(i=Ne.tensor_util.getTensorsInContainer(e.value),r=this.transform(e.value),a=Ne.tensor_util.getTensorsInContainer(r),this.outputQueue.pushAll(r),s=0,o=i;s<o.length;s++)l=o[s],Ne.tensor_util.isTensorInList(l,a)||l.dispose();return[2,!0]}})})},t}(Hd),Zw=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.baseErrorHandler=i,r.lastRead=null,r.iterator=null,r.moreIterators=e,r}return t.prototype.summary=function(){var e="TODO: fill in upstream of chained summaries";return e+" -> Chained"},t.prototype.next=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){return this.lastRead=this.readFromChain(this.lastRead),[2,this.lastRead]})})},t.prototype.readFromChain=function(e){return se(this,void 0,void 0,function(){var i,r;return oe(this,function(a){switch(a.label){case 0:return[4,e];case 1:return a.sent(),this.iterator==null?[4,this.moreIterators.next()]:[3,3];case 2:if(i=a.sent(),i.done)return[2,{value:null,done:!0}];this.iterator=i.value,this.baseErrorHandler!=null&&(this.iterator=this.iterator.handleErrors(this.baseErrorHandler)),a.label=3;case 3:return[4,this.iterator.next()];case 4:return r=a.sent(),r.done?(this.iterator=null,[2,this.readFromChain(e)]):[2,r]}})})},t}(xt),Fi;(function(n){n[n.FAIL=0]="FAIL",n[n.SHORTEST=1]="SHORTEST",n[n.LONGEST=2]="LONGEST"})(Fi||(Fi={}));var wB=function(n){Ve(t,n);function t(e,i){i===void 0&&(i=Fi.FAIL);var r=n.call(this)||this;return r.iterators=e,r.mismatchMode=i,r.count=0,r.currentPromise=null,r}return t.prototype.summary=function(){var e="TODO: fill in upstream of zip summaries";return"{"+e+"} -> Zip"},t.prototype.nextState=function(e){return se(this,void 0,void 0,function(){function i(o){if(o instanceof xt){var l=o.next();return{value:l.then(function(u){return r++,u.done&&a++,u.value}),recurse:!1}}else return{value:null,recurse:!0}}var r,a,s;return oe(this,function(o){switch(o.label){case 0:return[4,e];case 1:return o.sent(),r=0,a=0,[4,$w(this.iterators,i)];case 2:if(s=o.sent(),r===a)return[2,{value:null,done:!0}];if(a>0)switch(this.mismatchMode){case Fi.FAIL:throw new Error("Zipped streams should have the same length. "+("Mismatched at element "+this.count+"."));case Fi.SHORTEST:return[2,{value:null,done:!0}];case Fi.LONGEST:}return this.count++,[2,{value:s,done:!1}]}})})},t.prototype.next=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){return this.currentPromise=this.nextState(this.currentPromise),[2,this.currentPromise]})})},t}(xt),e0=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.bufferSize=i,r.buffer=new Xw(i),r}return t.prototype.summary=function(){return this.upstream.summary()+" -> Prefetch"},t.prototype.refill=function(){for(;!this.buffer.isFull();){var e=this.upstream.next();this.buffer.push(e)}},t.prototype.next=function(){return this.refill(),this.buffer.shift()},t}(xt),OB=function(n){Ve(t,n);function t(e,i,r){var a=n.call(this,e,i)||this;return a.upstream=e,a.windowSize=i,a.upstreamExhausted=!1,a.random=Yw(r||Ne.util.now().toString()),a.lastRead=Promise.resolve({value:null,done:!1}),a}return t.prototype.next=function(){return se(this,void 0,void 0,function(){var e=this;return oe(this,function(i){return this.lastRead=this.lastRead.then(function(){return e.serialNext()}),[2,this.lastRead]})})},t.prototype.randomInt=function(e){return Math.floor(this.random()*e)},t.prototype.chooseIndex=function(){return this.randomInt(this.buffer.length())},t.prototype.serialNext=function(){return se(this,void 0,void 0,function(){var e,i;return oe(this,function(r){switch(r.label){case 0:this.upstreamExhausted||this.refill(),r.label=1;case 1:return this.buffer.isEmpty()?[3,3]:(e=this.chooseIndex(),[4,this.buffer.shuffleExcise(e)]);case 2:if(i=r.sent(),i.done)this.upstreamExhausted=!0;else return this.refill(),[2,i];return[3,1];case 3:return[2,{value:null,done:!0}]}})})},t}(e0);var hs=function(){function n(){this.size=null}return n.prototype.batch=function(t,e){var i=this;e===void 0&&(e=!0);var r=this;Ne.util.assert(t>0,function(){return`batchSize needs to be positive, but it is
|
|
`+t});var a;return this.size===Infinity||this.size==null?a=this.size:e?a=Math.ceil(this.size/t):a=Math.floor(this.size/t),Qt(function(){return se(i,void 0,void 0,function(){return oe(this,function(s){switch(s.label){case 0:return[4,r.iterator()];case 1:return[2,s.sent().columnMajorBatch(t,e,EB)]}})})},a)},n.prototype.concatenate=function(t){var e=this,i=this,r;return this.size===Infinity||t.size===Infinity?r=Infinity:this.size!=null&&t.size!=null?r=this.size+t.size:r=null,Qt(function(){return se(e,void 0,void 0,function(){var a,s;return oe(this,function(o){switch(o.label){case 0:return[4,i.iterator()];case 1:return s=(a=o.sent()).concatenate,[4,t.iterator()];case 2:return[2,s.apply(a,[o.sent()])]}})})},r)},n.prototype.filter=function(t){var e=this,i=this,r;return this.size===Infinity?r=Infinity:r=null,Qt(function(){return se(e,void 0,void 0,function(){return oe(this,function(a){switch(a.label){case 0:return[4,i.iterator()];case 1:return[2,a.sent().filter(function(s){return Ne.tidy(function(){return t(s)})})]}})})},r)},n.prototype.forEachAsync=function(t){return se(this,void 0,void 0,function(){return oe(this,function(e){switch(e.label){case 0:return[4,this.iterator()];case 1:return[2,e.sent().forEachAsync(t)]}})})},n.prototype.map=function(t){var e=this,i=this;return Qt(function(){return se(e,void 0,void 0,function(){return oe(this,function(r){switch(r.label){case 0:return[4,i.iterator()];case 1:return[2,r.sent().map(function(a){return Ne.tidy(function(){return t(a)})})]}})})},this.size)},n.prototype.mapAsync=function(t){var e=this,i=this;return Qt(function(){return se(e,void 0,void 0,function(){return oe(this,function(r){switch(r.label){case 0:return[4,i.iterator()];case 1:return[2,r.sent().mapAsync(t)]}})})},this.size)},n.prototype.prefetch=function(t){var e=this;if(t==null)throw new RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");var i=this;return Qt(function(){return se(e,void 0,void 0,function(){return oe(this,function(r){switch(r.label){case 0:return[4,i.iterator()];case 1:return[2,r.sent().prefetch(t)]}})})},this.size)},n.prototype.repeat=function(t){var e=this,i=this,r;return this.size!=null&&t>0?r=this.size*t:t===0?r=0:this.size!=null&&(t===void 0||t<0)?r=Infinity:r=null,Qt(function(){return se(e,void 0,void 0,function(){var a,s=this;return oe(this,function(o){return a=Md(function(){return se(s,void 0,void 0,function(){var l;return oe(this,function(u){switch(u.label){case 0:return l={},[4,i.iterator()];case 1:return[2,(l.value=u.sent(),l.done=!1,l)]}})})}),[2,bB(a.take(t))]})})},r)},n.prototype.skip=function(t){var e=this,i=this,r;return this.size!=null&&t>=0&&this.size>=t?r=this.size-t:this.size!=null&&(this.size<t||t===void 0||t<0)?r=0:r=null,Qt(function(){return se(e,void 0,void 0,function(){return oe(this,function(a){switch(a.label){case 0:return[4,i.iterator()];case 1:return[2,a.sent().skip(t)]}})})},r)},n.prototype.shuffle=function(t,e,i){var r=this;if(i===void 0&&(i=!0),t==null||t<0)throw this.size==null?new RangeError("`Dataset.shuffle()` requires bufferSize to be specified."):new RangeError("`Dataset.shuffle()` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for `tf.Tensor`s), consider setting "+("bufferSize to the dataset size ("+this.size+" elements)"));var a=this,s=Yw(e||Ne.util.now().toString());return Qt(function(){return se(r,void 0,void 0,function(){var o;return oe(this,function(l){switch(l.label){case 0:return o=s.int32(),i&&(o+=s.int32()),[4,a.iterator()];case 1:return[2,l.sent().shuffle(t,o.toString())]}})})},this.size)},n.prototype.take=function(t){var e=this,i=this,r;return this.size!=null&&this.size>t?r=t:this.size!=null&&this.size<=t?r=this.size:r=null,Qt(function(){return se(e,void 0,void 0,function(){return oe(this,function(a){switch(a.label){case 0:return[4,i.iterator()];case 1:return[2,a.sent().take(t)]}})})},r)},n.prototype.toArray=function(){return se(this,void 0,void 0,function(){return oe(this,function(t){switch(t.label){case 0:if(this.size===Infinity)throw new Error("Can not convert infinite data stream to array.");return[4,this.iterator()];case 1:return[2,t.sent().toArray()]}})})},n.prototype.toArrayForTest=function(){return se(this,void 0,void 0,function(){return oe(this,function(t){switch(t.label){case 0:if(this.size===Infinity)throw new Error("Can not convert infinite data stream to array.");return[4,this.iterator()];case 1:return[2,t.sent().toArrayForTest()]}})})},n.MAX_BUFFER_SIZE=1e4,n}();function Qt(n,t){return t===void 0&&(t=null),new(function(e){Ve(i,e);function i(){var r=e!==null&&e.apply(this,arguments)||this;return r.size=t,r}return i.prototype.iterator=function(){return se(this,void 0,void 0,function(){return oe(this,function(r){return[2,n()]})})},i}(hs))}function DB(n){var t=this;return Qt(function(){return se(t,void 0,void 0,function(){return oe(this,function(e){return[2,Jw(n)]})})},n.length)}function kB(n){var t=this;if(!ua(n))throw new Error("The argument to zip() must be an object or array.");var e;if(Array.isArray(n))for(var i=0;i<n.length;i++)e=e==null?n[i].size:Math.min(e,n[i].size);else if(n instanceof Object)for(var r in n)e=e==null?n[r].size:Math.min(e,n[r].size);return Qt(function(){return se(t,void 0,void 0,function(){var a;return oe(this,function(s){switch(s.label){case 0:return[4,$w(n,function(o){if(o instanceof hs)return{value:o.iterator(),recurse:!1};if(ua(o))return{value:null,recurse:!0};throw new Error("Leaves of the structure passed to zip() must be Datasets, not primitives.")})];case 1:return a=s.sent(),[2,SB(a,Fi.SHORTEST)]}})})},e)}function EB(n){if(n===null)return null;var t=n[0];if(pB(t)){var e=FB(n);return{value:e,recurse:!1}}return{value:null,recurse:!0}}function FB(n){if(n.length===0)throw new Error("Can't make a batch of zero elements.");return n[0]instanceof Ne.Tensor?Ne.stack(n):Ne.tensor(n)}var t0=function(n){Ve(t,n);function t(e){var i=n.call(this)||this;return i.input=e,i}return t.prototype.iterator=function(){return se(this,void 0,void 0,function(){var e,i,r;return oe(this,function(a){switch(a.label){case 0:return[4,this.input.iterator()];case 1:return e=a.sent(),i=e.decodeUTF8(),r=i.split(`
|
|
`).map(function(s){return s.endsWith("\r")&&(s=s.slice(0,-1)),s}),[2,r]}})})},t}(hs);var $o='"',ds=Symbol("out"),n0=Symbol("field"),Xo=Symbol("quote"),Vd=Symbol("quoteafterquote"),i0=Symbol("quoteinquote"),r0=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.input=e,r.hasHeader=!0,r.fullColumnNames=null,r.columnNamesValidated=!1,r.columnConfigs=null,r.configuredColumnsOnly=!1,r.delimiter=",",r.delimWhitespace=!1,r.base=new t0(e),i||(i={}),r.hasHeader=!(i.hasHeader===!1),r.fullColumnNames=i.columnNames,r.columnConfigs=i.columnConfigs,r.configuredColumnsOnly=i.configuredColumnsOnly,i.delimWhitespace?(Ne.util.assert(i.delimiter==null,function(){return"Delimiter should not be provided when delimWhitespace is true."}),r.delimWhitespace=!0,r.delimiter=" "):r.delimiter=i.delimiter?i.delimiter:",",r}return t.prototype.columnNames=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){switch(e.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:e.sent(),e.label=2;case 2:return[2,this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames]}})})},t.prototype.setColumnNames=function(){return se(this,void 0,void 0,function(){var e,i,r,a,s,o,l,u=this;return oe(this,function(c){switch(c.label){case 0:return[4,this.maybeReadHeaderLine()];case 1:if(e=c.sent(),!this.fullColumnNames&&!e)throw new Error("Column names must be provided if there is no header line.");if(this.fullColumnNames&&e&&Ne.util.assert(e.length===this.fullColumnNames.length,function(){return"The length of provided columnNames ("+u.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+e.length.toString()+")."}),this.fullColumnNames||(this.fullColumnNames=e),i=this.fullColumnNames.reduce(function(h,d){return h[d]=h[d]+1||1,h},{}),r=Object.keys(i).filter(function(h){return i[h]>1}),Ne.util.assert(r.length===0,function(){return"Duplicate column names found: "+r.toString()}),this.columnConfigs){for(a=0,s=Object.keys(this.columnConfigs);a<s.length;a++)if(o=s[a],l=this.fullColumnNames.indexOf(o),l===-1)throw new Error('The key "'+o+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}return this.columnNamesValidated=!0,[2]}})})},t.prototype.maybeReadHeaderLine=function(){return se(this,void 0,void 0,function(){var e,i,r,a;return oe(this,function(s){switch(s.label){case 0:return this.hasHeader?[4,this.base.iterator()]:[3,3];case 1:return e=s.sent(),[4,e.next()];case 2:if(i=s.sent(),i.done)throw new Error("No data was found for CSV parsing.");return r=i.value,a=this.parseRow(r,!1),[2,a];case 3:return[2,null]}})})},t.prototype.iterator=function(){return se(this,void 0,void 0,function(){var e,i=this;return oe(this,function(r){switch(r.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:r.sent(),r.label=2;case 2:return[4,this.base.iterator()];case 3:return e=r.sent(),this.hasHeader&&(e=e.skip(1)),[2,e.map(function(a){return i.makeDataElement(a)})]}})})},t.prototype.makeDataElement=function(e){for(var i=this.parseRow(e),r={},a={},s=0;s<this.fullColumnNames.length;s++){var o=this.fullColumnNames[s],l=this.columnConfigs?this.columnConfigs[o]:null;if(this.configuredColumnsOnly&&!l)continue;var u=i[s],c=null;if(u==="")if(l&&l.default!==void 0)c=l.default;else{if(l&&(l.required||l.isLabel))throw new Error("Required column "+o+" is empty in this line: "+e);c=void 0}else{var h=Number(u);if(isNaN(h))l&&l.dtype==="bool"?c=this.getBoolean(u):c=u;else if(!l||!l.dtype)c=h;else switch(l.dtype){case"float32":c=h;break;case"int32":c=Math.floor(h);break;case"bool":c=this.getBoolean(u);break;default:c=h}}l&&l.isLabel?a[o]=c:r[o]=c}return Object.keys(a).length===0?r:{xs:r,ys:a}},t.prototype.getBoolean=function(e){return e==="1"||e.toLowerCase()==="true"?1:0},t.prototype.parseRow=function(e,i){i===void 0&&(i=!0);for(var r=[],a=0,s=e.length,o=ds,l=0;l<s;l++)switch(o){case ds:switch(e.charAt(l)){case $o:a=l+1,o=Xo;break;case this.delimiter:if(a=l+1,this.delimiter===" "&&this.delimWhitespace)break;r.push(""),o=ds;break;default:o=n0,a=l;break}break;case n0:switch(e.charAt(l)){case this.delimiter:r.push(e.substring(a,l)),o=ds,a=l+1;break}break;case Xo:switch(e.charAt(l)){case $o:o=Vd;break}break;case Vd:switch(e.charAt(l)){case this.delimiter:r.push(e.substring(a,l-1)),o=ds,a=l+1;break;case $o:o=Xo;break;default:o=i0;break}break;case i0:switch(e.charAt(l)){case $o:o=Xo;break}break}if(o===Vd?r.push(e.substring(a,s-1)):r.push(e.substring(a)),i&&r.length!==this.fullColumnNames.length)throw new Error("Invalid row in csv file. Should have "+this.fullColumnNames.length+" elements in a row, but got "+r);return r},t}(hs);var WB=function(n){Ve(t,n);function t(e){var i=n.call(this)||this;i.microphoneConfig=e,i.isClosed=!1,i.fftSize=e.fftSize||1024;var r=Math.log2(i.fftSize);if(i.fftSize<0||r<4||r>14||!Number.isInteger(r))throw new Error("Invalid fftSize: it must be a power of 2 between "+("2 to 4 and 2 to 14, but got "+i.fftSize));if(i.numFrames=e.numFramesPerSpectrogram||43,i.sampleRateHz=e.sampleRateHz,i.columnTruncateLength=e.columnTruncateLength||i.fftSize,i.audioTrackConstraints=e.audioTrackConstraints,i.smoothingTimeConstant=e.smoothingTimeConstant||0,i.includeSpectrogram=!(e.includeSpectrogram===!1),i.includeWaveform=e.includeWaveform===!0,!i.includeSpectrogram&&!i.includeWaveform)throw new Error("Both includeSpectrogram and includeWaveform are false. At least one type of data should be returned.");return i}return t.prototype.summary=function(){return"microphone"},t.create=function(e){return e===void 0&&(e={}),se(this,void 0,void 0,function(){var i;return oe(this,function(r){switch(r.label){case 0:if(Ne.env().get("IS_NODE"))throw new Error("microphone API is only supported in browser environment.");return i=new t(e),[4,i.start()];case 1:return r.sent(),[2,i]}})})},t.prototype.start=function(){return se(this,void 0,void 0,function(){var e,i,r,a;return oe(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),e=this,[4,navigator.mediaDevices.getUserMedia({audio:this.audioTrackConstraints==null?!0:this.audioTrackConstraints,video:!1})];case 1:return e.stream=s.sent(),[3,3];case 2:throw i=s.sent(),new Error("Error thrown while initializing video stream: "+i.message);case 3:if(!this.stream)throw new Error("Could not obtain audio from microphone.");if(r=window.AudioContext||window.webkitAudioContext,this.audioContext=new r,!this.sampleRateHz)this.sampleRateHz=this.audioContext.sampleRate;else if(this.audioContext.sampleRate!==this.sampleRateHz)throw new Error("Mismatch in sampling rate: "+("Expected: "+this.sampleRateHz+"; ")+("Actual: "+this.audioContext.sampleRate));return a=this.audioContext.createMediaStreamSource(this.stream),this.analyser=this.audioContext.createAnalyser(),this.analyser.fftSize=this.fftSize*2,this.analyser.smoothingTimeConstant=this.smoothingTimeConstant,a.connect(this.analyser),this.freqData=new Float32Array(this.fftSize),this.timeData=new Float32Array(this.fftSize),[2]}})})},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e,i,r,a,s;return oe(this,function(o){switch(o.label){case 0:return this.isClosed?[2,{value:null,done:!0}]:[4,this.getAudioData()];case 1:return r=o.sent(),this.includeSpectrogram&&(a=this.flattenQueue(r.freqDataQueue),e=this.getTensorFromAudioDataArray(a,[this.numFrames,this.columnTruncateLength,1])),this.includeWaveform&&(s=this.flattenQueue(r.timeDataQueue),i=this.getTensorFromAudioDataArray(s,[this.numFrames*this.fftSize,1])),[2,{value:{spectrogram:e,waveform:i},done:!1}]}})})},t.prototype.capture=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){switch(e.label){case 0:return[4,this.next()];case 1:return[2,e.sent().value]}})})},t.prototype.getAudioData=function(){return se(this,void 0,void 0,function(){var e,i,r,a=this;return oe(this,function(s){return e=[],i=[],r=0,[2,new Promise(function(o){var l=setInterval(function(){a.includeSpectrogram&&(a.analyser.getFloatFrequencyData(a.freqData),a.freqData[0]===-Infinity&&o({freqDataQueue:e,timeDataQueue:i}),e.push(a.freqData.slice(0,a.columnTruncateLength))),a.includeWaveform&&(a.analyser.getFloatTimeDomainData(a.timeData),i.push(a.timeData.slice())),++r===a.numFrames&&(clearInterval(l),o({freqDataQueue:e,timeDataQueue:i}))},a.fftSize/a.sampleRateHz*1e3)})]})})},t.prototype.stop=function(){this.isClosed||(this.isClosed=!0,this.analyser.disconnect(),this.audioContext.close(),this.stream!=null&&this.stream.getTracks().length>0&&this.stream.getTracks()[0].stop())},t.prototype.toArray=function(){throw new Error("Can not convert infinite audio stream to array.")},t.prototype.getSampleRate=function(){return this.sampleRateHz},t.prototype.flattenQueue=function(e){var i=e[0].length,r=new Float32Array(e.length*i);return e.forEach(function(a,s){return r.set(a,s*i)}),r},t.prototype.getTensorFromAudioDataArray=function(e,i){var r=new Float32Array(Ne.util.sizeFromShape(i));return r.set(e,r.length-e.length),Ne.tensor(r,i)},t}(xt);var UB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;if(r.webcamVideoElement=e,r.webcamConfig=i,r.isClosed=!0,r.resize=!1,r.needToResize())if(r.resize=!0,r.cropSize=[r.webcamConfig.resizeHeight,r.webcamConfig.resizeWidth],r.cropBoxInd=Ne.tensor1d([0],"int32"),r.webcamConfig.centerCrop){var a=r.webcamConfig.resizeWidth*1/r.webcamVideoElement.width,s=r.webcamConfig.resizeHeight*1/r.webcamVideoElement.height,o=(1-a)/2,l=(1-s)/2,u=o+a,c=s+l;r.cropBox=Ne.tensor2d([l,o,c,u],[1,4])}else r.cropBox=Ne.tensor2d([0,0,1,1],[1,4]);return r}return t.prototype.summary=function(){return"webcam"},t.create=function(e,i){return i===void 0&&(i={}),se(this,void 0,void 0,function(){var r;return oe(this,function(a){switch(a.label){case 0:if(Ne.env().get("IS_NODE"))throw new Error("tf.data.webcam is only supported in browser environment.");if(!e){if(e=document.createElement("video"),!i.resizeWidth||!i.resizeHeight)throw new Error("Please provide webcam video element, or resizeWidth and resizeHeight to create a hidden video element.");e.width=i.resizeWidth,e.height=i.resizeHeight}return r=new t(e,i),[4,r.start()];case 1:return a.sent(),[2,r]}})})},t.prototype.start=function(){return se(this,void 0,void 0,function(){var e,i,r=this;return oe(this,function(a){switch(a.label){case 0:this.webcamConfig.facingMode&&Ne.util.assert(this.webcamConfig.facingMode==="user"||this.webcamConfig.facingMode==="environment",function(){return"Invalid webcam facing mode: "+r.webcamConfig.facingMode+". Please provide 'user' or 'environment'"}),a.label=1;case 1:return a.trys.push([1,3,,4]),e=this,[4,navigator.mediaDevices.getUserMedia({video:{deviceId:this.webcamConfig.deviceId,facingMode:this.webcamConfig.facingMode?this.webcamConfig.facingMode:"user",width:this.webcamVideoElement.width,height:this.webcamVideoElement.height}})];case 2:return e.stream=a.sent(),[3,4];case 3:throw i=a.sent(),i.message="Error thrown while initializing video stream: "+i.message,i;case 4:if(!this.stream)throw new Error("Could not obtain video from webcam.");try{this.webcamVideoElement.srcObject=this.stream}catch(s){console.log(s),this.webcamVideoElement.src=window.URL.createObjectURL(this.stream)}return this.webcamVideoElement.play(),this.isClosed=!1,[2,new Promise(function(s){r.webcamVideoElement.onloadedmetadata=function(){s()}})]}})})},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e;return oe(this,function(i){if(this.isClosed)return[2,{value:null,done:!0}];try{e=Ne.browser.fromPixels(this.webcamVideoElement)}catch(r){throw new Error("Error thrown converting video to pixels: "+JSON.stringify(r))}if(this.resize)try{return[2,{value:this.cropAndResizeFrame(e),done:!1}]}catch(r){throw new Error("Error thrown cropping the video: "+r.message)}finally{e.dispose()}else return[2,{value:e,done:!1}];return[2]})})},t.prototype.needToResize=function(){return!!(this.webcamConfig.resizeWidth&&this.webcamConfig.resizeHeight&&(this.webcamVideoElement.width!==this.webcamConfig.resizeWidth||this.webcamVideoElement.height!==this.webcamConfig.resizeHeight))},t.prototype.cropAndResizeFrame=function(e){var i=this;return Ne.tidy(function(){var r=e.toFloat().expandDims(0),a;a=Ne.image.cropAndResize(r,i.cropBox,i.cropBoxInd,i.cropSize,"bilinear");var s=a.shape;return a.reshape(s.slice(1))})},t.prototype.capture=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){switch(e.label){case 0:return[4,this.next()];case 1:return[2,e.sent().value]}})})},t.prototype.stop=function(){var e=this.stream.getTracks();e.forEach(function(i){return i.stop()});try{this.webcamVideoElement.srcObject=null}catch(i){console.log(i),this.webcamVideoElement.src=null}this.isClosed=!0},t.prototype.toArray=function(){throw new Error("Can not convert infinite video stream to array.")},t}(xt);var a0=function(){function n(){}return n}();var s0=function(n){Ve(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.split=function(e){return new BB(this,e)},t}(xt),BB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.impl=new zB(e,i),r}return t.prototype.summary=function(){return this.impl.summary()},t.prototype.next=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){return[2,this.impl.next()]})})},t}(s0),zB=function(n){Ve(t,n);function t(e,i){var r=n.call(this)||this;return r.upstream=e,r.separator=i,r.carryover="",r}return t.prototype.summary=function(){return this.upstream.summary()+" -> Split('"+this.separator+"')"},t.prototype.pump=function(){return se(this,void 0,void 0,function(){var e,i,r,a,s;return oe(this,function(o){switch(o.label){case 0:return[4,this.upstream.next()];case 1:if(e=o.sent(),e.done)return this.carryover===""?[2,!1]:(this.outputQueue.push(this.carryover),this.carryover="",[2,!0]);for(i=e.value.split(this.separator),i[0]=this.carryover+i[0],r=0,a=i.slice(0,-1);r<a.length;r++)s=a[r],this.outputQueue.push(s);return this.carryover=i[i.length-1],[2,!0]}})})},t}(Hd);var _B=function(n){Ve(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.decodeUTF8=function(){return new PB(this)},t}(xt),PB=function(n){Ve(t,n);function t(e){var i=n.call(this)||this;return i.upstream=e,i.impl=new MB(e),i}return t.prototype.summary=function(){return this.impl.summary()},t.prototype.next=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){return[2,this.impl.next()]})})},t}(s0),MB=function(n){Ve(t,n);function t(e){var i=n.call(this)||this;if(i.upstream=e,Ne.env().get("IS_BROWSER"))i.decoder=new TextDecoder("utf-8");else{var r=require("string_decoder").StringDecoder;i.decoder=new r("utf8")}return i}return t.prototype.summary=function(){return this.upstream.summary()+" -> Utf8"},t.prototype.pump=function(){return se(this,void 0,void 0,function(){var e,i,r;return oe(this,function(a){switch(a.label){case 0:return[4,this.upstream.next()];case 1:return e=a.sent(),e.done?[2,!1]:(i=e.value,Ne.env().get("IS_BROWSER")?r=this.decoder.decode(i,{stream:!0}):r=this.decoder.write(Buffer.from(i.buffer)),this.outputQueue.push(r),[2,!0])}})})},t}(Hd);var o0=function(n){Ve(t,n);function t(e,i){i===void 0&&(i={});var r=n.call(this)||this;return r.file=e,r.options=i,Ne.util.assert(e instanceof Uint8Array||(Ne.env().get("IS_BROWSER")?e instanceof File||e instanceof Blob:!1),function(){return"FileChunkIterator only supports File, Blob and Uint8Array right now."}),r.offset=i.offset||0,r.chunkSize=i.chunkSize||1024*1024,r}return t.prototype.summary=function(){return"FileChunks "+this.file},t.prototype.next=function(){return se(this,void 0,void 0,function(){var e,i,r=this;return oe(this,function(a){switch(a.label){case 0:return this.offset>=(this.file instanceof Uint8Array?this.file.byteLength:this.file.size)?[2,{value:null,done:!0}]:(e=new Promise(function(s,o){var l=r.offset+r.chunkSize;if(r.file instanceof Uint8Array)s(new Uint8Array(r.file.slice(r.offset,l)));else{var u=new FileReader;u.onload=function(h){var d=u.result;if(d instanceof ArrayBuffer&&(d=new Uint8Array(d)),!(d instanceof Uint8Array))return o(new TypeError("FileReader returned unknown type."));s(d)},u.onabort=function(h){return o(new Error("Aborted"))},u.onerror=function(h){return o(new Error(h.type))};var c=r.file.slice(r.offset,l);u.readAsArrayBuffer(c)}r.offset=l}),i={},[4,e]);case 1:return[2,(i.value=a.sent(),i.done=!1,i)]}})})},t}(_B);function VB(n,t){return t===void 0&&(t={}),se(this,void 0,void 0,function(){var e,i,r,a,s;return oe(this,function(o){switch(o.label){case 0:return typeof n=="string"?e=n:(e=n.url,i=HB(n)),[4,Ne.util.fetch(e,i)];case 1:return r=o.sent(),r.ok?(s=Uint8Array.bind,[4,r.arrayBuffer()]):[3,3];case 2:return a=new(s.apply(Uint8Array,[void 0,o.sent()])),[2,new o0(a,t)];case 3:throw new Error(r.statusText)}})})}var HB=function(n){var t={method:n.method,headers:n.headers,body:n.body,mode:n.mode,credentials:n.credentials,cache:n.cache,redirect:n.redirect,referrer:n.referrer,integrity:n.integrity};return t};function l0(n){return typeof n=="string"&&n.substr(0,7)==="file://"}var u0=function(n){Ve(t,n);function t(e,i){i===void 0&&(i={});var r=n.call(this)||this;return r.input=e,r.options=i,r}return t.prototype.iterator=function(){return se(this,void 0,void 0,function(){var e;return oe(this,function(i){return l0(this.input)&&Ne.env().get("IS_NODE")&&(e=require("fs"),this.input=e.readFileSync(this.input.substr(7))),[2,new o0(this.input,this.options)]})})},t}(a0);var c0=function(n){Ve(t,n);function t(e,i){i===void 0&&(i={});var r=n.call(this)||this;return r.url=e,r.fileOptions=i,r}return t.prototype.iterator=function(){return se(this,void 0,void 0,function(){return oe(this,function(e){return l0(this.url)?[2,new u0(this.url,this.fileOptions).iterator()]:[2,VB(this.url,this.fileOptions)]})})},t}(a0);function qB(n,t){return t===void 0&&(t={}),new r0(new c0(n),t)}function GB(n){var t=this,e=Md(n);return Qt(function(){return se(t,void 0,void 0,function(){return oe(this,function(i){return[2,e]})})})}function YB(n){var t=this;return Qt(function(){return se(t,void 0,void 0,function(){var e;return oe(this,function(i){switch(i.label){case 0:return[4,n()];case 1:return e=i.sent(),[2,Md(function(){return e.next()})]}})})})}function jB(n,t){return se(this,void 0,void 0,function(){return oe(this,function(e){return[2,UB.create(n,t)]})})}function KB(n){return se(this,void 0,void 0,function(){return oe(this,function(t){return[2,WB.create(n)]})})}var $B="2.6.0";Yt.CSVDataset=r0;Yt.Dataset=hs;Yt.FileDataSource=u0;Yt.TextLineDataset=t0;Yt.URLDataSource=c0;Yt.array=DB;Yt.csv=qB;Yt.func=GB;Yt.generator=YB;Yt.microphone=KB;Yt.version_data=$B;Yt.webcam=jB;Yt.zip=kB});var p0=Le((d0,qd)=>{(function(n,t,e){function i(o){var l=this,u=s();l.next=function(){var c=2091639*l.s0+l.c*23283064365386963e-26;return l.s0=l.s1,l.s1=l.s2,l.s2=c-(l.c=c|0)},l.c=1,l.s0=u(" "),l.s1=u(" "),l.s2=u(" "),l.s0-=u(o),l.s0<0&&(l.s0+=1),l.s1-=u(o),l.s1<0&&(l.s1+=1),l.s2-=u(o),l.s2<0&&(l.s2+=1),u=null}function r(o,l){return l.c=o.c,l.s0=o.s0,l.s1=o.s1,l.s2=o.s2,l}function a(o,l){var u=new i(o),c=l&&l.state,h=u.next;return h.int32=function(){return u.next()*4294967296|0},h.double=function(){return h()+(h()*2097152|0)*11102230246251565e-32},h.quick=h,c&&(typeof c=="object"&&r(c,u),h.state=function(){return r(u,{})}),h}function s(){var o=4022871197,l=function(u){u=u.toString();for(var c=0;c<u.length;c++){o+=u.charCodeAt(c);var h=.02519603282416938*o;o=h>>>0,h-=o,h*=o,o=h>>>0,h-=o,o+=h*4294967296}return(o>>>0)*23283064365386963e-26};return l}t&&t.exports?t.exports=a:e&&e.amd?e(function(){return a}):this.alea=a})(d0,typeof qd=="object"&&qd,typeof define=="function"&&define)});var m0=Le((f0,Gd)=>{(function(n,t,e){function i(s){var o=this,l="";o.x=0,o.y=0,o.z=0,o.w=0,o.next=function(){var c=o.x^o.x<<11;return o.x=o.y,o.y=o.z,o.z=o.w,o.w^=o.w>>>19^c^c>>>8},s===(s|0)?o.x=s:l+=s;for(var u=0;u<l.length+64;u++)o.x^=l.charCodeAt(u)|0,o.next()}function r(s,o){return o.x=s.x,o.y=s.y,o.z=s.z,o.w=s.w,o}function a(s,o){var l=new i(s),u=o&&o.state,c=function(){return(l.next()>>>0)/4294967296};return c.double=function(){do var h=l.next()>>>11,d=(l.next()>>>0)/4294967296,p=(h+d)/(1<<21);while(p===0);return p},c.int32=l.next,c.quick=c,u&&(typeof u=="object"&&r(u,l),c.state=function(){return r(l,{})}),c}t&&t.exports?t.exports=a:e&&e.amd?e(function(){return a}):this.xor128=a})(f0,typeof Gd=="object"&&Gd,typeof define=="function"&&define)});var v0=Le((g0,Yd)=>{(function(n,t,e){function i(s){var o=this,l="";o.next=function(){var c=o.x^o.x>>>2;return o.x=o.y,o.y=o.z,o.z=o.w,o.w=o.v,(o.d=o.d+362437|0)+(o.v=o.v^o.v<<4^(c^c<<1))|0},o.x=0,o.y=0,o.z=0,o.w=0,o.v=0,s===(s|0)?o.x=s:l+=s;for(var u=0;u<l.length+64;u++)o.x^=l.charCodeAt(u)|0,u==l.length&&(o.d=o.x<<10^o.x>>>4),o.next()}function r(s,o){return o.x=s.x,o.y=s.y,o.z=s.z,o.w=s.w,o.v=s.v,o.d=s.d,o}function a(s,o){var l=new i(s),u=o&&o.state,c=function(){return(l.next()>>>0)/4294967296};return c.double=function(){do var h=l.next()>>>11,d=(l.next()>>>0)/4294967296,p=(h+d)/(1<<21);while(p===0);return p},c.int32=l.next,c.quick=c,u&&(typeof u=="object"&&r(u,l),c.state=function(){return r(l,{})}),c}t&&t.exports?t.exports=a:e&&e.amd?e(function(){return a}):this.xorwow=a})(g0,typeof Yd=="object"&&Yd,typeof define=="function"&&define)});var b0=Le((y0,jd)=>{(function(n,t,e){function i(s){var o=this;o.next=function(){var u=o.x,c=o.i,h,d,p;return h=u[c],h^=h>>>7,d=h^h<<24,h=u[c+1&7],d^=h^h>>>10,h=u[c+3&7],d^=h^h>>>3,h=u[c+4&7],d^=h^h<<7,h=u[c+7&7],h=h^h<<13,d^=h^h<<9,u[c]=d,o.i=c+1&7,d};function l(u,c){var h,d,p=[];if(c===(c|0))d=p[0]=c;else for(c=""+c,h=0;h<c.length;++h)p[h&7]=p[h&7]<<15^c.charCodeAt(h)+p[h+1&7]<<13;for(;p.length<8;)p.push(0);for(h=0;h<8&&p[h]===0;++h);for(h==8?d=p[7]=-1:d=p[h],u.x=p,u.i=0,h=256;h>0;--h)u.next()}l(o,s)}function r(s,o){return o.x=s.x.slice(),o.i=s.i,o}function a(s,o){s==null&&(s=+new Date);var l=new i(s),u=o&&o.state,c=function(){return(l.next()>>>0)/4294967296};return c.double=function(){do var h=l.next()>>>11,d=(l.next()>>>0)/4294967296,p=(h+d)/(1<<21);while(p===0);return p},c.int32=l.next,c.quick=c,u&&(u.x&&r(u,l),c.state=function(){return r(l,{})}),c}t&&t.exports?t.exports=a:e&&e.amd?e(function(){return a}):this.xorshift7=a})(y0,typeof jd=="object"&&jd,typeof define=="function"&&define)});var S0=Le((w0,Kd)=>{(function(n,t,e){function i(s){var o=this;o.next=function(){var u=o.w,c=o.X,h=o.i,d,p;return o.w=u=u+1640531527|0,p=c[h+34&127],d=c[h=h+1&127],p^=p<<13,d^=d<<17,p^=p>>>15,d^=d>>>12,p=c[h]=p^d,o.i=h,p+(u^u>>>16)|0};function l(u,c){var h,d,p,f,m,g=[],v=128;for(c===(c|0)?(d=c,c=null):(c=c+"\0",d=0,v=Math.max(v,c.length)),p=0,f=-32;f<v;++f)c&&(d^=c.charCodeAt((f+32)%c.length)),f===0&&(m=d),d^=d<<10,d^=d>>>15,d^=d<<4,d^=d>>>13,f>=0&&(m=m+1640531527|0,h=g[f&127]^=d+m,p=h==0?p+1:0);for(p>=128&&(g[(c&&c.length||0)&127]=-1),p=127,f=4*128;f>0;--f)d=g[p+34&127],h=g[p=p+1&127],d^=d<<13,h^=h<<17,d^=d>>>15,h^=h>>>12,g[p]=d^h;u.w=m,u.X=g,u.i=p}l(o,s)}function r(s,o){return o.i=s.i,o.w=s.w,o.X=s.X.slice(),o}function a(s,o){s==null&&(s=+new Date);var l=new i(s),u=o&&o.state,c=function(){return(l.next()>>>0)/4294967296};return c.double=function(){do var h=l.next()>>>11,d=(l.next()>>>0)/4294967296,p=(h+d)/(1<<21);while(p===0);return p},c.int32=l.next,c.quick=c,u&&(u.X&&r(u,l),c.state=function(){return r(l,{})}),c}t&&t.exports?t.exports=a:e&&e.amd?e(function(){return a}):this.xor4096=a})(w0,typeof Kd=="object"&&Kd,typeof define=="function"&&define)});var I0=Le((L0,$d)=>{(function(n,t,e){function i(s){var o=this,l="";o.next=function(){var c=o.b,h=o.c,d=o.d,p=o.a;return c=c<<25^c>>>7^h,h=h-d|0,d=d<<24^d>>>8^p,p=p-c|0,o.b=c=c<<20^c>>>12^h,o.c=h=h-d|0,o.d=d<<16^h>>>16^p,o.a=p-c|0},o.a=0,o.b=0,o.c=2654435769|0,o.d=1367130551,s===Math.floor(s)?(o.a=s/4294967296|0,o.b=s|0):l+=s;for(var u=0;u<l.length+20;u++)o.b^=l.charCodeAt(u)|0,o.next()}function r(s,o){return o.a=s.a,o.b=s.b,o.c=s.c,o.d=s.d,o}function a(s,o){var l=new i(s),u=o&&o.state,c=function(){return(l.next()>>>0)/4294967296};return c.double=function(){do var h=l.next()>>>11,d=(l.next()>>>0)/4294967296,p=(h+d)/(1<<21);while(p===0);return p},c.int32=l.next,c.quick=c,u&&(typeof u=="object"&&r(u,l),c.state=function(){return r(l,{})}),c}t&&t.exports?t.exports=a:e&&e.amd?e(function(){return a}):this.tychei=a})(L0,typeof $d=="object"&&$d,typeof define=="function"&&define)});var A0=Le((vV,Jo)=>{(function(n,t){var e=this,i=256,r=6,a=52,s="random",o=t.pow(i,r),l=t.pow(2,a),u=l*2,c=i-1,h;function d(w,S,L){var N=[];S=S==!0?{entropy:!0}:S||{};var C=g(m(S.entropy?[w,b(n)]:w??v(),3),N),R=new p(N),D=function(){for(var k=R.g(r),W=o,F=0;k<l;)k=(k+F)*i,W*=i,F=R.g(1);for(;k>=u;)k/=2,W/=2,F>>>=1;return(k+F)/W};return D.int32=function(){return R.g(4)|0},D.quick=function(){return R.g(4)/4294967296},D.double=D,g(b(R.S),n),(S.pass||L||function(k,W,F,P){return P&&(P.S&&f(P,R),k.state=function(){return f(R,{})}),F?(t[s]=k,W):k})(D,C,"global"in S?S.global:this==t,S.state)}t["seed"+s]=d;function p(w){var S,L=w.length,N=this,C=0,R=N.i=N.j=0,D=N.S=[];for(L||(w=[L++]);C<i;)D[C]=C++;for(C=0;C<i;C++)D[C]=D[R=c&R+w[C%L]+(S=D[C])],D[R]=S;(N.g=function(k){for(var W,F=0,P=N.i,H=N.j,_=N.S;k--;)W=_[P=c&P+1],F=F*i+_[c&(_[P]=_[H=c&H+W])+(_[H]=W)];return N.i=P,N.j=H,F})(i)}function f(w,S){return S.i=w.i,S.j=w.j,S.S=w.S.slice(),S}function m(w,S){var L=[],N=typeof w,C;if(S&&N=="object")for(C in w)try{L.push(m(w[C],S-1))}catch(R){}return L.length?L:N=="string"?w:w+"\0"}function g(w,S){for(var L=w+"",N,C=0;C<L.length;)S[c&C]=c&(N^=S[c&C]*19)+L.charCodeAt(C++);return b(S)}function v(){try{var w;return h&&(w=h.randomBytes)?w=w(i):(w=new Uint8Array(i),(e.crypto||e.msCrypto).getRandomValues(w)),b(w)}catch(N){var S=e.navigator,L=S&&S.plugins;return[+new Date,e,L,e.screen,b(n)]}}function b(w){return String.fromCharCode.apply(0,w)}if(g(t.random(),n),typeof Jo=="object"&&Jo.exports){Jo.exports=d;try{h=require("crypto")}catch(w){}}else typeof define=="function"&&define.amd&&define(function(){return d})})([],Math)});var N0=Le((yV,T0)=>{var XB=p0(),JB=m0(),ZB=v0(),QB=b0(),ez=S0(),tz=I0(),br=A0();br.alea=XB;br.xor128=JB;br.xorwow=ZB;br.xorshift7=QB;br.xor4096=ez;br.tychei=tz;T0.exports=br});var Z0=Le(ps=>{"use strict";Object.defineProperty(ps,"__esModule",{value:!0});var T=lr(),nz=N0();var Xd=function(n,t){return Xd=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var r in i)i.hasOwnProperty(r)&&(e[r]=i[r])},Xd(n,t)};function iz(n,t){Xd(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function x0(n,t,e,i){function r(a){return a instanceof e?a:new e(function(s){s(a)})}return new(e||(e=Promise))(function(a,s){function o(c){try{u(i.next(c))}catch(h){s(h)}}function l(c){try{u(i.throw(c))}catch(h){s(h)}}function u(c){c.done?a(c.value):r(c.value).then(o,l)}u((i=i.apply(n,t||[])).next())})}function C0(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,r,a,s;return s={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(u){return function(c){return l([u,c])}}function l(u){if(i)throw new TypeError("Generator is already executing.");for(;e;)try{if(i=1,r&&(a=u[0]&2?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;(r=0,a)&&(u=[u[0]&2,a.value]);switch(u[0]){case 0:case 1:a=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,r=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){e.label=u[1];break}if(u[0]===6&&e.label<a[1]){e.label=a[1],a=u;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(u);break}a[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(n,e)}catch(c){u=[6,c],r=0}finally{i=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function ae(n,t){Array.isArray(n)||(n=[n]),n.forEach(function(e){e!=null&&T.util.assert(e.dtype!=="complex64",function(){return t+" does not support complex64 tensors in the CPU backend."})})}var rz=T.kernel_impls.nonMaxSuppressionV3Impl,az=T.kernel_impls.split,sz=T.kernel_impls.tile,oz=T.kernel_impls.topkImpl,lz=T.kernel_impls.whereImpl;function Jd(n,t,e,i){if(e==="linear")return n.linear(t);if(e==="relu")return n.relu(t);if(e==="elu")return T.elu(t);if(e==="relu6")return n.relu6(t);if(e==="prelu")return n.prelu(t,i);throw new Error("Activation "+e+" has not been implemented for the CPU backend.")}var R0=function(n){iz(t,n);function t(){var e=n.call(this)||this;return e.blockSize=48,e.firstUse=!0,e.data=new T.DataStorage(e,T.engine()),e}return t.prototype.write=function(e,i,r){this.firstUse&&(this.firstUse=!1,T.env().get("IS_NODE")&&T.backend_util.warn(`
|
|
============================
|
|
Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
|
|
============================`));var a={};return this.data.set(a,{values:e,dtype:r,refCount:1}),a},t.prototype.makeTensorInfo=function(e,i,r){var a=this.write(r,e,i);return{dataId:a,shape:e,dtype:i}},t.prototype.incRef=function(e){var i=this.data.get(e);i.refCount++},t.prototype.decRef=function(e){if(this.data.has(e)){var i=this.data.get(e);i.refCount--}},t.prototype.move=function(e,i,r,a){this.data.set(e,{values:i,dtype:a,refCount:1})},t.prototype.numDataIds=function(){return this.data.numDataIds()},t.prototype.read=function(e){return x0(this,void 0,void 0,function(){return C0(this,function(i){return[2,this.readSync(e)]})})},t.prototype.readSync=function(e){var i=this.data.get(e),r=i.dtype,a=i.complexTensorInfos;if(r==="complex64"){var s=this.readSync(a.real.dataId),o=this.readSync(a.imag.dataId);return T.backend_util.mergeRealAndImagArrays(s,o)}return this.data.get(e).values},t.prototype.bufferSync=function(e){var i=this.readSync(e.dataId),r=i;if(e.dtype==="string")try{r=i.map(function(a){return T.util.decodeString(a)})}catch(a){throw new Error("Failed to decode encoded string bytes into utf-8")}return T.buffer(e.shape,e.dtype,r)},t.prototype.makeOutput=function(e,i,r){var a=this.write(e,i,r);return T.engine().makeTensorFromDataId(a,i,r,this)},t.prototype.disposeData=function(e){if(this.data.has(e)){var i=this.data.get(e).complexTensorInfos;i!=null&&(this.disposeData(i.real.dataId),this.disposeData(i.imag.dataId)),this.data.delete(e)}},t.prototype.disposeIntermediateTensorInfo=function(e){var i=e.dataId;if(this.data.has(i)){var r=this.data.get(i);r.refCount--,r.refCount<1&&this.disposeData(i)}},t.prototype.time=function(e){return x0(this,void 0,void 0,function(){var i,r;return C0(this,function(a){return i=T.util.now(),e(),r=T.util.now()-i,[2,{kernelMs:r}]})})},t.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},t.prototype.stridedSlice=function(e,i,r,a){ae(e,"stridedSlice");var s=T.slice_util.computeOutShape(i,r,a);if(s.some(function(p){return p===0}))return T.tensor([],s);for(var o=T.buffer(s,e.dtype),l=this.bufferSync(e),u=0;u<o.size;u++){for(var c=o.indexToLoc(u),h=new Array(c.length),d=0;d<h.length;d++)h[d]=c[d]*a[d]+i[d];o.set.apply(o,[l.get.apply(l,h)].concat(c))}return o.toTensor()},t.prototype.diag=function(e){for(var i=this.readSync(e.dataId),r=T.buffer([e.size,e.size],e.dtype),a=r.values,s=0;s<i.length;s++)a[s*e.size+s]=i[s];return r.toTensor()},t.prototype.unstack=function(e,i){for(var r=e.shape[i],a=new Array(e.rank-1),s=0,o=0;o<e.rank;o++)o!==i&&(a[s++]=e.shape[o]);var l=new Array(e.rank).fill(0),u=e.shape.slice();u[i]=1;for(var c=new Array(r),o=0;o<c.length;o++)l[i]=o,c[o]=T.slice(e,l,u).reshape(a);return c},t.prototype.reverse=function(e,i){ae(e,"reverse");for(var r=T.buffer(e.shape,e.dtype),a=this.bufferSync(e),s=function(l){var u=r.indexToLoc(l),c=u.slice();i.forEach(function(h){return c[h]=e.shape[h]-1-c[h]}),r.set.apply(r,[a.get.apply(a,c)].concat(u))},o=0;o<r.size;o++)s(o);return r.toTensor()},t.prototype.neg=function(e){return ae(e,"neg"),T.mul(T.scalar(-1),e)},t.prototype.addN=function(e){var i=this;ae(e,"addN");for(var r=e.map(function(c){return i.readSync(c.dataId)}),a=T.buffer(e[0].shape,e[0].dtype),s=a.values,o=0;o<e.length;o++)for(var l=r[o],u=0;u<s.length;u++)s[u]+=l[u];return a.toTensor()},t.prototype.softmax=function(e,i){var r=T.util.parseAxisParam([i],e.shape),a=T.max(e,r),s=T.backend_util.expandShapeToKeepDim(a.shape,r),o=T.sub(e,a.reshape(s)),l=T.exp(o),u=this.sum(l,r).reshape(s);return T.div(l,u)},t.prototype.pow=function(e,i){return ae([e,i],"pow"),this.broadcastedBinaryOp(e,i,e.dtype,function(r,a){return Math.pow(r,a)})},t.prototype.batchMatMul=function(e,i,r,a){ae([e,i],"matMul");for(var s=r?e.shape[1]:e.shape[2],o=r?e.shape[2]:e.shape[1],l=a?i.shape[1]:i.shape[2],u=e.shape[0],c=this.readSync(e.dataId),h=this.readSync(i.dataId),d=r?[e.strides[0],1,e.strides[1]]:[e.strides[0],e.strides[1],1],p=d[0],f=d[1],m=d[2],g=a?[1,i.strides[1],i.strides[0]]:[i.strides[1],1,i.strides[0]],v=g[0],b=g[1],w=g[2],S=o*l,L=T.buffer([u,o,l],e.dtype),N=L.values,C=this.blockSize,R=0;R<u;R++)for(var D=0;D<o;D+=C)for(var k=0;k<l;k+=C)for(var W=0;W<s;W+=C)for(var F=Math.min(D+C,o),P=Math.min(k+C,l),H=Math.min(W+C,s),_=D;_<F;_++)for(var j=k;j<P;j++){for(var K=0,q=W;q<H;q++)K+=c[R*p+_*f+q*m]*h[q*v+j*b+R*w];N[R*S+(_*l+j)]+=K}return L.toTensor()},t.prototype.fusedBatchMatMul=function(e){var i=e.a,r=e.b,a=e.transposeA,s=e.transposeB,o=e.bias,l=e.activation,u=e.preluActivationWeights,c=this.batchMatMul(i,r,a,s);return o&&(c=T.add(c,o)),l&&(c=Jd(this,c,l,u)),c},t.prototype.floorDiv=function(e,i){ae([e,i],"floorDiv");var r=function(s,o){return Math.floor(s/o)},a="int32";return this.broadcastedBinaryOp(e,i,a,r)},t.prototype.sum=function(e,i){ae(e,"sum"),T.backend_util.assertAxesAreInnerMostDims("sum",i,e.rank);for(var r=T.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=T.upcastType(e.dtype,"int32"),l=T.zeros(a,o),u=T.util.sizeFromShape(s),c=this.readSync(l.dataId),h=this.readSync(e.dataId),d=0;d<c.length;++d){for(var p=d*u,f=0,m=0;m<u;++m)f+=h[p+m];c[d]=f}return l},t.prototype.prod=function(e,i){ae(e,"sum");for(var r=T.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=T.upcastType(e.dtype,"int32"),l=T.zeros(a,o),u=T.util.sizeFromShape(s),c=this.readSync(l.dataId),h=this.readSync(e.dataId),d=0;d<c.length;++d){for(var p=d*u,f=1,m=0;m<u;++m)f*=h[p+m];c[d]=f}return l},t.prototype.unsortedSegmentSum=function(e,i,r){ae(e,"unsortedSegmentSum");for(var a=[],s=e.rank-i.rank,o=0;o<s;++o)i=i.expandDims(o+1);for(var o=0;o<r;++o){var l=T.scalar(o,"int32"),u=T.equal(l,i).asType("float32"),c=u.mul(e).sum(0);a.push(c)}return T.stack(a)},t.prototype.argMin=function(e,i){ae(e,"argMin");var r=[i];T.backend_util.assertAxesAreInnerMostDims("argMin",r,e.rank);for(var a=T.backend_util.computeOutAndReduceShapes(e.shape,r),s=a[0],o=a[1],l=T.zeros(s,"int32"),u=T.util.sizeFromShape(o),c=this.readSync(l.dataId),h=this.readSync(e.dataId),d=0;d<c.length;++d){for(var p=d*u,f=h[p],m=0,g=0;g<u;++g){var v=h[p+g];v<f&&(f=v,m=g)}c[d]=m}return l},t.prototype.argMax=function(e,i){ae(e,"argMax");var r=[i];T.backend_util.assertAxesAreInnerMostDims("argMax",r,e.rank);for(var a=T.backend_util.computeOutAndReduceShapes(e.shape,r),s=a[0],o=a[1],l=T.zeros(s,"int32"),u=T.util.sizeFromShape(o),c=this.readSync(l.dataId),h=this.readSync(e.dataId),d=0;d<c.length;++d){for(var p=d*u,f=h[p],m=0,g=0;g<u;++g){var v=h[p+g];v>f&&(f=v,m=g)}c[d]=m}return l},t.prototype.cumsum=function(e,i,r,a){if(ae(e,"cumsum"),i!==e.rank-1)throw new Error("backend.cumsum in CPU expects an inner-most axis="+(e.rank-1)+" "+("but got axis="+i));for(var s=T.upcastType(e.dtype,"int32"),o=T.zeros(e.shape,s),l=this.readSync(o.dataId),u=this.readSync(e.dataId),c=e.shape[e.rank-1],h=a?function(g,v){return g+c-v-1}:function(g,v){return g+v},d=0;d<u.length;d+=c)for(var p=0;p<c;p++){var f=h(d,p);if(p===0)l[f]=r?0:u[f];else{var m=h(d,p-1);l[f]=r?u[m]+l[m]:u[f]+l[m]}}return o},t.prototype.equal=function(e,i){return ae([e,i],"equal"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r===a?1:0})},t.prototype.notEqual=function(e,i){return ae([e,i],"notEqual"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r!==a?1:0})},t.prototype.less=function(e,i){return ae([e,i],"less"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r<a?1:0})},t.prototype.lessEqual=function(e,i){return ae([e,i],"lessEqual"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r<=a?1:0})},t.prototype.greater=function(e,i){return ae([e,i],"greater"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r>a?1:0})},t.prototype.greaterEqual=function(e,i){return ae([e,i],"greaterEqual"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r>=a?1:0})},t.prototype.logicalAnd=function(e,i){return ae([e,i],"logicalAnd"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r&&a})},t.prototype.logicalOr=function(e,i){return ae([e,i],"logicalOr"),this.broadcastedBinaryOp(e,i,"bool",function(r,a){return r||a})},t.prototype.select=function(e,i,r){ae([e,i,r],"select");for(var a=this.readSync(e.dataId),s=this.readSync(i.dataId),o=this.readSync(r.dataId),l=T.zeros(i.shape,T.upcastType(i.dtype,r.dtype)),u=this.readSync(l.dataId),c=0,h=e.rank===0||e.rank>1||i.rank===1?1:T.util.sizeFromShape(i.shape.slice(1)),d=0;d<a.length;d++)for(var p=0;p<h;p++)a[d]===1?u[c++]=s[d]:u[c++]=o[d];return l},t.prototype.where=function(e){ae([e],"where");var i=this.readSync(e.dataId);return lz(e.shape,i)},t.prototype.topk=function(e,i,r){ae(e,"topk");var a=this.readSync(e.dataId);return oz(a,e.shape,e.dtype,i,r)},t.prototype.min=function(e,i){ae(e,"min"),T.backend_util.assertAxesAreInnerMostDims("min",i,e.rank);for(var r=T.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=T.zeros(a,e.dtype),l=T.util.sizeFromShape(s),u=this.readSync(o.dataId),c=this.readSync(e.dataId),h=0;h<u.length;++h){for(var d=h*l,p=c[d],f=0;f<l;++f){var m=c[d+f];m<p&&(p=m)}u[h]=p}return o},t.prototype.minimum=function(e,i){return ae([e,i],"minimum"),this.broadcastedBinaryOp(e,i,e.dtype,function(r,a){return Math.min(r,a)})},t.prototype.mod=function(e,i){return ae([e,i],"mod"),this.broadcastedBinaryOp(e,i,e.dtype,function(r,a){var s=r%a;return r<0&&a<0||r>=0&&a>=0?s:(s+a)%a})},t.prototype.maximum=function(e,i){return ae([e,i],"maximum"),this.broadcastedBinaryOp(e,i,e.dtype,function(r,a){return Math.max(r,a)})},t.prototype.all=function(e,i){ae(e,"all"),T.backend_util.assertAxesAreInnerMostDims("all",i,e.rank);for(var r=T.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=T.zeros(a,e.dtype),l=T.util.sizeFromShape(s),u=this.readSync(o.dataId),c=this.readSync(e.dataId),h=0;h<u.length;++h){for(var d=h*l,p=c[d],f=0;f<l;++f){var m=c[d+f];p=p&&m}u[h]=p}return o},t.prototype.any=function(e,i){ae(e,"any"),T.backend_util.assertAxesAreInnerMostDims("any",i,e.rank);for(var r=T.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=T.zeros(a,e.dtype),l=T.util.sizeFromShape(s),u=this.readSync(o.dataId),c=this.readSync(e.dataId),h=0;h<u.length;++h){for(var d=h*l,p=c[d],f=0;f<l;++f){var m=c[d+f];p=p||m}u[h]=p}return o},t.prototype.squaredDifference=function(e,i){return ae([e,i],"squaredDifference"),this.broadcastedBinaryOp(e,i,e.dtype,function(r,a){var s=r-a;return s*s})},t.prototype.linear=function(e){return e},t.prototype.relu=function(e){ae(e,"relu");for(var i=T.zeros(e.shape,e.dtype),r=this.readSync(i.dataId),a=this.readSync(e.dataId),s=0;s<a.length;++s)r[s]=Math.max(0,a[s]);return i},t.prototype.relu6=function(e){ae(e,"relu");for(var i=T.zeros(e.shape,e.dtype),r=this.readSync(i.dataId),a=this.readSync(e.dataId),s=0;s<a.length;++s)r[s]=Math.min(Math.max(0,a[s]),6);return i},t.prototype.prelu=function(e,i){return ae([e,i],"prelu"),this.broadcastedBinaryOp(e,i,e.dtype,function(r,a){return r<0?a*r:r})},t.prototype.eluDer=function(e,i){ae([e,i],"eluDer");for(var r=new Float32Array(i.size),a=this.readSync(i.dataId),s=this.readSync(e.dataId),o=0;o<a.length;++o){var l=a[o];l>=1?r[o]=s[o]:r[o]=s[o]*(l+1)}return this.makeOutput(r,i.shape,"float32")},t.prototype.atan2=function(e,i){return ae([e,i],"atan2"),this.broadcastedBinaryOp(e,i,e.dtype,function(r,a){return Math.atan2(r,a)})},t.prototype.fusedConv2d=function(e){var i=e.input,r=e.filter,a=e.convInfo,s=e.bias,o=e.activation,l=e.preluActivationWeights,u=this.conv2d(i,r,a);return s&&(u=T.add(u,s)),o&&(u=Jd(this,u,o,l)),u},t.prototype.conv2d=function(e,i,r){ae([e,i],"conv2d");for(var a=r.filterHeight,s=r.filterWidth,o=r.dilationHeight,l=r.dilationWidth,u=r.padInfo.left,c=r.padInfo.top,h=r.dataFormat==="channelsLast",d=T.buffer(r.outShape,e.dtype),p=e.strides[0],f=h?e.strides[1]:e.strides[2],m=h?e.strides[2]:1,g=h?1:e.strides[1],v=d.strides[0],b=h?d.strides[1]:d.strides[2],w=h?d.strides[2]:1,S=h?1:d.strides[1],L=this.readSync(e.dataId),N=this.readSync(i.dataId),C=d.values,R=0;R<r.batchSize;++R)for(var D=R*p,k=R*v,W=0;W<r.outHeight;++W)for(var F=k+W*b,P=W*r.strideHeight-c,H=0;H<a;H++){var _=P+H*o;if(_<0||_>=r.inHeight)continue;for(var j=H*i.strides[0],K=D+_*f,q=0;q<r.outWidth;++q)for(var G=F+q*w,Z=q*r.strideWidth-u,X=0;X<s;X++){var ee=Z+X*l;if(ee<0||ee>=r.inWidth)continue;for(var ne=j+X*i.strides[1],ie=K+ee*m,te=ne,re=0;re<r.inChannels;++re){for(var le=L[ie+re*g],he=0;he<r.outChannels;++he)C[G+he*S]+=le*N[te+he];te+=r.outChannels}}}return d.toTensor()},t.prototype.conv3d=function(e,i,r){for(var a=r.filterDepth,s=r.filterHeight,o=r.filterWidth,l=r.dilationDepth,u=r.dilationHeight,c=r.dilationWidth,h=r.padInfo.front,d=r.padInfo.left,p=r.padInfo.top,f=T.buffer(r.outShape,e.dtype),m=this.readSync(e.dataId),g=this.readSync(i.dataId),v=f.values,b=0;b<r.batchSize;++b)for(var w=b*e.strides[0],S=b*f.strides[0],L=0;L<r.outDepth;++L)for(var N=S+L*f.strides[1],C=L*r.strideDepth-h,R=0;R<a;R++){var D=C+R*l;if(D<0||D>=r.inDepth)continue;for(var k=R*i.strides[0],W=w+D*e.strides[1],F=0;F<r.outHeight;++F)for(var P=N+F*f.strides[2],H=F*r.strideHeight-p,_=0;_<s;_++){var j=H+_*u;if(j<0||j>=r.inHeight)continue;for(var K=k+_*i.strides[1],q=W+j*e.strides[2],G=0;G<r.outWidth;++G)for(var Z=P+G*r.outChannels,X=G*r.strideWidth-d,ee=0;ee<o;ee++){var ne=X+ee*c;if(ne<0||ne>=r.inWidth)continue;for(var ie=K+ee*i.strides[2],te=q+ne*r.inChannels,re=ie,le=0;le<r.inChannels;++le){for(var he=m[te+le],ye=0;ye<r.outChannels;++ye)v[Z+ye]+=he*g[re+ye];re+=r.outChannels}}}}return f.toTensor()},t.prototype.conv2dDerInput=function(e,i,r){ae([e,i],"conv2dDerInput");for(var a=T.buffer(r.inShape,"float32"),s=a.values,o=this.readSync(e.dataId),l=this.readSync(i.dataId),u=i.strides,c=u[0],h=u[1],d=u[2],p=r.batchSize,f=r.filterHeight,m=r.filterWidth,g=r.inChannels,v=r.inHeight,b=r.inWidth,w=r.outChannels,S=r.outHeight,L=r.outWidth,N=r.strideHeight,C=r.strideWidth,R=r.dataFormat,D=f-1-r.padInfo.top,k=m-1-r.padInfo.left,W=R==="channelsLast",F=a.strides[0],P=W?a.strides[1]:a.strides[2],H=W?a.strides[2]:1,_=W?1:a.strides[1],j=e.strides[0],K=W?e.strides[1]:e.strides[2],q=W?e.strides[2]:1,G=W?1:e.strides[1],Z=0;Z<p;++Z)for(var X=0;X<g;++X)for(var ee=0;ee<v;++ee)for(var ne=ee-D,ie=Math.max(0,Math.ceil(ne/N)),te=Math.min(S,(f+ne)/N),re=0;re<b;++re){for(var le=re-k,he=Math.max(0,Math.ceil(le/C)),ye=Math.min(L,(m+le)/C),Oe=0,Fe=ie;Fe<te;++Fe)for(var _e=Fe*N-ne,Me=he;Me<ye;++Me)for(var dt=Me*C-le,Lt=j*Z+K*Fe+q*Me,Ge=c*(f-1-_e)+h*(m-1-dt)+d*X,Ue=0;Ue<w;++Ue){var me=o[Lt+G*Ue],Ft=l[Ge+Ue];Oe+=me*Ft}var lt=F*Z+P*ee+H*re+_*X;s[lt]=Oe}return a.toTensor()},t.prototype.conv3dDerInput=function(e,i,r){for(var a=T.buffer(r.inShape,"float32"),s=a.values,o=a.strides,l=o[0],u=o[1],c=o[2],h=o[3],d=this.readSync(e.dataId),p=e.strides,f=p[0],m=p[1],g=p[2],v=p[3],b=this.readSync(i.dataId),w=i.strides,S=w[0],L=w[1],N=w[2],C=w[3],R=r.batchSize,D=r.filterDepth,k=r.filterHeight,W=r.filterWidth,F=r.inChannels,P=r.inDepth,H=r.inHeight,_=r.inWidth,j=r.outChannels,K=r.outDepth,q=r.outHeight,G=r.outWidth,Z=r.strideDepth,X=r.strideHeight,ee=r.strideWidth,ne=D-1-r.padInfo.front,ie=k-1-r.padInfo.top,te=W-1-r.padInfo.left,re=0;re<R;++re)for(var le=0;le<F;++le)for(var he=0;he<P;++he)for(var ye=he-ne,Oe=Math.max(0,Math.ceil(ye/Z)),Fe=Math.min(K,(D+ye)/Z),_e=0;_e<H;++_e)for(var Me=_e-ie,dt=Math.max(0,Math.ceil(Me/X)),Lt=Math.min(q,(k+Me)/X),Ge=0;Ge<_;++Ge){for(var Ue=Ge-te,me=Math.max(0,Math.ceil(Ue/ee)),Ft=Math.min(G,(W+Ue)/ee),lt=0,pt=Oe;pt<Fe;++pt)for(var En=pt*Z-ye,Et=dt;Et<Lt;++Et)for(var It=Et*X-Me,Ce=me;Ce<Ft;++Ce)for(var Wt=Ce*ee-Ue,ft=f*re+m*pt+g*Et+v*Ce,it=S*(D-1-En)+L*(k-1-It)+N*(W-1-Wt)+C*le,cn=0;cn<j;++cn){var Os=d[ft+cn],_t=b[it+cn];lt+=Os*_t}s[l*re+u*he+c*_e+h*Ge+le]=lt}return a.toTensor()},t.prototype.conv2dDerFilter=function(e,i,r){ae([e,i],"conv2dDerFilter");for(var a=r.strideHeight,s=r.strideWidth,o=r.filterHeight,l=r.filterWidth,u=r.dataFormat==="channelsLast",c=T.buffer(r.filterShape,"float32"),h=r.padInfo.left,d=r.padInfo.top,p=this.bufferSync(e),f=this.bufferSync(i),m=0;m<o;++m)for(var g=Math.max(0,Math.ceil((d-m)/a)),v=Math.min(r.outHeight,(r.inHeight+d-m)/a),b=0;b<l;++b)for(var w=Math.max(0,Math.ceil((h-b)/s)),S=Math.min(r.outWidth,(r.inWidth+h-b)/s),L=0;L<r.inChannels;++L)for(var N=0;N<r.outChannels;++N){for(var C=0,R=0;R<r.batchSize;++R)for(var D=g;D<v;++D)for(var k=m+D*a-d,W=w;W<S;++W){var F=b+W*s-h;u?C+=p.get(R,k,F,L)*f.get(R,D,W,N):C+=p.get(R,L,k,F)*f.get(R,N,D,W)}c.set(C,m,b,L,N)}return c.toTensor()},t.prototype.conv3dDerFilter=function(e,i,r){for(var a=r.strideDepth,s=r.strideHeight,o=r.strideWidth,l=r.filterDepth,u=r.filterHeight,c=r.filterWidth,h=T.buffer(r.filterShape,"float32"),d=h.values,p=h.strides,f=p[0],m=p[1],g=p[2],v=p[3],b=this.readSync(i.dataId),w=i.strides,S=w[0],L=w[1],N=w[2],C=w[3],R=this.readSync(e.dataId),D=e.strides,k=D[0],W=D[1],F=D[2],P=D[3],H=r.padInfo.front,_=r.padInfo.left,j=r.padInfo.top,K=0;K<l;++K)for(var q=Math.max(0,Math.ceil((H-K)/a)),G=Math.min(r.outDepth,(r.inDepth+H-K)/a),Z=K*f,X=0;X<u;++X)for(var ee=Math.max(0,Math.ceil((j-X)/s)),ne=Math.min(r.outHeight,(r.inHeight+j-X)/s),ie=X*m+Z,te=0;te<c;++te)for(var re=Math.max(0,Math.ceil((_-te)/o)),le=Math.min(r.outWidth,(r.inWidth+_-te)/o),he=te*g+ie,ye=0;ye<r.inChannels;++ye)for(var Oe=ye*v+he,Fe=0;Fe<r.outChannels;++Fe){for(var _e=0,Me=0;Me<r.batchSize;++Me)for(var dt=Me*k,Lt=Me*S,Ge=q;Ge<G;++Ge)for(var Ue=K+Ge*a-H,me=Ue*W+dt,Ft=Ge*L+Lt,lt=ee;lt<ne;++lt)for(var pt=X+lt*s-j,En=pt*F+me,Et=lt*N+Ft,It=re;It<le;++It){var Ce=te+It*o-_,Wt=Ce*P+En,ft=It*C+Et;_e+=R[Wt+ye]*b[ft+Fe]}d[Oe+Fe]=_e}return h.toTensor()},t.prototype.fusedDepthwiseConv2D=function(e){var i=e.input,r=e.filter,a=e.convInfo,s=e.bias,o=e.activation,l=e.preluActivationWeights,u=this.depthwiseConv2D(i,r,a);return s&&(u=T.add(u,s)),o&&(u=Jd(this,u,o,l)),u},t.prototype.depthwiseConv2D=function(e,i,r){ae([e,i],"depthwiseConv2D");for(var a=r.filterHeight,s=r.filterWidth,o=r.dilationHeight,l=r.dilationWidth,u=r.padInfo.left,c=r.padInfo.top,h=r.outChannels/r.inChannels,d=T.buffer(r.outShape,e.dtype),p=this.readSync(e.dataId),f=this.readSync(i.dataId),m=d.values,g=0;g<r.batchSize;++g)for(var v=g*e.strides[0],b=g*d.strides[0],w=0;w<r.outHeight;++w)for(var S=b+w*d.strides[1],L=w*r.strideHeight-u,N=0;N<a;++N){var C=L+N*o;if(C<0||C>=r.inHeight)continue;for(var R=N*i.strides[0],D=v+C*e.strides[1],k=0;k<r.outWidth;++k)for(var W=S+k*d.strides[2],F=k*r.strideWidth-c,P=0;P<s;++P){var H=F+P*l;if(H<0||H>=r.inWidth)continue;for(var _=R+P*i.strides[1],j=D+H*r.inChannels,K=W,q=_,G=0;G<r.inChannels;++G){for(var Z=p[j+G],X=0;X<h;++X)m[K+X]+=Z*f[q+X];K+=h,q+=h}}}return d.toTensor()},t.prototype.depthwiseConv2DDerInput=function(e,i,r){ae([e,i],"depthwiseConv2DDerInput");for(var a=T.buffer(r.inShape,"float32"),s=a.values,o=a.strides,l=o[0],u=o[1],c=o[2],h=this.readSync(e.dataId),d=e.strides,p=d[0],f=d[1],m=d[2],g=this.readSync(i.dataId),v=i.strides,b=v[0],w=v[1],S=v[2],L=r.batchSize,N=r.filterHeight,C=r.filterWidth,R=r.inChannels,D=r.inHeight,k=r.inWidth,W=r.outChannels,F=r.outHeight,P=r.outWidth,H=r.strideHeight,_=r.strideWidth,j=N-1-r.padInfo.top,K=C-1-r.padInfo.left,q=W/R,G=0;G<L;++G)for(var Z=0;Z<R;++Z)for(var X=0;X<D;++X)for(var ee=X-j,ne=Math.max(0,Math.ceil(ee/H)),ie=Math.min(F,(N+ee)/H),te=0;te<k;++te){for(var re=te-K,le=Math.max(0,Math.ceil(re/_)),he=Math.min(P,(C+re)/_),ye=0,Oe=ne;Oe<ie;++Oe)for(var Fe=Oe*H-ee,_e=le;_e<he;++_e)for(var Me=_e*_-re,dt=p*G+f*Oe+m*_e,Lt=b*(N-1-Fe)+w*(C-1-Me)+S*Z,Ge=0;Ge<q;++Ge){var Ue=Z*q+Ge,me=h[dt+Ue],Ft=g[Lt+Ge];ye+=me*Ft}s[l*G+u*X+c*te+Z]=ye}return a.toTensor()},t.prototype.depthwiseConv2DDerFilter=function(e,i,r){ae([e,i],"depthwiseConv2DDerFilter");for(var a=r.strideHeight,s=r.strideWidth,o=r.filterHeight,l=r.filterWidth,u=T.buffer(r.filterShape,"float32"),c=r.padInfo.left,h=r.padInfo.top,d=r.outChannels/r.inChannels,p=this.bufferSync(e),f=this.bufferSync(i),m=0;m<o;++m)for(var g=Math.max(0,Math.ceil((h-m)/a)),v=Math.min(r.outHeight,(r.inHeight+h-m)/a),b=0;b<l;++b)for(var w=Math.max(0,Math.ceil((c-b)/s)),S=Math.min(r.outWidth,(r.inWidth+c-b)/s),L=0;L<r.outChannels;++L){for(var N=Math.trunc(L/d),C=L%d,R=0,D=0;D<r.batchSize;++D)for(var k=g;k<v;++k)for(var W=m+k*a-h,F=w;F<S;++F){var P=b+F*s-c;R+=p.get(D,W,P,N)*f.get(D,k,F,L)}u.set(R,m,b,N,C)}return u.toTensor()},t.prototype.tile=function(e,i){return ae(e,"tile"),sz(this.bufferSync(e),i)},t.prototype.gather=function(e,i,r){ae([e,i],"gather");var a=e.shape.slice(),s=this.readSync(i.dataId);a[r]=s.length;for(var o=T.buffer(a,e.dtype),l=this.bufferSync(e),u=0;u<o.size;++u){var c=o.indexToLoc(u),h=c.slice();h[r]=s[c[r]];var d=l.locToIndex(h);o.values[u]=l.values[d]}return o.toTensor()},t.prototype.batchToSpaceND=function(e,i,r){ae([e],"batchToSpaceND");var a=i.reduce(function(h,d){return h*d}),s=T.backend_util.getReshaped(e.shape,i,a),o=T.backend_util.getPermuted(s.length,i.length),l=T.backend_util.getReshapedPermuted(e.shape,i,a),u=T.backend_util.getSliceBeginCoords(r,i.length),c=T.backend_util.getSliceSize(l,r,i.length);return T.transpose(e.reshape(s),o).reshape(l).slice(u,c)},t.prototype.pool3d=function(e,i,r){ae(e,"pool3d");for(var a=i.strideDepth,s=i.strideHeight,o=i.strideWidth,l=i.dilationDepth,u=i.dilationHeight,c=i.dilationWidth,h=i.effectiveFilterDepth,d=i.effectiveFilterHeight,p=i.effectiveFilterWidth,f=i.padInfo.front,m=i.padInfo.top,g=i.padInfo.left,v=r==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,b=this.readSync(e.dataId),w=T.buffer(i.outShape,e.dtype),S=w.values,L=i.outShape[1]*i.outShape[2]*i.outShape[3]*i.outShape[4],N=i.outShape[2]*i.outShape[3]*i.outShape[4],C=i.outShape[3]*i.outShape[4],R=i.outShape[4],D=0;D<i.batchSize;++D)for(var k=D*L,W=D*e.strides[0],F=0;F<i.inChannels;++F)for(var P=0;P<i.outDepth;++P){for(var H=P*a-f,_=H;_<0;)_+=l;for(var j=Math.min(i.inDepth,h+H),K=k+P*N,q=0;q<i.outHeight;++q){for(var G=q*s-m,Z=G;Z<0;)Z+=u;for(var X=Math.min(i.inHeight,d+G),ee=K+q*C,ne=0;ne<i.outWidth;++ne){for(var ie=ne*o-g,te=ie;te<0;)te+=c;for(var re=Math.min(i.inWidth,p+ie),le=ee+ne*R,he=v,ye=0,Oe=0,Fe=_;Fe<j;Fe+=l){for(var _e=W+Fe*e.strides[1],Me=Z;Me<X;Me+=u){for(var dt=_e+Me*e.strides[2],Lt=te;Lt<re;Lt+=c){var Ge=dt+Lt*e.strides[3],Ue=b[Ge+F];if(r==="max"&&Ue>he?he=Ue:r==="avg"&&(ye+=Ue,Oe++),isNaN(he))break}if(isNaN(he))break}if(isNaN(he))break}var me=le+F;S[me]=r==="avg"?ye/Oe:he}}}return w.toTensor()},t.prototype.avgPool3d=function(e,i){return ae(e,"avgPool3d"),this.pool3d(e,i,"avg").toFloat()},t.prototype.avgPool3dBackprop=function(e,i,r){ae([e,i],"avgPool3dBackprop");for(var a=r.strideDepth,s=r.strideHeight,o=r.strideWidth,l=r.filterDepth,u=r.filterHeight,c=r.filterWidth,h=r.dilationDepth,d=r.dilationHeight,p=r.dilationWidth,f=r.effectiveFilterDepth,m=r.effectiveFilterHeight,g=r.effectiveFilterWidth,v=f-1-r.padInfo.front,b=g-1-r.padInfo.left,w=m-1-r.padInfo.top,S=T.buffer(i.shape,"float32"),L=1/(l*u*c),N=this.bufferSync(e),C=0;C<r.batchSize;++C)for(var R=0;R<r.inChannels;++R)for(var D=0;D<r.inDepth;++D)for(var k=0;k<r.inHeight;++k)for(var W=0;W<r.inWidth;++W){for(var F=D-v,P=k-w,H=W-b,_=0,j=0;j<f;j+=h){var K=(F+j)/a;if(K<0||K>=r.outDepth||Math.floor(K)!==K)continue;for(var q=0;q<m;q+=d){var G=(P+q)/s;if(G<0||G>=r.outHeight||Math.floor(G)!==G)continue;for(var Z=0;Z<g;Z+=p){var X=(H+Z)/o;if(X<0||X>=r.outWidth||Math.floor(X)!==X)continue;var ee=N.get(C,K,G,X,R);_+=ee}}}S.set(_*L,C,D,k,W,R)}return S.toTensor()},t.prototype.maxPool3d=function(e,i){return ae(e,"maxPool3d"),this.pool3d(e,i,"max").toFloat()},t.prototype.maxPool3dPositions=function(e,i){for(var r=T.buffer(i.outShape,"int32"),a=i.strideDepth,s=i.strideHeight,o=i.strideWidth,l=i.dilationDepth,u=i.dilationHeight,c=i.dilationWidth,h=i.effectiveFilterDepth,d=i.effectiveFilterHeight,p=i.effectiveFilterWidth,f=i.padInfo.front,m=i.padInfo.top,g=i.padInfo.left,v=this.bufferSync(e),b=0;b<i.batchSize;++b)for(var w=0;w<i.inChannels;++w)for(var S=0;S<i.outDepth;++S){for(var L=S*a-f,N=L;N<0;)N+=l;for(var C=Math.min(i.inDepth,h+L),R=0;R<i.outHeight;++R){for(var D=R*s-m,k=D;k<0;)k+=u;for(var W=Math.min(i.inHeight,d+D),F=0;F<i.outWidth;++F){for(var P=F*o-g,H=P;H<0;)H+=c;for(var _=Math.min(i.inWidth,p+P),j=Number.NEGATIVE_INFINITY,K=-1,q=N;q<C;q+=l)for(var G=q-L,Z=k;Z<W;Z+=u)for(var X=Z-D,ee=H;ee<_;ee+=c){var ne=ee-P,ie=v.get(b,q,Z,ee,w);ie>=j&&(j=ie,K=G*d*p+X*d+ne)}r.set(K,b,S,R,F,w)}}}return r.toTensor()},t.prototype.maxPool3dBackprop=function(e,i,r,a){ae([i,r],"maxPool3dBackprop");for(var s=this.maxPool3dPositions(i,a),o=a.strideDepth,l=a.strideHeight,u=a.strideWidth,c=a.dilationDepth,h=a.dilationHeight,d=a.dilationWidth,p=a.effectiveFilterDepth,f=a.effectiveFilterHeight,m=a.effectiveFilterWidth,g=p-1-a.padInfo.front,v=m-1-a.padInfo.left,b=f-1-a.padInfo.top,w=T.buffer(i.shape,"float32"),S=this.bufferSync(s),L=this.bufferSync(e),N=0;N<a.batchSize;++N)for(var C=0;C<a.inChannels;++C)for(var R=0;R<a.inDepth;++R)for(var D=0;D<a.inHeight;++D)for(var k=0;k<a.inWidth;++k){for(var W=R-g,F=D-b,P=k-v,H=0,_=0;_<p;_+=c){var j=(W+_)/o;if(j<0||j>=a.outDepth||Math.floor(j)!==j)continue;for(var K=0;K<f;K+=h){var q=(F+K)/l;if(q<0||q>=a.outHeight||Math.floor(q)!==q)continue;for(var G=0;G<m;G+=d){var Z=(P+G)/u;if(Z<0||Z>=a.outWidth||Math.floor(Z)!==Z)continue;var X=p*f*m-1-S.get(N,j,q,Z,C),ee=_*f*m+K*m+G,ne=X===ee?1:0;if(ne===0)continue;var ie=L.get(N,j,q,Z,C);H+=ie*ne}}}w.set(H,N,R,D,k,C)}return w.toTensor()},t.prototype.resizeBilinear=function(e,i,r,a){ae(e,"resizeBilinear");for(var s=e.shape,o=s[0],l=s[1],u=s[2],c=s[3],h=this.readSync(e.dataId),d=new Float32Array(T.util.sizeFromShape([o,i,r,c])),p=[a&&i>1?l-1:l,a&&r>1?u-1:u],f=[a&&i>1?i-1:i,a&&r>1?r-1:r],m=0,g=p[0]/f[0],v=p[1]/f[1],b=0;b<o;b++)for(var w=0;w<i;w++)for(var S=g*w,L=Math.floor(S),N=S-L,C=Math.min(l-1,Math.ceil(S)),R=b*e.strides[0]+L*e.strides[1],D=b*e.strides[0]+C*e.strides[1],k=0;k<r;k++)for(var W=v*k,F=Math.floor(W),P=W-F,H=Math.min(u-1,Math.ceil(W)),_=R+F*e.strides[2],j=D+F*e.strides[2],K=R+H*e.strides[2],q=D+H*e.strides[2],G=0;G<c;G++){var Z=h[_+G],X=h[j+G],ee=h[K+G],ne=h[q+G],ie=Z+(ee-Z)*P,te=X+(ne-X)*P,re=ie+(te-ie)*N;d[m++]=re}return T.tensor(d,[o,i,r,c])},t.prototype.resizeBilinearBackprop=function(e,i,r){ae([e,i],"resizeBilinearBackprop");for(var a=i.shape,s=a[0],o=a[1],l=a[2],u=a[3],c=e.shape,h=c[1],d=c[2],p=new Float32Array(s*o*l*u),f=[r&&h>1?o-1:o,r&&d>1?l-1:l],m=[r&&h>1?h-1:h,r&&d>1?d-1:d],g=f[0]/m[0],v=f[1]/m[1],b=this.readSync(e.dataId),w=0,S=0;S<s;S++)for(var L=S*i.strides[0],N=0;N<h;N++)for(var C=N*g,R=Math.floor(C),D=Math.min(Math.ceil(C),o-1),k=L+R*i.strides[1],W=L+D*i.strides[1],F=C-R,P=1-F,H=0;H<d;H++)for(var _=H*v,j=Math.floor(_),K=Math.min(Math.ceil(_),l-1),q=_-j,G=1-q,Z=k+j*i.strides[2],X=k+K*i.strides[2],ee=W+j*i.strides[2],ne=W+K*i.strides[2],ie=P*G,te=P*q,re=F*G,le=F*q,he=0;he<u;he++){var ye=b[w++];p[Z+he]+=ye*ie,p[X+he]+=ye*te,p[ee+he]+=ye*re,p[ne+he]+=ye*le}return T.tensor4d(p,[s,l,o,u],i.dtype)},t.prototype.resizeNearestNeighbor=function(e,i,r,a){ae(e,"resizeNearestNeighbor");for(var s=e.shape,o=s[0],l=s[1],u=s[2],c=s[3],h=this.readSync(e.dataId),d=new Float32Array(o*i*r*c),p=[a&&i>1?l-1:l,a&&r>1?u-1:u],f=[a&&i>1?i-1:i,a&&r>1?r-1:r],m=p[0]/f[0],g=p[1]/f[1],v=0,b=0;b<o;b++)for(var w=b*e.strides[0],S=0;S<i;S++)for(var L=m*S,N=Math.min(l-1,a?Math.round(L):Math.floor(L)),C=w+N*e.strides[1],R=0;R<r;R++)for(var D=g*R,k=Math.min(u-1,a?Math.round(D):Math.floor(D)),W=C+k*e.strides[2],F=0;F<c;F++){var P=h[W+F];d[v++]=P}return T.tensor(d,[o,i,r,c],e.dtype)},t.prototype.resizeNearestNeighborBackprop=function(e,i,r){ae([e,i],"resizeNearestNeighborBackprop");for(var a=i.shape,s=a[0],o=a[1],l=a[2],u=a[3],c=e.shape,h=c[1],d=c[2],p=new Float32Array(s*o*l*u),f=this.readSync(e.dataId),m=[r&&h>1?o-1:o,r&&d>1?l-1:l],g=[r&&h>1?h-1:h,r&&d>1?d-1:d],v=m[0]/g[0],b=m[1]/g[1],w=1/v,S=1/b,L=Math.ceil(w)*2+2,N=Math.ceil(S)*2+2,C=0;C<s;C++)for(var R=C*i.strides[0],D=0;D<o;D++)for(var k=R+D*i.strides[1],W=Math.floor(D*w),F=Math.floor(W-L/2),P=0;P<l;P++)for(var H=k+P*i.strides[2],_=Math.floor(P*S),j=Math.floor(_-N/2),K=0;K<u;K++){for(var q=0,G=0;G<L;G++){var Z=G+F;if(Z<0||Z>=h)continue;var X=R+Z*e.strides[1],ee=Z*v,ne=Math.min(o-1,r?Math.round(ee):Math.floor(ee));if(D!==ne)continue;for(var ie=0;ie<N;ie++){var te=ie+j;if(te<0||te>=d)continue;var re=X+te*e.strides[2],le=te*b,he=Math.min(l-1,r?Math.round(le):Math.floor(le));P===he&&(q+=f[re+K])}}p[H+K]=q}return T.tensor4d(p,i.shape,i.dtype)},t.prototype.localResponseNormalization4D=function(e,i,r,a,s){ae(e,"localResponseNormalization4D");var o=e.shape[3],l=o-1,u=this.readSync(e.dataId),c=e.size,h=new Float32Array(c);function d(g){for(var v=g%o,b=g-v+Math.max(0,v-i),w=g-v+Math.min(v+i,l),S=0;b<=w;b++){var L=u[b];S+=L*L}return S}for(var p=0;p<c;p++){var f=d(p),m=u[p]*Math.pow(r+a*f,-s);h[p]=m}return T.tensor4d(h,e.shape)},t.prototype.LRNGrad=function(e,i,r,a,s,o,l){ae(e,"LRNGrad");for(var u=e.shape[3],c=this.readSync(e.dataId),h=this.readSync(i.dataId),d=this.readSync(r.dataId),p=new Float32Array(e.size),f=e.size,m=0;m<f;m++){for(var g=m%u,v=m-g+Math.max(0,g-a),b=m-g+Math.min(u,g+a+1),w=0,S=v;S<b;S++)w+=Math.pow(h[S],2);w=o*w+s;for(var S=v;S<b;S++){var L=-2*o*l*h[S]*d[m]/w;m===S&&(L+=Math.pow(w,-l)),L*=c[m],p[S]+=L}}return T.tensor4d(p,e.shape)},t.prototype.multinomial=function(e,i,r,a){ae(e,"multinomial");for(var s=i?e:T.softmax(e),o=s.shape[0],l=s.shape[1],u=T.zeros([o,r],"int32"),c=this.readSync(u.dataId),h=this.readSync(s.dataId),d=0;d<o;++d){var p=d*l,f=new Float32Array(l-1);f[0]=h[p];for(var m=1;m<f.length;++m)f[m]=f[m-1]+h[p+m];for(var g=nz.alea(a.toString()),v=d*r,b=0;b<r;++b){var w=g();c[v+b]=f.length;for(var S=0;S<f.length;S++)if(w<f[S]){c[v+b]=S;break}}}return u},t.prototype.oneHot=function(e,i,r,a){ae(e,"oneHot");var s=new Float32Array(e.size*i);s.fill(a);for(var o=this.readSync(e.dataId),l=0;l<e.size;++l)o[l]>=0&&o[l]<i&&(s[l*i+o[l]]=r);return T.tensor2d(s,[e.size,i],"int32")},t.prototype.nonMaxSuppression=function(e,i,r,a,s){ae(e,"nonMaxSuppression");var o=this.readSync(e.dataId),l=this.readSync(i.dataId);return rz(o,l,r,a,s)},t.prototype.depthToSpace=function(e,i,r){T.util.assert(r==="NHWC",function(){return"Only NHWC dataFormat supported on CPU for depthToSpace. Got "+r}),T.util.assert(i>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+i});for(var a=e.shape[0],s=e.shape[1],o=e.shape[2],l=e.shape[3],u=s*i,c=o*i,h=l/(i*i),d=this.readSync(e.dataId),p=new Float32Array(a*u*c*h),f=0,m=0;m<a;++m)for(var g=0;g<u;++g)for(var v=Math.floor(g/i),b=g%i,w=0;w<c;++w)for(var S=Math.floor(w/i),L=w%i,N=(b*i+L)*h,C=0;C<h;++C){var R=C+N,D=R+l*(S+o*(v+s*m));p[f++]=d[D]}return T.tensor4d(p,[a,u,c,h])},t.prototype.broadcastedBinaryOp=function(e,i,r,a){var s=T.backend_util.assertAndGetBroadcastShape(e.shape,i.shape),o=T.buffer(s,r),l=this.readSync(e.dataId),u=this.readSync(i.dataId),c=T.backend_util.getBroadcastDims(e.shape,s),h=T.backend_util.getBroadcastDims(i.shape,s),d=o.values;if(c.length+h.length===0)for(var p=0;p<d.length;++p)d[p]=a(l[p%l.length],u[p%u.length]);else for(var f=this.bufferSync(e),m=this.bufferSync(i),g=function(v){var b=o.indexToLoc(v),w=b.slice(-e.rank);c.forEach(function(C){return w[C]=0});var S=f.locToIndex(w),L=b.slice(-i.rank);h.forEach(function(C){return L[C]=0});var N=m.locToIndex(L);d[v]=a(l[S],u[N])},p=0;p<d.length;++p)g(p);return o.toTensor()},t.prototype.split=function(e,i,r){return az(e,i,r)},t.prototype.dispose=function(){},t.prototype.floatPrecision=function(){return 32},t.prototype.epsilon=function(){return n.prototype.epsilon.call(this)},t.prototype.cropAndResize=function(e,i,r,a,s,o){for(var l=e.shape,u=l[0],c=l[1],h=l[2],d=l[3],p=i.shape[0],f=a[0],m=a[1],g=T.buffer([p,f,m,d],"float32"),v=this.readSync(i.dataId),b=this.readSync(r.dataId),w=this.readSync(e.dataId),S=e.strides,L=g.strides,N=0;N<p;N++){var C=N*4,R=v[C],D=v[C+1],k=v[C+2],W=v[C+3],F=b[N];if(F>=u)continue;for(var P=f>1?(k-R)*(c-1)/(f-1):0,H=m>1?(W-D)*(h-1)/(m-1):0,_=0;_<f;_++){var j=f>1?R*(c-1)+_*P:.5*(R+k)*(c-1);if(j<0||j>c-1){for(var K=0;K<m;K++)for(var q=0;q<d;q++){var G=q+K*L[2]+_*L[1]+N*L[0];g.values[G]=o}continue}if(s==="bilinear")for(var Z=Math.floor(j),X=Math.ceil(j),ee=j-Z,K=0;K<m;K++){var ne=m>1?D*(h-1)+K*H:.5*(D+W)*(h-1);if(ne<0||ne>h-1){for(var q=0;q<d;q++){var G=q+K*L[2]+_*L[1]+N*L[0];g.values[G]=o}continue}for(var ie=Math.floor(ne),te=Math.ceil(ne),re=ne-ie,q=0;q<d;q++){var G=q+ie*S[2]+Z*S[1]+F*S[0],le=w[G];G=q+te*S[2]+Z*S[1]+F*S[0];var he=w[G];G=q+ie*S[2]+X*S[1]+F*S[0];var ye=w[G];G=q+te*S[2]+X*S[1]+F*S[0];var Oe=w[G],Fe=le+(he-le)*re,_e=ye+(Oe-ye)*re;G=q+K*L[2]+_*L[1]+N*L[0],g.values[G]=Fe+(_e-Fe)*ee}}else for(var K=0;K<m;++K){var ne=m>1?D*(h-1)+K*H:.5*(D+W)*(h-1);if(ne<0||ne>h-1){for(var q=0;q<d;q++){var G=q+K*L[2]+_*L[1]+N*L[0];g.values[G]=o}continue}for(var Me=Math.round(ne),dt=Math.round(j),q=0;q<d;q++){var Lt=q+Me*S[2]+dt*S[1]+F*S[0],Ge=q+K*L[2]+_*L[1]+N*L[0];g.values[Ge]=w[Lt]}}}}return g.toTensor()},t.prototype.sparseToDense=function(e,i,r,a){var s=T.backend_util.calculateShapes(i,e,r),o=s.sliceRank,l=s.numUpdates,u=s.sliceSize,c=s.strides,h=s.outputSize,d=!1;return this.scatter(e,i,r,h,u,l,o,c,a,d)},t.prototype.gatherND=function(e,i){var r=i.shape,a=r[r.length-1],s=T.backend_util.prepareAndValidate(e,i),o=s[0],l=s[1],u=s[2],c=s[3];if(l===0)return T.tensor([],o,e.dtype);for(var h=new T.TensorBuffer([l,u],e.dtype),d=this.readSync(i.dataId),p=this.readSync(e.dataId),f=0;f<l;f++){for(var m=[],g=0,v=0;v<a;v++){var b=d[f*a+v];g+=b*c[v],m.push(b)}if(g<0||g>=e.size/u)throw new Error("Invalid indices: "+m+" does not index into "+e.shape);for(var w=0;w<u;w++)h.values[f*u+w]=p[g*u+w]}return h.toTensor().reshape(o)},t.prototype.scatterND=function(e,i,r){var a=T.backend_util.calculateShapes(i,e,r),s=a.sliceRank,o=a.numUpdates,l=a.sliceSize,u=a.strides,c=a.outputSize,h=T.scalar(0),d=!0;return this.scatter(e,i,r,c,l,o,s,u,h,d)},t.prototype.fill=function(e,i,r){r=r||T.util.inferDtype(i);var a=T.util.getArrayFromDType(r,T.util.sizeFromShape(e));return a.fill(i),T.engine().makeTensor(a,e,r,this)},t.prototype.onesLike=function(e){if(e.dtype==="string")throw new Error("onesLike is not supported for string tensors");return this.fill(e.shape,1,e.dtype)},t.prototype.zerosLike=function(e){var i=T.util.getArrayFromDType(e.dtype,T.util.sizeFromShape(e.shape));return this.makeOutput(i,e.shape,e.dtype)},t.prototype.linspace=function(e,i,r){return T.backend_util.linspaceImpl(e,i,r)},t.prototype.scatter=function(e,i,r,a,s,o,l,u,c,h){var d=[a/s,s],p=this.readSync(e.dataId),f=this.readSync(i.dataId);if(a===0)return T.tensor([],r,i.dtype);var m=new T.TensorBuffer(d,i.dtype);m.values.fill(this.readSync(c.dataId)[0]);for(var g=0;g<o;g++){for(var v=[],b=0,w=0;w<l;w++){var S=p[g*l+w];v.push(S),b+=S*u[w]}if(b<0||b>=a/s)throw new Error("Invalid indices: "+v+" does not index into "+r);for(var L=0;L<s;L++)h?m.values[b*s+L]+=f[g*s+L]:m.values[b*s+L]=i.rank===0?f[0]:f[g*s+L]}return m.toTensor().reshape(r)},t}(T.KernelBackend);function O0(n){for(var t=new Float32Array(n.length),e=0;e<n.length;++e)t[e]=Math.abs(n[e]);return t}var uz=function(n){var t=n.inputs.x,e=n.backend,i=new Float32Array(T.util.sizeFromShape(t.shape));if(t.dtype!=="complex64"){var r=e.data.get(t.dataId).values;i=O0(r)}else for(var a=e.data.get(t.dataId),s=a.complexTensorInfos.real,o=a.complexTensorInfos.imag,l=e.data.get(s.dataId).values,u=e.data.get(o.dataId).values,c=0;c<l.length;c++){var h=l[c],d=u[c];i[c]=Math.hypot(h,d)}return e.makeOutput(i,t.shape,"float32")},cz={kernelName:T.Abs,backendName:"cpu",kernelFunc:uz};function wr(n){return function(t,e,i,r,a){var s=T.backend_util.assertAndGetBroadcastShape(t,e),o=s.length,l=T.util.computeStrides(s),u=T.util.sizeFromShape(s),c=T.util.getTypedArrayFromDType(a,u),h=t.length,d=e.length,p=T.util.computeStrides(t),f=T.util.computeStrides(e),m=T.backend_util.getBroadcastDims(t,s),g=T.backend_util.getBroadcastDims(e,s);if(m.length+g.length===0)for(var v=0;v<c.length;++v)c[v]=n(i[v%i.length],r[v%r.length]);else for(var b=function(w){var S=T.util.indexToLoc(w,o,l),L=S.slice(-h);m.forEach(function(D){return L[D]=0});var N=T.util.locToIndex(L,h,p),C=S.slice(-d);g.forEach(function(D){return C[D]=0});var R=T.util.locToIndex(C,d,f);c[w]=n(i[N],r[R])},v=0;v<c.length;++v)b(v);return[c,s]}}function Cn(n){var t=n.inputs,e=n.backend,i=t.real,r=t.imag,a=e.data.get(i.dataId).values,s=e.data.get(r.dataId).values,o=e.makeTensorInfo(i.shape,"complex64"),l=e.data.get(o.dataId);return l.complexTensorInfos={real:e.makeTensorInfo(i.shape,"float32",a),imag:e.makeTensorInfo(r.shape,"float32",s)},o}var hz={kernelName:T.Complex,backendName:"cpu",kernelFunc:Cn};function ca(n){var t=n.inputs,e=n.backend,i=t.x;return e.incRef(i.dataId),{dataId:i.dataId,shape:i.shape,dtype:i.dtype}}var dz={kernelName:T.Identity,backendName:"cpu",kernelFunc:ca};function fs(n){var t=n.inputs,e=n.backend,i=t.input,r=e.data.get(i.dataId).complexTensorInfos.real,a=e.data.get(r.dataId).values;return e.makeTensorInfo(r.shape,r.dtype,a)}var pz={kernelName:T.Real,backendName:"cpu",kernelFunc:fs};function ms(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=i.dtype;if(a==="complex64"){if(r.dtype==="complex64")return ca({inputs:{x:r},backend:e});var s=T.zeros(r.shape),o=ms({inputs:{x:r},backend:e,attrs:{dtype:"float32"}}),l=Cn({inputs:{real:o,imag:s},backend:e});return s.dispose(),e.disposeIntermediateTensorInfo(o),l}if(r.dtype==="complex64"){var u=fs({inputs:{input:r},backend:e}),l=ms({inputs:{x:u},backend:e,attrs:{dtype:a}});return e.disposeIntermediateTensorInfo(u),l}if(!T.util.hasEncodingLoss(r.dtype,a)){var l=ca({inputs:{x:r},backend:e});return{dataId:l.dataId,shape:l.shape,dtype:a}}if(a==="int32"){var c=e.data.get(r.dataId).values,h=Int32Array.from(c);return e.makeTensorInfo(r.shape,"int32",h)}if(a==="bool"){var d=e.data.get(r.dataId).values,p=T.util.toTypedArray([0],r.dtype),f=wr(function(v,b){return v!==b?1:0})(r.shape,[],d,p,"bool"),m=f[0],g=f[1];return e.makeTensorInfo(g,"bool",m)}throw new Error("Error in Cast: failed to cast "+r.dtype+" to "+a)}var fz={kernelName:T.Cast,backendName:"cpu",kernelFunc:ms};function ha(n,t,e,i){return e==null?function(r){var a=r.inputs,s=r.backend,o=a,l=o.a,u=o.b,c=s;ae([l,u],n);var h=c.data.get(l.dataId).values,d=c.data.get(u.dataId).values,p=i||l.dtype,f=t(l.shape,u.shape,h,d,p),m=f[0],g=f[1];return c.makeTensorInfo(g,p,m)}:function(r){var a=r.inputs,s=r.backend,o=a,l=o.a,u=o.b,c=s;if(l.dtype==="complex64"||u.dtype==="complex64"){var h=ms({inputs:{x:l},backend:c,attrs:{dtype:"complex64"}}),d=c.data.get(h.dataId),p=d.complexTensorInfos.real,f=d.complexTensorInfos.imag,m=c.data.get(p.dataId).values,g=c.data.get(f.dataId).values,v=ms({inputs:{x:u},backend:c,attrs:{dtype:"complex64"}}),b=c.data.get(v.dataId),w=b.complexTensorInfos.real,S=b.complexTensorInfos.imag,L=c.data.get(w.dataId).values,N=c.data.get(S.dataId).values,C=e(l.shape,u.shape,m,g,L,N),R=C[0],D=C[1],k=C[2],W=c.makeTensorInfo(k,"float32",R),F=c.makeTensorInfo(k,"float32",D),P=Cn({inputs:{real:W,imag:F},backend:c});return c.disposeIntermediateTensorInfo(h),c.disposeIntermediateTensorInfo(v),c.disposeIntermediateTensorInfo(W),c.disposeIntermediateTensorInfo(F),P}else{var H=c.data.get(l.dataId).values,_=c.data.get(u.dataId).values,j=i||l.dtype,K=t(l.shape,u.shape,H,_,j),q=K[0],k=K[1];return c.makeTensorInfo(k,j,q)}}}function Zd(n){return function(t,e,i,r,a,s){var o=T.backend_util.assertAndGetBroadcastShape(t,e),l=T.util.sizeFromShape(o),u=o.length,c=T.util.computeStrides(o),h=T.util.getTypedArrayFromDType("float32",l),d=T.util.getTypedArrayFromDType("float32",l),p=T.backend_util.getBroadcastDims(t,o),f=T.backend_util.getBroadcastDims(e,o),m=T.backend_util.mergeRealAndImagArrays(i,r),g=T.backend_util.mergeRealAndImagArrays(a,s),v=t.length,b=T.util.computeStrides(t),w=e.length,S=T.util.computeStrides(e);if(p.length+f.length===0)for(var L=0;L<h.length;L++){var N=L%m.length,C=L%g.length,R=n(m[N*2],m[N*2+1],g[C*2],g[C*2+1]);h[L]=R.real,d[L]=R.imag}else for(var D=function(k){var W=T.util.indexToLoc(k,u,c),F=W.slice(-v);p.forEach(function(K){return F[K]=0});var P=T.util.locToIndex(F,v,b),H=W.slice(-w);f.forEach(function(K){return H[K]=0});var _=T.util.locToIndex(H,w,S),j=n(m[P*2],m[P*2+1],g[_*2],g[_*2+1]);h[k]=j.real,d[k]=j.imag},L=0;L<h.length;L++)D(L);return[h,d,o]}}var E0=wr(function(n,t){return n+t}),mz=Zd(function(n,t,e,i){return{real:n+e,imag:t+i}}),D0=ha(T.Add,E0,mz),gz={kernelName:T.Add,backendName:"cpu",kernelFunc:D0};function da(n){return function(t,e,i){for(var r=T.util.getTypedArrayFromDType(e,t.length),a=0;a<t.length;++a)r[a]=n(t[a],i);return r}}function $e(n,t,e){return function(i){var r=i.inputs,a=i.attrs,s=i.backend,o=r.x;if(ae(o,n),o.dtype==="string"||e==="string")throw new Error("unaryKernelFunc does not support string input/output");for(var l=s,u=l.data.get(o.dataId).values,c=T.util.sizeFromShape(o.shape),h=e||o.dtype,d=T.util.getArrayFromDType(h,c),p=0;p<c;++p)d[p]=t(u[p],a);return l.makeTensorInfo(o.shape,h,d)}}function pa(n,t,e){return function(i){var r=i.inputs,a=i.attrs,s=i.backend,o=r.x;if(ae(o,n),o.dtype==="string"||e==="string")throw new Error("unaryKernelFunc does not support string input/output");var l=s,u=l.data.get(o.dataId).values,c=e||o.dtype,h=t(u,c,a);return l.makeTensorInfo(o.shape,c,h)}}var k0=da(function(n){return Math.ceil(n)}),vz=pa(T.Ceil,k0),yz={kernelName:T.Ceil,backendName:"cpu",kernelFunc:vz};var F0=da(function(n){return Math.exp(n)}),bz=pa(T.Exp,F0),wz={kernelName:T.Exp,backendName:"cpu",kernelFunc:bz};var W0=da(function(n){return Math.expm1(n)}),Sz=pa(T.Expm1,W0),Lz={kernelName:T.Expm1,backendName:"cpu",kernelFunc:Sz};var U0=da(function(n){return Math.floor(n)}),Iz=pa(T.Floor,U0),Az={kernelName:T.Floor,backendName:"cpu",kernelFunc:Iz};var B0=da(function(n){return Math.log(n)}),Tz=pa(T.Log,B0),Nz={kernelName:T.Log,backendName:"cpu",kernelFunc:Tz};function z0(n,t,e,i){for(var r=T.util.getTypedArrayFromDType(i,T.util.sizeFromShape(e)),a=0;a<r.length;++a){for(var s=a*t,o=n[s],l=0;l<t;++l){var u=n[s+l];u>o&&(o=u)}r[a]=o}return r}var P0=wr(function(n,t){return n*t}),xz=Zd(function(n,t,e,i){return{real:n*e-t*i,imag:n*i+t*e}}),_0=ha(T.Multiply,P0,xz),Cz={kernelName:T.Multiply,backendName:"cpu",kernelFunc:_0};var M0=da(function(n){return 1/Math.sqrt(n)}),Rz=pa(T.Rsqrt,M0),Oz={kernelName:T.Rsqrt,backendName:"cpu",kernelFunc:Rz};function H0(n,t,e,i,r){var a=T.slice_util.isSliceContinous(i,t,e),s=T.util.sizeFromShape(e),o=T.util.computeStrides(i);if(a){var l=T.slice_util.computeFlatOffset(t,o);return n.subarray(l,l+s)}for(var u=T.util.getTypedArrayFromDType(r,s),c=0;c<s;++c){var h=e.length,d=T.util.computeStrides(e),p=T.util.indexToLoc(c,h,d),f=p.map(function(g,v){return g+t[v]}),m=T.util.locToIndex(f,i.length,o);u[c]=n[m]}return u}function Qd(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=i.begin,s=i.size;ae(r,"slice");var o=T.slice_util.parseSliceParams(r,a,s),l=o[0],u=o[1];T.slice_util.assertParamsValid(r,l,u);var c=e.data.get(r.dataId).values,h=H0(c,l,u,r.shape,r.dtype);return e.makeTensorInfo(u,r.dtype,h)}var Ez={kernelName:T.Slice,backendName:"cpu",kernelFunc:Qd};var V0=wr(function(n,t){return n-t}),Dz=Zd(function(n,t,e,i){return{real:n-e,imag:t-i}}),q0=ha(T.Sub,V0,Dz),kz={kernelName:T.Sub,backendName:"cpu",kernelFunc:q0};function ep(n,t,e,i,r){for(var a=t.length,s=T.util.sizeFromShape(t),o=T.util.computeStrides(t),l=T.util.computeStrides(r),u=T.util.getTypedArrayFromDType(e,T.util.sizeFromShape(r)),c=0;c<s;++c){for(var h=T.util.indexToLoc(c,a,o),d=new Array(h.length),p=0;p<d.length;p++)d[p]=h[i[p]];var f=T.util.locToIndex(d,a,l);u[f]=n[c]}return u}function G0(n,t,e,i){for(var r=T.util.parseAxisParam(t,e)[0],a=[1,e[0],1],s=0;s<r;s++)a[0]*=e[s];a[1]=e[r];for(var s=r+1;s<e.length;s++)a[2]*=e[s];for(var o={},l=new Int32Array(e[r]),u=new T.TensorBuffer(a,i,n),c=[],h=a[0]===1&&a[2]===1,s=0;s<e[r];s++){var d=void 0;if(h)d=n[s].toString();else{for(var p=[],f=0;f<a[0];f++)for(var m=0;m<a[2];m++)p.push(u.get(f,s,m));d=p.join(",")}if(o[d]!==void 0)l[s]=o[d];else{var g=Object.keys(o).length;o[d]=g,l[s]=g,c.push(s)}}var v=a.slice();v[1]=Object.keys(o).length;var b=new T.TensorBuffer(v,i);c.forEach(function(S,L){for(var N=0;N<a[0];N++)for(var C=0;C<a[2];C++)b.set(u.get(N,S,C),N,L,C)});var w=e.slice();return w[r]=v[1],{outputValues:b.values,outputShape:w,indices:l}}var Fz={__proto__:null,simpleAbsImpl:O0,addImpl:E0,ceilImpl:k0,expImpl:F0,expm1Impl:W0,floorImpl:U0,logImpl:B0,maxImpl:z0,multiplyImpl:P0,rsqrtImpl:M0,sliceImpl:H0,subImpl:V0,transposeImpl:ep,uniqueImpl:G0};var Wz="2.6.0";T.registerBackend("cpu",function(){return new R0},1);var Uz=$e(T.Acos,function(n){return Math.acos(n)}),Bz={kernelName:T.Acos,backendName:"cpu",kernelFunc:Uz};var zz=$e(T.Acosh,function(n){return Math.acosh(n)}),Pz={kernelName:T.Acosh,backendName:"cpu",kernelFunc:zz};var _z=$e(T.Asin,function(n){return Math.asin(n)}),Mz={kernelName:T.Asin,backendName:"cpu",kernelFunc:_z};var Hz=$e(T.Asinh,function(n){return Math.asinh(n)}),Vz={kernelName:T.Asinh,backendName:"cpu",kernelFunc:Hz};var qz=$e(T.Atan,function(n){return Math.atan(n)}),Gz={kernelName:T.Atan,backendName:"cpu",kernelFunc:qz};var Yz=$e(T.Atanh,function(n){return Math.atanh(n)}),jz={kernelName:T.Atanh,backendName:"cpu",kernelFunc:Yz};function tp(n,t,e,i,r,a){for(var s=r.strideHeight,o=r.strideWidth,l=r.dilationHeight,u=r.dilationWidth,c=r.effectiveFilterHeight,h=r.effectiveFilterWidth,d=r.padInfo.top,p=r.padInfo.left,f=a==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,m=T.buffer(r.outShape,e),g=m.values,v=r.outShape[1]*r.outShape[2]*r.outShape[3],b=r.outShape[2]*r.outShape[3],w=r.outShape[3],S=0;S<r.batchSize;++S)for(var L=S*v,N=S*i[0],C=0;C<r.inChannels;++C)for(var R=0;R<r.outHeight;++R)for(var D=R*s-d,k=Math.max(0,D),W=Math.min(r.inHeight,c+D),F=L+R*b,P=0;P<r.outWidth;++P){for(var H=P*o-p,_=Math.max(0,H),j=Math.min(r.inWidth,h+H),K=f,q=0,G=0,Z=k;Z<W;Z+=l){for(var X=N+Z*i[1],ee=_;ee<j;ee+=u){var ne=X+ee*i[2],ie=n[ne+C];a==="max"&&ie>K?K=ie:a==="avg"&&(q+=ie,G++)}if(isNaN(K))break}var te=F+P*w+C;g[te]=a==="avg"?q/G:K}return m}function Y0(n,t,e,i,r,a){r===void 0&&(r=!1),a===void 0&&(a=!1);for(var s=T.buffer(i.outShape,"int32"),o=i.strideHeight,l=i.strideWidth,u=i.dilationHeight,c=i.dilationWidth,h=i.effectiveFilterHeight,d=i.effectiveFilterWidth,p=i.padInfo.top,f=i.padInfo.left,m=T.buffer(t,e,n),g=0;g<i.batchSize;++g)for(var v=0;v<i.inChannels;++v)for(var b=0;b<i.outHeight;++b){for(var w=b*o-p,S=w;S<0;)S+=u;for(var L=Math.min(i.inHeight,h+w),N=0;N<i.outWidth;++N){for(var C=N*l-f,R=C;R<0;)R+=c;for(var D=Math.min(i.inWidth,d+C),k=Number.NEGATIVE_INFINITY,W=-1,F=S;F<L;F+=u)for(var P=F-w,H=R;H<D;H+=c){var _=H-C,j=m.get(g,F,H,v);j>k&&(k=j,r?W=a?((g*i.inHeight+F)*i.inWidth+H)*i.inChannels+v:(F*i.inWidth+H)*i.inChannels+v:W=P*d+_)}s.set(W,g,b,N,v)}}return s}function Kz(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x;ae(r,"avgPool");var a=i.filterSize,s=i.strides,o=i.pad,l=i.dimRoundingMode,u=1;T.util.assert(T.backend_util.eitherStridesOrDilationsAreOne(s,u),function(){return"Error in avgPool: Either strides or dilations must be 1. "+("Got strides "+s+" and dilations '"+u+"'")});var c=T.backend_util.computePool2DInfo(r.shape,a,s,u,o,l),h;if(c.filterWidth===1&&c.filterHeight===1&&T.util.arraysEqual(c.inShape,c.outShape))h=ca({inputs:{x:r},backend:e});else{var d=e.data.get(r.dataId).values,p=T.util.computeStrides(r.shape),f=tp(d,r.shape,r.dtype,p,c,"avg");h=e.makeTensorInfo(c.outShape,r.dtype,f.values)}return h}var $z={kernelName:T.AvgPool,backendName:"cpu",kernelFunc:Kz};function Xz(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.dy,a=t.input,s=a;ae([r,a],"avgPoolBackprop");for(var o=i.filterSize,l=i.strides,u=i.pad,c=T.backend_util.computePool2DInfo(s.shape,o,l,1,u),h=c.strideHeight,d=c.strideWidth,p=c.filterHeight,f=c.filterWidth,m=c.dilationHeight,g=c.dilationWidth,v=c.effectiveFilterHeight,b=c.effectiveFilterWidth,w=b-1-c.padInfo.left,S=v-1-c.padInfo.top,L=T.buffer(s.shape,"float32"),N=1/(p*f),C=e.data.get(r.dataId).values,R=T.buffer(r.shape,"float32",C),D=0;D<c.batchSize;++D)for(var k=0;k<c.inChannels;++k)for(var W=0;W<c.inHeight;++W)for(var F=0;F<c.inWidth;++F){for(var P=W-S,H=F-w,_=0,j=0;j<v;j+=m){var K=(P+j)/h;if(K<0||K>=c.outHeight||Math.floor(K)!==K)continue;for(var q=0;q<b;q+=g){var G=(H+q)/d;if(G<0||G>=c.outWidth||Math.floor(G)!==G)continue;var Z=R.get(D,K,G,k);_+=Z}}L.set(_*N,D,W,F,k)}return e.makeTensorInfo(L.shape,L.dtype,L.values)}var Jz={kernelName:T.AvgPoolBackprop,backendName:"cpu",kernelFunc:Xz};function Zz(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=t.scale,s=t.offset,o=t.mean,l=t.variance;T.util.assert(o.shape.length===l.shape.length,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),T.util.assert(s==null||o.shape.length===s.shape.length,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),T.util.assert(a==null||o.shape.length===a.shape.length,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}),ae([r,o,l,a,s],"batchNorm");var u=i.varianceEpsilon;u==null&&(u=.001);for(var c=e.data.get(r.dataId).values,h=e.data.get(o.dataId).values,d=e.data.get(l.dataId).values,p=a?e.data.get(a.dataId).values:new Float32Array([1]),f=s?e.data.get(s.dataId).values:new Float32Array([0]),m=new Float32Array(c.length),g=f.length,v=p.length,b=d.length,w=h.length,S=0,L=0,N=0,C=0,R=0;R<c.length;++R)m[R]=f[S++]+(c[R]-h[L++])*p[N++]/Math.sqrt(d[C++]+u),S>=g&&(S=0),L>=w&&(L=0),N>=v&&(N=0),C>=b&&(C=0);return e.makeTensorInfo(r.shape,r.dtype,m)}var Qz={kernelName:T.FusedBatchNorm,backendName:"cpu",kernelFunc:Zz};var eP=$e(T.ClipByValue,function(n,t){var e=t;return n>e.clipValueMax?e.clipValueMax:n<e.clipValueMin?e.clipValueMin:n}),tP={kernelName:T.ClipByValue,backendName:"cpu",kernelFunc:eP};function Zo(n){var t=n.inputs,e=n.backend,i=t.input,r=e.data.get(i.dataId).complexTensorInfos.imag,a=e.data.get(r.dataId).values;return e.makeTensorInfo(r.shape,r.dtype,a)}var nP={kernelName:T.Imag,backendName:"cpu",kernelFunc:Zo};function Wi(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=i.shape,s=T.util.sizeFromShape(r.shape),o=T.util.inferFromImplicitShape(a,s),l=T.util.sizeFromShape(o);T.util.assert(s===l,function(){return"The new shape ("+o+") has "+l+" elements and the old "+("shape ("+r.shape+") has "+s+" elements. The new shape and old ")+"shape must have the same number of elements."}),e.incRef(r.dataId);var u=e.data.get(r.dataId);if(u.complexTensorInfos!=null){var c=u.complexTensorInfos.real,h=u.complexTensorInfos.imag;c.shape=o,h.shape=o}return{dataId:r.dataId,shape:o,dtype:r.dtype}}var iP={kernelName:T.Reshape,backendName:"cpu",kernelFunc:Wi};function gs(n){var t=n.inputs,e=n.backend,i=n.attrs,r=i.axis,a=T.util.parseAxisParam(r,t[0].shape)[0],s=T.backend_util.computeOutShape(t.map(function(S){return S.shape}),a);if(T.util.sizeFromShape(s)===0)return e.makeTensorInfo(s,t[0].dtype,[]);var o=t.filter(function(S){return T.util.sizeFromShape(S.shape)>0});if(o.length===1)return o[0];var l=o.map(function(S){return S.shape});if(T.backend_util.assertParamsConsistent(l,a),o[0].dtype==="complex64"){var u=o.map(function(S){return fs({inputs:{input:S},backend:e})}),c=o.map(function(S){return Zo({inputs:{input:S},backend:e})}),h=gs({inputs:u,backend:e,attrs:{axis:r}}),d=gs({inputs:c,backend:e,attrs:{axis:r}}),p=Cn({inputs:{real:h,imag:d},backend:e});return u.forEach(function(S){return e.disposeIntermediateTensorInfo(S)}),c.forEach(function(S){return e.disposeIntermediateTensorInfo(S)}),e.disposeIntermediateTensorInfo(h),e.disposeIntermediateTensorInfo(d),p}var f=o.map(function(S){var L=T.util.sizeFromShape(S.shape.slice(a)),N=[-1,L];return Wi({inputs:{x:S},backend:e,attrs:{shape:N}})});s=T.backend_util.computeOutShape(f.map(function(S){return S.shape}),1);var m=T.util.getTypedArrayFromDType(o[0].dtype,T.util.sizeFromShape(s));if(f[0].shape[0]===1){var g=0;f.forEach(function(S){var L=e.data.get(S.dataId).values,N=T.util.sizeFromShape(S.shape);m.set(L,g),g+=N})}else{var v=0;f.forEach(function(S){for(var L=e.data.get(S.dataId).values,N=0,C=0;C<S.shape[0];++C)for(var R=C*s[1]+v,D=0;D<S.shape[1];++D)m[R+D]=L[N++];v+=S.shape[1]})}var b=T.backend_util.computeOutShape(o.map(function(S){return S.shape}),a),w=e.makeTensorInfo(b,t[0].dtype,m);return f.forEach(function(S){return e.disposeIntermediateTensorInfo(S)}),w}var rP={kernelName:T.Concat,backendName:"cpu",kernelFunc:gs};var aP=$e(T.Cos,function(n){return Math.cos(n)}),sP={kernelName:T.Cos,backendName:"cpu",kernelFunc:aP};var oP=$e(T.Cosh,function(n){return Math.cosh(n)}),lP={kernelName:T.Cosh,backendName:"cpu",kernelFunc:oP};var uP={kernelName:T.Dilation2D,backendName:"cpu",kernelFunc:function(n){for(var t=n.inputs,e=n.backend,i=n.attrs,r=t,a=r.x,s=r.filter,o=i,l=o.strides,u=o.pad,c=o.dilations,h=e,d=h.data.get(a.dataId).values,p=a.shape.length,f=h.data.get(s.dataId).values,m=s.shape.length,g=T.backend_util.computeDilation2DInfo(a.shape,s.shape,l,u,"NHWC",c),v=g.batchSize,b=g.inHeight,w=g.inWidth,S=g.inChannels,L=g.outHeight,N=g.outWidth,C=g.padInfo,R=g.strideHeight,D=g.strideWidth,k=g.filterHeight,W=g.filterWidth,F=g.dilationHeight,P=g.dilationWidth,H=g.outShape,_=T.util.sizeFromShape(H),j=H.length,K=T.util.getArrayFromDType(a.dtype,_),q=0;q<v;++q)for(var G=0;G<L;++G)for(var Z=G*R-C.top,X=0;X<N;++X)for(var ee=X*D-C.left,ne=0;ne<S;++ne){for(var ie=Number.MIN_SAFE_INTEGER,te=0;te<k;++te){var re=Z+te*F;if(re>=0&&re<b)for(var le=0;le<W;++le){var he=ee+le*P;if(he>=0&&he<w){var ye=T.util.locToIndex([q,re,he,ne],p,T.util.computeStrides(a.shape)),Oe=T.util.locToIndex([te,le,ne],m,T.util.computeStrides(s.shape)),Fe=d[ye]+f[Oe];Fe>ie&&(ie=Fe)}}}var _e=T.util.locToIndex([q,G,X,ne],j,T.util.computeStrides(H));K[_e]=ie}var Me=h.write(T.util.toTypedArray(K,a.dtype),H,a.dtype);return{dataId:Me,shape:H,dtype:a.dtype}}};var cP={kernelName:T.Dilation2DBackpropFilter,backendName:"cpu",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t,a=r.x,s=r.filter,o=r.dy,l=i,u=l.strides,c=l.pad,h=l.dilations,d=e,p=T.util.toNestedArray(a.shape,d.data.get(a.dataId).values),f=T.util.toNestedArray(s.shape,d.data.get(s.dataId).values),m=T.backend_util.computeDilation2DInfo(a.shape,s.shape,u,c,"NHWC",h),g=m.batchSize,v=m.inHeight,b=m.inWidth,w=m.inChannels,S=m.outHeight,L=m.outWidth,N=m.padInfo,C=m.strideHeight,R=m.strideWidth,D=m.filterHeight,k=m.filterWidth,W=m.dilationHeight,F=m.dilationWidth,P=m.outShape;T.util.assert(o.rank===P.length,function(){return"Error in "+T.Dilation2DBackpropFilter+", dy "+("must have the same rank as output "+P.length+", but got ")+(""+o.rank)});for(var H=T.util.toNestedArray(P,d.data.get(o.dataId).values),_=T.util.makeZerosNestedTypedArray(s.shape,s.dtype),j=0;j<g;++j)for(var K=0;K<S;++K)for(var q=K*C-N.top,G=0;G<L;++G)for(var Z=G*R-N.left,X=0;X<w;++X){for(var ee=Number.MIN_SAFE_INTEGER,ne=0,ie=0,te=0;te<D;++te){var re=q+te*W;if(re>=0&&re<v)for(var le=0;le<k;++le){var he=Z+le*F;if(he>=0&&he<b){var ye=p[j][re][he][X]+f[te][le][X];ye>ee&&(ee=ye,ne=te,ie=le)}}}_[ne][ie][X]+=H[j][K][G][X]}var Oe=d.write(T.util.toTypedArray(_,a.dtype),s.shape,s.dtype);return{dataId:Oe,shape:s.shape,dtype:s.dtype}}};var hP={kernelName:T.Dilation2DBackpropInput,backendName:"cpu",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t,a=r.x,s=r.filter,o=r.dy,l=i,u=l.strides,c=l.pad,h=l.dilations,d=e,p=T.util.toNestedArray(a.shape,d.data.get(a.dataId).values),f=T.util.toNestedArray(s.shape,d.data.get(s.dataId).values),m=T.backend_util.computeDilation2DInfo(a.shape,s.shape,u,c,"NHWC",h),g=m.batchSize,v=m.inHeight,b=m.inWidth,w=m.inChannels,S=m.outHeight,L=m.outWidth,N=m.padInfo,C=m.strideHeight,R=m.strideWidth,D=m.filterHeight,k=m.filterWidth,W=m.dilationHeight,F=m.dilationWidth,P=m.outShape;T.util.assert(o.rank===P.length,function(){return"Error in "+T.Dilation2DBackpropInput+", dy "+("must have the same rank as output "+P.length+", but got ")+(""+o.rank)});for(var H=T.util.toNestedArray(P,d.data.get(o.dataId).values),_=T.util.makeZerosNestedTypedArray(a.shape,a.dtype),j=0;j<g;++j)for(var K=0;K<S;++K)for(var q=K*C-N.top,G=0;G<L;++G)for(var Z=G*R-N.left,X=0;X<w;++X){for(var ee=Number.MIN_SAFE_INTEGER,ne=q<0?0:q,ie=Z<0?0:Z,te=0;te<D;++te){var re=q+te*W;if(re>=0&&re<v)for(var le=0;le<k;++le){var he=Z+le*F;if(he>=0&&he<b){var ye=p[j][re][he][X]+f[te][le][X];ye>ee&&(ee=ye,ne=re,ie=he)}}}_[j][ne][ie][X]+=H[j][K][G][X]}var Oe=d.write(T.util.toTypedArray(_,a.dtype),a.shape,a.dtype);return{dataId:Oe,shape:a.shape,dtype:a.dtype}}};var dP=wr(function(n,t){return n/t}),pP=ha(T.Div,dP),np={kernelName:T.Div,backendName:"cpu",kernelFunc:pP};var fP=$e(T.Elu,function(n){return n>=0?n:Math.exp(n)-1}),mP={kernelName:T.Elu,backendName:"cpu",kernelFunc:fP};var gP=T.backend_util.ERF_P,vP=T.backend_util.ERF_A1,yP=T.backend_util.ERF_A2,bP=T.backend_util.ERF_A3,wP=T.backend_util.ERF_A4,SP=T.backend_util.ERF_A5,LP=$e(T.Erf,function(n){var t=Math.sign(n),e=Math.abs(n),i=1/(1+gP*e);return t*(1-((((SP*i+wP)*i+bP)*i+yP)*i+vP)*i*Math.exp(-e*e))}),IP={kernelName:T.Erf,backendName:"cpu",kernelFunc:LP};function j0(n,t,e){for(var i=n.shape,r=i[0],a=i[1],s=e.data.get(n.dataId),o=s.complexTensorInfos.real,l=s.complexTensorInfos.imag,u=[r,a],c=T.util.sizeFromShape(u),h=T.util.getTypedArrayFromDType("float32",c),d=T.util.getTypedArrayFromDType("float32",c),p=0;p<r;p++){for(var f=Qd({inputs:{x:o},backend:e,attrs:{begin:[p,0],size:[1,a]}}),m=Qd({inputs:{x:l},backend:e,attrs:{begin:[p,0],size:[1,a]}}),g=Cn({inputs:{real:f,imag:m},backend:e}),v=AP(g,t,e),b=v.real,w=v.imag,S=T.backend_util.mergeRealAndImagArrays(b,w),L=0;L<a;L++){var N=T.backend_util.getComplexWithIndex(S,L);h[p*a+L]=N.real,d[p*a+L]=N.imag}e.disposeIntermediateTensorInfo(f),e.disposeIntermediateTensorInfo(m),e.disposeIntermediateTensorInfo(g)}var C=e.makeTensorInfo(u,"float32",h),R=e.makeTensorInfo(u,"float32",d),D=Cn({inputs:{real:C,imag:R},backend:e});return e.disposeIntermediateTensorInfo(C),e.disposeIntermediateTensorInfo(R),D}function AP(n,t,e){var i=T.util.sizeFromShape(n.shape),r=e.data.get(n.dataId),a=e.data.get(r.complexTensorInfos.real.dataId).values,s=e.data.get(r.complexTensorInfos.imag.dataId).values;if(TP(i)){var o=ip(a,s,i,t,e),l=[n.shape[0],n.shape[1]];if(t){var u=e.makeTensorInfo(l,"float32",o.real),c=e.makeTensorInfo(l,"float32",o.imag),h=e.makeTensorInfo([],"float32",T.util.createScalarValue(i,"float32")),d=ca({inputs:{x:h},backend:e}),p=np.kernelFunc({inputs:{a:u,b:h},backend:e}),f=np.kernelFunc({inputs:{a:c,b:d},backend:e}),m=e.data.get(p.dataId).values,g=e.data.get(f.dataId).values;return e.disposeIntermediateTensorInfo(u),e.disposeIntermediateTensorInfo(c),e.disposeIntermediateTensorInfo(h),e.disposeIntermediateTensorInfo(d),e.disposeIntermediateTensorInfo(p),e.disposeIntermediateTensorInfo(f),{real:m,imag:g}}return o}else{var v=T.backend_util.mergeRealAndImagArrays(a,s),b=NP(v,i,t);return T.backend_util.splitRealAndImagArrays(b)}}function TP(n){return(n&n-1)===0}function ip(n,t,e,i,r){if(e===1)return{real:n,imag:t};var a=T.backend_util.mergeRealAndImagArrays(n,t),s=e/2,o=T.backend_util.complexWithEvenIndex(a),l=o.real,u=o.imag,c=[l.length],h=r.makeTensorInfo(c,"float32",l),d=r.makeTensorInfo(c,"float32",u),p=Cn({inputs:{real:h,imag:d},backend:r}),f=T.backend_util.complexWithOddIndex(a),m=f.real,g=f.imag,v=[m.length],b=r.makeTensorInfo(v,"float32",m),w=r.makeTensorInfo(v,"float32",g),S=Cn({inputs:{real:b,imag:w},backend:r}),L=ip(l,u,s,i,r),N=L.real,C=L.imag,R=[N.length],D=r.makeTensorInfo(R,"float32",N),k=r.makeTensorInfo(R,"float32",C),W=Cn({inputs:{real:D,imag:k},backend:r}),F=ip(m,g,s,i,r),P=F.real,H=F.imag,_=[P.length],j=r.makeTensorInfo(_,"float32",P),K=r.makeTensorInfo(_,"float32",H),q=Cn({inputs:{real:j,imag:K},backend:r}),G=T.backend_util.exponents(e,i),Z=[G.real.length],X=r.makeTensorInfo(Z,"float32",G.real),ee=r.makeTensorInfo(Z,"float32",G.imag),ne=Cn({inputs:{real:X,imag:ee},backend:r}),ie=_0({inputs:{a:ne,b:q},backend:r}),te=D0({inputs:{a:W,b:ie},backend:r}),re=q0({inputs:{a:W,b:ie},backend:r}),le=fs({inputs:{input:te},backend:r}),he=fs({inputs:{input:re},backend:r}),ye=Zo({inputs:{input:te},backend:r}),Oe=Zo({inputs:{input:re},backend:r}),Fe=gs({inputs:[le,he],backend:r,attrs:{axis:0}}),_e=gs({inputs:[ye,Oe],backend:r,attrs:{axis:0}}),Me=r.data.get(Fe.dataId).values,dt=r.data.get(_e.dataId).values;return r.disposeIntermediateTensorInfo(h),r.disposeIntermediateTensorInfo(d),r.disposeIntermediateTensorInfo(p),r.disposeIntermediateTensorInfo(b),r.disposeIntermediateTensorInfo(w),r.disposeIntermediateTensorInfo(S),r.disposeIntermediateTensorInfo(D),r.disposeIntermediateTensorInfo(k),r.disposeIntermediateTensorInfo(W),r.disposeIntermediateTensorInfo(j),r.disposeIntermediateTensorInfo(K),r.disposeIntermediateTensorInfo(q),r.disposeIntermediateTensorInfo(X),r.disposeIntermediateTensorInfo(ee),r.disposeIntermediateTensorInfo(ne),r.disposeIntermediateTensorInfo(ie),r.disposeIntermediateTensorInfo(te),r.disposeIntermediateTensorInfo(re),r.disposeIntermediateTensorInfo(le),r.disposeIntermediateTensorInfo(ye),r.disposeIntermediateTensorInfo(he),r.disposeIntermediateTensorInfo(Oe),r.disposeIntermediateTensorInfo(Fe),r.disposeIntermediateTensorInfo(_e),{real:Me,imag:dt}}function NP(n,t,e){for(var i=new Float32Array(t*2),r=0;r<t;r++){for(var a=0,s=0,o=0;o<t;o++){var l=T.backend_util.exponent(r*o,t,e),u=T.backend_util.getComplexWithIndex(n,o);a+=u.real*l.real-u.imag*l.imag,s+=u.real*l.imag+u.imag*l.real}e&&(a/=t,s/=t),T.backend_util.assignToTypedArray(i,a,s,r)}return i}function xP(n){var t=n.inputs,e=n.backend,i=t.input,r=T.util.sizeFromShape(i.shape),a=i.shape[i.shape.length-1],s=r/a,o=Wi({inputs:{x:i},backend:e,attrs:{shape:[s,a]}}),l=j0(o,!1,e),u=Wi({inputs:{x:l},backend:e,attrs:{shape:i.shape}});return e.disposeIntermediateTensorInfo(o),e.disposeIntermediateTensorInfo(l),u}var CP={kernelName:T.FFT,backendName:"cpu",kernelFunc:xP};var RP={kernelName:T.FlipLeftRight,backendName:"cpu",kernelFunc:function(n){for(var t=n.inputs,e=n.attrs,i=n.backend,r=t.image,a=i,s=T.util.getTypedArrayFromDType(r.dtype,T.util.sizeFromShape(r.shape)),o=r.shape,l=o[0],u=o[1],c=o[2],h=o[3],d=a.data.get(r.dataId).values,p=0;p<l;p++)for(var f=p*c*u*h,m=0;m<u;m++)for(var g=m*(c*h),v=0;v<c;v++)for(var b=v*h,w=0;w<h;w++){var S=[l,m,v,w],L=S[2],N=Math.round(c-L),C=f+g+b+w,R=d[C];if(N>=0&&N<c){var D=N*h,k=f+g+D+w;R=d[k]}s[C]=R}var W=a.write(s,r.shape,r.dtype);return{dataId:W,shape:r.shape,dtype:r.dtype}}};function OP(n){var t=n.inputs,e=n.backend,i=t.input,r=T.util.sizeFromShape(i.shape),a=i.shape[i.shape.length-1],s=r/a,o=Wi({inputs:{x:i},backend:e,attrs:{shape:[s,a]}}),l=j0(o,!0,e),u=Wi({inputs:{x:l},backend:e,attrs:{shape:i.shape}});return e.disposeIntermediateTensorInfo(o),e.disposeIntermediateTensorInfo(l),u}var EP={kernelName:T.IFFT,backendName:"cpu",kernelFunc:OP};var DP=$e(T.IsFinite,function(n){return Number.isFinite(n)?1:0},"bool"),kP={kernelName:T.IsFinite,backendName:"cpu",kernelFunc:DP};var FP=$e(T.IsInf,function(n){return Math.abs(n)===Infinity?1:0},"bool"),WP={kernelName:T.IsInf,backendName:"cpu",kernelFunc:FP};var UP=$e(T.IsNan,function(n){return Number.isNaN(n)?1:0},"bool"),BP={kernelName:T.IsNan,backendName:"cpu",kernelFunc:UP};var zP=$e(T.Log1p,function(n){return Math.log1p(n)}),PP={kernelName:T.Log1p,backendName:"cpu",kernelFunc:zP};var _P=$e(T.LogicalNot,function(n){return n?0:1},"bool"),MP={kernelName:T.LogicalNot,backendName:"cpu",kernelFunc:_P};var HP={kernelName:T.Max,backendName:"cpu",kernelFunc:function(n){var t=n.inputs,e=n.attrs,i=n.backend,r=t.x,a=e,s=a.reductionIndices,o=a.keepDims,l=i,u=r.shape,c=u.length,h=T.util.parseAxisParam(s,u),d=h,p=T.backend_util.getAxesPermutation(d,c),f=l.data.get(r.dataId).values;if(p!=null){for(var m=new Array(c),g=0;g<m.length;g++)m[g]=u[p[g]];f=ep(f,u,r.dtype,p,m),d=T.backend_util.getInnerMostAxes(d.length,c),u=m}ae(r,"max"),T.backend_util.assertAxesAreInnerMostDims("max",d,c);var v=T.backend_util.computeOutAndReduceShapes(u,d),b=v[0],w=v[1],S=T.util.sizeFromShape(w),L=z0(f,S,b,r.dtype),N=l.write(L,b,r.dtype),C=b;if(o){var m=T.backend_util.expandShapeToKeepDim(b,h);C=m}return{dataId:N,shape:C,dtype:r.dtype}}};function VP(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x;ae(r,"maxPool");var a=i.filterSize,s=i.strides,o=i.pad,l=i.dimRoundingMode,u=1;T.util.assert(T.backend_util.eitherStridesOrDilationsAreOne(s,u),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+s+" and dilations '"+u+"'")});var c=T.backend_util.computePool2DInfo(r.shape,a,s,u,o,l),h;if(c.filterWidth===1&&c.filterHeight===1&&T.util.arraysEqual(c.inShape,c.outShape))h=ca({inputs:{x:r},backend:e});else{var d=e.data.get(r.dataId).values,p=T.util.computeStrides(r.shape),f=tp(d,r.shape,r.dtype,p,c,"max");h=e.makeTensorInfo(c.outShape,r.dtype,f.values)}return h}var qP={kernelName:T.MaxPool,backendName:"cpu",kernelFunc:VP};function GP(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.dy,a=t.input,s=t.output,o=a;ae([a,s],"maxPoolBackprop");for(var l=i.filterSize,u=i.strides,c=i.pad,h=i.dimRoundingMode,d=T.backend_util.computePool2DInfo(o.shape,l,u,1,c,h),p=e.data.get(o.dataId).values,f=T.buffer(d.outShape,o.dtype,Y0(p,o.shape,o.dtype,d).values),m=d.strideHeight,g=d.strideWidth,v=d.dilationHeight,b=d.dilationWidth,w=d.effectiveFilterHeight,S=d.effectiveFilterWidth,L=S-1-d.padInfo.left,N=w-1-d.padInfo.top,C=T.buffer(o.shape,"float32"),R=e.data.get(r.dataId).values,D=T.buffer(r.shape,"float32",R),k=0;k<d.batchSize;++k)for(var W=0;W<d.inChannels;++W)for(var F=0;F<d.inHeight;++F)for(var P=0;P<d.inWidth;++P){for(var H=F-N,_=P-L,j=0,K=0;K<w;K+=v){var q=(H+K)/m;if(q<0||q>=d.outHeight||Math.floor(q)!==q)continue;for(var G=0;G<S;G+=b){var Z=(_+G)/g;if(Z<0||Z>=d.outWidth||Math.floor(Z)!==Z)continue;var X=w*S-1-f.get(k,q,Z,W),ee=K*S+G,ne=X===ee?1:0;if(ne===0)continue;var ie=D.get(k,q,Z,W);j+=ie*ne}}C.set(j,k,F,P,W)}return e.makeTensorInfo(C.shape,C.dtype,C.values)}var YP={kernelName:T.MaxPoolBackprop,backendName:"cpu",kernelFunc:GP};function jP(n,t,e,i,r){var a=T.util.computeStrides(t),s=tp(n,t,e,a,r,"max"),o=Y0(n,t,e,r,!0,i);return[s.values,o.values]}var KP={kernelName:T.MaxPoolWithArgmax,backendName:"cpu",kernelFunc:function(n){var t=n.inputs,e=n.attrs,i=n.backend,r=t.x,a=e,s=a.filterSize,o=a.strides,l=a.pad,u=a.includeBatchInIndex,c=i;ae(r,"MaxPoolWithArgmax");var h=c.data.get(r.dataId).values,d=T.backend_util.computePool2DInfo(r.shape,s,o,[1,1],l),p=jP(h,r.shape,r.dtype,u,d),f=p[0],m=p[1],g=c.write(f,d.outShape,r.dtype),v=c.write(m,d.outShape,r.dtype);return[{dataId:g,shape:d.outShape,dtype:r.dtype},{dataId:v,shape:d.outShape,dtype:"int32"}]}};var $P=T.kernel_impls.nonMaxSuppressionV4Impl,XP={kernelName:T.NonMaxSuppressionV4,backendName:"cpu",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t,a=r.boxes,s=r.scores,o=i,l=o.maxOutputSize,u=o.iouThreshold,c=o.scoreThreshold,h=o.padToMaxOutputSize,d=e;ae(a,"NonMaxSuppressionPadded");var p=d.data.get(a.dataId).values,f=d.data.get(s.dataId).values,m=$P(p,f,l,u,c,h),g=m.selectedIndices,v=m.validOutputs;return[g,v]}};var JP=T.kernel_impls.nonMaxSuppressionV5Impl,ZP={kernelName:T.NonMaxSuppressionV5,backendName:"cpu",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t,a=r.boxes,s=r.scores,o=i,l=o.maxOutputSize,u=o.iouThreshold,c=o.scoreThreshold,h=o.softNmsSigma,d=e;ae(a,"NonMaxSuppressionWithScore");var p=d.data.get(a.dataId).values,f=d.data.get(s.dataId).values,m=l,g=u,v=c,b=h,w=JP(p,f,m,g,v,b),S=w.selectedIndices,L=w.selectedScores;return[S,L]}};var QP=wr(function(n,t){return n!==t?1:0}),e_=ha(T.NotEqual,QP,null,"bool"),t_={kernelName:T.NotEqual,backendName:"cpu",kernelFunc:e_};function n_(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=i.paddings,s=i.constantValue;ae(r,"pad");var o=a.map(function(N,C){return N[0]+r.shape[C]+N[1]}),l=a.map(function(N){return N[0]}),u=e.data.get(r.dataId).values,c=T.util.sizeFromShape(r.shape),h=r.shape.length,d=T.util.computeStrides(r.shape),p=T.util.sizeFromShape(o),f=o.length,m=T.util.computeStrides(o),g=T.util.getTypedArrayFromDType(r.dtype,p);s!==0&&g.fill(s);for(var v=0;v<c;v++){var b=T.util.indexToLoc(v,h,d),w=b.map(function(N,C){return N+l[C]}),S=T.util.locToIndex(w,f,m);g[S]=u[v]}var L=e.write(g,o,r.dtype);return{dataId:L,shape:o,dtype:r.dtype}}var K0={kernelName:T.PadV2,backendName:"cpu",kernelFunc:n_};var i_=$e(T.Reciprocal,function(n){return 1/n}),r_={kernelName:T.Reciprocal,backendName:"cpu",kernelFunc:i_};var a_={kernelName:T.RotateWithOffset,backendName:"cpu",kernelFunc:function(n){for(var t=n.inputs,e=n.attrs,i=n.backend,r=t.image,a=e,s=a.radians,o=a.fillValue,l=a.center,u=i,c=T.util.getTypedArrayFromDType(r.dtype,T.util.sizeFromShape(r.shape)),h=r.shape,d=h[0],p=h[1],f=h[2],m=h[3],g=T.backend_util.getImageCenter(l,p,f),v=g[0],b=g[1],w=255,S=Math.sin(s),L=Math.cos(s),N=u.data.get(r.dataId).values,C=0;C<d;C++)for(var R=C*f*p*m,D=0;D<p;D++)for(var k=D*(f*m),W=0;W<f;W++)for(var F=W*m,P=0;P<m;P++){var H=[d,D,W,P],_=H[2],j=H[1],K=(_-v)*L-(j-b)*S,q=(_-v)*S+(j-b)*L;K=Math.round(K+v),q=Math.round(q+b);var G=o;if(typeof o!="number"&&(P===3?G=w:G=o[P]),K>=0&&K<f&&q>=0&&q<p){var Z=q*(f*m),X=K*m,ee=R+Z+X+P;G=N[ee]}var ne=R+k+F+P;c[ne]=G}var ie=u.write(c,r.shape,r.dtype);return{dataId:ie,shape:r.shape,dtype:r.dtype}}};var s_=$e(T.Round,function(n){var t=Math.floor(n);return n-t<.5?Math.floor(n):n-t>.5?Math.ceil(n):t%2===0?t:t+1}),o_={kernelName:T.Round,backendName:"cpu",kernelFunc:s_};var l_=T.backend_util.SELU_SCALEALPHA,u_=T.backend_util.SELU_SCALE,c_=$e(T.Selu,function(n){return n>=0?u_*n:l_*(Math.exp(n)-1)}),h_={kernelName:T.Selu,backendName:"cpu",kernelFunc:c_};var d_=$e(T.Sigmoid,function(n){return 1/(1+Math.exp(-n))}),p_={kernelName:T.Sigmoid,backendName:"cpu",kernelFunc:d_};var f_=$e(T.Sign,function(n){return n<0?-1:n>0?1:0}),m_={kernelName:T.Sign,backendName:"cpu",kernelFunc:f_};var g_=$e(T.Sin,function(n){return Math.sin(n)}),v_={kernelName:T.Sin,backendName:"cpu",kernelFunc:g_};var y_=$e(T.Sinh,function(n){return Math.sinh(n)}),b_={kernelName:T.Sinh,backendName:"cpu",kernelFunc:y_};var w_=11920928955078125e-23,$0=Math.log(w_)+2,S_=$e(T.Softplus,function(n){var t=n>-$0,e=n<$0,i=Math.exp(n),r;return e?r=i:t?r=n:r=Math.log(1+i),r}),L_={kernelName:T.Softplus,backendName:"cpu",kernelFunc:S_};function X0(n){var t=n.inputs,e=n.attrs,i=n.backend,r=t.x,a=e.perm;ae(r,"transpose");for(var s=r.shape.length,o=new Array(s),l=0;l<o.length;l++)o[l]=r.shape[a[l]];var u=i.data.get(r.dataId).values,c=ep(u,r.shape,r.dtype,a,o),h=i.write(c,o,r.dtype);return{dataId:h,shape:o,dtype:r.dtype}}var I_={kernelName:T.Transpose,backendName:"cpu",kernelFunc:X0};function A_(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=i.blockShape,s=i.paddings;ae([r],"spaceToBatchND");var o=T.util.sizeFromShape(a),l=[[0,0]];l.push.apply(l,s);for(var u=1+a.length;u<r.shape.length;++u)l.push([0,0]);var c=K0.kernelFunc({inputs:{x:r},backend:e,attrs:{paddings:l,constantValue:0}}),h=T.backend_util.getReshaped(c.shape,a,o,!1),d=T.backend_util.getPermuted(h.length,a.length,!1),p=T.backend_util.getReshapedPermuted(c.shape,a,o,!1),f={x:c},m={shape:h},g=Wi({inputs:f,backend:e,attrs:m}),v={x:g},b={perm:d},w=X0({inputs:v,backend:e,attrs:b}),S={x:w},L={shape:p},N=Wi({inputs:S,backend:e,attrs:L});return e.disposeIntermediateTensorInfo(c),e.disposeIntermediateTensorInfo(g),e.disposeIntermediateTensorInfo(w),N}var T_={kernelName:T.SpaceToBatchND,backendName:"cpu",kernelFunc:A_};var N_=$e(T.Sqrt,function(n){return Math.sqrt(n)}),x_={kernelName:T.Sqrt,backendName:"cpu",kernelFunc:N_};var C_={kernelName:T.Square,backendName:"cpu",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=t.x,r=e;ae(i,"square");for(var a=r.data.get(i.dataId).values,s=new Float32Array(a.length),o=0;o<a.length;++o){var l=a[o];s[o]=l*l}var u=r.write(s,i.shape,i.dtype);return{dataId:u,shape:i.shape,dtype:i.dtype}}};var R_=wr(function(n,t){var e=n-t;return e*e}),O_=ha(T.SquaredDifference,R_),E_={kernelName:T.SquaredDifference,backendName:"cpu",kernelFunc:O_};var D_=$e(T.Step,function(n,t){var e=t;return isNaN(n)?NaN:n>0?1:e.alpha}),k_={kernelName:T.Step,backendName:"cpu",kernelFunc:D_};var F_=$e(T.Tan,function(n){return Math.tan(n)}),W_={kernelName:T.Tan,backendName:"cpu",kernelFunc:F_};var U_=$e(T.Tanh,function(n){return Math.tanh(n)}),B_={kernelName:T.Tanh,backendName:"cpu",kernelFunc:U_};function z_(n){var t=n.inputs,e=n.attrs,i=n.backend,r=e.axis,a=t.x;ae(a,"unique");var s=i.data.get(a.dataId).values,o=G0(s,r,a.shape,a.dtype),l=o.outputValues,u=o.outputShape,c=o.indices;return[i.makeTensorInfo(u,a.dtype,l),i.makeTensorInfo([c.length],"int32",c)]}var P_={kernelName:T.Unique,backendName:"cpu",kernelFunc:z_};var __=[cz,Bz,Pz,gz,Mz,Vz,Gz,jz,$z,Jz,Qz,fz,yz,tP,hz,rP,sP,lP,uP,hP,cP,np,mP,IP,wz,Lz,CP,RP,Az,dz,EP,nP,kP,WP,BP,Nz,PP,MP,qP,YP,KP,HP,Cz,XP,ZP,t_,K0,pz,r_,iP,a_,o_,Oz,h_,p_,m_,v_,b_,Ez,L_,T_,x_,C_,E_,k_,kz,W_,B_,I_,P_];for(var rp=0,J0=__;rp<J0.length;rp++){var M_=J0[rp];T.registerKernel(M_)}ps.MathBackendCPU=R0;ps.shared=Fz;ps.version_cpu=Wz});var FL=Le(qn=>{"use strict";Object.defineProperty(qn,"__esModule",{value:!0});var x=lr();var ap=function(n,t){return ap=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var r in i)i.hasOwnProperty(r)&&(e[r]=i[r])},ap(n,t)};function H_(n,t){ap(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function Qo(n,t,e,i){function r(a){return a instanceof e?a:new e(function(s){s(a)})}return new(e||(e=Promise))(function(a,s){function o(c){try{u(i.next(c))}catch(h){s(h)}}function l(c){try{u(i.throw(c))}catch(h){s(h)}}function u(c){c.done?a(c.value):r(c.value).then(o,l)}u((i=i.apply(n,t||[])).next())})}function el(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,r,a,s;return s={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(u){return function(c){return l([u,c])}}function l(u){if(i)throw new TypeError("Generator is already executing.");for(;e;)try{if(i=1,r&&(a=u[0]&2?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;(r=0,a)&&(u=[u[0]&2,a.value]);switch(u[0]){case 0:case 1:a=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,r=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){e.label=u[1];break}if(u[0]===6&&e.label<a[1]){e.label=a[1],a=u;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(u);break}a[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(n,e)}catch(c){u=[6,c],r=0}finally{i=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}var Sr={},sp={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function Q0(n,t){Sr[n]=t}function Gn(n){if(!(n in Sr)){var t=V_(n);if(t!==null)Sr[n]=t;else return console.log("Could not get context for WebGL version",n),null}var e=Sr[n];return e.isContextLost()?(delete Sr[n],Gn(n)):(e.disable(e.DEPTH_TEST),e.disable(e.STENCIL_TEST),e.disable(e.BLEND),e.disable(e.DITHER),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SAMPLE_COVERAGE),e.enable(e.SCISSOR_TEST),e.enable(e.CULL_FACE),e.cullFace(e.BACK),Sr[n])}function q_(n){if(typeof OffscreenCanvas!="undefined"&&n===2)return new OffscreenCanvas(300,150);if(typeof document!="undefined")return document.createElement("canvas");throw new Error("Cannot create a canvas in this context")}function V_(n){if(n!==1&&n!==2)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var t=q_(n);return t.addEventListener("webglcontextlost",function(e){e.preventDefault(),delete Sr[n]},!1),n===1?t.getContext("webgl",sp)||t.getContext("experimental-webgl",sp):t.getContext("webgl2",sp)}var vs;(function(n){n[n.DENSE=0]="DENSE",n[n.SHARED_BATCH=1]="SHARED_BATCH"})(vs||(vs={}));var on;(function(n){n[n.RENDER=0]="RENDER",n[n.UPLOAD=1]="UPLOAD",n[n.PIXELS=2]="PIXELS",n[n.DOWNLOAD=3]="DOWNLOAD"})(on||(on={}));var Ot;(function(n){n[n.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",n[n.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",n[n.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",n[n.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",n[n.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16"})(Ot||(Ot={}));function ys(n,t){return[t,n]}function G_(n,t){return n*t}function bs(n){var t=x.util.sizeFromShape(n),e=Math.ceil(t/4);return x.util.sizeToSquarishShape(e)}function fa(n,t){return[Math.max(1,Math.ceil(t/2)),Math.max(1,Math.ceil(n/2))]}function Y_(n,t){var e=fa(n,t),i=e[0],r=e[1];return i*r*4}function op(n,t){var e=n,i,r,a,s,o,l,u,c,h,d;return x.env().getNumber("WEBGL_VERSION")===2?(i=e.R32F,r=e.R16F,a=e.RGBA16F,s=e.RGBA32F,o=e.RED,u=4,c=1,h=e.HALF_FLOAT,d=e.FLOAT):(i=n.RGBA,r=n.RGBA,a=n.RGBA,s=e.RGBA,o=n.RGBA,u=4,c=4,h=t!=null?t.HALF_FLOAT_OES:null,d=n.FLOAT),l=n.RGBA,{internalFormatFloat:i,internalFormatHalfFloat:r,internalFormatPackedHalfFloat:a,internalFormatPackedFloat:s,textureFormatFloat:o,downloadTextureFormat:l,downloadUnpackNumChannels:u,defaultNumChannels:c,textureTypeHalfFloat:h,textureTypeFloat:d}}function ce(n,t){var e=t();return x.env().getBool("DEBUG")&&j_(n),e}function j_(n){var t=n.getError();if(t!==n.NO_ERROR)throw new Error("WebGL Error: "+eS(n,t))}var K_=596e-10,$_=65504;function tS(n){return!!(x.env().getBool("WEBGL_RENDER_FLOAT32_ENABLED")||n===0||K_<Math.abs(n)&&Math.abs(n)<$_)}function eS(n,t){switch(t){case n.NO_ERROR:return"NO_ERROR";case n.INVALID_ENUM:return"INVALID_ENUM";case n.INVALID_VALUE:return"INVALID_VALUE";case n.INVALID_OPERATION:return"INVALID_OPERATION";case n.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case n.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case n.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"Unknown error code "+t}}function ws(n,t){return li(n,function(){return n.getExtension(t)},'Extension "'+t+'" not supported on this browser.')}function nS(n,t){var e=li(n,function(){return n.createShader(n.VERTEX_SHADER)},"Unable to create vertex WebGLShader.");if(ce(n,function(){return n.shaderSource(e,t)}),ce(n,function(){return n.compileShader(e)}),n.getShaderParameter(e,n.COMPILE_STATUS)===!1)throw console.log(n.getShaderInfoLog(e)),new Error("Failed to compile vertex shader.");return e}function iS(n,t){var e=li(n,function(){return n.createShader(n.FRAGMENT_SHADER)},"Unable to create fragment WebGLShader.");if(ce(n,function(){return n.shaderSource(e,t)}),ce(n,function(){return n.compileShader(e)}),n.getShaderParameter(e,n.COMPILE_STATUS)===!1)throw X_(t,n.getShaderInfoLog(e)),new Error("Failed to compile fragment shader.");return e}var J_=/ERROR: [0-9]+:([0-9]+):/g;function X_(n,t){var e=J_.exec(t);if(e==null){console.log("Couldn't parse line number in error: "+t),console.log(n);return}for(var i=+e[1],r=n.split(`
|
|
`),a=r.length.toString().length+2,s=r.map(function(d,p){return x.util.rightPad((p+1).toString(),a)+d}),o=0,l=0;l<s.length;l++)o=Math.max(s[l].length,o);var u=s.slice(0,i-1),c=s.slice(i-1,i),h=s.slice(i);console.log(u.join(`
|
|
`)),console.log(t.split(`
|
|
`)[0]),console.log("%c "+x.util.rightPad(c[0],o),"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(h.join(`
|
|
`))}function rS(n){return li(n,function(){return n.createProgram()},"Unable to create WebGLProgram.")}function aS(n,t){if(ce(n,function(){return n.linkProgram(t)}),n.getProgramParameter(t,n.LINK_STATUS)===!1)throw console.log(n.getProgramInfoLog(t)),new Error("Failed to link vertex and fragment shaders.")}function tl(n,t){if(ce(n,function(){return n.validateProgram(t)}),n.getProgramParameter(t,n.VALIDATE_STATUS)===!1)throw console.log(n.getProgramInfoLog(t)),new Error("Shader program validation failed.")}function sS(n,t){var e=li(n,function(){return n.createBuffer()},"Unable to create WebGLBuffer");return ce(n,function(){return n.bindBuffer(n.ARRAY_BUFFER,e)}),ce(n,function(){return n.bufferData(n.ARRAY_BUFFER,t,n.STATIC_DRAW)}),e}function oS(n,t){var e=li(n,function(){return n.createBuffer()},"Unable to create WebGLBuffer");return ce(n,function(){return n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,e)}),ce(n,function(){return n.bufferData(n.ELEMENT_ARRAY_BUFFER,t,n.STATIC_DRAW)}),e}function Z_(){return x.env().getNumber("WEBGL_VERSION")===2?1:4}function lS(n){return li(n,function(){return n.createTexture()},"Unable to create WebGLTexture.")}function uS(n,t){var e=x.env().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(n<=0||t<=0){var i="["+n+"x"+t+"]";throw new Error("Requested texture size "+i+" is invalid.")}if(n>e||t>e){var i="["+n+"x"+t+"]",r="["+e+"x"+e+"]";throw new Error("Requested texture size "+i+" greater than WebGL maximum on this browser / GPU "+r+".")}}function cS(n){return li(n,function(){return n.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function lp(n,t,e,i,r,a,s){var o=n.getAttribLocation(t,e);return o===-1?!1:(ce(n,function(){return n.bindBuffer(n.ARRAY_BUFFER,i)}),ce(n,function(){return n.vertexAttribPointer(o,r,n.FLOAT,!1,a,s)}),ce(n,function(){return n.enableVertexAttribArray(o)}),!0)}function dS(n,t,e){hS(n,e),ce(n,function(){return n.activeTexture(n.TEXTURE0+e)}),ce(n,function(){return n.bindTexture(n.TEXTURE_2D,t)})}function Q_(n,t){hS(n,t),ce(n,function(){return n.activeTexture(n.TEXTURE0+t)}),ce(n,function(){return n.bindTexture(n.TEXTURE_2D,null)})}function pS(n,t,e){return li(n,function(){return n.getUniformLocation(t,e)},'uniform "'+e+'" not present in program.')}function fS(n,t,e){return n.getUniformLocation(t,e)}function mS(n,t,e,i){ce(n,function(){return dS(n,t,i)}),ce(n,function(){return n.uniform1i(e,i)})}function eM(n){ce(n,function(){return n.bindFramebuffer(n.FRAMEBUFFER,null)}),ce(n,function(){return n.viewport(0,0,n.canvas.width,n.canvas.height)}),ce(n,function(){return n.scissor(0,0,n.canvas.width,n.canvas.height)})}function nl(n,t,e){ce(n,function(){return n.bindFramebuffer(n.FRAMEBUFFER,e)}),ce(n,function(){return n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,t,0)})}function up(n,t){ce(n,function(){return n.bindFramebuffer(n.FRAMEBUFFER,t)}),ce(n,function(){return n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,null,0)})}function Ss(n){var t=n.checkFramebufferStatus(n.FRAMEBUFFER);if(t!==n.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+gS(n,t))}function gS(n,t){switch(t){case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+t}}function li(n,t,e){var i=ce(n,function(){return t()});if(i==null)throw new Error(e);return i}function hS(n,t){var e=n.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,i=t+n.TEXTURE0;if(i<n.TEXTURE0||i>e){var r="[gl.TEXTURE0, gl.TEXTURE"+e+"]";throw new Error("textureUnit must be in "+r+".")}}function Lr(n,t){return t===void 0&&(t=2),x.util.sizeFromShape(n.slice(0,n.length-t))}function Ir(n){if(n.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[n.length>1?n[n.length-2]:1,n[n.length-1]]}function il(n){var t=[1,1,1],e=n.length===0||n.length===1&&n[0]===1;return e||(t=[Lr(n)].concat(Ir(n))),t}function vS(n,t){var e;t===void 0&&(t=!1);var i=x.env().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(t&&(i=i*2,n=n.map(function(u,c){return c>=n.length-2?x.util.nearestLargerEven(n[c]):n[c]}),n.length===1&&(n=[2,n[0]])),n.length!==2){var r=x.util.squeezeShape(n);n=r.newShape}var a=x.util.sizeFromShape(n);if(n.length<=1&&a<=i)return[1,a];if(n.length===2&&n[0]<=i&&n[1]<=i)return n;if(n.length===3&&n[0]*n[1]<=i&&n[2]<=i)return[n[0]*n[1],n[2]];if(n.length===3&&n[0]<=i&&n[1]*n[2]<=i)return[n[0],n[1]*n[2]];if(n.length===4&&n[0]*n[1]*n[2]<=i&&n[3]<=i)return[n[0]*n[1]*n[2],n[3]];if(n.length===4&&n[0]<=i&&n[1]*n[2]*n[3]<=i)return[n[0],n[1]*n[2]*n[3]];if(t){var s=Lr(n),o=2,l=2;return n.length&&(e=Ir(n),o=e[0],l=e[1]),a=s*(o/2)*(l/2),x.util.sizeToSquarishShape(a).map(function(u){return u*2})}return x.util.sizeToSquarishShape(a)}function rl(n){return n%2===0}function Ls(n,t){if(n=n.slice(-2),t=t.slice(-2),x.util.arraysEqual(n,t))return!0;if(!n.length||!t.length)return!0;if(n[0]===0||n[1]===0||t[0]===0||t[1]===0)return!0;if(n.length!==t.length){var e=n.slice(-1)[0],i=t.slice(-1)[0];if(e===i)return!0;if(rl(e)&&rl(i)&&(n[0]===1||t[0]===1))return!0}return n[1]===t[1]&&rl(n[0])&&rl(t[0])}var al,sl;function yS(n){if(al==null){var t=Gn(n);al=t.getParameter(t.MAX_TEXTURE_SIZE)}return al}function tM(){al=null}function nM(){sl=null}function bS(n){if(sl==null){var t=Gn(n);sl=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,sl)}function wS(n){if(n===0)return 0;var t,e=Gn(n);return ln(e,"EXT_disjoint_timer_query_webgl2")&&n===2?t=2:ln(e,"EXT_disjoint_timer_query")?t=1:t=0,t}function ln(n,t){var e=n.getExtension(t);return e!=null}function cp(n){try{var t=Gn(n);if(t!=null)return!0}catch(e){return console.log("Error when getting WebGL context: ",e),!1}return!1}function SS(n){if(n===0)return!1;var t=Gn(n);if(n===1){if(!ln(t,"OES_texture_float"))return!1}else if(!ln(t,"EXT_color_buffer_float"))return!1;var e=hp(t);return e}function LS(n){if(n===0)return!1;var t=Gn(n);if(n===1){if(!ln(t,"OES_texture_float"))return!1;if(!ln(t,"WEBGL_color_buffer_float"))return!1}else{if(ln(t,"EXT_color_buffer_float"))return hp(t);var e="EXT_color_buffer_half_float";if(ln(t,e)){var i=t.getExtension(e);return iM(t,i)}return!1}var r=hp(t);return r}function hp(n){var t=op(n),e=n.createTexture();n.bindTexture(n.TEXTURE_2D,e);var i=1,r=1;n.texImage2D(n.TEXTURE_2D,0,t.internalFormatFloat,i,r,0,t.textureFormatFloat,t.textureTypeFloat,null);var a=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,a),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,e,0);var s=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;return n.bindTexture(n.TEXTURE_2D,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.deleteTexture(e),n.deleteFramebuffer(a),s}function iM(n,t){var e=op(n,t),i=n.createTexture();n.bindTexture(n.TEXTURE_2D,i);var r=1,a=1;n.texImage2D(n.TEXTURE_2D,0,e.internalFormatHalfFloat,r,a,0,e.textureFormatFloat,e.textureTypeHalfFloat,null);var s=n.createFramebuffer();n.bindFramebuffer(n.FRAMEBUFFER,s),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0);var o=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;return n.bindTexture(n.TEXTURE_2D,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.deleteTexture(i),n.deleteFramebuffer(s),o}function IS(n){if(n!==2)return!1;var t=Gn(n),e=t.fenceSync!=null;return e}function ma(n,t){Array.isArray(n)||(n=[n]),n.forEach(function(e){e!=null&&x.util.assert(e.dtype!=="complex64",function(){return t+" does not support complex64 tensors in the WebGL backend."})})}var rM={__proto__:null,callAndCheck:ce,canBeRepresented:tS,getWebGLErrorMessage:eS,getExtensionOrThrow:ws,createVertexShader:nS,createFragmentShader:iS,createProgram:rS,linkProgram:aS,validateProgram:tl,createStaticVertexBuffer:sS,createStaticIndexBuffer:oS,getNumChannels:Z_,createTexture:lS,validateTextureSize:uS,createFramebuffer:cS,bindVertexBufferToProgramAttribute:lp,bindTextureUnit:dS,unbindTextureUnit:Q_,getProgramUniformLocationOrThrow:pS,getProgramUniformLocation:fS,bindTextureToProgramUniformSampler:mS,bindCanvasToFramebuffer:eM,bindColorTextureToFramebuffer:nl,unbindColorTextureFromFramebuffer:up,validateFramebuffer:Ss,getFramebufferErrorMessage:gS,getBatchDim:Lr,getRowsCols:Ir,getShapeAs3D:il,getTextureShapeFromLogicalShape:vS,isReshapeFree:Ls,getWebGLMaxTextureSize:yS,resetMaxTextureSize:tM,resetMaxTexturesInShader:nM,getMaxTexturesInShader:bS,getWebGLDisjointQueryTimerVersion:wS,hasExtension:ln,isWebGLVersionEnabled:cp,isCapableOfRenderingToFloatTexture:SS,isDownloadFloatTextureEnabled:LS,isWebGLFenceEnabled:IS,assertNotComplex:ma};var we=x.env();we.registerFlag("HAS_WEBGL",function(){return we.getNumber("WEBGL_VERSION")>0});we.registerFlag("WEBGL_VERSION",function(){return cp(2)?2:cp(1)?1:0});we.registerFlag("WEBGL_CHECK_NUMERICAL_PROBLEMS",function(){return!1});we.registerFlag("WEBGL_BUFFER_SUPPORTED",function(){return we.get("WEBGL_VERSION")===2});we.registerFlag("WEBGL_CPU_FORWARD",function(){return!0});we.registerFlag("WEBGL_FORCE_F16_TEXTURES",function(){return!1});we.registerFlag("WEBGL_PACK",function(){return we.getBool("HAS_WEBGL")});we.registerFlag("WEBGL_PACK_NORMALIZATION",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_PACK_CLIP",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_PACK_DEPTHWISECONV",function(){return!1});we.registerFlag("WEBGL_PACK_BINARY_OPERATIONS",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_PACK_UNARY_OPERATIONS",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_PACK_REDUCE",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_LAZILY_UNPACK",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_CONV_IM2COL",function(){return we.getBool("WEBGL_PACK")});we.registerFlag("WEBGL_MAX_TEXTURE_SIZE",function(){return yS(we.getNumber("WEBGL_VERSION"))});we.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER",function(){return bS(we.getNumber("WEBGL_VERSION"))});we.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",function(){var n=we.getNumber("WEBGL_VERSION");return n===0?0:wS(n)});we.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",function(){return we.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&!x.device_util.isMobile()});we.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE",function(){return SS(we.getNumber("WEBGL_VERSION"))});we.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED",function(){return we.getBool("WEBGL_FORCE_F16_TEXTURES")?!1:we.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")});we.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED",function(){return LS(we.getNumber("WEBGL_VERSION"))});we.registerFlag("WEBGL_FENCE_API_ENABLED",function(){return IS(we.getNumber("WEBGL_VERSION"))});we.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM",function(){var n=we.getBool("WEBGL_RENDER_FLOAT32_ENABLED");return n?4:0});we.registerFlag("WEBGL_DELETE_TEXTURE_THRESHOLD",function(){return-1},function(n){if(n<0&&n!==-1)throw new Error("WEBGL_DELETE_TEXTURE_THRESHOLD must be -1 (indicating never "+("delete) or at least 0, but got "+n+"."))});function aM(n){const t=new Float32Array(n.length);for(let e=0;e<n.length;++e)t[e]=Math.abs(n[e]);return t}function dp(n){return(t,e,i,r,a)=>{const s=x.backend_util.assertAndGetBroadcastShape(t,e),o=s.length,l=x.util.computeStrides(s),u=x.util.sizeFromShape(s),c=x.util.getTypedArrayFromDType(a,u),h=t.length,d=e.length,p=x.util.computeStrides(t),f=x.util.computeStrides(e),m=x.backend_util.getBroadcastDims(t,s),g=x.backend_util.getBroadcastDims(e,s);if(m.length+g.length===0)for(let v=0;v<c.length;++v)c[v]=n(i[v%i.length],r[v%r.length]);else for(let v=0;v<c.length;++v){const b=x.util.indexToLoc(v,o,l),w=b.slice(-h);m.forEach(C=>w[C]=0);const S=x.util.locToIndex(w,h,p),L=b.slice(-d);g.forEach(C=>L[C]=0);const N=x.util.locToIndex(L,d,f);c[v]=n(i[S],r[N])}return[c,s]}}const sM=dp((n,t)=>n+t);function ga(n){return(t,e,i)=>{const r=x.util.getTypedArrayFromDType(e,t.length);for(let a=0;a<t.length;++a)r[a]=n(t[a],i);return r}}const oM=ga(n=>Math.ceil(n));const lM=ga(n=>Math.exp(n));const uM=ga(n=>Math.expm1(n));const cM=ga(n=>Math.floor(n));const hM=ga(n=>Math.log(n));function dM(n,t,e,i){const r=x.util.getTypedArrayFromDType(i,x.util.sizeFromShape(e));for(let a=0;a<r.length;++a){const s=a*t;let o=n[s];for(let l=0;l<t;++l){const u=n[s+l];u>o&&(o=u)}r[a]=o}return r}const pM=dp((n,t)=>n*t);const fM=ga(n=>1/Math.sqrt(n));function mM(n,t,e,i,r){const a=x.slice_util.isSliceContinous(i,t,e),s=x.util.sizeFromShape(e),o=x.util.computeStrides(i);if(a){const u=x.slice_util.computeFlatOffset(t,o);return n.subarray(u,u+s)}const l=x.util.getTypedArrayFromDType(r,s);for(let u=0;u<s;++u){const c=e.length,h=x.util.computeStrides(e),d=x.util.indexToLoc(u,c,h),p=d.map((m,g)=>m+t[g]),f=x.util.locToIndex(p,i.length,o);l[u]=n[f]}return l}const gM=dp((n,t)=>n-t);function vM(n,t,e,i,r){const a=t.length,s=x.util.sizeFromShape(t),o=x.util.computeStrides(t),l=x.util.computeStrides(r),u=x.util.getTypedArrayFromDType(e,x.util.sizeFromShape(r));for(let c=0;c<s;++c){const h=x.util.indexToLoc(c,a,o),d=new Array(h.length);for(let f=0;f<d.length;f++)d[f]=h[i[f]];const p=x.util.locToIndex(d,a,l);u[p]=n[c]}return u}function yM(n,t,e,i){const r=x.util.parseAxisParam(t,e)[0],a=[1,e[0],1];for(let f=0;f<r;f++)a[0]*=e[f];a[1]=e[r];for(let f=r+1;f<e.length;f++)a[2]*=e[f];const s={},o=new Int32Array(e[r]),l=new x.TensorBuffer(a,i,n),u=[],c=a[0]===1&&a[2]===1;for(let f=0;f<e[r];f++){let m;if(c)m=n[f].toString();else{const g=[];for(let v=0;v<a[0];v++)for(let b=0;b<a[2];b++)g.push(l.get(v,f,b));m=g.join(",")}if(s[m]!==void 0)o[f]=s[m];else{const g=Object.keys(s).length;s[m]=g,o[f]=g,u.push(f)}}const h=a.slice();h[1]=Object.keys(s).length;const d=new x.TensorBuffer(h,i);u.forEach((f,m)=>{for(let g=0;g<a[0];g++)for(let v=0;v<a[2];v++)d.set(l.get(g,f,v),g,m,v)});const p=e.slice();return p[r]=h[1],{outputValues:d.values,outputShape:p,indices:o}}var bM=aM,wM=sM,SM=oM,LM=lM,IM=uM,AM=cM,TM=hM,NM=dM,xM=pM,CM=fM,RM=mM,OM=gM,AS=vM,EM=yM;var DM=function(){function n(t,e){this.outputShape=[],this.outputShape=t,this.variableNames=e.map(function(a,s){return"T"+s});var i=[];this.variableNames.forEach(function(a){i.push("float v"+a+" = get"+a+"AtOutCoords();")});var r=this.variableNames.map(function(a){return"v"+a}).join(" + ");this.userCode=`
|
|
void main() {
|
|
`+i.join(`
|
|
`)+`
|
|
|
|
float result = `+r+`;
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var kM=function(){function n(t,e){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.variableNames=e.map(function(a,s){return"T"+s});var i=[];this.variableNames.forEach(function(a){i.push("vec4 v"+a+" = get"+a+"AtOutCoords();")});var r=this.variableNames.map(function(a){return"v"+a}).join(" + ");this.userCode=`
|
|
void main() {
|
|
`+i.join(`
|
|
`)+`
|
|
|
|
vec4 result = `+r+`;
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var FM=function(){function n(t,e,i){this.variableNames=["A"];var r=t.windowSize,a=t.batchSize,s=t.outSize;i||this.variableNames.push("bestIndicesA"),this.outputShape=[a,s];var o=e==="max"?">":"<",l=i?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode=`
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int outIdx = coords[1];
|
|
int inOffset = outIdx * `+r+`;
|
|
|
|
int bestIndex = inOffset;
|
|
float bestValue = getA(batch, bestIndex);
|
|
|
|
for (int i = 0; i < `+r+`; i++) {
|
|
int inIdx = `+l+`;
|
|
float candidate = getA(batch, inIdx);
|
|
if (candidate `+o+` bestValue) {
|
|
bestValue = candidate;
|
|
bestIndex = inIdx;
|
|
}
|
|
}
|
|
setOutput(float(bestIndex));
|
|
}
|
|
`}return n}();function TS(n,t){return["x","y","z","w","u","v"].slice(0,t).map(function(e){return n+"."+e})}function en(n,t){return t===1?[n]:TS(n,t)}function WM(n,t){if(n===1)return"rc";for(var e="",i=0;i<n;i++)e+=t[i],i<n-1&&(e+=",");return e}function Bt(){var n,t,e,i,r,a,s,o,l,u;return x.env().getNumber("WEBGL_VERSION")===2?(n="#version 300 es",t="in",e="out",i="in",r="texture",a="outputColor",s="out vec4 outputColor;",o=`
|
|
bool isnan_custom(float val) {
|
|
return (val > 0.0 || val < 0.0) ? false : val != 0.0;
|
|
}
|
|
|
|
bvec4 isnan_custom(vec4 val) {
|
|
return bvec4(isnan_custom(val.x),
|
|
isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
|
|
}
|
|
|
|
#define isnan(value) isnan_custom(value)
|
|
`,l="",u=`
|
|
#define round(value) newRound(value)
|
|
int newRound(float value) {
|
|
return int(floor(value + 0.5));
|
|
}
|
|
|
|
ivec4 newRound(vec4 value) {
|
|
return ivec4(floor(value + vec4(0.5)));
|
|
}
|
|
`):(n="",t="attribute",e="varying",i="varying",r="texture2D",a="gl_FragColor",s="",o=`
|
|
#define isnan(value) isnan_custom(value)
|
|
bool isnan_custom(float val) {
|
|
return (val > 0. || val < 1. || val == 0.) ? false : true;
|
|
}
|
|
bvec4 isnan_custom(vec4 val) {
|
|
return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
|
|
}
|
|
`,l=`
|
|
uniform float INFINITY;
|
|
|
|
bool isinf(float val) {
|
|
return abs(val) == INFINITY;
|
|
}
|
|
bvec4 isinf(vec4 val) {
|
|
return equal(abs(val), vec4(INFINITY));
|
|
}
|
|
`,u=`
|
|
int round(float value) {
|
|
return int(floor(value + 0.5));
|
|
}
|
|
|
|
ivec4 round(vec4 value) {
|
|
return ivec4(floor(value + vec4(0.5)));
|
|
}
|
|
`),{version:n,attribute:t,varyingVs:e,varyingFs:i,texture2D:r,output:a,defineOutput:s,defineSpecialNaN:o,defineSpecialInf:l,defineRound:u}}function Ar(n,t,e){e===void 0&&(e="index");var i=x.util.computeStrides(t);return i.map(function(r,a){var s="int "+n[a]+" = "+e+" / "+r,o=a===i.length-1?"int "+n[a+1]+" = "+e+" - "+n[a]+" * "+r:"index -= "+n[a]+" * "+r;return s+"; "+o+";"}).join("")}function pp(n){var t=x.util.computeStrides(n).map(function(e){return e.toString()});return`
|
|
int getFlatIndex(ivec3 coords) {
|
|
return coords.x * `+t[0]+" + coords.y * "+t[1]+` + coords.z;
|
|
}
|
|
`}var NS=`
|
|
const float FLOAT_MAX = 1.70141184e38;
|
|
const float FLOAT_MIN = 1.17549435e-38;
|
|
|
|
lowp vec4 encode_float(highp float v) {
|
|
if (isnan(v)) {
|
|
return vec4(255, 255, 255, 255);
|
|
}
|
|
|
|
highp float av = abs(v);
|
|
|
|
if(av < FLOAT_MIN) {
|
|
return vec4(0.0, 0.0, 0.0, 0.0);
|
|
} else if(v > FLOAT_MAX) {
|
|
return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;
|
|
} else if(v < -FLOAT_MAX) {
|
|
return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;
|
|
}
|
|
|
|
highp vec4 c = vec4(0,0,0,0);
|
|
|
|
highp float e = floor(log2(av));
|
|
highp float m = exp2(fract(log2(av))) - 1.0;
|
|
|
|
c[2] = floor(128.0 * m);
|
|
m -= c[2] / 128.0;
|
|
c[1] = floor(32768.0 * m);
|
|
m -= c[1] / 32768.0;
|
|
c[0] = floor(8388608.0 * m);
|
|
|
|
highp float ebias = e + 127.0;
|
|
c[3] = floor(ebias / 2.0);
|
|
ebias -= c[3] * 2.0;
|
|
c[2] += floor(ebias) * 128.0;
|
|
|
|
c[3] += 128.0 * step(0.0, -v);
|
|
|
|
return c / 255.0;
|
|
}
|
|
`;var xS=x.backend_util.getBroadcastDims;function qM(n,t,e,i){var r=[];n.forEach(function(f){var m=x.util.sizeFromShape(f.shapeInfo.logicalShape);f.shapeInfo.isUniform?r.push("uniform float "+f.name+(m>1?"["+m+"]":"")+";"):(r.push("uniform sampler2D "+f.name+";"),r.push("uniform int offset"+f.name+";"))});var a=r.join(`
|
|
`),s=n.map(function(f){return UM(f,t,i)}).join(`
|
|
`),o=t.texShape,l=Bt(),u=PM(l),c,h,d=HM(l);t.isPacked?(c=BM(t.logicalShape,o),h=MM(l)):(c=zM(t.logicalShape,o),h=_M(l)),i&&(d+=VM);var p=[d,u,h,a,c,s,e].join(`
|
|
`);return p}function va(n){var t=n.shapeInfo.logicalShape;switch(t.length){case 0:return GM(n);case 1:return YM(n);case 2:return jM(n);case 3:return KM(n);case 4:return $M(n);case 5:return XM(n);case 6:return JM(n);default:throw new Error(t.length+"-D input sampling is not yet supported")}}function CS(n){var t=n.shapeInfo.logicalShape;switch(t.length){case 0:return ZM(n);case 1:return QM(n);case 2:return e5(n);case 3:return t5(n);default:return n5(n)}}function UM(n,t,e){e===void 0&&(e=!1);var i="";e?i+=CS(n):i+=va(n);var r=n.shapeInfo.logicalShape,a=t.logicalShape;return r.length<=a.length&&(e?i+=i5(n,t):i+=r5(n,t)),i}function BM(n,t){switch(n.length){case 0:return RS();case 1:return a5(n,t);case 2:return l5(n,t);case 3:return s5(n,t);default:return o5(n,t)}}function zM(n,t){switch(n.length){case 0:return RS();case 1:return u5(n,t);case 2:return f5(n,t);case 3:return c5(n,t);case 4:return h5(n,t);case 5:return d5(n,t);case 6:return p5(n,t);default:throw new Error(n.length+"-D output sampling is not yet supported")}}function PM(n){return`
|
|
float sampleTexture(sampler2D textureSampler, vec2 uv) {
|
|
return `+n.texture2D+`(textureSampler, uv).r;
|
|
}
|
|
`}function _M(n){return`
|
|
void setOutput(float val) {
|
|
`+n.output+` = vec4(val, 0, 0, 0);
|
|
}
|
|
`}function MM(n){return`
|
|
void setOutput(vec4 val) {
|
|
`+n.output+` = val;
|
|
}
|
|
`}function HM(n){var t=n.version+`
|
|
precision highp float;
|
|
precision highp int;
|
|
precision highp sampler2D;
|
|
`+n.varyingFs+` vec2 resultUV;
|
|
`+n.defineOutput+`
|
|
const vec2 halfCR = vec2(0.5, 0.5);
|
|
|
|
struct ivec5
|
|
{
|
|
int x;
|
|
int y;
|
|
int z;
|
|
int w;
|
|
int u;
|
|
};
|
|
|
|
struct ivec6
|
|
{
|
|
int x;
|
|
int y;
|
|
int z;
|
|
int w;
|
|
int u;
|
|
int v;
|
|
};
|
|
|
|
uniform float NAN;
|
|
`+n.defineSpecialNaN+`
|
|
`+n.defineSpecialInf+`
|
|
`+n.defineRound+`
|
|
|
|
int imod(int x, int y) {
|
|
return x - y * (x / y);
|
|
}
|
|
|
|
int idiv(int a, int b, float sign) {
|
|
int res = a / b;
|
|
int mod = imod(a, b);
|
|
if (sign < 0. && mod != 0) {
|
|
res -= 1;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//Based on the work of Dave Hoskins
|
|
//https://www.shadertoy.com/view/4djSRW
|
|
#define HASHSCALE1 443.8975
|
|
float random(float seed){
|
|
vec2 p = resultUV * seed;
|
|
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
|
|
p3 += dot(p3, p3.yzx + 19.19);
|
|
return fract((p3.x + p3.y) * p3.z);
|
|
}
|
|
|
|
`+m5+`
|
|
`+g5+`
|
|
`+v5+`
|
|
`;return t}var m5=`
|
|
vec2 uvFromFlat(int texNumR, int texNumC, int index) {
|
|
int texR = index / texNumC;
|
|
int texC = index - texR * texNumC;
|
|
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
}
|
|
vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
|
|
int texelIndex = index / 2;
|
|
int texR = texelIndex / texNumC;
|
|
int texC = texelIndex - texR * texNumC;
|
|
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
}
|
|
`,g5=`
|
|
vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
|
|
int texNumC, int row, int col) {
|
|
int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
|
|
int texR = texelIndex / texNumC;
|
|
int texC = texelIndex - texR * texNumC;
|
|
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
}
|
|
`,v5=`
|
|
vec2 packedUVfrom3D(int texNumR, int texNumC,
|
|
int texelsInBatch, int texelsInLogicalRow, int b,
|
|
int row, int col) {
|
|
int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);
|
|
int texR = index / texNumC;
|
|
int texC = index - texR * texNumC;
|
|
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
}
|
|
`,VM=`
|
|
float getChannel(vec4 frag, vec2 innerDims) {
|
|
vec2 modCoord = mod(innerDims, 2.);
|
|
return modCoord.x == 0. ?
|
|
(modCoord.y == 0. ? frag.r : frag.g) :
|
|
(modCoord.y == 0. ? frag.b : frag.a);
|
|
}
|
|
float getChannel(vec4 frag, int dim) {
|
|
float modCoord = mod(float(dim), 2.);
|
|
return modCoord == 0. ? frag.r : frag.g;
|
|
}
|
|
`;function RS(){return`
|
|
int getOutputCoords() {
|
|
return 0;
|
|
}
|
|
`}function a5(n,t){var e=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)];return e[0]===1?`
|
|
int getOutputCoords() {
|
|
return 2 * int(resultUV.x * `+e[1]+`.0);
|
|
}
|
|
`:e[1]===1?`
|
|
int getOutputCoords() {
|
|
return 2 * int(resultUV.y * `+e[0]+`.0);
|
|
}
|
|
`:`
|
|
int getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+e[0]+", "+e[1]+`));
|
|
return 2 * (resTexRC.x * `+e[1]+` + resTexRC.y);
|
|
}
|
|
`}function u5(n,t){return t[0]===1?`
|
|
int getOutputCoords() {
|
|
return int(resultUV.x * `+t[1]+`.0);
|
|
}
|
|
`:t[1]===1?`
|
|
int getOutputCoords() {
|
|
return int(resultUV.y * `+t[0]+`.0);
|
|
}
|
|
`:`
|
|
int getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+t[0]+", "+t[1]+`));
|
|
return resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
}
|
|
`}function s5(n,t){var e=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)],i=Math.ceil(n[2]/2),r=i*Math.ceil(n[1]/2);return`
|
|
ivec3 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+e[0]+", "+e[1]+`));
|
|
int index = resTexRC.x * `+e[1]+` + resTexRC.y;
|
|
|
|
int b = index / `+r+`;
|
|
index -= b * `+r+`;
|
|
|
|
int r = 2 * (index / `+i+`);
|
|
int c = imod(index, `+i+`) * 2;
|
|
|
|
return ivec3(b, r, c);
|
|
}
|
|
`}function c5(n,t){var e=Ar(["r","c","d"],n);return`
|
|
ivec3 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+t[0]+", "+t[1]+`));
|
|
int index = resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
`+e+`
|
|
return ivec3(r, c, d);
|
|
}
|
|
`}function o5(n,t){for(var e=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)],i=Math.ceil(n[n.length-1]/2),r=i*Math.ceil(n[n.length-2]/2),a=r,s="",o="b, r, c",l=2;l<n.length-1;l++)a*=n[n.length-l-1],s=`
|
|
int b`+l+" = index / "+a+`;
|
|
index -= b`+l+" * "+a+`;
|
|
`+s,o="b"+l+", "+o;return`
|
|
ivec`+n.length+` getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+e[0]+", "+e[1]+`));
|
|
int index = resTexRC.x * `+e[1]+` + resTexRC.y;
|
|
|
|
`+s+`
|
|
|
|
int b = index / `+r+`;
|
|
index -= b * `+r+`;
|
|
|
|
int r = 2 * (index / `+i+`);
|
|
int c = imod(index, `+i+`) * 2;
|
|
|
|
return ivec`+n.length+"("+o+`);
|
|
}
|
|
`}function h5(n,t){var e=Ar(["r","c","d","d2"],n);return`
|
|
ivec4 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+t[0]+", "+t[1]+`));
|
|
int index = resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
`+e+`
|
|
return ivec4(r, c, d, d2);
|
|
}
|
|
`}function d5(n,t){var e=Ar(["r","c","d","d2","d3"],n);return`
|
|
ivec5 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx * vec2(`+t[0]+`,
|
|
`+t[1]+`));
|
|
|
|
int index = resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
|
|
`+e+`
|
|
|
|
ivec5 outShape = ivec5(r, c, d, d2, d3);
|
|
return outShape;
|
|
}
|
|
`}function p5(n,t){var e=Ar(["r","c","d","d2","d3","d4"],n);return`
|
|
ivec6 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+t[0]+", "+t[1]+`));
|
|
int index = resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
|
|
`+e+`
|
|
|
|
ivec6 result = ivec6(r, c, d, d2, d3, d4);
|
|
return result;
|
|
}
|
|
`}function l5(n,t){var e=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)];if(x.util.arraysEqual(n,t))return`
|
|
ivec2 getOutputCoords() {
|
|
return 2 * ivec2(resultUV.yx * vec2(`+e[0]+", "+e[1]+`));
|
|
}
|
|
`;var i=Math.ceil(n[1]/2);return`
|
|
ivec2 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+e[0]+", "+e[1]+`));
|
|
|
|
int index = resTexRC.x * `+e[1]+` + resTexRC.y;
|
|
int r = 2 * (index / `+i+`);
|
|
int c = imod(index, `+i+`) * 2;
|
|
|
|
return ivec2(r, c);
|
|
}
|
|
`}function f5(n,t){return x.util.arraysEqual(n,t)?`
|
|
ivec2 getOutputCoords() {
|
|
return ivec2(resultUV.yx * vec2(`+t[0]+", "+t[1]+`));
|
|
}
|
|
`:n[1]===1?`
|
|
ivec2 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+t[0]+", "+t[1]+`));
|
|
int index = resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
return ivec2(index, 0);
|
|
}
|
|
`:n[0]===1?`
|
|
ivec2 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+t[0]+", "+t[1]+`));
|
|
int index = resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
return ivec2(0, index);
|
|
}
|
|
`:`
|
|
ivec2 getOutputCoords() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+t[0]+", "+t[1]+`));
|
|
int index = resTexRC.x * `+t[1]+` + resTexRC.y;
|
|
int r = index / `+n[1]+`;
|
|
int c = index - r * `+n[1]+`;
|
|
return ivec2(r, c);
|
|
}
|
|
`}function Tr(n){return"offset"+n}function ZM(n){var t=n.name,e="get"+t.charAt(0).toUpperCase()+t.slice(1),i=Bt();return`
|
|
vec4 `+e+`() {
|
|
return `+i.texture2D+"("+t+`, halfCR);
|
|
}
|
|
`}function GM(n){var t=n.name,e="get"+t.charAt(0).toUpperCase()+t.slice(1);if(n.shapeInfo.isUniform)return"float "+e+"() {return "+t+";}";var i=n.shapeInfo.texShape,r=i[0],a=i[1];if(r===1&&a===1)return`
|
|
float `+e+`() {
|
|
return sampleTexture(`+t+`, halfCR);
|
|
}
|
|
`;var s=n.shapeInfo.texShape,o=s[0],l=s[1],u=Tr(t);return`
|
|
float `+e+`() {
|
|
vec2 uv = uvFromFlat(`+o+", "+l+", "+u+`);
|
|
return sampleTexture(`+t+`, uv);
|
|
}
|
|
`}function QM(n){var t=n.name,e="get"+t.charAt(0).toUpperCase()+t.slice(1),i=n.shapeInfo.texShape,r=[Math.ceil(i[0]/2),Math.ceil(i[1]/2)],a=Bt();return`
|
|
vec4 `+e+`(int index) {
|
|
vec2 uv = packedUVfrom1D(
|
|
`+r[0]+", "+r[1]+`, index);
|
|
return `+a.texture2D+"("+t+`, uv);
|
|
}
|
|
`}function YM(n){var t=n.name,e="get"+t.charAt(0).toUpperCase()+t.slice(1);if(n.shapeInfo.isUniform)return`
|
|
float `+e+`(int index) {
|
|
`+ya(n)+`
|
|
}
|
|
`;var i=n.shapeInfo.texShape,r=i[0],a=i[1];if(a===1&&r===1)return`
|
|
float `+e+`(int index) {
|
|
return sampleTexture(`+t+`, halfCR);
|
|
}
|
|
`;var s=Tr(t);return a===1?`
|
|
float `+e+`(int index) {
|
|
vec2 uv = vec2(0.5, (float(index + `+s+") + 0.5) / "+r+`.0);
|
|
return sampleTexture(`+t+`, uv);
|
|
}
|
|
`:r===1?`
|
|
float `+e+`(int index) {
|
|
vec2 uv = vec2((float(index + `+s+") + 0.5) / "+a+`.0, 0.5);
|
|
return sampleTexture(`+t+`, uv);
|
|
}
|
|
`:`
|
|
float `+e+`(int index) {
|
|
vec2 uv = uvFromFlat(`+r+", "+a+", index + "+s+`);
|
|
return sampleTexture(`+t+`, uv);
|
|
}
|
|
`}function e5(n){var t=n.shapeInfo.logicalShape,e=n.name,i="get"+e.charAt(0).toUpperCase()+e.slice(1),r=n.shapeInfo.texShape,a=r[0],s=r[1],o=Bt();if(r!=null&&x.util.arraysEqual(t,r))return`
|
|
vec4 `+i+`(int row, int col) {
|
|
vec2 uv = (vec2(col, row) + halfCR) / vec2(`+s+".0, "+a+`.0);
|
|
|
|
return `+o.texture2D+"("+e+`, uv);
|
|
}
|
|
`;var l=[Math.ceil(r[0]/2),Math.ceil(r[1]/2)],u=Math.ceil(t[1]/2);return`
|
|
vec4 `+i+`(int row, int col) {
|
|
vec2 uv = packedUVfrom2D(`+u+", "+l[0]+", "+l[1]+`, row, col);
|
|
return `+o.texture2D+"("+e+`, uv);
|
|
}
|
|
`}function jM(n){var t=n.shapeInfo.logicalShape,e=n.name,i="get"+e.charAt(0).toUpperCase()+e.slice(1),r=n.shapeInfo.texShape;if(r!=null&&x.util.arraysEqual(t,r)){var a=r[0],s=r[1];return`
|
|
float `+i+`(int row, int col) {
|
|
vec2 uv = (vec2(col, row) + halfCR) / vec2(`+s+".0, "+a+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`}var o=x.util.squeezeShape(t),l=o.newShape,u=o.keptDims,c=l;if(c.length<t.length){var h=ba(n,c),d=["row","col"];return`
|
|
`+va(h)+`
|
|
float `+i+`(int row, int col) {
|
|
return `+i+"("+wa(d,u)+`);
|
|
}
|
|
`}if(n.shapeInfo.isUniform)return`
|
|
float `+i+`(int row, int col) {
|
|
int index = round(dot(vec2(row, col), vec2(`+t[1]+`, 1)));
|
|
`+ya(n)+`
|
|
}
|
|
`;var p=r[0],f=r[1],m=Tr(e);return f===1?`
|
|
float `+i+`(int row, int col) {
|
|
float index = dot(vec3(row, col, `+m+"), vec3("+t[1]+`, 1, 1));
|
|
vec2 uv = vec2(0.5, (index + 0.5) / `+p+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`:p===1?`
|
|
float `+i+`(int row, int col) {
|
|
float index = dot(vec3(row, col, `+m+"), vec3("+t[1]+`, 1, 1));
|
|
vec2 uv = vec2((index + 0.5) / `+f+`.0, 0.5);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`:`
|
|
float `+i+`(int row, int col) {
|
|
// Explicitly use integer operations as dot() only works on floats.
|
|
int index = row * `+t[1]+" + col + "+m+`;
|
|
vec2 uv = uvFromFlat(`+p+", "+f+`, index);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`}function t5(n){var t=n.shapeInfo.logicalShape,e=n.name,i="get"+e.charAt(0).toUpperCase()+e.slice(1),r=n.shapeInfo.texShape,a=[Math.ceil(r[0]/2),Math.ceil(r[1]/2)];if(t[0]===1){var s=t.slice(1),o=[1,2],l=ba(n,s),u=["b","row","col"];return`
|
|
`+CS(l)+`
|
|
vec4 `+i+`(int b, int row, int col) {
|
|
return `+i+"("+wa(u,o)+`);
|
|
}
|
|
`}var c=a[0],h=a[1],d=Math.ceil(t[2]/2),p=d*Math.ceil(t[1]/2),f=Bt();return`
|
|
vec4 `+i+`(int b, int row, int col) {
|
|
vec2 uv = packedUVfrom3D(
|
|
`+c+", "+h+", "+p+", "+d+`, b, row, col);
|
|
return `+f.texture2D+"("+e+`, uv);
|
|
}
|
|
`}function KM(n){var t=n.shapeInfo.logicalShape,e=n.name,i="get"+e.charAt(0).toUpperCase()+e.slice(1),r=t[1]*t[2],a=t[2],s=x.util.squeezeShape(t),o=s.newShape,l=s.keptDims,u=o;if(u.length<t.length){var c=ba(n,u),h=["row","col","depth"];return`
|
|
`+va(c)+`
|
|
float `+i+`(int row, int col, int depth) {
|
|
return `+i+"("+wa(h,l)+`);
|
|
}
|
|
`}if(n.shapeInfo.isUniform)return`
|
|
float `+i+`(int row, int col, int depth) {
|
|
int index = round(dot(vec3(row, col, depth),
|
|
vec3(`+r+", "+a+`, 1)));
|
|
`+ya(n)+`
|
|
}
|
|
`;var d=n.shapeInfo.texShape,p=d[0],f=d[1],m=n.shapeInfo.flatOffset;if(f===r&&m==null)return`
|
|
float `+i+`(int row, int col, int depth) {
|
|
float texR = float(row);
|
|
float texC = dot(vec2(col, depth), vec2(`+a+`, 1));
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+f+".0, "+p+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;if(f===a&&m==null)return`
|
|
float `+i+`(int row, int col, int depth) {
|
|
float texR = dot(vec2(row, col), vec2(`+t[1]+`, 1));
|
|
float texC = float(depth);
|
|
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(`+f+".0, "+p+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;var g=Tr(e);return`
|
|
float `+i+`(int row, int col, int depth) {
|
|
// Explicitly use integer operations as dot() only works on floats.
|
|
int index = row * `+r+" + col * "+a+" + depth + "+g+`;
|
|
vec2 uv = uvFromFlat(`+p+", "+f+`, index);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`}function n5(n){for(var t=n.shapeInfo.logicalShape,e=t.length,i=n.name,r="get"+i.charAt(0).toUpperCase()+i.slice(1),a=n.shapeInfo.texShape,s=[Math.ceil(a[0]/2),Math.ceil(a[1]/2)],o=s[0],l=s[1],u=Math.ceil(t[e-1]/2),c=u*Math.ceil(t[e-2]/2),h="int b, int row, int col",d="b * "+c+" + (row / 2) * "+u+" + (col / 2)",p=2;p<e-1;p++)h="int b"+p+", "+h,c*=t[e-p-1],d="b"+p+" * "+c+" + "+d;var f=Bt();return`
|
|
vec4 `+r+"("+h+`) {
|
|
int index = `+d+`;
|
|
int texR = index / `+l+`;
|
|
int texC = index - texR * `+l+`;
|
|
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(`+l+", "+o+`);
|
|
return `+f.texture2D+"("+i+`, uv);
|
|
}
|
|
`}function $M(n){var t=n.shapeInfo.logicalShape,e=n.name,i="get"+e.charAt(0).toUpperCase()+e.slice(1),r=t[3],a=t[2]*r,s=t[1]*a,o=x.util.squeezeShape(t),l=o.newShape,u=o.keptDims;if(l.length<t.length){var c=ba(n,l),h=["row","col","depth","depth2"];return`
|
|
`+va(c)+`
|
|
float `+i+`(int row, int col, int depth, int depth2) {
|
|
return `+i+"("+wa(h,u)+`);
|
|
}
|
|
`}if(n.shapeInfo.isUniform)return`
|
|
float `+i+`(int row, int col, int depth, int depth2) {
|
|
int index = round(dot(vec4(row, col, depth, depth2),
|
|
vec4(`+s+", "+a+", "+r+`, 1)));
|
|
`+ya(n)+`
|
|
}
|
|
`;var d=n.shapeInfo.flatOffset,p=n.shapeInfo.texShape,f=p[0],m=p[1];if(m===s&&d==null)return`
|
|
float `+i+`(int row, int col, int depth, int depth2) {
|
|
float texR = float(row);
|
|
float texC =
|
|
dot(vec3(col, depth, depth2),
|
|
vec3(`+a+", "+r+`, 1));
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+m+".0, "+f+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;if(m===r&&d==null)return`
|
|
float `+i+`(int row, int col, int depth, int depth2) {
|
|
float texR = dot(vec3(row, col, depth),
|
|
vec3(`+t[1]*t[2]+", "+t[2]+`, 1));
|
|
float texC = float(depth2);
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+m+".0, "+f+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;var g=Tr(e);return`
|
|
float `+i+`(int row, int col, int depth, int depth2) {
|
|
// Explicitly use integer operations as dot() only works on floats.
|
|
int index = row * `+s+" + col * "+a+` +
|
|
depth * `+r+` + depth2;
|
|
vec2 uv = uvFromFlat(`+f+", "+m+", index + "+g+`);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`}function XM(n){var t=n.shapeInfo.logicalShape,e=n.name,i="get"+e.charAt(0).toUpperCase()+e.slice(1),r=t[4],a=t[3]*r,s=t[2]*a,o=t[1]*s,l=x.util.squeezeShape(t),u=l.newShape,c=l.keptDims;if(u.length<t.length){var h=ba(n,u),d=["row","col","depth","depth2","depth3"];return`
|
|
`+va(h)+`
|
|
float `+i+`(int row, int col, int depth, int depth2, int depth3) {
|
|
return `+i+"("+wa(d,c)+`);
|
|
}
|
|
`}if(n.shapeInfo.isUniform)return`
|
|
float `+i+`(int row, int col, int depth, int depth2, int depth3) {
|
|
float index = dot(
|
|
vec4(row, col, depth, depth2),
|
|
vec4(`+o+", "+s+", "+a+", "+r+`)) +
|
|
depth3;
|
|
`+ya(n)+`
|
|
}
|
|
`;var p=n.shapeInfo.flatOffset,f=n.shapeInfo.texShape,m=f[0],g=f[1];if(g===o&&p==null)return`
|
|
float `+i+`(int row, int col, int depth, int depth2, int depth3) {
|
|
int texR = row;
|
|
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
vec4(`+s+", "+a+", "+r+`, 1));
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+g+".0, "+m+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;if(g===r&&p==null)return`
|
|
float `+i+`(int row, int col, int depth, int depth2, int depth3) {
|
|
float texR = dot(
|
|
vec4(row, col, depth, depth2),
|
|
vec4(`+t[1]*t[2]*t[3]+`,
|
|
`+t[2]*t[3]+", "+t[3]+`, 1));
|
|
int texC = depth3;
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+g+".0, "+m+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;var v=Tr(e);return`
|
|
float `+i+`(int row, int col, int depth, int depth2, int depth3) {
|
|
// Explicitly use integer operations as dot() only works on floats.
|
|
int index = row * `+o+" + col * "+s+" + depth * "+a+` +
|
|
depth2 * `+r+" + depth3 + "+v+`;
|
|
vec2 uv = uvFromFlat(`+m+", "+g+`, index);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`}function JM(n){var t=n.shapeInfo.logicalShape,e=n.name,i="get"+e.charAt(0).toUpperCase()+e.slice(1),r=x.util.squeezeShape(t),a=r.newShape,s=r.keptDims;if(a.length<t.length){var o=ba(n,a),l=["row","col","depth","depth2","depth3","depth4"];return`
|
|
`+va(o)+`
|
|
float `+i+`(int row, int col, int depth,
|
|
int depth2, int depth3, int depth4) {
|
|
return `+i+"("+wa(l,s)+`);
|
|
}
|
|
`}var u=t[5],c=t[4]*u,h=t[3]*c,d=t[2]*h,p=t[1]*d;if(n.shapeInfo.isUniform)return`
|
|
float `+i+`(int row, int col, int depth,
|
|
int depth2, int depth3, int depth4) {
|
|
int index = round(dot(
|
|
vec4(row, col, depth, depth2),
|
|
vec4(`+p+", "+d+", "+h+", "+c+`)) +
|
|
dot(
|
|
vec2(depth3, depth4),
|
|
vec2(`+u+`, 1)));
|
|
`+ya(n)+`
|
|
}
|
|
`;var f=n.shapeInfo.flatOffset,m=n.shapeInfo.texShape,g=m[0],v=m[1];if(v===p&&f==null)return`
|
|
float `+i+`(int row, int col, int depth,
|
|
int depth2, int depth3, int depth4) {
|
|
int texR = row;
|
|
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
vec4(`+d+", "+h+", "+c+", "+u+`)) +
|
|
float(depth4);
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+v+".0, "+g+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;if(v===u&&f==null)return`
|
|
float `+i+`(int row, int col, int depth,
|
|
int depth2, int depth3, int depth4) {
|
|
float texR = dot(vec4(row, col, depth, depth2),
|
|
vec4(`+t[1]*t[2]*t[3]*t[4]+`,
|
|
`+t[2]*t[3]*t[4]+`,
|
|
`+t[3]*t[4]+`,
|
|
`+t[4]+`)) + float(depth3);
|
|
int texC = depth4;
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+v+".0, "+g+`.0);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`;var b=Tr(e);return`
|
|
float `+i+`(int row, int col, int depth,
|
|
int depth2, int depth3, int depth4) {
|
|
// Explicitly use integer operations as dot() only works on floats.
|
|
int index = row * `+p+" + col * "+d+" + depth * "+h+` +
|
|
depth2 * `+c+" + depth3 * "+u+" + depth4 + "+b+`;
|
|
vec2 uv = uvFromFlat(`+g+", "+v+`, index);
|
|
return sampleTexture(`+e+`, uv);
|
|
}
|
|
`}function ya(n){var t=n.name,e=x.util.sizeFromShape(n.shapeInfo.logicalShape);return e<2?"return "+t+";":`
|
|
for (int i = 0; i < `+e+`; i++) {
|
|
if (i == index) {
|
|
return `+t+`[i];
|
|
}
|
|
}
|
|
`}function i5(n,t){var e=n.name,i=e.charAt(0).toUpperCase()+e.slice(1),r="get"+i+"AtOutCoords",a=n.shapeInfo.logicalShape.length,s=t.logicalShape.length,o=xS(n.shapeInfo.logicalShape,t.logicalShape),l=Ze(s),u=s-a,c,h=["x","y","z","w","u","v"];a===0?c="":s<2&&o.length>=1?c="coords = 0;":c=o.map(function(S){return"coords."+h[S+u]+" = 0;"}).join(`
|
|
`);var d="";s<2&&a>0?d="coords":d=n.shapeInfo.logicalShape.map(function(S,L){return"coords."+h[L+u]}).join(", ");var p="return outputValue;",f=x.util.sizeFromShape(n.shapeInfo.logicalShape),m=f===1,g=x.util.sizeFromShape(t.logicalShape),v=g===1;if(a===1&&!m&&!v)p=`
|
|
return vec4(outputValue.xy, outputValue.xy);
|
|
`;else if(m&&!v)s===1?p=`
|
|
return vec4(outputValue.x, outputValue.x, 0., 0.);
|
|
`:p=`
|
|
return vec4(outputValue.x);
|
|
`;else if(o.length){var b=a-2,w=a-1;o.indexOf(b)>-1&&o.indexOf(w)>-1?p="return vec4(outputValue.x);":o.indexOf(b)>-1?p="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":o.indexOf(w)>-1&&(p="return vec4(outputValue.xx, outputValue.zz);")}return`
|
|
vec4 `+r+`() {
|
|
`+l+` coords = getOutputCoords();
|
|
`+c+`
|
|
vec4 outputValue = get`+i+"("+d+`);
|
|
`+p+`
|
|
}
|
|
`}function r5(n,t){var e=n.name,i=e.charAt(0).toUpperCase()+e.slice(1),r="get"+i+"AtOutCoords",a=t.texShape,s=n.shapeInfo.texShape,o=n.shapeInfo.logicalShape.length,l=t.logicalShape.length;if(!n.shapeInfo.isUniform&&o===l&&n.shapeInfo.flatOffset==null&&x.util.arraysEqual(s,a))return`
|
|
float `+r+`() {
|
|
return sampleTexture(`+e+`, resultUV);
|
|
}
|
|
`;var u=Ze(l),c=xS(n.shapeInfo.logicalShape,t.logicalShape),h=l-o,d,p=["x","y","z","w","u","v"];o===0?d="":l<2&&c.length>=1?d="coords = 0;":d=c.map(function(m){return"coords."+p[m+h]+" = 0;"}).join(`
|
|
`);var f="";return l<2&&o>0?f="coords":f=n.shapeInfo.logicalShape.map(function(m,g){return"coords."+p[g+h]}).join(", "),`
|
|
float `+r+`() {
|
|
`+u+` coords = getOutputCoords();
|
|
`+d+`
|
|
return get`+i+"("+f+`);
|
|
}
|
|
`}function Ze(n){if(n<=1)return"int";if(n===2)return"ivec2";if(n===3)return"ivec3";if(n===4)return"ivec4";if(n===5)return"ivec5";if(n===6)return"ivec6";throw Error("GPU for rank "+n+" is not yet supported")}function ba(n,t){var e=JSON.parse(JSON.stringify(n));return e.shapeInfo.logicalShape=t,e}function wa(n,t){return t.map(function(e){return n[e]}).join(", ")}var y5=function(){function n(t,e,i,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,x.util.assert(t.length>2,function(){return"Packed arg"+(i.charAt(0).toUpperCase()+i.slice(1))+" supports only inputs with rank above 2."});var a=t[t.length-1],s=Math.ceil(a/e);this.outputShape=t.slice(0,-1),s>1&&this.outputShape.push(s),r||this.variableNames.push("bestIndicesA");var o=this.outputShape,l=o.length,u=Ze(l),c=en("coords",l),h,d;if(s===1){d=l+1;var p=Ze(d);h=`
|
|
`+p+" sourceLocR = "+p+"("+c.join()+`, 0);
|
|
++`+c[l-1]+`;
|
|
`+p+" sourceLocG = "+p+"("+c.join()+`, 0);
|
|
++`+c[l-2]+`;
|
|
`+p+" sourceLocA = "+p+"("+c.join()+`, 0);
|
|
--`+c[l-1]+`;
|
|
`+p+" sourceLocB = "+p+"("+c.join()+`, 0);
|
|
--`+c[l-2]+";"}else d=l,h=`
|
|
`+u+` sourceLocR = coords;
|
|
++`+c[l-1]+`;
|
|
`+u+` sourceLocG = coords;
|
|
++`+c[l-2]+`;
|
|
`+u+` sourceLocA = coords;
|
|
--`+c[l-1]+`;
|
|
`+u+` sourceLocB = coords;
|
|
--`+c[l-2]+";";var f=["x","y","z","w","u","v"].slice(0,d),m="."+f[d-1],g=f.map(function(D){return"int "+D}),v=en("sourceLocR",d-1).concat("inIdx.r"),b=en("sourceLocG",d-1).concat("inIdx.g"),w=en("sourceLocB",d-1).concat("inIdx.b"),S=en("sourceLocA",d-1).concat("inIdx.a"),L=i==="max"?"greaterThan":"lessThan",N=r?"":`
|
|
inIdx = round(vec4(getBestIndicesAChannel(`+v.join()+`),
|
|
getBestIndicesAChannel(`+b.join()+`),
|
|
getBestIndicesAChannel(`+w.join()+`),
|
|
getBestIndicesAChannel(`+S.join()+")));",C=`vec4(
|
|
getAChannel(`+v.join()+`),
|
|
hasNextCol ? getAChannel(`+b.join()+`) : 0.,
|
|
hasNextRow ? getAChannel(`+w.join()+`) : 0.,
|
|
hasNextRow && hasNextCol ? getAChannel(`+S.join()+") : 0.)",R=r?"":`
|
|
float getBestIndicesAChannel(`+g.join()+`) {
|
|
return getChannel(getBestIndicesA(`+f.join()+`),
|
|
vec2(`+f.slice(-2).join()+`));
|
|
}`;this.userCode=`
|
|
float getAChannel(`+g.join()+`) {
|
|
return getChannel(getA(`+f.join()+`),
|
|
vec2(`+f.slice(-2).join()+`));
|
|
}
|
|
`+R+`
|
|
void main() {
|
|
`+u+` coords = getOutputCoords();
|
|
bool hasNextCol = `+c[l-1]+" < "+(o[l-1]-1)+`;
|
|
bool hasNextRow = `+c[l-2]+" < "+(o[l-2]-1)+`;
|
|
`+h+`
|
|
ivec4 srcIdx = ivec4(sourceLocR`+m+", sourceLocG"+m+`,
|
|
sourceLocB`+m+", sourceLocA"+m+") * "+e+`;
|
|
ivec4 inIdx = srcIdx;
|
|
vec4 bestIndex = vec4(inIdx);
|
|
vec4 bestValue = `+C+`;
|
|
|
|
for (int i = 0; i < `+e+`; i++) {
|
|
inIdx = srcIdx;
|
|
`+N+`
|
|
vec4 candidate = `+C+`;
|
|
bvec4 nan = isnan(candidate);
|
|
bvec4 replace = bvec4(
|
|
vec4(`+L+`(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));
|
|
|
|
bestValue = vec4(replace.x ? candidate.x : bestValue.x,
|
|
replace.y ? candidate.y : bestValue.y,
|
|
replace.z ? candidate.z : bestValue.z,
|
|
replace.w ? candidate.w : bestValue.w);
|
|
bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));
|
|
srcIdx++;
|
|
}
|
|
setOutput(bestIndex);
|
|
}
|
|
`}return n}();var b5=function(){function n(t){this.variableNames=["dy"],this.outputShape=t.inShape;var e=t.filterHeight,i=t.filterWidth,r=t.strideHeight,a=t.strideWidth,s=t.dilationHeight,o=t.dilationWidth,l=t.effectiveFilterHeight,u=t.effectiveFilterWidth,c=l-1-t.padInfo.top,h=u-1-t.padInfo.left,d=1/(e*i);this.userCode=`
|
|
const ivec2 pads = ivec2(`+c+", "+h+`);
|
|
const float avgMultiplier = float(`+d+`);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int d = coords[3];
|
|
|
|
ivec2 dyRCCorner = coords.yz - pads;
|
|
int dyRCorner = dyRCCorner.x;
|
|
int dyCCorner = dyRCCorner.y;
|
|
|
|
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
for (int wR = 0; wR < `+l+`;
|
|
wR += `+s+`) {
|
|
float dyR = float(dyRCorner + wR) / `+r+`.0;
|
|
|
|
if (dyR < 0.0 || dyR >= `+t.outHeight+`.0 || fract(dyR) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyR = int(dyR);
|
|
|
|
for (int wC = 0; wC < `+u+`;
|
|
wC+= `+o+`) {
|
|
float dyC = float(dyCCorner + wC) / `+a+`.0;
|
|
|
|
if (dyC < 0.0 || dyC >= `+t.outWidth+`.0 ||
|
|
fract(dyC) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyC = int(dyC);
|
|
|
|
float dyValue = getDy(b, idyR, idyC, d);
|
|
|
|
dotProd += dyValue * avgMultiplier;
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}(),w5=function(){function n(t){this.variableNames=["dy"],this.outputShape=t.inShape;var e=t.filterDepth,i=t.filterHeight,r=t.filterWidth,a=t.strideDepth,s=t.strideHeight,o=t.strideWidth,l=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,h=t.effectiveFilterDepth,d=t.effectiveFilterHeight,p=t.effectiveFilterWidth,f=h-1-t.padInfo.front,m=d-1-t.padInfo.top,g=p-1-t.padInfo.left,v=1/(e*i*r);this.userCode=`
|
|
const ivec3 pads = ivec3(`+f+", "+m+", "+g+`);
|
|
const float avgMultiplier = float(`+v+`);
|
|
|
|
void main() {
|
|
ivec5 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
int ch = coords.u;
|
|
|
|
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
|
|
int dyDCorner = dyCorner.x;
|
|
int dyRCorner = dyCorner.y;
|
|
int dyCCorner = dyCorner.z;
|
|
|
|
// Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
|
|
// dx(xD, xR, xC, ch).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
|
|
for (int wD = 0; wD < `+h+`;
|
|
wD += `+l+`) {
|
|
float dyD = float(dyDCorner + wD) / `+a+`.0;
|
|
|
|
if (dyD < 0.0 || dyD >= `+t.outDepth+`.0 || fract(dyD) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyD = int(dyD);
|
|
|
|
for (int wR = 0; wR < `+d+`;
|
|
wR += `+u+`) {
|
|
float dyR = float(dyRCorner + wR) / `+s+`.0;
|
|
|
|
if (dyR < 0.0 || dyR >= `+t.outHeight+`.0 ||
|
|
fract(dyR) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyR = int(dyR);
|
|
|
|
for (int wC = 0; wC < `+p+`;
|
|
wC += `+c+`) {
|
|
float dyC = float(dyCCorner + wC) / `+o+`.0;
|
|
|
|
if (dyC < 0.0 || dyC >= `+t.outWidth+`.0 ||
|
|
fract(dyC) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyC = int(dyC);
|
|
|
|
float dyValue = getDy(batch, idyD, idyR, idyC, ch);
|
|
|
|
dotProd += dyValue * avgMultiplier;
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}();var OS={REAL:"return areal * breal - aimag * bimag;",IMAG:"return areal * bimag + aimag * breal;"},ES=function(){function n(t,e,i){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=x.backend_util.assertAndGetBroadcastShape(e,i),this.userCode=`
|
|
float binaryOpComplex(
|
|
float areal, float aimag, float breal, float bimag) {
|
|
`+t+`
|
|
}
|
|
|
|
void main() {
|
|
float areal = getARealAtOutCoords();
|
|
float aimag = getAImagAtOutCoords();
|
|
float breal = getBRealAtOutCoords();
|
|
float bimag = getBImagAtOutCoords();
|
|
setOutput(binaryOpComplex(areal, aimag, breal, bimag));
|
|
}
|
|
`}return n}();var DS=`
|
|
if (isnan(a)) return a;
|
|
if (isnan(b)) return b;
|
|
`,fp="return a + b;",mp="return a - b;",kS="return a * b;",S5=`
|
|
float s = sign(a) * sign(b);
|
|
int ia = round(a);
|
|
int ib = round(b);
|
|
if (ib != 0) {
|
|
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
|
|
return float(idiv(ia, ib, s));
|
|
} else {
|
|
return NAN;
|
|
}
|
|
`,L5=`
|
|
if(a < 0.0 && floor(b) < b){
|
|
return NAN;
|
|
}
|
|
if (b == 0.0) {
|
|
return 1.0;
|
|
}
|
|
return (round(mod(b, 2.0)) != 1) ?
|
|
pow(abs(a), b) : sign(a) * pow(abs(a), b);
|
|
`,I5="return float(a == b);",A5="return float(a != b);",T5="return float(a < b);",N5="return float(a <= b);",x5="return float(a > b);",C5="return float(a >= b);",R5="return float(a >= 1.0 && b >= 1.0);",O5="return float(a >= 1.0 || b >= 1.0);",E5=DS+`
|
|
return max(a, b);
|
|
`,D5=DS+`
|
|
return min(a, b);
|
|
`,k5=`if (b == 0.0) return NAN;
|
|
return mod(a, b);`,F5="return (b >= 1.0) ? a : a * (b + 1.0);",FS="return (a < 0.) ? b * a : a;",St=function(){function n(t,e,i){this.variableNames=["A","B"],this.outputShape=x.backend_util.assertAndGetBroadcastShape(e,i),this.userCode=`
|
|
float binaryOperation(float a, float b) {
|
|
`+t+`
|
|
}
|
|
|
|
void main() {
|
|
float a = getAAtOutCoords();
|
|
float b = getBAtOutCoords();
|
|
setOutput(binaryOperation(a, b));
|
|
}
|
|
`}return n}();var ol=`
|
|
result.r = isNaN.r > 0. ? NAN : result.r;
|
|
result.g = isNaN.g > 0. ? NAN : result.g;
|
|
result.b = isNaN.b > 0. ? NAN : result.b;
|
|
result.a = isNaN.a > 0. ? NAN : result.a;
|
|
`,W5=`
|
|
ivec4 ia = round(a);
|
|
ivec4 ib = round(b);
|
|
bvec4 cond = notEqual(ib, ivec4(0));
|
|
ivec4 result = ivec4(0);
|
|
vec4 s = sign(a) * sign(b);
|
|
|
|
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
|
|
if (cond[0]) {
|
|
result[0] = idiv(ia[0], ib[0], s[0]);
|
|
}
|
|
if (cond[1]) {
|
|
result[1] = idiv(ia[1], ib[1], s[1]);
|
|
}
|
|
if (cond[2]) {
|
|
result[2] = idiv(ia[2], ib[2], s[2]);
|
|
}
|
|
if (cond[3]) {
|
|
result[3] = idiv(ia[3], ib[3], s[3]);
|
|
}
|
|
return vec4(result);
|
|
`,U5=`
|
|
// isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.
|
|
vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));
|
|
vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);
|
|
vec4 result = multiplier * pow(abs(a), b);
|
|
|
|
// Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
|
|
bvec4 isExpZero = equal(b, vec4(0.0));
|
|
result.r = isExpZero.r ? 1.0 : result.r;
|
|
result.g = isExpZero.g ? 1.0 : result.g;
|
|
result.b = isExpZero.b ? 1.0 : result.b;
|
|
result.a = isExpZero.a ? 1.0 : result.a;
|
|
|
|
vec4 isNaN = vec4(lessThan(a, vec4(0.0))) * vec4(lessThan(floor(b), b));
|
|
`+ol+`
|
|
return result;
|
|
`,WS=`
|
|
vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
|
|
return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
|
|
`,B5=`
|
|
vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));
|
|
return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));
|
|
`,z5=`
|
|
return vec4(equal(a, b));
|
|
`,P5=`
|
|
return vec4(notEqual(a, b));
|
|
`,_5=`
|
|
return vec4(lessThan(a, b));
|
|
`,M5=`
|
|
return vec4(lessThanEqual(a, b));
|
|
`,H5=`
|
|
return vec4(greaterThan(a, b));
|
|
`,V5=`
|
|
return vec4(greaterThanEqual(a, b));
|
|
`,q5=`
|
|
return vec4(
|
|
vec4(greaterThanEqual(a, vec4(1.0))) *
|
|
vec4(greaterThanEqual(b, vec4(1.0))));
|
|
`,G5=`
|
|
return min(
|
|
vec4(greaterThanEqual(a, vec4(1.0))) +
|
|
vec4(greaterThanEqual(b, vec4(1.0))),
|
|
vec4(1.0));
|
|
`,Y5=`
|
|
vec4 result = vec4(max(a, b));
|
|
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
|
|
`+ol+`
|
|
return result;
|
|
`,j5=`
|
|
vec4 result = vec4(min(a, b));
|
|
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
|
|
`+ol+`
|
|
return result;
|
|
`,K5=`
|
|
vec4 result = mod(a, b);
|
|
vec4 isNaN = vec4(equal(b, vec4(0.0)));
|
|
`+ol+`
|
|
return result;
|
|
`,Ui=function(){function n(t,e,i,r){r===void 0&&(r=!1),this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=x.backend_util.assertAndGetBroadcastShape(e,i);var a=this.outputShape.length,s="";if(r)if(a===0||x.util.sizeFromShape(this.outputShape)===1)s=`
|
|
result.y = 0.;
|
|
result.z = 0.;
|
|
result.w = 0.;
|
|
`;else{var o=Ze(a);if(s=`
|
|
`+o+` coords = getOutputCoords();
|
|
`,a===1)s+=`
|
|
result.y = (coords + 1) >= `+this.outputShape[0]+` ? 0. : result.y;
|
|
result.z = 0.;
|
|
result.w = 0.;
|
|
`;else{var l=en("coords",a);s+=`
|
|
bool nextRowOutOfBounds =
|
|
(`+l[a-2]+" + 1) >= "+this.outputShape[a-2]+`;
|
|
bool nextColOutOfBounds =
|
|
(`+l[a-1]+" + 1) >= "+this.outputShape[a-1]+`;
|
|
result.y = nextColOutOfBounds ? 0. : result.y;
|
|
result.z = nextRowOutOfBounds ? 0. : result.z;
|
|
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
|
|
`}}this.userCode=`
|
|
vec4 binaryOperation(vec4 a, vec4 b) {
|
|
`+t+`
|
|
}
|
|
|
|
void main() {
|
|
vec4 a = getAAtOutCoords();
|
|
vec4 b = getBAtOutCoords();
|
|
|
|
vec4 result = binaryOperation(a, b);
|
|
`+s+`
|
|
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var $5=function(){function n(t){this.variableNames=["A"],this.outputShape=t,this.userCode=`
|
|
uniform float minVal;
|
|
uniform float maxVal;
|
|
|
|
void main() {
|
|
float value = getAAtOutCoords();
|
|
if (isnan(value)) {
|
|
setOutput(value);
|
|
return;
|
|
}
|
|
|
|
setOutput(clamp(value, minVal, maxVal));
|
|
}
|
|
`}return n.prototype.getCustomSetupFunc=function(t,e){var i=this;return function(r,a){i.minLoc==null&&(i.minLoc=r.getUniformLocationNoThrow(a,"minVal"),i.maxLoc=r.getUniformLocationNoThrow(a,"maxVal")),r.gl.uniform1f(i.minLoc,t),r.gl.uniform1f(i.maxLoc,e)}},n}();var X5=function(){function n(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode=`
|
|
uniform float minVal;
|
|
uniform float maxVal;
|
|
|
|
void main() {
|
|
vec4 value = getAAtOutCoords();
|
|
|
|
if (any(isnan(value))) {
|
|
setOutput(value);
|
|
return;
|
|
}
|
|
|
|
setOutput(clamp(value, vec4(minVal), vec4(maxVal)));
|
|
}
|
|
`}return n.prototype.getCustomSetupFunc=function(t,e){var i=this;return function(r,a){i.minLoc==null&&(i.minLoc=r.getUniformLocationNoThrow(a,"minVal"),i.maxLoc=r.getUniformLocationNoThrow(a,"maxVal")),r.gl.uniform1f(i.minLoc,t),r.gl.uniform1f(i.maxLoc,e)}},n}();var J5=function(){function n(t){this.variableNames=["real","imag"],this.outputShape=t,this.userCode=`
|
|
void main() {
|
|
float re = abs(getRealAtOutCoords());
|
|
float im = abs(getImagAtOutCoords());
|
|
float mx = max(re, im);
|
|
|
|
// sadly the length function in glsl is not underflow-safe
|
|
// (at least not on Intel GPUs). So the safe solution is
|
|
// to ensure underflow-safety in all cases.
|
|
setOutput(
|
|
mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))
|
|
);
|
|
}
|
|
`}return n}();var Z5=function(){function n(t){this.outputShape=[],this.outputShape=x.backend_util.computeOutShape(t,1),this.variableNames=t.map(function(l,u){return"T"+u});var e=new Array(t.length-1);e[0]=t[0][1];for(var i=1;i<e.length;i++)e[i]=e[i-1]+t[i][1];for(var r=["if (yC < "+e[0]+") setOutput(getT0(yR, yC));"],i=1;i<e.length;i++){var a=e[i-1];r.push("else if (yC < "+e[i]+") "+("setOutput(getT"+i+"(yR, yC-"+a+"));"))}var s=e.length,o=e[e.length-1];r.push("else setOutput(getT"+s+"(yR, yC-"+o+"));"),this.userCode=`
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
int yR = coords.x;
|
|
int yC = coords.y;
|
|
|
|
`+r.join(`
|
|
`)+`
|
|
}
|
|
`}return n}();var Q5=function(){function n(t,e){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=x.backend_util.computeOutShape(t,e);var i=this.outputShape,r=i.length,a=Ze(r),s=en("coords",r),o=["x","y","z","w","u","v"].slice(0,r);this.variableNames=t.map(function(v,b){return"T"+b});var l=new Array(t.length-1);l[0]=t[0][e];for(var u=1;u<l.length;u++)l[u]=l[u-1]+t[u][e];for(var c=o[e],h=o.slice(-2),d=o.join(),p="if ("+c+" < "+l[0]+`) {
|
|
return getChannel(
|
|
getT0(`+d+"), vec2("+h.join()+`));
|
|
}`,u=1;u<l.length;u++){var f=l[u-1];p+=`
|
|
if (`+c+" < "+l[u]+" && "+c+" >= "+l[u-1]+`) {
|
|
return getChannel(
|
|
getT`+u+"("+ll(o,c,f)+`),
|
|
vec2(`+ll(h,c,f)+`));
|
|
}`}var m=l.length,g=l[l.length-1];p+=`
|
|
return getChannel(
|
|
getT`+m+"("+ll(o,c,g)+`),
|
|
vec2(`+ll(h,c,g)+"));",this.userCode=`
|
|
float getValue(`+o.map(function(v){return"int "+v})+`) {
|
|
`+p+`
|
|
}
|
|
|
|
void main() {
|
|
`+a+` coords = getOutputCoords();
|
|
vec4 result = vec4(getValue(`+s+`), 0., 0., 0.);
|
|
|
|
`+s[r-1]+" = "+s[r-1]+` + 1;
|
|
if (`+s[r-1]+" < "+i[r-1]+`) {
|
|
result.g = getValue(`+s+`);
|
|
}
|
|
|
|
`+s[r-2]+" = "+s[r-2]+` + 1;
|
|
if (`+s[r-2]+" < "+i[r-2]+`) {
|
|
result.a = getValue(`+s+`);
|
|
}
|
|
|
|
`+s[r-1]+" = "+s[r-1]+` - 1;
|
|
if (`+s[r-2]+" < "+i[r-2]+` &&
|
|
`+s[r-1]+" < "+i[r-1]+`) {
|
|
result.b = getValue(`+s+`);
|
|
}
|
|
setOutput(result);
|
|
}
|
|
`}return n}();function ll(n,t,e){var i=n.indexOf(t),r=n.map(function(a,s){return s===i?a+" - "+e:a});return r.join()}var e9=function(){function n(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideHeight,i=t.strideWidth,r=t.padInfo.top,a=t.padInfo.left,s=t.dataFormat==="channelsLast";this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int wR = coords.x;
|
|
int wC = coords.y;
|
|
int d1 = coords.z;
|
|
int d2 = coords.w;
|
|
|
|
// Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
|
|
for (int b = 0; b < `+t.batchSize+`; b++) {
|
|
for (int yR = 0; yR < `+t.outHeight+`; yR++) {
|
|
int xR = wR + yR * `+e+" - "+r+`;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int yC = 0; yC < `+t.outWidth+`; yC++) {
|
|
int xC = wC + yC * `+i+" - "+a+`;
|
|
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
continue;
|
|
}
|
|
|
|
if (`+s+`) {
|
|
float dyValue = getDy(b, yR, yC, d2);
|
|
float xValue = getX(b, xR, xC, d1);
|
|
dotProd += (xValue * dyValue);
|
|
} else {
|
|
float dyValue = getDy(b, d2, yR, yC);
|
|
float xValue = getX(b, d1, xR, xC);
|
|
dotProd += (xValue * dyValue);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}(),t9=function(){function n(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,i=t.filterWidth,r=t.strideHeight,a=t.strideWidth,s=t.dataFormat==="channelsLast",o=e-1-t.padInfo.top,l=i-1-t.padInfo.left,u=s?1:2,c=s?2:3,h=s?3:1;this.userCode=`
|
|
const ivec2 pads = ivec2(`+o+", "+l+`);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int d1 = coords[`+h+`];
|
|
|
|
ivec2 dyCorner = ivec2(coords[`+u+"], coords["+c+`]) - pads;
|
|
int dyRCorner = dyCorner.x;
|
|
int dyCCorner = dyCorner.y;
|
|
|
|
// Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
for (int wR = 0; wR < `+e+`; wR++) {
|
|
float dyR = float(dyRCorner + wR) / `+r+`.0;
|
|
|
|
if (dyR < 0.0 || dyR >= `+t.outHeight+`.0 || fract(dyR) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyR = int(dyR);
|
|
|
|
int wRPerm = `+e+` - 1 - wR;
|
|
|
|
for (int wC = 0; wC < `+i+`; wC++) {
|
|
float dyC = float(dyCCorner + wC) / `+a+`.0;
|
|
|
|
if (dyC < 0.0 || dyC >= `+t.outWidth+`.0 ||
|
|
fract(dyC) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyC = int(dyC);
|
|
|
|
int wCPerm = `+i+` - 1 - wC;
|
|
|
|
for (int d2 = 0; d2 < `+t.outChannels+`; d2++) {
|
|
|
|
if (`+s+`) {
|
|
float xValue = getDy(batch, idyR, idyC, d2);
|
|
float wValue = getW(wRPerm, wCPerm, d1, d2);
|
|
dotProd += xValue * wValue;
|
|
} else {
|
|
float xValue = getDy(batch, d2, idyR, idyC);
|
|
float wValue = getW(wRPerm, wCPerm, d1, d2);
|
|
dotProd += xValue * wValue;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}(),n9=function(){function n(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideDepth,i=t.strideHeight,r=t.strideWidth,a=t.padInfo.front,s=t.padInfo.top,o=t.padInfo.left;this.userCode=`
|
|
void main() {
|
|
ivec5 coords = getOutputCoords();
|
|
int wF = coords.x;
|
|
int wR = coords.y;
|
|
int wC = coords.z;
|
|
int d1 = coords.w;
|
|
int d2 = coords.u;
|
|
|
|
float dotProd = 0.0;
|
|
|
|
for (int b = 0; b < `+t.batchSize+`; b++) {
|
|
for (int yF = 0; yF < `+t.outDepth+`; yF++) {
|
|
int xF = wF + yF * `+e+" - "+a+`;
|
|
|
|
if (xF < 0 || xF >= `+t.inDepth+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int yR = 0; yR < `+t.outHeight+`; yR++) {
|
|
int xR = wR + yR * `+i+" - "+s+`;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int yC = 0; yC < `+t.outWidth+`; yC++) {
|
|
int xC = wC + yC * `+r+" - "+o+`;
|
|
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
continue;
|
|
}
|
|
|
|
float dyValue = getDy(b, yF, yR, yC, d2);
|
|
float xValue = getX(b, xF, xR, xC, d1);
|
|
dotProd += (xValue * dyValue);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}(),i9=function(){function n(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterDepth,i=t.filterHeight,r=t.filterWidth,a=t.strideDepth,s=t.strideHeight,o=t.strideWidth,l=e-1-t.padInfo.front,u=i-1-t.padInfo.top,c=r-1-t.padInfo.left;this.userCode=`
|
|
const ivec3 pads = ivec3(`+l+", "+u+", "+c+`);
|
|
|
|
void main() {
|
|
ivec5 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
int d1 = coords.u;
|
|
|
|
|
|
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
|
|
int dyFCorner = dyCorner.x;
|
|
int dyRCorner = dyCorner.y;
|
|
int dyCCorner = dyCorner.z;
|
|
|
|
float dotProd = 0.0;
|
|
for (int wF = 0; wF < `+e+`; wF++) {
|
|
float dyF = float(dyFCorner + wF) / `+a+`.0;
|
|
|
|
if (dyF < 0.0 || dyF >= `+t.outDepth+`.0 || fract(dyF) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyF = int(dyF);
|
|
|
|
int wFPerm = `+e+` - 1 - wF;
|
|
|
|
for (int wR = 0; wR < `+i+`; wR++) {
|
|
float dyR = float(dyRCorner + wR) / `+s+`.0;
|
|
|
|
if (dyR < 0.0 || dyR >= `+t.outHeight+`.0 ||
|
|
fract(dyR) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyR = int(dyR);
|
|
|
|
int wRPerm = `+i+` - 1 - wR;
|
|
|
|
for (int wC = 0; wC < `+r+`; wC++) {
|
|
float dyC = float(dyCCorner + wC) / `+o+`.0;
|
|
|
|
if (dyC < 0.0 || dyC >= `+t.outWidth+`.0 ||
|
|
fract(dyC) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyC = int(dyC);
|
|
|
|
int wCPerm = `+r+` - 1 - wC;
|
|
|
|
for (int d2 = 0; d2 < `+t.outChannels+`; d2++) {
|
|
float xValue = getDy(batch, idyF, idyR, idyC, d2);
|
|
float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);
|
|
dotProd += xValue * wValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}();var r9=function(){function n(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideHeight,i=t.strideWidth,r=t.padInfo.top,a=t.padInfo.left,s=t.outChannels/t.inChannels;this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int wR = coords.x;
|
|
int wC = coords.y;
|
|
int d1 = coords.z;
|
|
int dm = coords.w;
|
|
int d2 = d1 * `+s+` + dm;
|
|
|
|
float dotProd = 0.0;
|
|
|
|
// TO DO: Vec4 over the batch size
|
|
for (int b = 0; b < `+t.batchSize+`; b++) {
|
|
for (int yR = 0; yR < `+t.outHeight+`; yR++) {
|
|
int xR = wR + yR * `+e+" - "+r+`;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int yC = 0; yC < `+t.outWidth+`; yC++) {
|
|
int xC = wC + yC * `+i+" - "+a+`;
|
|
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
continue;
|
|
}
|
|
|
|
float dyValue = getDy(b, yR, yC, d2);
|
|
float xValue = getX(b, xR, xC, d1);
|
|
dotProd += (xValue * dyValue);
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}(),a9=function(){function n(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,i=t.filterWidth,r=t.strideHeight,a=t.strideWidth,s=e-1-t.padInfo.top,o=i-1-t.padInfo.left,l=t.outChannels/t.inChannels;this.userCode=`
|
|
const ivec2 pads = ivec2(`+s+", "+o+`);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int d1 = coords[3];
|
|
ivec2 dyCorner = coords.yz - pads;
|
|
int dyRCorner = dyCorner.x;
|
|
int dyCCorner = dyCorner.y;
|
|
|
|
float dotProd = 0.0;
|
|
|
|
for (int wR = 0; wR < `+e+`; wR++) {
|
|
float dyR = float(dyRCorner + wR) / `+r+`.0;
|
|
|
|
if (dyR < 0.0 || dyR >= `+t.outHeight+`.0 || fract(dyR) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyR = int(dyR);
|
|
|
|
int wRPerm = `+e+` - 1 - wR;
|
|
|
|
for (int wC = 0; wC < `+i+`; wC++) {
|
|
float dyC = float(dyCCorner + wC) / `+a+`.0;
|
|
|
|
if (dyC < 0.0 || dyC >= `+t.outWidth+`.0 ||
|
|
fract(dyC) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyC = int(dyC);
|
|
|
|
int wCPerm = `+i+` - 1 - wC;
|
|
|
|
// TO DO: Vec4 over the channelMul
|
|
for (int dm = 0; dm < `+l+`; dm++) {
|
|
int d2 = d1 * `+l+` + dm;
|
|
float xValue = getDy(batch, idyR, idyC, d2);
|
|
float wValue = getW(wRPerm, wCPerm, d1, dm);
|
|
dotProd += xValue * wValue;
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}();var US=function(){function n(t,e,i,r){e===void 0&&(e=!1),i===void 0&&(i=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.outputShape=t.outShape;var a=t.padInfo.top,s=t.padInfo.left,o=t.strideHeight,l=t.strideWidth,u=t.dilationHeight,c=t.dilationWidth,h=t.filterHeight,d=t.filterWidth,p=Math.floor(t.inChannels/4)*4,f=t.inChannels%4,m=t.dataFormat==="channelsLast",g=m?1:2,v=m?2:3,b=m?3:1,w="",S="";i&&(r?w=`float activation(float a) {
|
|
float b = getPreluActivationWeightsAtOutCoords();
|
|
`+i+`
|
|
}`:w=`
|
|
float activation(float x) {
|
|
`+i+`
|
|
}
|
|
`,S="result = activation(result);");var L=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode=`
|
|
`+w+`
|
|
|
|
const ivec2 strides = ivec2(`+o+", "+l+`);
|
|
const ivec2 pads = ivec2(`+a+", "+s+`);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int d2 = coords[`+b+`];
|
|
|
|
ivec2 xRCCorner =
|
|
ivec2(coords[`+g+"], coords["+v+`]) * strides - pads;
|
|
int xRCorner = xRCCorner.x;
|
|
int xCCorner = xRCCorner.y;
|
|
|
|
// Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
for (int wR = 0; wR < `+h+`; wR++) {
|
|
int xR = xRCorner + wR * `+u+`;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wC = 0; wC < `+d+`; wC++) {
|
|
int xC = xCCorner + wC * `+c+`;
|
|
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int d1 = 0; d1 < `+p+`; d1 += 4) {
|
|
vec4 wValues = vec4(
|
|
getW(wR, wC, d1, d2),
|
|
getW(wR, wC, d1 + 1, d2),
|
|
getW(wR, wC, d1 + 2, d2),
|
|
getW(wR, wC, d1 + 3, d2)
|
|
);
|
|
|
|
if (`+m+`) {
|
|
vec4 xValues = vec4(
|
|
getX(batch, xR, xC, d1),
|
|
getX(batch, xR, xC, d1 + 1),
|
|
getX(batch, xR, xC, d1 + 2),
|
|
getX(batch, xR, xC, d1 + 3)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
} else {
|
|
vec4 xValues = vec4(
|
|
getX(batch, d1, xR, xC),
|
|
getX(batch, d1 + 1, xR, xC),
|
|
getX(batch, d1 + 2, xR, xC),
|
|
getX(batch, d1 + 3, xR, xC)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
}
|
|
}
|
|
|
|
if (`+(f===1)+`) {
|
|
|
|
if (`+m+`) {
|
|
dotProd +=
|
|
getX(batch, xR, xC, `+p+`) *
|
|
getW(wR, wC, `+p+`, d2);
|
|
} else {
|
|
dotProd +=
|
|
getX(batch, `+p+`, xR, xC) *
|
|
getW(wR, wC, `+p+`, d2);
|
|
}
|
|
|
|
} else if (`+(f===2)+`) {
|
|
vec2 wValues = vec2(
|
|
getW(wR, wC, `+p+`, d2),
|
|
getW(wR, wC, `+p+` + 1, d2)
|
|
);
|
|
|
|
if (`+m+`) {
|
|
vec2 xValues = vec2(
|
|
getX(batch, xR, xC, `+p+`),
|
|
getX(batch, xR, xC, `+p+` + 1)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
} else {
|
|
vec2 xValues = vec2(
|
|
getX(batch, `+p+`, xR, xC),
|
|
getX(batch, `+p+` + 1, xR, xC)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
}
|
|
|
|
} else if (`+(f===3)+`) {
|
|
vec3 wValues = vec3(
|
|
getW(wR, wC, `+p+`, d2),
|
|
getW(wR, wC, `+p+` + 1, d2),
|
|
getW(wR, wC, `+p+` + 2, d2)
|
|
);
|
|
|
|
if (`+m+`) {
|
|
vec3 xValues = vec3(
|
|
getX(batch, xR, xC, `+p+`),
|
|
getX(batch, xR, xC, `+p+` + 1),
|
|
getX(batch, xR, xC, `+p+` + 2)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
} else {
|
|
vec3 xValues = vec3(
|
|
getX(batch, `+p+`, xR, xC),
|
|
getX(batch, `+p+` + 1, xR, xC),
|
|
getX(batch, `+p+` + 2, xR, xC)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
float result = dotProd;
|
|
`+L+`
|
|
`+S+`
|
|
setOutput(result);
|
|
}
|
|
`}return n}(),s9=function(){function n(t){this.variableNames=["x","W"],this.outputShape=t.outShape;var e=t.padInfo.front,i=t.padInfo.top,r=t.padInfo.left,a=t.strideDepth,s=t.strideHeight,o=t.strideWidth,l=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,h=t.filterDepth,d=t.filterHeight,p=t.filterWidth,f=Math.floor(t.inChannels/4)*4,m=t.inChannels%4;this.userCode=`
|
|
const ivec3 strides = ivec3(`+a+", "+s+", "+o+`);
|
|
const ivec3 pads = ivec3(`+e+", "+i+", "+r+`);
|
|
|
|
void main() {
|
|
ivec5 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
int d2 = coords.u;
|
|
|
|
ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
|
|
int xFCorner = xFRCCorner.x;
|
|
int xRCorner = xFRCCorner.y;
|
|
int xCCorner = xFRCCorner.z;
|
|
|
|
// Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get
|
|
// y(yF, yR, yC, d2). ? = to be determined. : = across all
|
|
// values in that axis.
|
|
float dotProd = 0.0;
|
|
for (int wF = 0; wF < `+h+`; wF++) {
|
|
int xF = xFCorner + wF * `+l+`;
|
|
|
|
if (xF < 0 || xF >= `+t.inDepth+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wR = 0; wR < `+d+`; wR++) {
|
|
int xR = xRCorner + wR * `+u+`;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wC = 0; wC < `+p+`; wC++) {
|
|
int xC = xCCorner + wC * `+c+`;
|
|
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int d1 = 0; d1 < `+f+`; d1 += 4) {
|
|
vec4 xValues = vec4(
|
|
getX(batch, xF, xR, xC, d1),
|
|
getX(batch, xF, xR, xC, d1 + 1),
|
|
getX(batch, xF, xR, xC, d1 + 2),
|
|
getX(batch, xF, xR, xC, d1 + 3)
|
|
);
|
|
vec4 wValues = vec4(
|
|
getW(wF, wR, wC, d1, d2),
|
|
getW(wF, wR, wC, d1 + 1, d2),
|
|
getW(wF, wR, wC, d1 + 2, d2),
|
|
getW(wF, wR, wC, d1 + 3, d2)
|
|
);
|
|
|
|
dotProd += dot(xValues, wValues);
|
|
}
|
|
|
|
if (`+(m===1)+`) {
|
|
dotProd +=
|
|
getX(batch, xF, xR, xC, `+f+`) *
|
|
getW(wF, wR, wC, `+f+`, d2);
|
|
} else if (`+(m===2)+`) {
|
|
vec2 xValues = vec2(
|
|
getX(batch, xF, xR, xC, `+f+`),
|
|
getX(batch, xF, xR, xC, `+f+` + 1)
|
|
);
|
|
vec2 wValues = vec2(
|
|
getW(wF, wR, wC, `+f+`, d2),
|
|
getW(wF, wR, wC, `+f+` + 1, d2)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
} else if (`+(m===3)+`) {
|
|
vec3 xValues = vec3(
|
|
getX(batch, xF, xR, xC, `+f+`),
|
|
getX(batch, xF, xR, xC, `+f+` + 1),
|
|
getX(batch, xF, xR, xC, `+f+` + 2)
|
|
);
|
|
vec3 wValues = vec3(
|
|
getW(wF, wR, wC, `+f+`, d2),
|
|
getW(wF, wR, wC, `+f+` + 1, d2),
|
|
getW(wF, wR, wC, `+f+` + 2, d2)
|
|
);
|
|
dotProd += dot(xValues, wValues);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}();var BS=function(){function n(t,e,i,r){e===void 0&&(e=!1),i===void 0&&(i=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.outputShape=t.outShape;var a=t.inHeight,s=t.inWidth,o=t.padInfo.top,l=t.padInfo.left,u=t.strideHeight,c=t.strideWidth,h=t.dilationHeight,d=t.dilationWidth,p=t.filterHeight,f=t.filterWidth,m=t.outChannels/t.inChannels,g="",v="";i&&(r?g=`float activation(float a) {
|
|
float b = getPreluActivationWeightsAtOutCoords();
|
|
`+i+`
|
|
}`:g=`
|
|
float activation(float x) {
|
|
`+i+`
|
|
}
|
|
`,v="result = activation(result);");var b=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode=`
|
|
`+g+`
|
|
|
|
const ivec2 strides = ivec2(`+u+", "+c+`);
|
|
const ivec2 pads = ivec2(`+o+", "+l+`);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
ivec2 xRCCorner = coords.yz * strides - pads;
|
|
int d2 = coords.w;
|
|
int d1 = d2 / `+m+`;
|
|
int q = d2 - d1 * `+m+`;
|
|
|
|
int xRCorner = xRCCorner.x;
|
|
int xCCorner = xRCCorner.y;
|
|
|
|
// Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
// TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.
|
|
for (int wR = 0; wR < `+p+`; wR++) {
|
|
int xR = xRCorner + wR * `+h+`;
|
|
|
|
if (xR < 0 || xR >= `+a+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wC = 0; wC < `+f+`; wC++) {
|
|
int xC = xCCorner + wC * `+d+`;
|
|
|
|
if (xC < 0 || xC >= `+s+`) {
|
|
continue;
|
|
}
|
|
|
|
float xVal = getX(batch, xR, xC, d1);
|
|
float wVal = getW(wR, wC, d1, q);
|
|
dotProd += xVal * wVal;
|
|
}
|
|
}
|
|
|
|
float result = dotProd;
|
|
`+b+`
|
|
`+v+`
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var zS=function(){function n(t,e,i,r){e===void 0&&(e=!1),i===void 0&&(i=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t.outShape;for(var a=t.inHeight,s=t.inWidth,o=t.padInfo.top,l=t.padInfo.left,u=t.strideHeight,c=t.strideWidth,h=t.dilationHeight,d=t.dilationWidth,p=t.filterHeight,f=t.filterWidth,m=f,g="int xR; int xC; int xCOffset;",v=0;v<p;v++)for(var b=0;b<f;b++)g+=`
|
|
vec4 xTexelR`+v+"C"+b*2+` = vec4(0.);
|
|
vec4 wR`+v+"C"+b+` = vec4(0.);
|
|
vec4 xR`+v+"C"+b+" = vec4(0.);";for(var v=0;v<p;v++)for(var w=0;w<m;w++){var b=w*2;if(g+=`
|
|
xR = xRCorner + `+v*h+`;
|
|
xC = xCCorner + `+b*d+`;
|
|
`,c===1){if(b<f&&(l%2===1?g+=`
|
|
xCOffset = xC + 1;
|
|
if(xR >= 0 && xR < `+a+" && xCOffset >= 0 && xCOffset < "+s+`) {
|
|
xTexelR`+v+"C"+b+` = getX(batch, xR, xCOffset, d1);
|
|
|
|
// Need to manually clear unused channels in case
|
|
// we're reading from recycled texture.
|
|
if(xCOffset + 1 >= `+s+`) {
|
|
xTexelR`+v+"C"+b+`.zw = vec2(0.);
|
|
}
|
|
} else {
|
|
xTexelR`+v+"C"+b+` = vec4(0.);
|
|
}
|
|
|
|
xCOffset = xC + 1 - 2;
|
|
if(xR >= 0 && xR < `+a+" && xCOffset >= 0 && xCOffset < "+s+`) {
|
|
vec4 previous = getX(batch, xR, xCOffset, d1);
|
|
|
|
// Need to manually clear unused channels in case
|
|
// we're reading from recycled texture.
|
|
if(xCOffset + 1 >= `+s+`) {
|
|
previous.zw = vec2(0.);
|
|
}
|
|
|
|
xR`+v+"C"+b+" = vec4(previous.zw, xTexelR"+v+"C"+b+`.xy);
|
|
} else {
|
|
xR`+v+"C"+b+" = vec4(0, 0, xTexelR"+v+"C"+b+`.xy);
|
|
}
|
|
`:g+=`
|
|
if(xR >= 0 && xR < `+a+" && xC >= 0 && xC < "+s+`) {
|
|
xTexelR`+v+"C"+b+` = getX(batch, xR, xC, d1);
|
|
} else {
|
|
xTexelR`+v+"C"+b+` = vec4(0.);
|
|
}
|
|
|
|
xR`+v+"C"+b+" = xTexelR"+v+"C"+b+`;
|
|
`,b+1<f)){var S=l%2===0?x.util.nearestLargerEven(d):d;d%2===0&&l%2===1||d%2!==0&&l%2!==1?(g+=`
|
|
xCOffset = xC + `+l%2+" + "+S+`;
|
|
|
|
if(xR >= 0 && xR < `+a+` &&
|
|
xCOffset >= 0 && xCOffset < `+s+`) {
|
|
xTexelR`+v+"C"+(b+2)+` = getX(batch, xR, xCOffset, d1);
|
|
}
|
|
`,d>1&&(g+=`
|
|
xCOffset -= 2;
|
|
if(xR >= 0 && xR < `+a+` &&
|
|
xCOffset >= 0 && xCOffset < `+s+`) {
|
|
xTexelR`+v+"C"+b+` = getX(batch, xR, xCOffset, d1);
|
|
} else {
|
|
xTexelR`+v+"C"+b+` = vec4(0.);
|
|
}
|
|
`),g+=`
|
|
xR`+v+"C"+(b+1)+` = vec4(
|
|
xTexelR`+v+"C"+b+".zw, xTexelR"+v+"C"+(b+2)+`.xy);
|
|
`):g+=`
|
|
xCOffset = xC + `+S+`;
|
|
|
|
if(xR >= 0 && xR < `+a+` &&
|
|
xCOffset >= 0 && xCOffset < `+s+`) {
|
|
xTexelR`+v+"C"+(b+2)+` = getX(batch, xR, xCOffset, d1);
|
|
}
|
|
|
|
xR`+v+"C"+(b+1)+" = xTexelR"+v+"C"+(b+2)+`;
|
|
`}}else b<f&&(g+=`
|
|
if(xR >= 0 && xR < `+a+`) {
|
|
`,l%2===1?(g+=`
|
|
xCOffset = xC + 1 - `+c+`;
|
|
if(xCOffset >= 0 && xCOffset < `+s+`) {
|
|
xTexelR`+v+"C"+b+` = getX(batch, xR, xCOffset, d1);
|
|
} else {
|
|
xTexelR`+v+"C"+b+` = vec4(0.);
|
|
}
|
|
|
|
if(xC + 1 >= 0 && xC + 1 < `+s+`) {
|
|
xTexelR`+v+"C"+(b+2)+` = getX(batch, xR, xC + 1, d1);
|
|
} else {
|
|
xTexelR`+v+"C"+(b+2)+` = vec4(0.);
|
|
}
|
|
|
|
xR`+v+"C"+b+` = vec4(
|
|
xTexelR`+v+"C"+b+".zw, xTexelR"+v+"C"+(b+2)+`.zw);
|
|
`,b+1<f&&(g+=`
|
|
vec4 final = vec4(0.);
|
|
xCOffset = xC + 1 + `+c+`;
|
|
if(xCOffset >= 0 && xCOffset < `+s+`) {
|
|
final = getX(batch, xR, xCOffset, d1);
|
|
}
|
|
xR`+v+"C"+(b+1)+" = vec4(xTexelR"+v+"C"+(b+2)+`.xy, final.xy);
|
|
`)):(g+=`
|
|
if(xC >= 0 && xC < `+s+`) {
|
|
xTexelR`+v+"C"+b+` = getX(batch, xR, xC, d1);
|
|
} else {
|
|
xTexelR`+v+"C"+b+` = vec4(0.);
|
|
}
|
|
|
|
xCOffset = xC + `+c+`;
|
|
if(xCOffset >= 0 && xCOffset < `+s+`) {
|
|
xTexelR`+v+"C"+(b+2)+` = getX(batch, xR, xCOffset, d1);
|
|
} else {
|
|
xTexelR`+v+"C"+(b+2)+` = vec4(0.);
|
|
}
|
|
|
|
xR`+v+"C"+b+` = vec4(
|
|
xTexelR`+v+"C"+b+".xy, xTexelR"+v+"C"+(b+2)+`.xy);
|
|
`,b+1<f&&(g+=`
|
|
xR`+v+"C"+(b+1)+` = vec4(
|
|
xTexelR`+v+"C"+b+".zw, xTexelR"+v+"C"+(b+2)+`.zw);
|
|
`)),g+="}");b<f&&(g+=`
|
|
vec4 wTexelR`+v+"C"+b+" = getW("+v+", "+b+`, d1, q);
|
|
wR`+v+"C"+b+" = vec4(wTexelR"+v+"C"+b+".xz, wTexelR"+v+"C"+b+`.xz);
|
|
`,b+1<f&&(g+=`
|
|
vec4 wTexelR`+v+"C"+(b+1)+" = getW("+v+", "+(b+1)+`, d1, q);
|
|
wR`+v+"C"+(b+1)+` =
|
|
vec4(wTexelR`+v+"C"+(b+1)+".xz, wTexelR"+v+"C"+(b+1)+".xz);"))}for(var v=0;v<p;v++)for(var b=0;b<f;b++)g+="dotProd += xR"+v+"C"+b+" * wR"+v+"C"+b+";";var L="",N="";i&&(r?L=`vec4 activation(vec4 a) {
|
|
vec4 b = getPreluActivationWeightsAtOutCoords();
|
|
`+i+`
|
|
}`:L=`vec4 activation(vec4 x) {
|
|
`+i+`
|
|
}`,N="result = activation(result);");var C=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode=`
|
|
`+L+`
|
|
|
|
const ivec2 strides = ivec2(`+u+", "+c+`);
|
|
const ivec2 pads = ivec2(`+o+", "+l+`);
|
|
|
|
void main() {
|
|
|
|
ivec4 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
ivec2 xRCCorner = coords.yz * strides - pads;
|
|
int d2 = coords.w;
|
|
int d1 = d2;
|
|
int q = 0;
|
|
int xRCorner = xRCCorner.x;
|
|
int xCCorner = xRCCorner.y;
|
|
|
|
vec4 dotProd = vec4(0.);
|
|
|
|
`+g+`
|
|
|
|
vec4 result = dotProd;
|
|
`+C+`
|
|
`+N+`
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var o9=function(){function n(t,e,i,r,a){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var s=t[0],o=t[1],l=t[2],u=t[3],c=e[0],h=i[0],d=i[1];this.outputShape=[c,h,d,u];var p=r==="bilinear"?1:0,f=[o-1+".0",l-1+".0"],m=f[0],g=f[1],v=h>1?[""+(o-1)/(h-1),"(y2-y1) * height_ratio","y1*"+m+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+m],b=v[0],w=v[1],S=v[2],L=d>1?[""+(l-1)/(d-1),"(x2-x1) * width_ratio","x1*"+g+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+g],N=L[0],C=L[1],R=L[2];this.userCode=`
|
|
const float height_ratio = float(`+b+`);
|
|
const float width_ratio = float(`+N+`);
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int y = coords[1];
|
|
int x = coords[2];
|
|
int d = coords[3];
|
|
|
|
// get box vals
|
|
float y1 = getBoxes(b,0);
|
|
float x1 = getBoxes(b,1);
|
|
float y2 = getBoxes(b,2);
|
|
float x2 = getBoxes(b,3);
|
|
|
|
// get image in batch index
|
|
int bInd = round(getBoxInd(b));
|
|
if(bInd < 0 || bInd >= `+s+`) {
|
|
return;
|
|
}
|
|
|
|
float height_scale = `+w+`;
|
|
float width_scale = `+C+`;
|
|
|
|
float in_y = `+S+`;
|
|
if( in_y < 0.0 || in_y > `+m+` ) {
|
|
setOutput(float(`+a+`));
|
|
return;
|
|
}
|
|
float in_x = `+R+`;
|
|
if( in_x < 0.0 || in_x > `+g+` ) {
|
|
setOutput(float(`+a+`));
|
|
return;
|
|
}
|
|
|
|
vec2 sourceFracIndexCR = vec2(in_x,in_y);
|
|
if(`+p+` == 1) {
|
|
// Compute the four integer indices.
|
|
ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);
|
|
ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));
|
|
|
|
float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);
|
|
float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);
|
|
float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);
|
|
float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);
|
|
|
|
vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);
|
|
|
|
float top = topLeft + (topRight - topLeft) * fracCR.x;
|
|
float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;
|
|
float newValue = top + (bottom - top) * fracCR.y;
|
|
setOutput(newValue);
|
|
} else {
|
|
// Compute the coordinators of nearest neighbor point.
|
|
ivec2 sourceNearestCR = ivec2(floor(
|
|
sourceFracIndexCR + vec2(0.5,0.5)));
|
|
float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);
|
|
setOutput(newValue);
|
|
}
|
|
}
|
|
`}return n}(),MS=function(){function n(t,e,i){this.variableNames=["x"],this.outputShape=t;var r=t.length,a=e?"0.0":"getX("+PS(r,"coords")+")",s=t[t.length-1],o="",l="";e?(o=i?"end != "+(s-1):"end != 0",l=i?"end + 1":"end - 1"):(o=i?"end + pow2 < "+s:"end >= pow2",l=i?"end + pow2":"end - pow2"),this.userCode=`
|
|
uniform float index;
|
|
void main() {
|
|
`+Ze(r)+` coords = getOutputCoords();
|
|
int end = `+_S(r,"coords")+`;
|
|
float val = `+a+`;
|
|
int pow2 = int(pow(2.0, index));
|
|
if (`+o+`) {
|
|
int idx = `+l+`;
|
|
`+_S(r,"coords")+` = idx;
|
|
val += getX(`+PS(r,"coords")+`);
|
|
}
|
|
setOutput(val);
|
|
}
|
|
`}return n.prototype.getCustomSetupFunc=function(t){var e=this;return function(i,r){e.index==null&&(e.index=i.getUniformLocation(r,"index")),i.gl.uniform1f(e.index,t)}},n}();function PS(n,t){if(n===1)return""+t;if(n===2)return t+".x, "+t+".y";if(n===3)return t+".x, "+t+".y, "+t+".z";if(n===4)return t+".x, "+t+".y, "+t+".z, "+t+".w";throw Error("Cumulative sum for rank "+n+" is not yet supported")}function _S(n,t){if(n===1)return""+t;if(n===2)return t+".y";if(n===3)return t+".z";if(n===4)return t+".w";throw Error("Cumulative sum for rank "+n+" is not yet supported")}var l9=function(){function n(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=vs.DENSE;var e=bs(t),i=Bt();this.outputShape=t,this.userCode=`
|
|
ivec3 outCoordsFromFlatIndex(int index) {
|
|
`+Ar(["r","c","d"],t)+`
|
|
return ivec3(r, c, d);
|
|
}
|
|
|
|
void main() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+e[0]+", "+e[1]+`));
|
|
int index = 4 * (resTexRC.x * `+e[1]+` + resTexRC.y);
|
|
|
|
vec4 result = vec4(0.);
|
|
|
|
for (int i=0; i<4; i++) {
|
|
int flatIndex = index + i;
|
|
ivec3 rc = outCoordsFromFlatIndex(flatIndex);
|
|
result[i] = getA(rc.x, rc.y, rc.z);
|
|
}
|
|
|
|
`+i.output+` = result;
|
|
}
|
|
`}return n}();var u9=function(){function n(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=vs.DENSE;var e=bs(t),i=Bt();this.outputShape=t,this.userCode=`
|
|
ivec3 outCoordsFromFlatIndex(int index) {
|
|
`+Ar(["r","c","d"],t)+`
|
|
return ivec3(r, c, d);
|
|
}
|
|
|
|
void main() {
|
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
vec2(`+e[0]+", "+e[1]+`));
|
|
int index = 4 * (resTexRC.x * `+e[1]+` + resTexRC.y);
|
|
|
|
vec4 result = vec4(0.);
|
|
|
|
for (int i=0; i<4; i++) {
|
|
int flatIndex = index + i;
|
|
ivec3 rc = outCoordsFromFlatIndex(flatIndex);
|
|
result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));
|
|
}
|
|
|
|
`+i.output+` = result;
|
|
}
|
|
`}return n}();var c9=function(){function n(t,e,i){this.variableNames=["x"],this.outputShape=[],this.outputShape=t,this.blockSize=e,this.dataFormat=i,this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int h = `+this.getHeightCoordString()+`;
|
|
int w = `+this.getWidthCoordString()+`;
|
|
int d = `+this.getDepthCoordString()+`;
|
|
|
|
int in_h = h / `+e+`;
|
|
int offset_h = imod(h, `+e+`);
|
|
int in_w = w / `+e+`;
|
|
int offset_w = imod(w, `+e+`);
|
|
int offset_d = (offset_h * `+e+` + offset_w) *
|
|
`+this.getOutputDepthSize()+`;
|
|
int in_d = d + offset_d;
|
|
|
|
float result = `+this.getInputSamplingString()+`;
|
|
setOutput(result);
|
|
}
|
|
`}return n.prototype.getHeightCoordString=function(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"},n.prototype.getWidthCoordString=function(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"},n.prototype.getDepthCoordString=function(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"},n.prototype.getOutputDepthSize=function(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]},n.prototype.getInputSamplingString=function(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},n}();var h9=function(){function n(t){this.variableNames=["X"],this.outputShape=[t,t],this.userCode=`
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;
|
|
setOutput(val);
|
|
}
|
|
`}return n}();var d9=function(){function n(t){this.variableNames=["A"],this.outTexUsage=on.DOWNLOAD;var e=Bt();this.outputShape=t,this.userCode=`
|
|
`+NS+`
|
|
|
|
void main() {
|
|
float x = getAAtOutCoords();
|
|
`+e.output+` = encode_float(x);
|
|
}
|
|
`}return n}();var p9=function(){function n(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=on.DOWNLOAD;var e=Bt();this.outputShape=t,this.userCode=`
|
|
`+NS+`
|
|
|
|
void main() {
|
|
ivec3 coords = getOutputCoords();
|
|
float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));
|
|
`+e.output+` = encode_float(x);
|
|
}
|
|
`}return n}();var f9=function(){function n(t,e,i){i===void 0&&(i=!1),this.variableNames=["A"];var r=Bt(),a=e[0],s=e[1];this.outputShape=t;var o="result";i&&(o="floor(result * 255. + 0.5)"),this.userCode=`
|
|
`+pp(t)+`
|
|
|
|
void main() {
|
|
ivec3 coords = getOutputCoords();
|
|
|
|
int flatIndex = getFlatIndex(coords);
|
|
int offset = imod(flatIndex, 4);
|
|
|
|
flatIndex = idiv(flatIndex, 4, 1.);
|
|
|
|
int r = flatIndex / `+s+`;
|
|
int c = imod(flatIndex, `+s+`);
|
|
vec2 uv = (vec2(c, r) + halfCR) / vec2(`+s+".0, "+a+`.0);
|
|
vec4 values = `+r.texture2D+`(A, uv);
|
|
|
|
float result;
|
|
|
|
if(offset == 0) {
|
|
result = values[0];
|
|
} else if(offset == 1) {
|
|
result = values[1];
|
|
} else if(offset == 2) {
|
|
result = values[2];
|
|
} else {
|
|
result = values[3];
|
|
}
|
|
|
|
`+r.output+" = vec4("+o+`, 0., 0., 0.);
|
|
}
|
|
`}return n}();var m9=function(){function n(t,e,i){i===void 0&&(i=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var r=Bt(),a=e[0],s=e[1];this.outputShape=t;var o="",l="result";i&&(l="floor(result * 255. + 0.5)");for(var u=0;u<=1;u++)for(var c=0;c<=1;c++){var h=u*2+c;o+=`
|
|
localCoords = coords;
|
|
if(localCoords[2] + `+c+" < "+t[2]+`) {
|
|
localCoords[2] += `+c+`;
|
|
if(localCoords[1] + `+u+" < "+t[1]+`) {
|
|
localCoords[1] += `+u+`;
|
|
|
|
flatIndex = getFlatIndex(localCoords);
|
|
offset = imod(flatIndex, 4);
|
|
|
|
flatIndex = idiv(flatIndex, 4, 1.);
|
|
|
|
r = flatIndex / `+s+`;
|
|
c = imod(flatIndex, `+s+`);
|
|
uv = (vec2(c, r) + halfCR) / vec2(`+s+".0, "+a+`.0);
|
|
values = `+r.texture2D+`(A, uv);
|
|
|
|
if(offset == 0) {
|
|
result[`+h+`] = values[0];
|
|
} else if(offset == 1) {
|
|
result[`+h+`] = values[1];
|
|
} else if(offset == 2) {
|
|
result[`+h+`] = values[2];
|
|
} else {
|
|
result[`+h+`] = values[3];
|
|
}
|
|
}
|
|
}
|
|
`}this.userCode=`
|
|
`+pp(t)+`
|
|
|
|
void main() {
|
|
ivec3 coords = getOutputCoords();
|
|
|
|
vec4 result = vec4(0.);
|
|
int flatIndex, r, c, offset;
|
|
ivec3 localCoords;
|
|
vec2 uv;
|
|
vec4 values;
|
|
|
|
`+o+`
|
|
|
|
`+r.output+" = "+l+`;
|
|
}
|
|
`}return n}();var HS={REAL:"return real * expR - imag * expI;",IMAG:"return real * expI + imag * expR;"},VS=function(){function n(t,e,i){this.variableNames=["real","imag"];var r=e[1];this.outputShape=e;var a=i?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,s=i?r+".0":"1.0";this.userCode=`
|
|
const float exponentMultiplier = `+a+`;
|
|
|
|
float unaryOpComplex(float real, float expR, float imag, float expI) {
|
|
`+t+`
|
|
}
|
|
|
|
float mulMatDFT(int batch, int index) {
|
|
float indexRatio = float(index) / float(`+r+`);
|
|
float exponentMultiplierTimesIndexRatio =
|
|
exponentMultiplier * indexRatio;
|
|
|
|
float result = 0.0;
|
|
|
|
for (int i = 0; i < `+r+`; i++) {
|
|
// x = (-2|2 * PI / N) * index * i;
|
|
float x = exponentMultiplierTimesIndexRatio * float(i);
|
|
float expR = cos(x);
|
|
float expI = sin(x);
|
|
float real = getReal(batch, i);
|
|
float imag = getImag(batch, i);
|
|
|
|
result +=
|
|
unaryOpComplex(real, expR, imag, expI) / `+s+`;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
setOutput(mulMatDFT(coords[0], coords[1]));
|
|
}
|
|
`}return n}();var g9=function(){function n(t,e){this.outputShape=[],this.variableNames=["x"],this.outputShape=t,this.userCode=`
|
|
uniform float value;
|
|
void main() {
|
|
// Input can be obtained from uniform value.
|
|
setOutput(value);
|
|
}
|
|
`}return n.prototype.getCustomSetupFunc=function(t){var e=this;return function(i,r){e.valueLoc==null&&(e.valueLoc=i.getUniformLocationNoThrow(r,"value")),i.gl.uniform1f(e.valueLoc,t)}},n}();var y9=function(){function n(t,e,i){this.variableNames=["A","indices"];var r=t.slice();r[i]=e,this.outputShape=r,this.rank=r.length;var a=Ze(this.rank),s=v9(t,i);this.userCode=`
|
|
void main() {
|
|
`+a+` resRC = getOutputCoords();
|
|
setOutput(getA(`+s+`));
|
|
}
|
|
`}return n}();function v9(n,t){var e=n.length;if(e>4)throw Error("Gather for rank "+e+" is not yet supported");if(e===1)return"int(getIndices(resRC))";for(var i=["resRC.x","resRC.y","resRC.z","resRC.w"],r=[],a=0;a<n.length;a++)a===t?r.push("int(getIndices("+i[a]+"))"):r.push(""+i[a]);return r.join()}var b9=function(){function n(t,e,i){this.sliceDim=t,this.strides=e,this.variableNames=["x","indices"],this.outputShape=i;var r=Ze(e.length),a=Ze(i.length),s=this.sliceDim>1?"strides[j]":"strides";this.userCode=`
|
|
`+r+" strides = "+r+"("+this.strides+`);
|
|
void main() {
|
|
`+a+` coords = getOutputCoords();
|
|
int flattenIndex = 0;
|
|
for (int j = 0; j < `+this.sliceDim+`; j++) {
|
|
int index = round(getIndices(coords[0], j));
|
|
flattenIndex += index * `+s+`;
|
|
}
|
|
setOutput(getX(flattenIndex, coords[1]));
|
|
}
|
|
`}return n}();function qS(n){var t=Bt(),e=t.version+`
|
|
precision highp float;
|
|
`+t.attribute+` vec3 clipSpacePos;
|
|
`+t.attribute+` vec2 uv;
|
|
`+t.varyingVs+` vec2 resultUV;
|
|
|
|
void main() {
|
|
gl_Position = vec4(clipSpacePos, 1);
|
|
resultUV = uv;
|
|
}`;return nS(n,e)}function GS(n){var t=new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]);return sS(n,t)}function YS(n){var t=new Uint16Array([0,1,2,2,1,3]);return oS(n,t)}function Is(n,t,e,i,r,a){uS(t,e);var s=lS(n),o=n.TEXTURE_2D;return ce(n,function(){return n.bindTexture(o,s)}),ce(n,function(){return n.texParameteri(o,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE)}),ce(n,function(){return n.texParameteri(o,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE)}),ce(n,function(){return n.texParameteri(o,n.TEXTURE_MIN_FILTER,n.NEAREST)}),ce(n,function(){return n.texParameteri(o,n.TEXTURE_MAG_FILTER,n.NEAREST)}),ce(n,function(){return n.texImage2D(o,0,i,t,e,0,r,a,null)}),ce(n,function(){return n.bindTexture(n.TEXTURE_2D,null)}),s}function gp(n){return n.internalFormatFloat}function jS(n,t,e,i){var r=ys(t,e),a=r[0],s=r[1];return Is(n,a,s,gp(i),i.textureFormatFloat,n.FLOAT)}function vp(n){return n.internalFormatHalfFloat}function KS(n,t,e,i){var r=ys(t,e),a=r[0],s=r[1];return Is(n,a,s,vp(i),i.textureFormatFloat,i.textureTypeHalfFloat)}function yp(n){return n.downloadTextureFormat}function $S(n,t,e,i){var r=ys(t,e),a=r[0],s=r[1];return Is(n,a,s,yp(i),n.RGBA,n.UNSIGNED_BYTE)}function bp(n){return n.internalFormatPackedFloat}function XS(n,t,e,i){var r=fa(t,e),a=r[0],s=r[1];return Is(n,a,s,bp(i),n.RGBA,n.FLOAT)}function wp(n){return n.internalFormatPackedHalfFloat}function JS(n,t,e,i){var r=fa(t,e),a=r[0],s=r[1];return Is(n,a,s,wp(i),n.RGBA,i.textureTypeHalfFloat)}function ZS(n,t,e){var i=0,r=3*4,a=3*4+2*4;ce(n,function(){return n.bindBuffer(n.ARRAY_BUFFER,e)});var s=lp(n,t,"clipSpacePos",e,3,a,i);return s&&lp(n,t,"uv",e,2,a,r)}function QS(n,t,e,i,r,a){ce(n,function(){return n.bindTexture(n.TEXTURE_2D,t)});var s,o,l;r instanceof Uint8Array?(s=new Uint8Array(e*i*4),o=n.UNSIGNED_BYTE,l=n.RGBA):(s=new Float32Array(e*i*4),o=n.FLOAT,l=a.internalFormatPackedFloat),s.set(r),ce(n,function(){return n.texImage2D(n.TEXTURE_2D,0,l,e,i,0,n.RGBA,o,s)}),ce(n,function(){return n.bindTexture(n.TEXTURE_2D,null)})}function eL(n,t,e){ce(n,function(){return n.bindTexture(n.TEXTURE_2D,t)}),e.data instanceof Uint8Array?ce(n,function(){return n.texImage2D(n.TEXTURE_2D,0,n.RGBA,e.width,e.height,0,n.RGBA,n.UNSIGNED_BYTE,e.data)}):ce(n,function(){return n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e)}),ce(n,function(){return n.bindTexture(n.TEXTURE_2D,null)})}function tL(n,t,e,i){var r=n.createBuffer();ce(n,function(){return n.bindBuffer(n.PIXEL_PACK_BUFFER,r)});var a=4,s=4,o=a*s*t*e;return ce(n,function(){return n.bufferData(n.PIXEL_PACK_BUFFER,o,n.STREAM_READ)}),ce(n,function(){return n.readPixels(0,0,e,t,n.RGBA,n.FLOAT,0)}),ce(n,function(){return n.bindBuffer(n.PIXEL_PACK_BUFFER,null)}),r}function nL(n,t,e){var i=n,r=new Float32Array(e);return i.bindBuffer(i.PIXEL_PACK_BUFFER,t),i.getBufferSubData(i.PIXEL_PACK_BUFFER,0,r),i.bindBuffer(i.PIXEL_PACK_BUFFER,null),r}function iL(n,t,e,i){var r=ys(t,e),a=r[0],s=r[1],o=4,l=new Uint8Array(G_(t*e,o));return ce(n,function(){return n.readPixels(0,0,a,s,i.downloadTextureFormat,n.UNSIGNED_BYTE,l)}),new Float32Array(l.buffer)}function rL(n,t,e,i,r,a,s,o){var l=n,u=new Float32Array(Y_(a,s));return l.bindBuffer(l.PIXEL_PACK_BUFFER,t),l.getBufferSubData(l.PIXEL_PACK_BUFFER,0,u),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),u}function aL(n,t,e){var i=new Float32Array(t*e*4);return ce(n,function(){return n.readPixels(0,0,e,t,n.RGBA,n.FLOAT,i)}),i}var w9={__proto__:null,createVertexShader:qS,createVertexBuffer:GS,createIndexBuffer:YS,getInternalFormatForFloat32MatrixTexture:gp,createFloat32MatrixTexture:jS,getInternalFormatForFloat16MatrixTexture:vp,createFloat16MatrixTexture:KS,getInternalFormatForUnsignedBytesMatrixTexture:yp,createUnsignedBytesMatrixTexture:$S,getInternalFormatForPackedMatrixTexture:bp,createPackedMatrixTexture:XS,getInternalFormatForFloat16PackedMatrixTexture:wp,createFloat16PackedMatrixTexture:JS,bindVertexProgramAttributeStreams:ZS,uploadDenseMatrixToTexture:QS,uploadPixelDataToTexture:eL,createBufferFromOutputTexture:tL,downloadFloat32MatrixFromBuffer:nL,downloadByteEncodedFloatMatrixFromOutputTexture:iL,downloadPackedMatrixFromBuffer:rL,downloadMatrixFromPackedOutputTexture:aL};var sL=function(){function n(t){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];var e=x.env().getNumber("WEBGL_VERSION");t!=null?(this.gl=t,Q0(e,t)):this.gl=Gn(e);var i="WEBGL_color_buffer_float",r="EXT_color_buffer_half_float";if(x.env().getNumber("WEBGL_VERSION")===1){var a="OES_texture_float",s="OES_texture_half_float";if(this.textureFloatExtension=ws(this.gl,a),ln(this.gl,s))this.textureHalfFloatExtension=ws(this.gl,s);else if(x.env().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(i),ln(this.gl,r))this.colorBufferHalfFloatExtension=ws(this.gl,r);else if(x.env().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(i="EXT_color_buffer_float",ln(this.gl,i))this.colorBufferFloatExtension=this.gl.getExtension(i);else if(ln(this.gl,r))this.colorBufferHalfFloatExtension=this.gl.getExtension(r);else throw new Error("GL context does not support color renderable floats");this.vertexBuffer=GS(this.gl),this.indexBuffer=YS(this.gl),this.framebuffer=cS(this.gl),this.textureConfig=op(this.gl,this.textureHalfFloatExtension)}return Object.defineProperty(n.prototype,"debug",{get:function(){return x.env().getBool("DEBUG")},enumerable:!0,configurable:!0}),n.prototype.dispose=function(){var t=this;if(this.disposed)return;this.program!=null&&console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."),this.outputTexture!=null&&console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");var e=this.gl;ce(e,function(){return e.finish()}),ce(e,function(){return e.bindFramebuffer(e.FRAMEBUFFER,null)}),ce(e,function(){return e.deleteFramebuffer(t.framebuffer)}),ce(e,function(){return e.bindBuffer(e.ARRAY_BUFFER,null)}),ce(e,function(){return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null)}),ce(e,function(){return e.deleteBuffer(t.indexBuffer)}),this.disposed=!0},n.prototype.createFloat32MatrixTexture=function(t,e){return this.throwIfDisposed(),jS(this.gl,t,e,this.textureConfig)},n.prototype.createFloat16MatrixTexture=function(t,e){return this.throwIfDisposed(),KS(this.gl,t,e,this.textureConfig)},n.prototype.createUnsignedBytesMatrixTexture=function(t,e){return this.throwIfDisposed(),$S(this.gl,t,e,this.textureConfig)},n.prototype.uploadPixelDataToTexture=function(t,e){this.throwIfDisposed(),eL(this.gl,t,e)},n.prototype.uploadDenseMatrixToTexture=function(t,e,i,r){this.throwIfDisposed(),QS(this.gl,t,e,i,r,this.textureConfig)},n.prototype.createFloat16PackedMatrixTexture=function(t,e){return this.throwIfDisposed(),JS(this.gl,t,e,this.textureConfig)},n.prototype.createPackedMatrixTexture=function(t,e){return this.throwIfDisposed(),XS(this.gl,t,e,this.textureConfig)},n.prototype.deleteMatrixTexture=function(t){var e=this;this.throwIfDisposed(),this.outputTexture===t&&(up(this.gl,this.framebuffer),this.outputTexture=null),ce(this.gl,function(){return e.gl.deleteTexture(t)})},n.prototype.downloadByteEncodedFloatMatrixFromOutputTexture=function(t,e,i){var r=this;return this.downloadMatrixDriver(t,function(){return iL(r.gl,e,i,r.textureConfig)})},n.prototype.downloadPackedMatrixFromBuffer=function(t,e,i,r,a,s){return rL(this.gl,t,e,i,r,a,s,this.textureConfig)},n.prototype.downloadFloat32MatrixFromBuffer=function(t,e){return nL(this.gl,t,e)},n.prototype.createBufferFromTexture=function(t,e,i){this.bindTextureToFrameBuffer(t);var r=tL(this.gl,e,i,this.textureConfig);return this.unbindTextureToFrameBuffer(),r},n.prototype.createAndWaitForFence=function(){var t=this.createFence(this.gl);return this.pollFence(t)},n.prototype.createFence=function(t){var e=this,i,r;if(x.env().getBool("WEBGL_FENCE_API_ENABLED")){var a=t,s=a.fenceSync(a.SYNC_GPU_COMMANDS_COMPLETE,0);t.flush(),r=function(){var o=a.clientWaitSync(s,0,0);return o===a.ALREADY_SIGNALED||o===a.CONDITION_SATISFIED},i=s}else x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(i=this.beginQuery(),this.endQuery(),r=function(){return e.isQueryAvailable(i,x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))}):r=function(){return!0};return{query:i,isFencePassed:r}},n.prototype.downloadMatrixFromPackedTexture=function(t,e,i){var r=this;return this.downloadMatrixDriver(t,function(){return aL(r.gl,e,i)})},n.prototype.createProgram=function(t){this.throwIfDisposed();var e=this.gl,i=iS(e,t),r=qS(e),a=rS(e);return ce(e,function(){return e.attachShader(a,r)}),ce(e,function(){return e.attachShader(a,i)}),aS(e,a),this.debug&&tl(e,a),this.vertexAttrsAreBound||(this.setProgram(a),this.vertexAttrsAreBound=ZS(e,this.program,this.vertexBuffer)),a},n.prototype.deleteProgram=function(t){var e=this;this.throwIfDisposed(),t===this.program&&(this.program=null),t!=null&&ce(this.gl,function(){return e.gl.deleteProgram(t)})},n.prototype.setProgram=function(t){var e=this;this.throwIfDisposed(),this.program=t,this.program!=null&&this.debug&&tl(this.gl,this.program),ce(this.gl,function(){return e.gl.useProgram(t)})},n.prototype.getUniformLocation=function(t,e,i){return i===void 0&&(i=!0),this.throwIfDisposed(),i?pS(this.gl,t,e):fS(this.gl,t,e)},n.prototype.getAttributeLocation=function(t,e){var i=this;return this.throwIfDisposed(),ce(this.gl,function(){return i.gl.getAttribLocation(t,e)})},n.prototype.getUniformLocationNoThrow=function(t,e){return this.throwIfDisposed(),this.gl.getUniformLocation(t,e)},n.prototype.setInputMatrixTexture=function(t,e,i){this.throwIfDisposed(),this.throwIfNoProgram(),mS(this.gl,t,e,i)},n.prototype.setOutputMatrixTexture=function(t,e,i){this.setOutputMatrixTextureDriver(t,i,e)},n.prototype.setOutputPackedMatrixTexture=function(t,e,i){this.throwIfDisposed();var r=fa(e,i),a=r[0],s=r[1];this.setOutputMatrixTextureDriver(t,a,s)},n.prototype.setOutputMatrixWriteRegion=function(t,e,i,r){this.setOutputMatrixWriteRegionDriver(i,t,r,e)},n.prototype.setOutputPackedMatrixWriteRegion=function(t,e,i,r){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},n.prototype.debugValidate=function(){this.program!=null&&tl(this.gl,this.program),Ss(this.gl)},n.prototype.executeProgram=function(){this.throwIfDisposed(),this.throwIfNoProgram();var t=this.gl;this.debug&&this.debugValidate(),ce(t,function(){return t.drawElements(t.TRIANGLES,6,t.UNSIGNED_SHORT,0)})},n.prototype.blockUntilAllProgramsCompleted=function(){var t=this;this.throwIfDisposed(),ce(this.gl,function(){return t.gl.finish()})},n.prototype.getQueryTimerExtension=function(){return this.disjointQueryTimerExtension==null&&(this.disjointQueryTimerExtension=ws(this.gl,x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2?"EXT_disjoint_timer_query_webgl2":"EXT_disjoint_timer_query")),this.disjointQueryTimerExtension},n.prototype.getQueryTimerExtensionWebGL2=function(){return this.getQueryTimerExtension()},n.prototype.getQueryTimerExtensionWebGL1=function(){return this.getQueryTimerExtension()},n.prototype.beginQuery=function(){if(x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2){var t=this.gl,e=this.getQueryTimerExtensionWebGL2(),i=t.createQuery();return t.beginQuery(e.TIME_ELAPSED_EXT,i),i}var r=this.getQueryTimerExtensionWebGL1(),a=r.createQueryEXT();return r.beginQueryEXT(r.TIME_ELAPSED_EXT,a),a},n.prototype.endQuery=function(){if(x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2){var t=this.gl,e=this.getQueryTimerExtensionWebGL2();t.endQuery(e.TIME_ELAPSED_EXT);return}var i=this.getQueryTimerExtensionWebGL1();i.endQueryEXT(i.TIME_ELAPSED_EXT)},n.prototype.waitForQueryAndGetTime=function(t){return Qo(this,void 0,void 0,function(){var e=this;return el(this,function(i){switch(i.label){case 0:return[4,x.util.repeatedTry(function(){return e.disposed||e.isQueryAvailable(t,x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))})];case 1:return i.sent(),[2,this.getQueryTime(t,x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))]}})})},n.prototype.getQueryTime=function(t,e){if(e===0)return null;if(e===2){var i=this.gl,r=i.getQueryParameter(t,i.QUERY_RESULT);return r/1e6}else{var a=this.getQueryTimerExtensionWebGL1(),r=a.getQueryObjectEXT(t,a.QUERY_RESULT_EXT);return r/1e6}},n.prototype.isQueryAvailable=function(t,e){if(e===0)return!0;if(e===2){var i=this.gl,r=this.getQueryTimerExtensionWebGL2(),a=i.getQueryParameter(t,i.QUERY_RESULT_AVAILABLE);return this.disjoint==null&&(this.disjoint=this.gl.getParameter(r.GPU_DISJOINT_EXT)),a&&!this.disjoint}else{var r=this.getQueryTimerExtensionWebGL1(),a=r.getQueryObjectEXT(t,r.QUERY_RESULT_AVAILABLE_EXT);return this.disjoint==null&&(this.disjoint=this.gl.getParameter(r.GPU_DISJOINT_EXT)),a&&!this.disjoint}},n.prototype.pollFence=function(t){var e=this;return new Promise(function(i){e.addItemToPoll(function(){return t.isFencePassed()},function(){return i()})})},n.prototype.pollItems=function(){for(var t=S9(this.itemsToPoll.map(function(r){return r.isDoneFn})),e=0;e<=t;++e){var i=this.itemsToPoll[e].resolveFn;i()}this.itemsToPoll=this.itemsToPoll.slice(t+1)},n.prototype.addItemToPoll=function(t,e){var i=this;if(this.itemsToPoll.push({isDoneFn:t,resolveFn:e}),this.itemsToPoll.length>1)return;x.util.repeatedTry(function(){return i.pollItems(),i.itemsToPoll.length===0})},n.prototype.bindTextureToFrameBuffer=function(t){this.throwIfDisposed(),nl(this.gl,t,this.framebuffer),this.debug&&Ss(this.gl)},n.prototype.unbindTextureToFrameBuffer=function(){this.outputTexture!=null?(nl(this.gl,this.outputTexture,this.framebuffer),this.debug&&Ss(this.gl)):up(this.gl,this.framebuffer)},n.prototype.downloadMatrixDriver=function(t,e){this.bindTextureToFrameBuffer(t);var i=e();return this.unbindTextureToFrameBuffer(),i},n.prototype.setOutputMatrixTextureDriver=function(t,e,i){this.throwIfDisposed();var r=this.gl;nl(r,t,this.framebuffer),this.debug&&Ss(r),this.outputTexture=t,ce(r,function(){return r.viewport(0,0,e,i)}),ce(r,function(){return r.scissor(0,0,e,i)})},n.prototype.setOutputMatrixWriteRegionDriver=function(t,e,i,r){var a=this;this.throwIfDisposed(),ce(this.gl,function(){return a.gl.scissor(t,e,i,r)})},n.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},n.prototype.throwIfNoProgram=function(){if(this.program==null)throw new Error("No GPU program is currently set.")},n}();function S9(n){for(var t=0;t<n.length;++t){var e=n[t]();if(!e)break}return t-1}function L9(n,t,e,i){var r=t.userCode,a=e.map(function(g,v){var b={logicalShape:g.shape,texShape:g.isUniform?null:g.texData.texShape,isUniform:g.isUniform,isPacked:g.isUniform?!1:g.texData.isPacked,flatOffset:null};return g.texData!=null&&g.texData.slice!=null&&g.texData.slice.flatOffset>0&&(b.flatOffset=g.texData.slice.flatOffset),{name:t.variableNames[v],shapeInfo:b}}),s=a.map(function(g){return g.shapeInfo}),o={logicalShape:i.shape,texShape:i.texData.texShape,isUniform:!1,isPacked:i.texData.isPacked,flatOffset:null},l=qM(a,o,r,t.packedInputs),u=n.createProgram(l),c=null,h=n.getUniformLocation(u,"NAN",!1);x.env().getNumber("WEBGL_VERSION")===1&&(c=n.getUniformLocation(u,"INFINITY",!1));for(var d={},p=0;p<t.variableNames.length;p++){var f=t.variableNames[p],m=!1;d[f]=n.getUniformLocation(u,f,m),d["offset"+f]=n.getUniformLocation(u,"offset"+f,m)}return{program:t,source:l,webGLProgram:u,uniformLocations:d,inShapeInfos:s,outShapeInfo:o,infLoc:c,nanLoc:h}}function oL(n,t){if(n.length!==t.length)throw Error("Binary was compiled with "+n.length+" inputs, but "+("was executed with "+t.length+" inputs"));n.forEach(function(e,i){var r=e.logicalShape,a=t[i],s=a.shape;if(!x.util.arraysEqual(r,s))throw Error("Binary was compiled with different shapes than "+("the current args. Shapes "+r+" and "+s+" must match"));if(e.isUniform&&a.isUniform)return;var o=e.texShape,l=a.isUniform?null:a.texData.texShape;if(!x.util.arraysEqual(o,l))throw Error("Binary was compiled with different texture shapes than the"+(" current args. Shape "+o+" and "+l+" must match"))})}function I9(n,t,e,i,r){oL(t.inShapeInfos,e),oL([t.outShapeInfo],[i]);var a=i.texData.texture,s=i.texData.texShape;i.texData.isPacked?n.setOutputPackedMatrixTexture(a,s[0],s[1]):n.setOutputMatrixTexture(a,s[0],s[1]),n.setProgram(t.webGLProgram),x.env().getNumber("WEBGL_VERSION")===1&&(t.infLoc!==null&&n.gl.uniform1f(t.infLoc,Infinity)),t.nanLoc!==null&&n.gl.uniform1f(t.nanLoc,NaN),e.forEach(function(o,l){var u=t.program.variableNames[l],c=t.uniformLocations[u],h=t.uniformLocations["offset"+u];if(c==null)return;if(o.isUniform){if(x.util.sizeFromShape(o.shape)<2)n.gl.uniform1f(c,o.uniformValues[0]);else{var d=o.uniformValues;d instanceof Float32Array||(d=new Float32Array(d)),n.gl.uniform1fv(c,d)}return}o.texData.slice!=null&&h!=null&&n.gl.uniform1i(h,o.texData.slice.flatOffset),n.setInputMatrixTexture(o.texData.texture,c,l)}),r!=null&&r(n,t.webGLProgram),n.executeProgram()}function A9(n,t,e){var i="";t.concat(e).forEach(function(s){var o=s.texData!=null&&s.texData.slice!=null&&s.texData.slice.flatOffset>0,l=s.isUniform?"uniform":s.texData.texShape;i+=s.shape+"_"+l+"_"+o});var r=n.userCode,a=n.constructor.name;return a+="_"+i+"_"+r,a}var T9=function(){function n(t,e,i){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;for(var r=i.filterWidth,a=i.inChannels,s=i.strideWidth,o=i.strideHeight,l=i.padInfo,u=i.outWidth,c=i.dilationWidth,h=i.dilationHeight,d=i.dataFormat,p=l.left,f=l.top,m=a*r,g=Bt(),v=d==="channelsLast",b=v?0:1,w=v?1:2,S="",L=0;L<=1;L++)for(var N=0;N<=1;N++)S+=`
|
|
blockIndex = rc.y + `+N+`;
|
|
pos = rc.x + `+L+`;
|
|
|
|
if(blockIndex < `+t[1]+" && pos < "+t[0]+`) {
|
|
offsetY = int(blockIndex / (`+u+")) * "+o+" - "+f+`;
|
|
d0 = offsetY + `+h+" * (pos / "+m+`);
|
|
|
|
if(d0 < `+e[b]+` && d0 >= 0) {
|
|
|
|
offsetX = int(mod(float(blockIndex), `+u+".) * "+s+". - "+p+`.);
|
|
d1 = offsetX + `+c+" * (int(mod(float(pos), "+m+".) / "+a+`.));
|
|
|
|
if(d1 < `+e[w]+` && d1 >= 0) {
|
|
|
|
ch = int(mod(float(pos), `+a+`.));
|
|
|
|
if (`+v+`) {
|
|
innerDims = vec2(d1, ch);
|
|
result[`+(L*2+N)+`] = getChannel(
|
|
getA(d0, int(innerDims.x),
|
|
int(innerDims.y)), innerDims);
|
|
} else {
|
|
innerDims = vec2(d0, d1);
|
|
result[`+(L*2+N)+`] = getChannel(
|
|
getA(ch, int(innerDims.x),
|
|
int(innerDims.y)), innerDims);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`;this.userCode=`
|
|
void main() {
|
|
ivec2 rc = getOutputCoords();
|
|
|
|
vec4 result = vec4(0);
|
|
|
|
int blockIndex, pos, offsetY, d0, offsetX, d1, ch;
|
|
vec2 innerDims;
|
|
|
|
`+S+`
|
|
|
|
`+g.output+` = result;
|
|
}
|
|
`}return n}();var N9=function(){function n(t,e,i,r,a){this.variableNames=["x"],this.outputShape=[];var s=e,o=t[3]-1;this.outputShape=t;var l,u="float("+i+") + float("+r+") * sum";a===.5?l="inversesqrt("+u+")":a===1?l="1.0/("+u+")":l="exp(log("+u+") * float(-"+a+"));",this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int r = coords[1];
|
|
int c = coords[2];
|
|
int d = coords[3];
|
|
float x = getX(b, r, c, d);
|
|
float sum = 0.0;
|
|
for (int j = -`+s+"; j <= "+s+`; j++) {
|
|
int idx = d + j;
|
|
if (idx >= 0 && idx <= `+o+`) {
|
|
float z = getX(b, r, c, idx);
|
|
sum += z * z;
|
|
}
|
|
}
|
|
float val = x * `+l+`;
|
|
setOutput(val);
|
|
}
|
|
`}return n}();var x9=function(){function n(t,e,i,r,a){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=t,this.depth=t[3],this.depthRadius=e,this.bias=i,this.alpha=r,this.beta=a,this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int r = coords[1];
|
|
int c = coords[2];
|
|
|
|
float result = 0.0;
|
|
for (int d = 0; d < `+this.depth+`; ++d) {
|
|
int depthBegin = int(max(0.0, float(d - `+e+`)));
|
|
int depthEnd = int(min(float(`+this.depth+`),
|
|
float(d + `+e+` + 1)));
|
|
|
|
const int MIN_DEPTH_BEGIN = 0;
|
|
const int MAX_DEPTH_END = `+this.depth+`;
|
|
|
|
float norm = 0.0;
|
|
for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {
|
|
if (k < depthBegin){
|
|
continue;
|
|
}
|
|
else if (k >= depthBegin && k < depthEnd) {
|
|
norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);
|
|
}
|
|
else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
norm = float(`+r+") * norm + float("+i+`);
|
|
|
|
for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){
|
|
if (k < depthBegin){
|
|
continue;
|
|
}
|
|
else if (k >= depthBegin && k < depthEnd){
|
|
float dyi = -2.0 * float(`+r+`)
|
|
* float(`+a+`)
|
|
* getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)
|
|
/ norm;
|
|
if (k == d) {
|
|
dyi += pow(norm, -1.0 * `+a+`);
|
|
}
|
|
if (k == coords[3]) {
|
|
dyi *= getDy(b, r, c, d);
|
|
result += dyi;
|
|
}
|
|
}
|
|
else {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var C9=function(){function n(t,e,i,r,a){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var s=e,o=t[3]-1;this.outputShape=t;var l,u="float("+i+") + float("+r+") * sum";a===.5?l="inversesqrt("+u+")":a===1?l="1.0/("+u+")":l="exp(log("+u+") * float(-"+a+"));",this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords.x;
|
|
int r = coords.y;
|
|
int c = coords.z;
|
|
int d = coords.w;
|
|
|
|
bool hasNextCol = d < `+this.outputShape[3]+`;
|
|
bool hasNextRow = c < `+this.outputShape[2]+`;
|
|
|
|
vec4 sum = vec4(0.);
|
|
vec4 xFragAtOutputCoords = getX(b, r, c, d);
|
|
|
|
vec4 xAtOutputCoords = vec4(
|
|
getChannel(xFragAtOutputCoords, vec2(c, d)),
|
|
hasNextCol ?
|
|
getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,
|
|
hasNextRow ?
|
|
getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,
|
|
(hasNextRow && hasNextCol) ?
|
|
getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0
|
|
);
|
|
|
|
int firstChannel = d - `+s+`;
|
|
vec2 cache = vec2(0.);
|
|
if(firstChannel >= 0){
|
|
vec4 firstChannelFrag = getX(b, r, c, firstChannel);
|
|
cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));
|
|
if(hasNextRow){
|
|
cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));
|
|
}
|
|
}
|
|
|
|
ivec2 depth = ivec2(d, d + 1);
|
|
for (int j = - `+s+"; j <= "+s+`; j++) {
|
|
ivec2 idx = depth + j;
|
|
bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));
|
|
bvec2 belowUpperBound = lessThanEqual(idx, ivec2(`+o+`));
|
|
|
|
bool depthInRange = aboveLowerBound.x && belowUpperBound.x;
|
|
bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;
|
|
|
|
if(depthInRange || depthPlusOneInRange){
|
|
vec4 z = vec4(0.);
|
|
vec4 xFragAtCurrentDepth;
|
|
z.xz = cache.xy;
|
|
if(depthPlusOneInRange && hasNextCol){
|
|
xFragAtCurrentDepth = idx.y != d ?
|
|
getX(b, r, c, idx.y) : xFragAtOutputCoords;
|
|
z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));
|
|
if(hasNextRow){
|
|
z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));
|
|
}
|
|
}
|
|
cache.xy = z.yw;
|
|
sum += z * z;
|
|
}
|
|
}
|
|
vec4 result = xAtOutputCoords * `+l+`;
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var R9=function(){function n(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.strideHeight,i=t.strideWidth,r=t.dilationHeight,a=t.effectiveFilterHeight,s=t.effectiveFilterWidth,o=a-1-t.padInfo.top,l=s-1-t.padInfo.left,u=a*s-1;this.userCode=`
|
|
const ivec2 pads = ivec2(`+o+", "+l+`);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int d = coords[3];
|
|
|
|
ivec2 dyRCCorner = coords.yz - pads;
|
|
int dyRCorner = dyRCCorner.x;
|
|
int dyCCorner = dyRCCorner.y;
|
|
|
|
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
for (int wR = 0; wR < `+a+`;
|
|
wR += `+r+`) {
|
|
float dyR = float(dyRCorner + wR) / `+e+`.0;
|
|
|
|
if (dyR < 0.0 || dyR >= `+t.outHeight+`.0 || fract(dyR) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyR = int(dyR);
|
|
|
|
for (int wC = 0; wC < `+s+`; wC++) {
|
|
float dyC = float(dyCCorner + wC) / `+i+`.0;
|
|
|
|
if (dyC < 0.0 || dyC >= `+t.outWidth+`.0 ||
|
|
fract(dyC) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyC = int(dyC);
|
|
|
|
float dyValue = getDy(b, idyR, idyC, d);
|
|
int maxPosValue = `+u+` - int(getMaxPos(b, idyR, idyC, d));
|
|
|
|
// Get the current value, check it against the value from the
|
|
// position matrix.
|
|
int curPosValue = wR * `+s+` + wC;
|
|
float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);
|
|
|
|
dotProd += dyValue * mask;
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}(),O9=function(){function n(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.strideDepth,i=t.strideHeight,r=t.strideWidth,a=t.dilationDepth,s=t.dilationHeight,o=t.dilationWidth,l=t.effectiveFilterDepth,u=t.effectiveFilterHeight,c=t.effectiveFilterWidth,h=l-1-t.padInfo.front,d=u-1-t.padInfo.top,p=c-1-t.padInfo.left,f=l*u*c-1;this.userCode=`
|
|
const ivec3 pads = ivec3(`+h+", "+d+", "+p+`);
|
|
|
|
void main() {
|
|
ivec5 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
int ch = coords.u;
|
|
|
|
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
|
|
int dyDCorner = dyCorner.x;
|
|
int dyRCorner = dyCorner.y;
|
|
int dyCCorner = dyCorner.z;
|
|
|
|
// Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get
|
|
// dx(xD, xR, xC, ch).
|
|
// ? = to be determined. : = across all values in that axis.
|
|
float dotProd = 0.0;
|
|
|
|
for (int wD = 0; wD < `+l+`;
|
|
wD += `+a+`) {
|
|
float dyD = float(dyDCorner + wD) / `+e+`.0;
|
|
|
|
if (dyD < 0.0 || dyD >= `+t.outDepth+`.0 || fract(dyD) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyD = int(dyD);
|
|
|
|
for (int wR = 0; wR < `+u+`;
|
|
wR += `+s+`) {
|
|
float dyR = float(dyRCorner + wR) / `+i+`.0;
|
|
|
|
if (dyR < 0.0 || dyR >= `+t.outHeight+`.0 ||
|
|
fract(dyR) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyR = int(dyR);
|
|
|
|
for (int wC = 0; wC < `+c+`;
|
|
wC += `+o+`) {
|
|
float dyC = float(dyCCorner + wC) / `+r+`.0;
|
|
|
|
if (dyC < 0.0 || dyC >= `+t.outWidth+`.0 ||
|
|
fract(dyC) > 0.0) {
|
|
continue;
|
|
}
|
|
int idyC = int(dyC);
|
|
|
|
float dyValue = getDy(batch, idyD, idyR, idyC, ch);
|
|
int maxPosValue = `+f+` -
|
|
int(getMaxPos(batch, idyD, idyR, idyC, ch));
|
|
|
|
// Get the current value, check it against the value from the
|
|
// position matrix.
|
|
int curPosValue =
|
|
wD * `+u+" * "+c+` +
|
|
wR * `+c+` + wC;
|
|
float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);
|
|
|
|
dotProd += dyValue * mask;
|
|
}
|
|
}
|
|
}
|
|
setOutput(dotProd);
|
|
}
|
|
`}return n}();var Sp=function(){function n(t,e,i,r,a,s,o){i===void 0&&(i=!1),r===void 0&&(r=!1),a===void 0&&(a=!1),s===void 0&&(s=null),o===void 0&&(o=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e;var l=i?t[1]:t[2],u=Math.ceil(l/2),c=i?"i * 2, rc.y":"rc.y, i * 2",h=r?"rc.z, i * 2":"i * 2, rc.z",d=i?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],p=r?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],f="",m="";s&&(o?f=`vec4 activation(vec4 a) {
|
|
vec4 b = getPreluActivationWeightsAtOutCoords();
|
|
`+s+`
|
|
}`:f=`vec4 activation(vec4 x) {
|
|
`+s+`
|
|
}`,m="result = activation(result);");var g=a?"result += getBiasAtOutCoords();":"";a&&this.variableNames.push("bias"),o&&this.variableNames.push("preluActivationWeights"),this.userCode=`
|
|
`+f+`
|
|
|
|
const float sharedDimension = `+u+`.0;
|
|
|
|
vec4 dot2x2ARowBCol(ivec3 rc) {
|
|
vec4 result = vec4(0);
|
|
for (int i = 0; i < `+u+`; i++) {
|
|
vec4 a = getMatrixA(rc.x, `+c+`);
|
|
vec4 b = getMatrixB(rc.x, `+h+`);
|
|
|
|
// These swizzled products need to be separately added.
|
|
// See: https://github.com/tensorflow/tfjs/issues/1735
|
|
result += (`+d[0]+" * "+p[0]+`);
|
|
result += (`+d[1]+" * "+p[1]+`);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void main() {
|
|
ivec3 rc = getOutputCoords();
|
|
vec4 result = dot2x2ARowBCol(rc);
|
|
|
|
`+g+`
|
|
|
|
`+m+`
|
|
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var E9=function(){function n(t,e,i){this.variableNames=["probs"],this.outputShape=[t,i],this.userCode=`
|
|
uniform float seed;
|
|
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
|
|
float r = random(seed);
|
|
float cdf = 0.0;
|
|
|
|
for (int i = 0; i < `+(e-1)+`; i++) {
|
|
cdf += getProbs(batch, i);
|
|
|
|
if (r < cdf) {
|
|
setOutput(float(i));
|
|
return;
|
|
}
|
|
}
|
|
|
|
// If no other event happened, last event happened.
|
|
setOutput(float(`+(e-1)+`));
|
|
}
|
|
`}return n.prototype.getCustomSetupFunc=function(t){var e=this;return function(i,r){e.seedLoc==null&&(e.seedLoc=i.getUniformLocation(r,"seed")),i.gl.uniform1f(e.seedLoc,t)}},n}();var D9=function(){function n(t,e,i,r){this.variableNames=["indices"],this.outputShape=[t,e],this.userCode=`
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
int index = round(getIndices(coords.x));
|
|
setOutput(mix(float(`+r+"), float("+i+`),
|
|
float(index == coords.y)));
|
|
}
|
|
`}return n}();var U9=function(){function n(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=t;var e=t.length;if(e===0)this.userCode=`
|
|
void main() {
|
|
setOutput(vec4(getA(), 0., 0., 0.));
|
|
}
|
|
`;else{var i=en("rc",e),r=Ze(e),a=k9(e,t,i),s=F9(e,t[t.length-1],t[t.length-2],i),o=W9(t,i);this.userCode=`
|
|
void main() {
|
|
`+r+` rc = getOutputCoords();
|
|
|
|
if(`+a+`) {
|
|
setOutput(vec4(0));
|
|
} else {
|
|
`+s+`
|
|
|
|
setOutput(vec4(`+o+`));
|
|
}
|
|
}
|
|
`}}return n}();function B9(n,t){for(var e=[],i=0;i<=1;i++)for(var r=0;r<=1;r++){for(var a=(i===0?"r":"rp1")+", "+(r===0?"c":"cp1"),s=2;s<n;s++)a=t[t.length-1-s]+","+a;e.push(a)}return e}function k9(n,t,e){if(n===1)return"rc > "+t[0];for(var i="",r=n-2;r<n;r++)i+=e[r]+" >= "+t[r],r<n-1&&(i+="||");return i}function F9(n,t,e,i){if(n===1)return"";var r=i.slice(-2);return`
|
|
int r = `+r[0]+`;
|
|
int c = `+r[1]+`;
|
|
int rp1 = r + 1;
|
|
int cp1 = c + 1;
|
|
|
|
bool cEdge = cp1 >= `+t+`;
|
|
bool rEdge = rp1 >= `+e+`;
|
|
`}function W9(n,t){var e=n.length,i=B9(e,t);return e===1?`getA(rc),
|
|
rc + 1 >= `+n[0]+` ? 0. : getA(rc + 1),
|
|
0, 0`:"getA("+i[0]+`),
|
|
cEdge ? 0. : getA(`+i[1]+`),
|
|
rEdge ? 0. : getA(`+i[2]+`),
|
|
rEdge || cEdge ? 0. : getA(`+i[3]+")"}var z9=function(){function n(t,e,i){this.variableNames=["x"],this.outputShape=e.map(function(u,c){return u[0]+t[c]+u[1]});var r=t.length,a=Ze(r),s=e.map(function(u){return u[0]}).join(","),o=e.map(function(u,c){return u[0]+t[c]}).join(","),l=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,r);if(r===1){this.userCode=`
|
|
int start = `+s+`;
|
|
int end = `+o+`;
|
|
|
|
void main() {
|
|
int outC = getOutputCoords();
|
|
if (outC < start || outC >= end) {
|
|
setOutput(float(`+i+`));
|
|
} else {
|
|
setOutput(getX(outC - start));
|
|
}
|
|
}
|
|
`;return}this.userCode=`
|
|
`+a+" start = "+a+"("+s+`);
|
|
`+a+" end = "+a+"("+o+`);
|
|
|
|
void main() {
|
|
`+a+` outC = getOutputCoords();
|
|
if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {
|
|
setOutput(float(`+i+`));
|
|
} else {
|
|
`+a+` coords = outC - start;
|
|
setOutput(getX(`+l+`));
|
|
}
|
|
}
|
|
`}return n}();var P9=function(){function n(t,e,i){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e.map(function(v,b){return v[0]+t[b]+v[1]});for(var r=t.length,a=Ze(r),s=e.map(function(v){return v[0]}).join(","),o=e.map(function(v,b){return v[0]+t[b]}).join(","),l=en("rc",r),u=en("source",r),c=l[r-1]+" < "+this.outputShape[r-1],h=r===1?"source":"vec2("+u.slice(-2).join()+")",d=[a+" rc = outputLoc;",l[r-1]+` += 1;
|
|
if(`+c+`) {
|
|
`,r===1?"":`}
|
|
rc = outputLoc;
|
|
`+l[r-2]+` += 1;
|
|
if(`+l[r-2]+" < "+this.outputShape[r-2]+") {",r===1?"":" "+l[r-1]+` += 1;
|
|
if(`+c+") {"],p=r===1?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",f="",m=0,g=r===1?2:4;m<g;m++)f+=`
|
|
`+d[m]+`
|
|
if (`+p+`) {
|
|
result[`+m+"] = float("+i+`);
|
|
} else {
|
|
`+a+` source = rc - start;
|
|
result[`+m+"] = getChannel(getX("+u.join()+"), "+h+`);
|
|
}
|
|
`;f+=r===1?"} ":"}}",this.userCode=`
|
|
const `+a+" start = "+a+"("+s+`);
|
|
const `+a+" end = "+a+"("+o+`);
|
|
|
|
void main() {
|
|
`+a+` outputLoc = getOutputCoords();
|
|
vec4 result = vec4(0.);
|
|
`+f+`
|
|
setOutput(result);
|
|
}
|
|
`}return n}();var As=function(){function n(t,e,i,r,a){if(r===void 0&&(r=!1),a===void 0&&(a=!1),this.variableNames=["x"],e==="avg"&&i)throw new Error("Cannot compute positions for average pool.");var s=t.filterWidth,o=t.strideHeight,l=t.strideWidth,u=t.dilationHeight,c=t.dilationWidth,h=t.effectiveFilterHeight,d=t.effectiveFilterWidth,p=t.padInfo.top,f=t.padInfo.left;this.outputShape=t.outShape;var m=e==="avg",g="((batch * "+t.inHeight+" + xR) * "+t.inWidth+" + xC) * "+t.inChannels+" + d",v="(xR * "+t.inWidth+" + xC) * "+t.inChannels+" + d",b="0.0";if(m||(b="-1.0 / 1e-20"),i){var w=">=";this.userCode=`
|
|
const ivec2 strides = ivec2(`+o+", "+l+`);
|
|
const ivec2 pads = ivec2(`+p+", "+f+`);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int d = coords[3];
|
|
|
|
ivec2 xRCCorner = coords.yz * strides - pads;
|
|
int xRCorner = xRCCorner.x;
|
|
int xCCorner = xRCCorner.y;
|
|
|
|
// max/min x(?, ?, d) to get y(yR, yC, d).
|
|
// ? = to be determined
|
|
float minMaxValue = 0.0;
|
|
float minMaxValueFound = 0.0;
|
|
int minMaxPosition = 0;
|
|
float avgValue = 0.0;
|
|
|
|
for (int wR = 0; wR < `+h+`;
|
|
wR += `+u+`) {
|
|
int xR = xRCorner + wR;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wC = 0; wC < `+d+`;
|
|
wC += `+c+`) {
|
|
int xC = xCCorner + wC;
|
|
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
continue;
|
|
}
|
|
|
|
float value = getX(batch, xR, xC, d);
|
|
|
|
// If a min / max value has already been found, use it. If not,
|
|
// use the current value.
|
|
float currMinMaxValue = mix(
|
|
value, minMaxValue, minMaxValueFound);
|
|
if (value `+w+` currMinMaxValue) {
|
|
minMaxValue = value;
|
|
minMaxValueFound = 1.0;
|
|
minMaxPosition = `+(r?a?g:v:"wR * "+d+" + wC")+`;
|
|
}
|
|
}
|
|
}
|
|
setOutput(float(minMaxPosition));
|
|
}
|
|
`;return}var S="max",L=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";e==="avg"&&(L="avgValue / count");var N=Math.floor(s/4)*4,C=s%4,R=`
|
|
if (`+m+`) {
|
|
avgValue += dot(values, ones);
|
|
} else {
|
|
minMaxValue = `+S+`(values, minMaxValue);
|
|
}
|
|
`;this.userCode=`
|
|
const ivec2 strides = ivec2(`+o+", "+l+`);
|
|
const ivec2 pads = ivec2(`+p+", "+f+`);
|
|
const float initializationValue = `+b+`;
|
|
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
|
|
float count = 0.0;
|
|
|
|
float getValue(int batch, int xR, int xC, int d) {
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
return initializationValue;
|
|
}
|
|
count += 1.0;
|
|
return getX(batch, xR, xC, d);
|
|
}
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int d = coords[3];
|
|
|
|
ivec2 xRCCorner = coords.yz * strides - pads;
|
|
int xRCorner = xRCCorner.x;
|
|
int xCCorner = xRCCorner.y;
|
|
|
|
// max/min x(?, ?, d) to get y(yR, yC, d).
|
|
// ? = to be determined
|
|
vec4 minMaxValue = vec4(`+b+`);
|
|
float avgValue = 0.0;
|
|
count = 0.0;
|
|
|
|
for (int wR = 0; wR < `+h+`;
|
|
wR += `+u+`) {
|
|
int xR = xRCorner + wR;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wC = 0; wC < `+N+`; wC += 4) {
|
|
int xC = xCCorner + wC * `+c+`;
|
|
|
|
vec4 values = vec4(
|
|
getValue(batch, xR, xC, d),
|
|
getValue(batch, xR, xC + `+c+`, d),
|
|
getValue(batch, xR, xC + 2 * `+c+`, d),
|
|
getValue(batch, xR, xC + 3 * `+c+`, d)
|
|
);
|
|
|
|
`+R+`
|
|
}
|
|
|
|
int xC = xCCorner + `+N+`;
|
|
if (`+(C===1)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, xR, xC, d),
|
|
initializationValue,
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
`+R+`
|
|
} else if (`+(C===2)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, xR, xC, d),
|
|
getValue(batch, xR, xC + `+c+`, d),
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
`+R+`
|
|
} else if (`+(C===3)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, xR, xC, d),
|
|
getValue(batch, xR, xC + `+c+`, d),
|
|
getValue(batch, xR, xC + 2 * `+c+`, d),
|
|
initializationValue
|
|
);
|
|
|
|
`+R+`
|
|
}
|
|
}
|
|
setOutput(`+L+`);
|
|
}
|
|
`}return n}(),Lp=function(){function n(t,e,i,r,a){if(r===void 0&&(r=!1),a===void 0&&(a=!1),this.variableNames=["x"],e==="avg"&&i)throw new Error("Cannot compute positions for average pool.");var s=t.filterWidth,o=t.strideDepth,l=t.strideHeight,u=t.strideWidth,c=t.dilationDepth,h=t.dilationHeight,d=t.dilationWidth,p=t.effectiveFilterDepth,f=t.effectiveFilterHeight,m=t.effectiveFilterWidth,g=t.padInfo.front,v=t.padInfo.top,b=t.padInfo.left;this.outputShape=t.outShape;var w=e==="avg",S="0.0";if(w||(S="-1.0 / 1e-20"),i){var L=">=";this.userCode=`
|
|
const ivec3 strides =
|
|
ivec3(`+o+", "+l+", "+u+`);
|
|
const ivec3 pads = ivec3(`+g+", "+v+", "+b+`);
|
|
|
|
void main() {
|
|
ivec5 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
int ch = coords.u;
|
|
|
|
ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
|
|
int xDCorner = xCorner.x;
|
|
int xRCorner = xCorner.y;
|
|
int xCCorner = xCorner.z;
|
|
|
|
// max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).
|
|
// ? = to be determined
|
|
float minMaxValue = 0.0;
|
|
float minMaxValueFound = 0.0;
|
|
int minMaxPosition = 0;
|
|
|
|
for (int wD = 0; wD < `+p+`;
|
|
wD += `+c+`) {
|
|
int xD = xDCorner + wD;
|
|
|
|
if (xD < 0 || xD >= `+t.inDepth+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wR = 0; wR < `+f+`;
|
|
wR += `+h+`) {
|
|
int xR = xRCorner + wR;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wC = 0; wC < `+m+`;
|
|
wC += `+d+`) {
|
|
int xC = xCCorner + wC;
|
|
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
continue;
|
|
}
|
|
|
|
float value = getX(batch, xD, xR, xC, ch);
|
|
|
|
// If a min / max value has already been found, use it. If not,
|
|
// use the current value.
|
|
float currMinMaxValue = mix(
|
|
value, minMaxValue, minMaxValueFound);
|
|
if (value `+L+` currMinMaxValue) {
|
|
minMaxValue = value;
|
|
minMaxValueFound = 1.0;
|
|
minMaxPosition = `+(r?a?"(((batch * "+t.inDepth+" + xD) * "+t.inHeight+" + xR) * "+t.inWidth+" + xC) * "+t.inChannels+" + ch":"((xD * "+t.inHeight+" + xR) * "+t.inWidth+" + xC) * "+t.inChannels+" + ch":"wD * "+f+" * "+m+` +
|
|
wR * `+m+" + wC")+`;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
setOutput(float(minMaxPosition));
|
|
}
|
|
`;return}var N="max",C=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";e==="avg"&&(C="avgValue / count");var R=Math.floor(s/4)*4,D=s%4,k=`
|
|
if (`+w+`) {
|
|
avgValue += dot(values, ones);
|
|
} else {
|
|
minMaxValue = `+N+`(values, minMaxValue);
|
|
}
|
|
`;this.userCode=`
|
|
const ivec3 strides =
|
|
ivec3(`+o+", "+l+", "+u+`);
|
|
const ivec3 pads = ivec3(`+g+", "+v+", "+b+`);
|
|
const float initializationValue = `+S+`;
|
|
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
|
|
float count = 0.0;
|
|
|
|
float getValue(int batch, int xD, int xR, int xC, int ch) {
|
|
if (xC < 0 || xC >= `+t.inWidth+`) {
|
|
return initializationValue;
|
|
}
|
|
count += 1.0;
|
|
return getX(batch, xD, xR, xC, ch);
|
|
}
|
|
|
|
void main() {
|
|
ivec5 coords = getOutputCoords();
|
|
int batch = coords.x;
|
|
int ch = coords.u;
|
|
|
|
ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
|
|
int xDCorner = xCorner.x;
|
|
int xRCorner = xCorner.y;
|
|
int xCCorner = xCorner.z;
|
|
|
|
// max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
|
|
// ? = to be determined
|
|
vec4 minMaxValue = vec4(`+S+`);
|
|
float avgValue = 0.0;
|
|
count = 0.0;
|
|
|
|
for (int wD = 0; wD < `+p+`;
|
|
wD += `+c+`) {
|
|
int xD = xDCorner + wD;
|
|
|
|
if (xD < 0 || xD >= `+t.inDepth+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wR = 0; wR < `+f+`;
|
|
wR += `+h+`) {
|
|
int xR = xRCorner + wR;
|
|
|
|
if (xR < 0 || xR >= `+t.inHeight+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int wC = 0; wC < `+R+`; wC += 4) {
|
|
int xC = xCCorner + wC * `+d+`;
|
|
|
|
vec4 values = vec4(
|
|
getValue(batch, xD, xR, xC, ch),
|
|
getValue(batch, xD, xR, xC + `+d+`, ch),
|
|
getValue(batch, xD, xR, xC + 2 * `+d+`, ch),
|
|
getValue(batch, xD, xR, xC + 3 * `+d+`, ch)
|
|
);
|
|
|
|
`+k+`
|
|
}
|
|
|
|
int xC = xCCorner + `+R+`;
|
|
if (`+(D===1)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, xD, xR, xC, ch),
|
|
initializationValue,
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
`+k+`
|
|
} else if (`+(D===2)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, xD, xR, xC, ch),
|
|
getValue(batch, xD, xR, xC + `+d+`, ch),
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
`+k+`
|
|
} else if (`+(D===3)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, xD, xR, xC, ch),
|
|
getValue(batch, xD, xR, xC + `+d+`, ch),
|
|
getValue(batch, xD, xR, xC + 2 * `+d+`, ch),
|
|
initializationValue
|
|
);
|
|
|
|
`+k+`
|
|
}
|
|
}
|
|
setOutput(`+C+`);
|
|
}
|
|
}
|
|
`}return n}();var lL=function(){function n(t,e){this.variableNames=["x"];var i=t.windowSize,r=t.batchSize,a=t.inSize,s=t.outSize;this.outputShape=[r,s];var o="0.0",l="";e==="prod"?o="1.0":e==="min"?(o="1.0 / 1e-20",l="min"):e==="max"&&(o="-1.0 / 1e-20",l="max");var u=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";e==="sum"?u="sumValue":e==="prod"?u="prodValue":e==="all"?u="allValue":e==="any"&&(u="anyValue");var c=Math.floor(i/4)*4,h=i%4,d=`
|
|
if (`+(e==="sum")+`) {
|
|
sumValue += dot(values, ones);
|
|
} else if (`+(e==="prod")+`) {
|
|
vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);
|
|
prodValue *= tmp[0] * tmp[1];
|
|
} else {
|
|
minMaxValue = `+l+`(values, minMaxValue);
|
|
}
|
|
`,p="vec4";e==="all"?(o="1.0",d=`
|
|
bool reducedAllValue = all(values);
|
|
float floatedReducedAllValue = float(reducedAllValue);
|
|
allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);
|
|
`,p="bvec4"):e==="any"&&(o="0.0",d=`
|
|
bool reducedAnyValue = any(values);
|
|
float floatedReducedAnyValue = float(reducedAnyValue);
|
|
anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);
|
|
`,p="bvec4");var f="";a%i>0&&(f=`
|
|
if (inIdx < 0 || inIdx >= `+a+`) {
|
|
return initializationValue;
|
|
}
|
|
`),this.userCode=`
|
|
const float initializationValue = `+o+`;
|
|
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
|
|
float getValue(int batch, int inIdx) {
|
|
`+f+`
|
|
return getX(batch, inIdx);
|
|
}
|
|
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int outIdx = coords[1];
|
|
int inOffset = outIdx * `+i+`;
|
|
|
|
vec4 minMaxValue = vec4(`+o+`);
|
|
float prodValue = 1.0;
|
|
float sumValue = 0.0;
|
|
float allValue = 1.0;
|
|
float anyValue = 0.0;
|
|
|
|
for (int i = 0; i < `+c+`; i += 4) {
|
|
int inIdx = inOffset + i;
|
|
`+p+" values = "+p+`(
|
|
getValue(batch, inIdx),
|
|
getValue(batch, inIdx + 1),
|
|
getValue(batch, inIdx + 2),
|
|
getValue(batch, inIdx + 3)
|
|
);
|
|
|
|
`+d+`
|
|
}
|
|
|
|
int inIdx = inOffset + `+c+`;
|
|
if (`+(h===1)+`) {
|
|
`+p+" values = "+p+`(
|
|
getValue(batch, inIdx),
|
|
initializationValue,
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
`+d+`
|
|
} else if (`+(h===2)+`) {
|
|
`+p+" values = "+p+`(
|
|
getValue(batch, inIdx),
|
|
getValue(batch, inIdx + 1),
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
`+d+`
|
|
} else if (`+(h===3)+`) {
|
|
`+p+" values = "+p+`(
|
|
getValue(batch, inIdx),
|
|
getValue(batch, inIdx + 1),
|
|
getValue(batch, inIdx + 2),
|
|
initializationValue
|
|
);
|
|
|
|
`+d+`
|
|
}
|
|
setOutput(`+u+`);
|
|
}
|
|
`}return n}();var uL=function(){function n(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;for(var i="",r=0;r<4;r++){var a="thisRC = rc;";r%2===1&&(a+="thisRC.z += 1;"),r>1&&(a+="thisRC.y += 1;"),i+=`
|
|
`+a+`
|
|
`+(r>0?"if(thisRC.y < rows && thisRC.z < cols){":"")+`
|
|
int flatIndex = getFlatIndex(thisRC);
|
|
|
|
ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
|
|
vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));
|
|
|
|
result[`+r+`] =
|
|
getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
|
|
`+(r>0?"}":"")+`
|
|
`}this.userCode=`
|
|
`+_9(e)+`
|
|
`+pp(t)+`
|
|
|
|
void main() {
|
|
ivec3 rc = getOutputCoords();
|
|
|
|
vec4 result = vec4(0.);
|
|
|
|
ivec3 thisRC;
|
|
int rows = `+t[1]+`;
|
|
int cols = `+t[2]+`;
|
|
|
|
`+i+`
|
|
|
|
setOutput(result);
|
|
}
|
|
`}return n}();function _9(n){var t=Ar(["r","c","d"],n);return`
|
|
ivec3 inputCoordsFromReshapedOutCoords(int index) {
|
|
`+t+`
|
|
return ivec3(r, c, d);
|
|
}
|
|
`}var M9=function(){function n(t,e,i){this.variableNames=["dy"],this.outputShape=[],this.outputShape=e.shape;var r=e.shape,a=r[1],s=r[2],o=t.shape,l=o[1],u=o[2],c=[i&&l>1?a-1:a,i&&u>1?s-1:s],h=[i&&l>1?l-1:l,i&&u>1?u-1:u],d=c[0]/h[0],p=c[1]/h[1],f=1/d,m=1/p,g=Math.ceil(f)*2+2,v=Math.ceil(m)*2+2;this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int d = coords[3];
|
|
int r = coords[1];
|
|
int c = coords[2];
|
|
|
|
float accumulator = 0.0;
|
|
|
|
const float heightScale = float(`+d+`);
|
|
const float widthScale = float(`+p+`);
|
|
|
|
const float invHeightScale = float(`+f+`);
|
|
const float invWidthScale = float(`+m+`);
|
|
|
|
const int winHeight = int(`+g+`);
|
|
const int winWidth = int(`+v+`);
|
|
|
|
// Compute bounds for where in dy we will look
|
|
float startRLerp = floor(float(r) * invHeightScale);
|
|
int startDyR = int(startRLerp - float(winHeight / 2));
|
|
|
|
float startCLerp = floor(float(c) * invWidthScale);
|
|
int startDyC = int(startCLerp - float(winWidth / 2));
|
|
|
|
// Loop over dy
|
|
for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
|
|
int dyR = dyROffset + startDyR;
|
|
|
|
// Guard against the window exceeding the bounds of dy
|
|
if (dyR < 0 || dyR >= `+l+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
|
|
int dyC = dyCOffset + startDyC;
|
|
|
|
// Guard against the window exceeding the bounds of dy
|
|
if (dyC < 0 || dyC >= `+u+`) {
|
|
continue;
|
|
}
|
|
|
|
float dxR = float(dyR) * heightScale;
|
|
int topDxRIndex = int(floor(dxR));
|
|
int bottomDxRIndex = int(min(ceil(dxR), `+(a-1)+`.0));
|
|
float dxRLerp = dxR - float(topDxRIndex);
|
|
float inverseDxRLerp = 1.0 - dxRLerp;
|
|
|
|
float dxC = float(dyC) * widthScale;
|
|
int leftDxCIndex = int(floor(dxC));
|
|
int rightDxCIndex = int(min(ceil(dxC), `+(s-1)+`.0));
|
|
float dxCLerp = dxC - float(leftDxCIndex);
|
|
float inverseDxCLerp = 1.0 - dxCLerp;
|
|
|
|
if (r == topDxRIndex && c == leftDxCIndex) {
|
|
// topLeft
|
|
accumulator +=
|
|
getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;
|
|
}
|
|
|
|
if (r == topDxRIndex && c == rightDxCIndex) {
|
|
// topRight
|
|
accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;
|
|
}
|
|
|
|
if (r == bottomDxRIndex && c == leftDxCIndex) {
|
|
// bottomLeft
|
|
accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;
|
|
}
|
|
|
|
if (r == bottomDxRIndex && c == rightDxCIndex) {
|
|
// bottomRight
|
|
accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;
|
|
}
|
|
}
|
|
}
|
|
// End loop over dy
|
|
|
|
setOutput(accumulator);
|
|
}
|
|
`}return n}();var H9=function(){function n(t,e,i,r){this.variableNames=["A"],this.outputShape=[];var a=t[0],s=t[1],o=t[2],l=t[3];this.outputShape=[a,e,i,l];var u=[r&&e>1?s-1:s,r&&i>1?o-1:o],c=[r&&e>1?e-1:e,r&&i>1?i-1:i];this.userCode=`
|
|
const vec2 effectiveInputOverOutputRatioRC = vec2(
|
|
`+u[0]/c[0]+`,
|
|
`+u[1]/c[1]+`);
|
|
const vec2 inputShapeRC = vec2(`+s+".0, "+o+`.0);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int d = coords[3];
|
|
ivec2 yRC = coords.yz;
|
|
|
|
// Fractional source index.
|
|
vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;
|
|
|
|
// Compute the four integer indices.
|
|
ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);
|
|
ivec2 sourceCeilRC = ivec2(
|
|
min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));
|
|
|
|
float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);
|
|
float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);
|
|
float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);
|
|
float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);
|
|
|
|
vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);
|
|
|
|
float top = topLeft + (topRight - topLeft) * fracRC.y;
|
|
float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;
|
|
float newValue = top + (bottom - top) * fracRC.x;
|
|
|
|
setOutput(newValue);
|
|
}
|
|
`}return n}();var V9=function(){function n(t,e,i,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var a=t[0],s=t[1],o=t[2],l=t[3];this.outputShape=[a,e,i,l];var u=[r&&e>1?s-1:s,r&&i>1?o-1:o],c=[r&&e>1?e-1:e,r&&i>1?i-1:i];this.userCode=`
|
|
const vec3 effectiveInputOverOutputRatioRC = vec3(
|
|
`+u[0]/c[0]+`,
|
|
`+u[1]/c[1]+`,
|
|
`+u[1]/c[1]+`);
|
|
const vec3 inputShapeRC = vec3(`+s+".0, "+o+`.0,
|
|
`+o+`.0);
|
|
|
|
float getAValue(int b, int r, int c, int d) {
|
|
return getChannel(getA(b, r, c, d), vec2(c, d));
|
|
}
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int d = coords[3];
|
|
// Calculate values for next column in yRC.z.
|
|
ivec3 yRC = coords.yzz + ivec3(0, 0, 1);
|
|
|
|
// Fractional source index.
|
|
vec3 sourceFracIndexRC = vec3(yRC) * effectiveInputOverOutputRatioRC;
|
|
|
|
// Compute the four integer indices.
|
|
ivec3 sourceFloorRC = ivec3(sourceFracIndexRC);
|
|
ivec3 sourceCeilRC = ivec3(
|
|
min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));
|
|
|
|
// Should we calculate next column and row elements in 2x2 packed cell.
|
|
bool hasNextCol = d < `+(l-1)+`;
|
|
bool hasNextRow = coords.z < `+(i-1)+`;
|
|
|
|
// In parallel, construct four corners for all four components in
|
|
// packed 2x2 cell.
|
|
vec4 topLeft = vec4(
|
|
getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),
|
|
hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)
|
|
: 0.0,
|
|
hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)
|
|
: 0.0,
|
|
(hasNextRow && hasNextCol) ?
|
|
getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);
|
|
|
|
vec4 bottomLeft = vec4(
|
|
getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),
|
|
hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)
|
|
: 0.0,
|
|
hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)
|
|
: 0.0,
|
|
(hasNextRow && hasNextCol) ?
|
|
getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);
|
|
|
|
vec4 topRight = vec4(
|
|
getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),
|
|
hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)
|
|
: 0.0,
|
|
hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)
|
|
: 0.0,
|
|
(hasNextRow && hasNextCol) ?
|
|
getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);
|
|
|
|
vec4 bottomRight = vec4(
|
|
getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),
|
|
hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)
|
|
: 0.0,
|
|
hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)
|
|
: 0.0,
|
|
(hasNextRow && hasNextCol) ?
|
|
getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);
|
|
|
|
vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);
|
|
|
|
vec4 top = mix(topLeft, topRight, fracRC.yyzz);
|
|
vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);
|
|
vec4 newValue = mix(top, bottom, fracRC.x);
|
|
|
|
setOutput(newValue);
|
|
}
|
|
`}return n}();var q9=function(){function n(t,e,i){this.variableNames=["dy"],this.outputShape=[],this.outputShape=e.shape;var r=e.shape,a=r[1],s=r[2],o=t.shape,l=o[1],u=o[2],c=[i&&l>1?a-1:a,i&&u>1?s-1:s],h=[i&&l>1?l-1:l,i&&u>1?u-1:u],d=c[0]/h[0],p=c[1]/h[1],f=1/d,m=1/p,g=Math.ceil(f)*2+2,v=Math.ceil(m)*2+2;this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int d = coords[3];
|
|
int r = coords[1];
|
|
int c = coords[2];
|
|
|
|
float accumulator = 0.0;
|
|
|
|
const float heightScale = float(`+d+`);
|
|
const float widthScale = float(`+p+`);
|
|
|
|
const float invHeightScale = float(`+f+`);
|
|
const float invWidthScale = float(`+m+`);
|
|
|
|
const int winHeight = int(`+g+`);
|
|
const int winWidth = int(`+v+`);
|
|
|
|
// Compute bounds for where in dy we will look
|
|
float startRLerp = floor(float(r) * invHeightScale);
|
|
int startDyR = int(floor(startRLerp - float(winHeight / 2)));
|
|
|
|
float startCLerp = floor(float(c) * invWidthScale);
|
|
int startDyC = int(floor(startCLerp - float(winWidth / 2)));
|
|
|
|
// Loop over dy
|
|
for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
|
|
int dyR = dyROffset + startDyR;
|
|
|
|
// Guard against the window exceeding the bounds of dy
|
|
if (dyR < 0 || dyR >= `+l+`) {
|
|
continue;
|
|
}
|
|
|
|
for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
|
|
int dyC = dyCOffset + startDyC;
|
|
|
|
// Guard against the window exceeding the bounds of dy
|
|
if (dyC < 0 || dyC >= `+u+`) {
|
|
continue;
|
|
}
|
|
|
|
float sourceFracRow =
|
|
float(`+c[0]+`) *
|
|
(float(dyR) / float(`+h[0]+`));
|
|
|
|
float sourceFracCol =
|
|
float(`+c[1]+`) *
|
|
(float(dyC) / float(`+h[1]+`));
|
|
|
|
int sourceNearestRow = int(min(
|
|
float(int(`+a+`) - 1),
|
|
`+i+` ? float(round(sourceFracRow)) :
|
|
float(floor(sourceFracRow))));
|
|
|
|
int sourceNearestCol = int(min(
|
|
float(int(`+s+`) - 1),
|
|
`+i+` ? float(round(sourceFracCol)) :
|
|
float(floor(sourceFracCol))));
|
|
|
|
if (r == sourceNearestRow && c == sourceNearestCol) {
|
|
accumulator += getDy(b, dyR, dyC, d);
|
|
}
|
|
}
|
|
}
|
|
// End loop over dy
|
|
|
|
setOutput(accumulator);
|
|
}
|
|
`}return n}();var G9=function(){function n(t,e,i,r){this.variableNames=["A"],this.outputShape=[];var a=t[0],s=t[1],o=t[2],l=t[3];this.outputShape=[a,e,i,l];var u=[r&&e>1?s-1:s,r&&i>1?o-1:o],c=[r&&e>1?e-1:e,r&&i>1?i-1:i],h=r?"0.5":"0.0";this.userCode=`
|
|
const vec2 effectiveInputOverOutputRatioRC = vec2(
|
|
`+u[0]/c[0]+`,
|
|
`+u[1]/c[1]+`);
|
|
const vec2 inputShapeRC = vec2(`+s+".0, "+o+`.0);
|
|
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int b = coords[0];
|
|
int d = coords[3];
|
|
ivec2 yRC = coords.yz;
|
|
|
|
// Fractional source index.
|
|
vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;
|
|
|
|
// Compute the coordinators of nearest neighbor point.
|
|
ivec2 sourceNearestRC = ivec2(
|
|
min(inputShapeRC - 1.0, floor(sourceFracIndexRC + `+h+`)));
|
|
|
|
float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);
|
|
|
|
setOutput(newValue);
|
|
}
|
|
`}return n}();var Y9=function(){function n(t,e){this.variableNames=["x"];var i=t.length;if(i>4)throw new Error("WebGL backend: Reverse of rank-"+i+" tensor is not yet supported");if(this.outputShape=t,i===1){this.userCode=`
|
|
void main() {
|
|
int coord = getOutputCoords();
|
|
setOutput(getX(`+t[0]+` - coord - 1));
|
|
}
|
|
`;return}var r=function(o){return e.indexOf(o)!==-1&&t[o]!==1?t[o]+" - coords["+o+"] - 1":"coords["+o+"]"},a=t.map(function(o,l){return r(l)}).join(","),s=Ze(i);this.userCode=`
|
|
void main() {
|
|
`+s+` coords = getOutputCoords();
|
|
setOutput(getX(`+a+`));
|
|
}
|
|
`}return n}();var j9=function(){function n(t,e){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var i=t.length;if(i>4)throw new Error("WebGL backend: Reverse of rank-"+i+" tensor is not yet supported");this.outputShape=t;var r=en("rc",i),a=r[i-1]+" + 1 < "+this.outputShape[i-1],s=r[i-2]+" + 1 < "+this.outputShape[i-2],o=Ze(i);i===1?this.userCode=`
|
|
void main(){
|
|
int rc = getOutputCoords();
|
|
vec4 result = vec4(0.);
|
|
result.r = getChannel(getX(`+t[0]+` - rc - 1),
|
|
`+t[0]+` - rc - 1);
|
|
if(`+a+`){
|
|
result.g = getChannel(getX(`+t[0]+` - (rc + 1) - 1),
|
|
`+t[0]+` - (rc + 1) - 1);
|
|
}
|
|
setOutput(result);
|
|
}
|
|
`:this.userCode=`
|
|
void main() {
|
|
`+o+` rc = getOutputCoords();
|
|
vec4 result = vec4(0.);
|
|
result.r = `+l(r.slice())+`;
|
|
if(`+a+`){
|
|
result.g = `+u(r.slice())+`;
|
|
}
|
|
if(`+s+`) {
|
|
result.b = `+c(r.slice())+`;
|
|
if(`+a+`) {
|
|
result.a = `+h(r.slice())+`;
|
|
}
|
|
}
|
|
setOutput(result);
|
|
}
|
|
`;function l(f){return d(f)}function u(f){return f[i-1]="("+f[i-1]+" + 1)",d(f)}function c(f){return f[i-2]="("+f[i-2]+" + 1)",d(f)}function h(f){return f[i-1]="("+f[i-1]+" + 1)",f[i-2]="("+f[i-2]+" + 1)",d(f)}function d(f){var m=t.map(function(b,w){return p(w,f)}),g=m.join(","),v=m.slice(-2).join(",");return"getChannel(getX("+g+"), vec2("+v+"))"}function p(f,m){return e.indexOf(f)!==-1&&t[f]!==1?t[f]+" - "+m[f]+" - 1":""+m[f]}}return n}();var cL=function(){function n(t,e,i,r,a,s,o){this.variableNames=["updates","indices","defaultValue"],this.outputShape=s;var l=Ze(a.length),u=Ze(s.length),c="";i===1?c="i":i===2&&(c="i, j");var h="getIndices("+c+")",d="";r===1?d="i":r===2&&(d="i, coords[1]");var p="getUpdates("+d+")",f=e>1?"strides[j]":"strides";this.userCode=`
|
|
`+l+" strides = "+l+"("+a+`);
|
|
|
|
void main() {
|
|
`+u+` coords = getOutputCoords();
|
|
float sum = 0.0;
|
|
bool found = false;
|
|
for (int i = 0; i < `+t+`; i++) {
|
|
int flattenedIndex = 0;
|
|
for (int j = 0; j < `+e+`; j++) {
|
|
int index = round(`+h+`);
|
|
flattenedIndex += index * `+f+`;
|
|
}
|
|
if (flattenedIndex == coords[0]) {
|
|
sum += `+p+`;
|
|
found = true;
|
|
}
|
|
}
|
|
setOutput(mix(getDefaultValue(), sum, float(found)));
|
|
}
|
|
`}return n}();var K9=function(){function n(t,e){this.variableNames=["x","segmentIds"];var i=t.windowSize,r=t.batchSize,a=t.inSize,s=t.numSegments,o=s*Math.ceil(a/i);this.outputShape=[r,o];var l="0.0",u="sumValue",c=Math.floor(i/4)*4,h=i%4,d=`
|
|
sumValue += dot(values, segFilter);
|
|
`,p="";a%i>0&&(p=`
|
|
if (inIdx < 0 || inIdx >= `+a+`) {
|
|
return initializationValue;
|
|
}
|
|
`);var f="";a%i>0&&(f=`
|
|
if (inIdx < 0 || inIdx >= `+a+`) {
|
|
return -1.0;
|
|
}
|
|
`),this.userCode=`
|
|
const float initializationValue = `+l+`;
|
|
|
|
float getValue(int batch, int inIdx) {
|
|
`+p+`
|
|
return getX(batch, inIdx);
|
|
}
|
|
|
|
float getSegmentIdAtIndex(int inIdx) {
|
|
`+f+`
|
|
return getSegmentIds(inIdx);
|
|
}
|
|
|
|
void main() {
|
|
ivec2 coords = getOutputCoords();
|
|
int batch = coords[0];
|
|
int outIdx = coords[1];
|
|
int inOffset = int(floor(float(outIdx) / float(
|
|
`+s+")) * float("+i+`));
|
|
int currentSeg = int(mod(float(outIdx), float(`+s+`)));
|
|
|
|
float sumValue = 0.0;
|
|
|
|
for (int i = 0; i < `+c+`; i += 4) {
|
|
int inIdx = inOffset + i;
|
|
vec4 values = vec4(
|
|
getValue(batch, inIdx),
|
|
getValue(batch, inIdx + 1),
|
|
getValue(batch, inIdx + 2),
|
|
getValue(batch, inIdx + 3)
|
|
);
|
|
|
|
vec4 segFilter = vec4(
|
|
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
|
|
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
|
|
int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
|
|
int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0
|
|
);
|
|
|
|
`+d+`
|
|
}
|
|
|
|
int inIdx = inOffset + `+c+`;
|
|
if (`+(h===1)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, inIdx),
|
|
initializationValue,
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
int inIdxSeg = int(getSegmentIdAtIndex(inIdx));
|
|
|
|
vec4 segFilter = vec4(
|
|
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
|
|
0,
|
|
0,
|
|
0
|
|
);
|
|
|
|
`+d+`
|
|
} else if (`+(h===2)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, inIdx),
|
|
getValue(batch, inIdx + 1),
|
|
initializationValue,
|
|
initializationValue
|
|
);
|
|
|
|
vec4 segFilter = vec4(
|
|
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
|
|
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
|
|
0,
|
|
0
|
|
);
|
|
|
|
`+d+`
|
|
} else if (`+(h===3)+`) {
|
|
vec4 values = vec4(
|
|
getValue(batch, inIdx),
|
|
getValue(batch, inIdx + 1),
|
|
getValue(batch, inIdx + 2),
|
|
initializationValue
|
|
);
|
|
|
|
vec4 segFilter = vec4(
|
|
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
|
|
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
|
|
int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
|
|
0
|
|
);
|
|
|
|
`+d+`
|
|
}
|
|
setOutput(`+u+`);
|
|
}
|
|
`}return n}();var $9=function(){function n(t,e,i){this.variableNames=["c","a","b"],this.outputShape=e;var r,a;if(i>4)throw Error("Where for rank "+i+" is not yet supported");if(i===1)a="resRC",r="resRC";else{for(var s=["resRC.x","resRC.y","resRC.z","resRC.w"],o=[],l=[],u=0;u<e.length;u++)l.push(""+s[u]),u<t&&o.push(""+s[u]);r=o.join(),a=l.join()}var c=Ze(i);this.userCode=`
|
|
void main() {
|
|
`+c+` resRC = getOutputCoords();
|
|
float cVal = getC(`+r+`);
|
|
if (cVal >= 1.0) {
|
|
setOutput(getA(`+a+`));
|
|
} else {
|
|
setOutput(getB(`+a+`));
|
|
}
|
|
}
|
|
`}return n}();var J9=function(){function n(t){this.variableNames=["source"],this.outputShape=t,this.rank=t.length;var e=Ze(this.rank),i="uniform int start["+this.rank+"];",r=X9(this.rank),a,s=t.map(function(o,l){return"sourceLoc."+Ip[l]+" = start["+l+"] + coords."+Ip[l]+";"});a=`
|
|
`+e+` sourceLoc;
|
|
`+e+` coords = getOutputCoords();
|
|
`+s.join(`
|
|
`)+`
|
|
`,this.userCode=`
|
|
`+i+`
|
|
void main() {
|
|
`+a+`
|
|
setOutput(getSource(`+r+`));
|
|
}
|
|
`}return n.prototype.getCustomSetupFunc=function(t){var e=this;if(t.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the "+("length of start ("+t.length+")"));return function(i,r){if(e.startLoc==null&&(e.startLoc=i.getUniformLocationNoThrow(r,"start"),e.startLoc==null))return;i.gl.uniform1iv(e.startLoc,t)}},n}(),Ip=["x","y","z","w","u","v"];function X9(n){if(n===1)return"sourceLoc";if(n<=6)return Ip.slice(0,n).map(function(t){return"sourceLoc."+t}).join(",");throw Error("Slicing for rank "+n+" is not yet supported")}var Z9=function(){function n(t){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.rank=t.length;var e=Ze(this.rank),i=en("coords",this.rank),r=en("sourceLoc",this.rank),a=this.rank===1?"sourceLoc":"vec2("+r.slice(-2).join()+")",s="getChannel(getSource("+r.join()+"), "+a+")",o=`
|
|
result.x = `+s+`;
|
|
if (++`+i[this.rank-1]+" < "+t[this.rank-1]+`) {
|
|
++`+r[this.rank-1]+`;
|
|
result.y = `+s+`;
|
|
--`+r[this.rank-1]+`;
|
|
}
|
|
`,l=this.rank===1?"":`
|
|
--`+i[this.rank-1]+`;
|
|
if (++`+i[this.rank-2]+" < "+t[this.rank-2]+`) {
|
|
++`+r[this.rank-2]+`;
|
|
result.z = `+s+`;
|
|
if (++`+i[this.rank-1]+" < "+t[this.rank-1]+`) {
|
|
++`+r[this.rank-1]+`;
|
|
result.w = `+s+`;
|
|
}
|
|
}
|
|
`,u=this.rank<=4?`sourceLoc = coords +
|
|
`+e+"("+t.map(function(c,h){return"start["+h+"]"}).join()+");":t.map(function(c,h){return r[h]+" = "+i[h]+" + start["+h+"];"}).join(`
|
|
`);this.userCode=`
|
|
uniform int start[`+this.rank+`];
|
|
void main() {
|
|
`+e+` coords = getOutputCoords();
|
|
`+e+` sourceLoc;
|
|
`+u+`
|
|
vec4 result = vec4(0.);
|
|
`+o+`
|
|
`+l+`
|
|
setOutput(result);
|
|
}
|
|
`}return n.prototype.getCustomSetupFunc=function(t){var e=this;if(t.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the "+("length of start ("+t.length+")"));return function(i,r){if(e.startLoc==null&&(e.startLoc=i.getUniformLocationNoThrow(r,"start"),e.startLoc==null))return;i.gl.uniform1iv(e.startLoc,t)}},n}();var Q9=function(){function n(t,e,i){this.variableNames=["x"],this.outputShape=i;var r=i.length,a=Ze(i.length),s=Ze(i.length),o="";if(r===1)o="coords * strides + begin";else{var l=0;o=i.map(function(u,c){return l++,i.length===1?"coords * strides["+c+"] + begin["+c+"]":"coords["+(l-1)+"] * strides["+c+"] + begin["+c+"]"}).join(",")}this.userCode=`
|
|
`+a+" begin = "+a+"("+t+`);
|
|
`+a+" strides = "+a+"("+e+`);
|
|
|
|
void main() {
|
|
`+s+` coords = getOutputCoords();
|
|
setOutput(getX(`+o+`));
|
|
}
|
|
`}return n}();var e6=function(){function n(t){this.gpgpu=t,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return n.prototype.acquireTexture=function(t,e,i){var r=dL(e,i),a=pL(t,r,i);a in this.freeTextures||(this.freeTextures[a]=[]),a in this.usedTextures||(this.usedTextures[a]=[]);var s=hL(t,r,this.gpgpu.gl,this.gpgpu.textureConfig,i);if(this.freeTextures[a].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=s,this.log();var o=this.freeTextures[a].shift();return this.usedTextures[a].push(o),o}var l;return r===Ot.PACKED_2X2_FLOAT32?l=this.gpgpu.createPackedMatrixTexture(t[0],t[1]):r===Ot.PACKED_2X2_FLOAT16?l=this.gpgpu.createFloat16PackedMatrixTexture(t[0],t[1]):r===Ot.UNPACKED_FLOAT32?l=this.gpgpu.createFloat32MatrixTexture(t[0],t[1]):r===Ot.UNPACKED_FLOAT16?l=this.gpgpu.createFloat16MatrixTexture(t[0],t[1]):r===Ot.PACKED_4X1_UNSIGNED_BYTE&&(l=this.gpgpu.createUnsignedBytesMatrixTexture(t[0],t[1])),this.usedTextures[a].push(l),this.numUsedTextures++,this._numBytesAllocated+=s,this.log(),l},n.prototype.releaseTexture=function(t,e,i,r){if(this.freeTextures==null)return;var a=dL(i,r),s=pL(e,a,r);s in this.freeTextures||(this.freeTextures[s]=[]);var o=hL(e,a,this.gpgpu.gl,this.gpgpu.textureConfig,r),l=x.env().get("WEBGL_DELETE_TEXTURE_THRESHOLD");l!==-1&&this._numBytesAllocated>l?(this.gpgpu.deleteMatrixTexture(t),this._numBytesAllocated-=o):(this.freeTextures[s].push(t),this.numFreeTextures++,this._numBytesFree+=o),this.numUsedTextures--;var u=this.usedTextures[s],c=u.indexOf(t);if(c<0)throw new Error("Cannot release a texture that was never provided by this texture manager");u.splice(c,1),this.log()},n.prototype.log=function(){if(!this.logEnabled)return;var t=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+t+")");var e=this._numBytesFree/this._numBytesAllocated;console.log("Bytes allocated: "+this._numBytesAllocated),console.log("Bytes unused: "+this._numBytesFree+" ("+Math.round(100*e)+"%)")},Object.defineProperty(n.prototype,"numBytesAllocated",{get:function(){return this._numBytesAllocated},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"numBytesFree",{get:function(){return this._numBytesFree},enumerable:!0,configurable:!0}),n.prototype.getNumUsedTextures=function(){return this.numUsedTextures},n.prototype.getNumFreeTextures=function(){return this.numFreeTextures},n.prototype.dispose=function(){var t=this;if(this.freeTextures==null)return;for(var e in this.freeTextures)this.freeTextures[e].forEach(function(i){t.gpgpu.deleteMatrixTexture(i)});for(var e in this.usedTextures)this.usedTextures[e].forEach(function(r){t.gpgpu.deleteMatrixTexture(r)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0},n}();function t6(n,t){var e=n;if(t===e.R32F)return 4;if(t===e.R16F)return 2;if(t===e.RGBA32F)return 16;if(t===n.RGBA)return 16;if(t===e.RGBA16F)return 8;throw new Error("Unknown internal format "+t)}function hL(n,t,e,i,r){var a=n6(t,i),s;if(r){var o=fa(n[0],n[1]),l=o[0],u=o[1];s=l*u}else{var c=ys(n[0],n[1]),h=c[0],d=c[1];s=h*d}var p=t6(e,a);return s*p}function n6(n,t){switch(n){case Ot.PACKED_2X2_FLOAT32:return bp(t);case Ot.PACKED_2X2_FLOAT16:return wp(t);case Ot.UNPACKED_FLOAT32:return gp(t);case Ot.UNPACKED_FLOAT16:return vp(t);case Ot.PACKED_4X1_UNSIGNED_BYTE:return yp(t);default:throw new Error("Unknown physical texture type "+n)}}function i6(n){return x.env().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?n?Ot.PACKED_2X2_FLOAT32:Ot.UNPACKED_FLOAT32:n?Ot.PACKED_2X2_FLOAT16:Ot.UNPACKED_FLOAT16}function dL(n,t){if(n===on.UPLOAD)return Ot.PACKED_2X2_FLOAT32;if(n===on.RENDER||n==null)return i6(t);if(n===on.DOWNLOAD||n===on.PIXELS)return Ot.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+n)}function pL(n,t,e){return n[0]+"_"+n[1]+"_"+t+"_"+e}var a6=function(){function n(t,e){this.variableNames=["A"];for(var i=new Array(t.length),r=0;r<i.length;r++)i[r]=t[r]*e[r];this.outputShape=i,this.rank=i.length;var a=Ze(this.rank),s=r6(t);this.userCode=`
|
|
void main() {
|
|
`+a+` resRC = getOutputCoords();
|
|
setOutput(getA(`+s+`));
|
|
}
|
|
`}return n}();function r6(n){var t=n.length;if(t>5)throw Error("Tile for rank "+t+" is not yet supported");if(t===1)return"imod(resRC, "+n[0]+")";for(var e=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],i=[],r=0;r<n.length;r++)i.push("imod("+e[r]+", "+n[r]+")");return i.join()}var Re=function(){function n(t,e){this.variableNames=["A"],this.outputShape=t,this.userCode=`
|
|
float unaryOperation(float x) {
|
|
`+e+`
|
|
}
|
|
|
|
void main() {
|
|
float x = getAAtOutCoords();
|
|
float y = unaryOperation(x);
|
|
|
|
setOutput(y);
|
|
}
|
|
`}return n}(),ui="if (isnan(x)) return x;",s6="return x;",fL="return abs(x);",mL=ui+`
|
|
return (x < 0.0) ? 0.0 : x;
|
|
`,gL=ui+`
|
|
return (x < 0.0) ? 0.0 : min(6.0, x);
|
|
`,vL="return (x >= 0.0) ? x : (exp(x) - 1.0);",o6=`
|
|
// Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
|
|
// see: https://arxiv.org/abs/1706.02515
|
|
float scaleAlpha = `+x.backend_util.SELU_SCALEALPHA+`;
|
|
float scale = `+x.backend_util.SELU_SCALE+`;
|
|
return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);
|
|
`;function l6(n){return n===void 0&&(n=0),ui+(`
|
|
return x > 0.0 ? 1.0 : float(`+n+`);
|
|
`)}var yL="return -x;",bL="return ceil(x);",wL="return floor(x);",u6=`
|
|
if (isnan(x)) { return 0.0; }
|
|
return sign(x);
|
|
`,c6="return float(isnan(x));",h6="return float(isinf(x));",d6="return float(!isnan(x) && !isinf(x));",p6=`
|
|
// OpenGL ES does not support round function.
|
|
// The algorithm is based on banker's rounding.
|
|
float base = floor(x);
|
|
if ((x - base) < 0.5) {
|
|
return floor(x);
|
|
} else if ((x - base) > 0.5) {
|
|
return ceil(x);
|
|
} else {
|
|
if (mod(base, 2.0) == 0.0) {
|
|
return base;
|
|
} else {
|
|
return base + 1.0;
|
|
}
|
|
}
|
|
`,SL="return exp(x);",LL="return exp(x) - 1.0;",f6=`if (x < 0.0) return NAN;
|
|
return log(x);`,m6="return log(1.0 + x);",g6="return sqrt(x);",v6="return inversesqrt(x);",y6="return 1.0 / (1.0 + exp(-1.0 * x));",b6=`
|
|
float epsilon = 1.1920928955078125e-7;
|
|
float threshold = log(epsilon) + 2.0;
|
|
|
|
bool too_large = x > -threshold;
|
|
bool too_small = x < threshold;
|
|
|
|
float result;
|
|
float exp_x = exp(x);
|
|
|
|
if (too_large){
|
|
result = x;
|
|
}
|
|
else if (too_small){
|
|
result = exp_x;
|
|
}
|
|
else{
|
|
result = log(exp_x + 1.0);
|
|
}
|
|
return result;
|
|
`,w6=ui+`
|
|
if (abs(x) > 1.) {
|
|
return NAN;
|
|
}
|
|
return asin(x);
|
|
`,S6=ui+`
|
|
if (abs(x) > 1.) {
|
|
return NAN;
|
|
}
|
|
return acos(x);
|
|
`,L6=ui+`
|
|
return atan(x);
|
|
`,I6=`
|
|
float e2x = exp(x);
|
|
return (e2x - 1.0 / e2x) / 2.0;
|
|
`,A6=`
|
|
float e2x = exp(-x);
|
|
return (e2x + 1.0 / e2x) / 2.0;
|
|
`,T6=`
|
|
float e2x = exp(-2.0 * abs(x));
|
|
return sign(x) * (1.0 - e2x) / (1.0 + e2x);
|
|
`,N6=ui+"return log(x + sqrt(x * x + 1.0));",x6=ui+`
|
|
if (x < 1.0) return NAN;
|
|
return log(x + sqrt(x * x - 1.0));`,C6=ui+`
|
|
if ((x < -1.0) || (x > 1.0)) return NAN;
|
|
return (log(1.0 + x) - log(1.0 - x)) / 2.0;`,R6=`
|
|
// Error function is calculated approximately with elementary function.
|
|
// See "Handbook of Mathematical Functions with Formulas,
|
|
// Graphs, and Mathematical Tables", Abramowitz and Stegun.
|
|
float p = `+x.backend_util.ERF_P+`;
|
|
float a1 = `+x.backend_util.ERF_A1+`;
|
|
float a2 = `+x.backend_util.ERF_A2+`;
|
|
float a3 = `+x.backend_util.ERF_A3+`;
|
|
float a4 = `+x.backend_util.ERF_A4+`;
|
|
float a5 = `+x.backend_util.ERF_A5+`;
|
|
|
|
float sign = sign(x);
|
|
x = abs(x);
|
|
float t = 1.0 / (1.0 + p * x);
|
|
return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));
|
|
`,O6="return 1.0 / x;",E6="return float(!(x >= 1.0));",D6="return float(int(x));",ul="return x;";var k6="return x;",F6=`
|
|
vec4 result = log(x);
|
|
vec4 isNaN = vec4(lessThan(x, vec4(0.0)));
|
|
result.r = isNaN.r == 1.0 ? NAN : result.r;
|
|
result.g = isNaN.g == 1.0 ? NAN : result.g;
|
|
result.b = isNaN.b == 1.0 ? NAN : result.b;
|
|
result.a = isNaN.a == 1.0 ? NAN : result.a;
|
|
|
|
return result;
|
|
`,IL=`
|
|
vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
|
|
bvec4 isNaN = isnan(x);
|
|
|
|
result.r = isNaN.r ? x.r : result.r;
|
|
result.g = isNaN.g ? x.g : result.g;
|
|
result.b = isNaN.b ? x.b : result.b;
|
|
result.a = isNaN.a ? x.a : result.a;
|
|
|
|
return result;
|
|
`,AL=`
|
|
vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));
|
|
bvec4 isNaN = isnan(x);
|
|
|
|
result.r = isNaN.r ? x.r : result.r;
|
|
result.g = isNaN.g ? x.g : result.g;
|
|
result.b = isNaN.b ? x.b : result.b;
|
|
result.a = isNaN.a ? x.a : result.a;
|
|
|
|
return result;
|
|
`,TL=`
|
|
vec4 result;
|
|
|
|
result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);
|
|
result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);
|
|
result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);
|
|
result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);
|
|
|
|
return result;
|
|
`,Ts=function(){function n(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode=`
|
|
vec4 unaryOperation(vec4 x) {
|
|
`+e+`
|
|
}
|
|
|
|
void main() {
|
|
vec4 x = getAAtOutCoords();
|
|
vec4 y = unaryOperation(x);
|
|
|
|
setOutput(y);
|
|
}
|
|
`}return n}();var W6=function(){function n(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=t;var e=t.length,i=en("rc",e),r=Ze(e),a=WM(e,i),s=i.slice(-2),o=e<=1?"rc":"vec2("+s.join(",")+")";this.userCode=`
|
|
void main() {
|
|
`+r+` rc = getOutputCoords();
|
|
vec4 packedInput = getA(`+a+`);
|
|
|
|
setOutput(getChannel(packedInput, `+o+`));
|
|
}
|
|
`}return n}();var NL=x.backend_util.segment_util,U6=x.kernel_impls.split,B6=x.kernel_impls.tile,z6=x.kernel_impls.topkImpl,P6=x.kernel_impls.whereImpl,_6=1e-7,M6=1e-4,cl={};function H6(n){return n in cl||(cl[n]={}),cl[n]}function hl(n,t){if(t===void 0&&(t=!1),n==="linear")return t?k6:s6;if(n==="relu")return t?IL:mL;if(n==="elu")return t?TL:vL;if(n==="relu6")return t?AL:gL;if(n==="prelu")return t?WS:FS;throw new Error("Activation "+n+" has not been implemented for the WebGL backend.")}var V6=128,q6=600;function G6(){return x.env().global.screen==null?1024:x.env().global.screen.height*x.env().global.screen.width*window.devicePixelRatio*q6/1024/1024}var xL=1e3,CL=function(n){H_(t,n);function t(e){var i=n.call(this)||this;if(i.pendingRead=new WeakMap,i.pendingDisposal=new WeakSet,i.dataRefCount=new WeakMap,i.numBytesInGPU=0,i.uploadWaitMs=0,i.downloadWaitMs=0,i.warnedAboutMemory=!1,i.warnedAboutCPUBackend=!1,i.pendingDeletes=0,i.disposed=!1,!x.env().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(e==null){var r=Gn(x.env().getNumber("WEBGL_VERSION"));i.binaryCache=H6(x.env().getNumber("WEBGL_VERSION")),i.gpgpu=new sL(r),i.canvas=r.canvas,i.gpgpuCreatedLocally=!0}else i.gpgpu=e,i.binaryCache={},i.gpgpuCreatedLocally=!1,i.canvas=e.gl.canvas;return i.textureManager=new e6(i.gpgpu),i.numMBBeforeWarning=G6(),i.texData=new x.DataStorage(i,x.engine()),i}return t.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},t.prototype.write=function(e,i,r){if((x.env().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")||x.env().getBool("DEBUG"))&&this.checkNumericalProblems(e),r==="complex64"&&e!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var a={};return this.texData.set(a,{shape:i,dtype:r,values:e,usage:on.UPLOAD,refCount:1}),a},t.prototype.incRef=function(e){var i=this.texData.get(e);i.refCount++},t.prototype.decRef=function(e){if(this.texData.has(e)){var i=this.texData.get(e);i.refCount--}},t.prototype.move=function(e,i,r,a){if(x.env().getBool("DEBUG")&&this.checkNumericalProblems(i),a==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(e,{shape:r,dtype:a,values:i,usage:on.UPLOAD,refCount:1})},t.prototype.disposeIntermediateTensorInfo=function(e){var i=e.dataId;if(this.texData.has(i)){var r=this.texData.get(i);r.refCount--,r.refCount<1&&this.disposeData(i)}},t.prototype.readSync=function(e){var i=this.texData.get(e),r=i.values,a=i.dtype,s=i.complexTensors,o=i.slice,l=i.shape,u=i.isPacked;if(o!=null){var c=void 0;u?c=new Ts(l,ul):c=new Re(l,ul);var h=this.runWebGLProgram(c,[{dataId:e,shape:l,dtype:a}],a),d=this.readSync(h.dataId);return this.disposeIntermediateTensorInfo(h),d}if(r!=null)return this.convertAndCacheOnCPU(e);if(a==="string")return r;var p=this.activeTimers!=null,f;p&&(f=x.util.now());var m;if(a==="complex64"){var g=s.real.dataSync(),v=s.imag.dataSync();m=x.backend_util.mergeRealAndImagArrays(g,v)}else m=this.getValuesFromTexture(e);return p&&(this.downloadWaitMs+=x.util.now()-f),this.convertAndCacheOnCPU(e,m)},t.prototype.read=function(e){return Qo(this,void 0,void 0,function(){var i,r,a,s,o,l,u,c,h,d,p,f,m,g,v,b,w,S,L,N,C,R;return el(this,function(D){switch(D.label){case 0:if(this.pendingRead.has(e))return i=this.pendingRead.get(e),[2,new Promise(function(k){return i.push(k)})];if(r=this.texData.get(e),a=r.values,s=r.shape,o=r.slice,l=r.dtype,u=r.complexTensors,c=r.isPacked,o!=null)return h=void 0,c?h=new Ts(s,ul):h=new Re(s,ul),d=this.runWebGLProgram(h,[{dataId:e,shape:s,dtype:l}],l),p=this.read(d.dataId),this.disposeIntermediateTensorInfo(d),[2,p];if(a!=null)return[2,this.convertAndCacheOnCPU(e)];if(!x.env().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&x.env().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");return f=null,l!=="complex64"&&x.env().get("WEBGL_BUFFER_SUPPORTED")&&(m=this.decode(e),g=this.texData.get(m.dataId),f=(R=this.gpgpu).createBufferFromTexture.apply(R,[g.texture].concat(bs(s)))),this.pendingRead.set(e,[]),l!=="complex64"?[4,this.gpgpu.createAndWaitForFence()]:[3,2];case 1:D.sent(),D.label=2;case 2:return l==="complex64"?[4,Promise.all([u.real.data(),u.imag.data()])]:[3,4];case 3:return b=D.sent(),w=b[0],S=b[1],v=x.backend_util.mergeRealAndImagArrays(w,S),[3,5];case 4:f==null?v=this.getValuesFromTexture(e):(L=x.util.sizeFromShape(s),v=this.gpgpu.downloadFloat32MatrixFromBuffer(f,L)),D.label=5;case 5:return m!=null&&this.disposeIntermediateTensorInfo(m),N=this.convertAndCacheOnCPU(e,v),C=this.pendingRead.get(e),this.pendingRead.delete(e),C.forEach(function(k){return k(N)}),this.pendingDisposal.has(e)&&(this.pendingDisposal.delete(e),this.disposeData(e),this.pendingDeletes--),[2,N]}})})},t.prototype.checkNumericalProblems=function(e){if(e==null)return;for(var i=0;i<e.length;i++){var r=e[i];if(!tS(r))throw x.env().getBool("WEBGL_RENDER_FLOAT32_CAPABLE")?Error("The value "+r+" cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'"):Error("The value "+r+" cannot be represented on this device.")}},t.prototype.getValuesFromTexture=function(e){var i,r=this.texData.get(e),a=r.shape,s=r.dtype,o=r.isPacked,l=x.util.sizeFromShape(a);if(x.env().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")){var u=this.decode(e),c=this.texData.get(u.dataId),h=(i=this.gpgpu).downloadMatrixFromPackedTexture.apply(i,[c.texture].concat(bs(a))).subarray(0,l);return this.disposeIntermediateTensorInfo(u),h}var d=x.env().getBool("WEBGL_PACK")&&o===!0,p=d?il(a):a,f=d?new p9(p):new d9(p),m=this.runWebGLProgram(f,[{shape:p,dtype:s,dataId:e}],"float32"),g=this.texData.get(m.dataId),v=this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(g.texture,g.texShape[0],g.texShape[1]).subarray(0,l);return this.disposeIntermediateTensorInfo(m),v},t.prototype.time=function(e){return Qo(this,void 0,void 0,function(){var i,r,a,s,o,l,u;return el(this,function(c){switch(c.label){case 0:return i=this.activeTimers,r=[],a=!1,this.programTimersStack==null?(this.programTimersStack=r,a=!0):this.activeTimers.push(r),this.activeTimers=r,e(),s=x.util.flatten(this.activeTimers.map(function(h){return h.query})).filter(function(h){return h!=null}),o=x.util.flatten(this.activeTimers.map(function(h){return h.name})).filter(function(h){return h!=null}),this.activeTimers=i,a&&(this.programTimersStack=null),l={uploadWaitMs:this.uploadWaitMs,downloadWaitMs:this.downloadWaitMs,kernelMs:null,wallMs:null},x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[4,Promise.all(s)]:[3,2];case 1:return u=c.sent(),l.kernelMs=x.util.sum(u),l.getExtraProfileInfo=function(){return u.map(function(h,d){return{name:o[d],ms:h}}).map(function(h){return h.name+": "+h.ms}).join(", ")},[3,3];case 2:l.kernelMs={error:"WebGL query timers are not supported in this environment."},c.label=3;case 3:return this.uploadWaitMs=0,this.downloadWaitMs=0,[2,l]}})})},t.prototype.memory=function(){return{unreliable:!1,numBytesInGPU:this.numBytesInGPU,numBytesInGPUAllocated:this.textureManager.numBytesAllocated,numBytesInGPUFree:this.textureManager.numBytesFree}},t.prototype.startTimer=function(){return x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?this.gpgpu.beginQuery():{startMs:x.util.now(),endMs:null}},t.prototype.endTimer=function(e){return x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?(this.gpgpu.endQuery(),e):(e.endMs=x.util.now(),e)},t.prototype.getQueryTime=function(e){return Qo(this,void 0,void 0,function(){var i;return el(this,function(r){return x.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[2,this.gpgpu.waitForQueryAndGetTime(e)]:(i=e,[2,i.endMs-i.startMs])})})},t.prototype.disposeData=function(e){if(this.pendingDisposal.has(e))return;if(this.pendingRead.has(e)){this.pendingDisposal.add(e),this.pendingDeletes++;return}if(!this.texData.has(e))return;this.releaseGPUData(e);var i=this.texData.get(e).complexTensors;i!=null&&(i.real.dispose(),i.imag.dispose()),this.texData.delete(e)},t.prototype.releaseGPUData=function(e){var i=this.texData.get(e),r=i.texture,a=i.dtype,s=i.texShape,o=i.usage,l=i.isPacked,u=i.slice,c=u&&u.origDataId||e,h=this.dataRefCount.get(c);h>1?this.dataRefCount.set(c,h-1):(this.dataRefCount.delete(c),r!=null&&(this.numBytesInGPU-=this.computeBytes(s,a),this.textureManager.releaseTexture(r,s,o,l)));var d=this.texData.get(e);d.texture=null,d.texShape=null,d.isPacked=!1,d.slice=null},t.prototype.getTexture=function(e){return this.uploadToGPU(e),this.texData.get(e).texture},t.prototype.getDataInfo=function(e){return this.texData.get(e)},t.prototype.getCPUBackend=function(){return x.env().getBool("WEBGL_CPU_FORWARD")?(this.cpuBackend==null&&(this.cpuBackend=x.engine().findBackend("cpu")),this.cpuBackend):null},t.prototype.shouldExecuteOnCPU=function(e,i){var r=this;i===void 0&&(i=V6);var a=this.getCPUBackend();return!this.warnedAboutCPUBackend&&a==null&&(console.warn("Your application contains ops that are small enough to be executed on the CPU backend, however the CPU backend cannot be found. Consider importing the CPU backend (@tensorflow/tfjs-backend-cpu) for better performance."),this.warnedAboutCPUBackend=!0),a!=null&&e.every(function(s){return r.texData.get(s.dataId).texture==null&&x.util.sizeFromShape(s.shape)<i})},t.prototype.getGPGPUContext=function(){return this.gpgpu},t.prototype.complex=function(e,i){var r=this.makeOutput(e.shape,"complex64"),a=this.texData.get(r.dataId);return a.complexTensors={real:x.engine().keep(e.clone()),imag:x.engine().keep(i.clone())},r},t.prototype.real=function(e){var i=this.texData.get(e.dataId);return i.complexTensors.real.clone()},t.prototype.imag=function(e){var i=this.texData.get(e.dataId);return i.complexTensors.imag.clone()},t.prototype.slice=function(e,i,r){if(this.shouldExecuteOnCPU([e])){var a=RM(this.texData.get(e.dataId).values,i,r,e.shape,e.dtype);return this.makeOutput(r,e.dtype,a)}if(x.util.sizeFromShape(r)===0)return x.tensor([],r,e.dtype);var s=this.texData.get(e.dataId).isPacked,o=x.slice_util.isSliceContinous(e.shape,i,r);if(s||!o){var l=x.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new Z9(r):new J9(r),u=l.getCustomSetupFunc(i);return this.compileAndRun(l,[e],null,u)}return this.uploadToGPU(e.dataId),this.shallowSlice(e,i,r)},t.prototype.shallowSlice=function(e,i,r){var a=this.texData.get(e.dataId),s=this.makeOutput(r,e.dtype),o=this.texData.get(s.dataId);Object.assign(o,a),o.shape=r,o.dtype=e.dtype;var l=x.slice_util.computeFlatOffset(i,e.strides);a.slice&&(l+=a.slice.flatOffset),o.slice={flatOffset:l,origDataId:a.slice&&a.slice.origDataId||e.dataId};var u=this.dataRefCount.get(o.slice.origDataId)||1;return this.dataRefCount.set(o.slice.origDataId,u+1),s},t.prototype.stridedSlice=function(e,i,r,a){var s=this,o=this.tryRunOnCpuOrThrow([e],function(){return s.cpuBackend.stridedSlice(e,i,r,a)});if(o)return o;var l=x.slice_util.computeOutShape(i,r,a);if(l.some(function(c){return c===0}))return x.tensor([],l);var u=new Q9(i,a,l);return this.compileAndRun(u,[e])},t.prototype.reverse=function(e,i){var r=x.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new j9(e.shape,i):new Y9(e.shape,i);return this.compileAndRun(r,[e])},t.prototype.concat=function(e,i){if(e[0].dtype==="complex64"){var r=e.map(function(f){return x.real(f)}),a=e.map(function(f){return x.imag(f)});return x.complex(this.concat(r,i),this.concat(a,i))}if(e.length===1)return e[0];if(e.length>x.env().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var s=Math.floor(e.length/2),o=this.concat(e.slice(0,s),i),l=this.concat(e.slice(s),i);return this.concat([o,l],i)}if(x.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&e[0].rank>1){var u=new Q5(e.map(function(f){return f.shape}),i);return this.compileAndRun(u,e)}var c=x.backend_util.computeOutShape(e.map(function(f){return f.shape}),i),h=e.map(function(f){return f.as2D(-1,x.util.sizeFromShape(f.shape.slice(i)))}),d=new Z5(h.map(function(f){return f.shape})),p=this.compileAndRun(d,h);return p.reshape(c)},t.prototype.neg=function(e){var i=this,r=this.tryRunOnCpuOrThrow([e],function(){return i.cpuBackend.neg(e)});if(r)return r;if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,yL,e.dtype);var a=new Re(e.shape,yL);return this.compileAndRun(a,[e])},t.prototype.batchMatMul=function(e,i,r,a){var s=r?e.shape[2]:e.shape[1],o=a?i.shape[1]:i.shape[2],l=r?e.shape[1]:e.shape[2],u=e.shape,c=u[0];if((s===1||o===1)&&l>xL){r&&(e=x.transpose(e,[0,2,1])),a&&(i=x.transpose(i,[0,2,1]));var h=o===1?e:e.as3D(c,l,1),d=o===1?2:1,p=o===1?i.as3D(c,1,l):i;return this.multiply(h,p).sum(d,!0)}var f=x.upcastType(e.dtype,i.dtype),m=new Sp(e.shape,[c,s,o],r,a);return this.compileAndRun(m,[e,i],f)},t.prototype.fusedBatchMatMul=function(e){var i=e.a,r=e.b,a=e.transposeA,s=e.transposeB,o=e.bias,l=e.activation,u=e.preluActivationWeights,c=a?i.shape[2]:i.shape[1],h=s?r.shape[1]:r.shape[2],d=i.shape,p=d[0],f=x.upcastType(i.dtype,r.dtype),m=o!=null,g=u!=null,v=l?hl(l,!0):null,b=new Sp(i.shape,[p,c,h],a,s,m,v,g),w=[i,r];return o&&w.push(o),u&&w.push(u),this.compileAndRun(b,w,f)},t.prototype.multiply=function(e,i){if(e.dtype==="complex64"){var r=this.texData.get(e.dataId),a=this.texData.get(i.dataId),s=new ES(OS.REAL,e.shape,i.shape),o=new ES(OS.IMAG,e.shape,i.shape),l=[this.makeComplexComponentTensorInfo(e,r.complexTensors.real),this.makeComplexComponentTensorInfo(e,r.complexTensors.imag),this.makeComplexComponentTensorInfo(i,a.complexTensors.real),this.makeComplexComponentTensorInfo(i,a.complexTensors.imag)],u=this.compileAndRun(s,l),c=this.compileAndRun(o,l),h=this.complex(u,c);return u.dispose(),c.dispose(),h}var d=x.upcastType(e.dtype,i.dtype);if(this.shouldExecuteOnCPU([e,i])){var r=this.texData.get(e.dataId),a=this.texData.get(i.dataId),p=xM(e.shape,i.shape,r.values,a.values,d),f=p[0],m=p[1];return this.makeOutput(m,d,f)}if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,kS,e.dtype);var g=new St(kS,e.shape,i.shape);return this.compileAndRun(g,[e,i],e.dtype)},t.prototype.localResponseNormalization4D=function(e,i,r,a,s){var o=x.env().getBool("WEBGL_PACK_NORMALIZATION")?new C9(e.shape,i,r,a,s):new N9(e.shape,i,r,a,s);return this.compileAndRun(o,[e])},t.prototype.LRNGrad=function(e,i,r,a,s,o,l){var u=new x9(i.shape,a,s,o,l);return this.compileAndRun(u,[i,r,e])},t.prototype.tile=function(e,i){if(e.dtype==="string"){var r=this.readSync(e.dataId),a=r.map(function(l){return x.util.decodeString(l)}),s=x.buffer(e.shape,e.dtype,a);return B6(s,i)}var o=new a6(e.shape,i);return this.compileAndRun(o,[e])},t.prototype.pad=function(e,i,r){var a=x.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new P9(e.shape,i,r):new z9(e.shape,i,r);return this.compileAndRun(a,[e])},t.prototype.gather=function(e,i,r){var a=this,s=this.tryRunOnCpuOrThrow([e,i],function(){return a.cpuBackend.gather(e,i,r)});if(s)return s;var o=new y9(e.shape,i.size,r);return this.compileAndRun(o,[e,i])},t.prototype.batchToSpaceND=function(e,i,r){x.util.assert(e.rank<=4,function(){return"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"});var a=i.reduce(function(h,d){return h*d}),s=x.backend_util.getReshaped(e.shape,i,a),o=x.backend_util.getPermuted(s.length,i.length),l=x.backend_util.getReshapedPermuted(e.shape,i,a),u=x.backend_util.getSliceBeginCoords(r,i.length),c=x.backend_util.getSliceSize(l,r,i.length);return x.transpose(e.reshape(s),o).reshape(l).slice(u,c)},t.prototype.spaceToBatchND=function(e,i,r){x.util.assert(e.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var a=i.reduce(function(p,f){return p*f}),s=[[0,0]];s.push.apply(s,r);for(var o=1+i.length;o<e.shape.length;++o)s.push([0,0]);var l=e.pad(s),u=x.backend_util.getReshaped(l.shape,i,a,!1),c=x.backend_util.getPermuted(u.length,i.length,!1),h=x.backend_util.getReshapedPermuted(l.shape,i,a,!1),d=x.transpose(l.reshape(u),c);return x.reshape(d,h)},t.prototype.reduce=function(e,i,r){var a=e.shape[0],s=e.shape[1],o=x.backend_util.computeOptimalWindowSize(s),l=Math.ceil(s/o),u={windowSize:o,inSize:s,batchSize:a,outSize:l},c=new lL(u,i),h=this.compileAndRun(c,[e],r);return h.shape[1]===1?h:this.reduce(h,i,r)},t.prototype.argReduce=function(e,i,r){r===void 0&&(r=null);var a=e.shape[0],s=e.shape[1];r!=null&&(a=r.shape[0],s=r.shape[1]);var o=x.backend_util.computeOptimalWindowSize(s),l={windowSize:o,inSize:s,batchSize:a,outSize:Math.ceil(s/o)},u=new FM(l,i,r==null),c=[e];r!=null&&c.push(r);var h=this.compileAndRun(u,c,"int32");return h.shape[1]===1?h:this.argReduce(e,i,h)},t.prototype.argReducePacked=function(e,i,r){r===void 0&&(r=null);var a=r!=null?r.shape:e.shape,s=a[a.length-1],o=x.backend_util.computeOptimalWindowSize(s),l=new y5(a,o,i,r==null),u=r==null?[e]:[e,r],c=this.compileAndRun(l,u,"int32");return c.rank===e.rank?this.argReducePacked(e,i,c):c},t.prototype.sum=function(e,i){x.backend_util.assertAxesAreInnerMostDims("sum",i,e.rank);var r=x.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=x.util.sizeFromShape(s),l=e.as2D(-1,o),u=x.sumOutType(e.dtype);return this.reduce(l,"sum",u).reshape(a)},t.prototype.prod=function(e,i){var r=this,a=this.tryRunOnCpuOrThrow([e],function(){return r.cpuBackend.prod(e,i)});if(a)return a;var s=x.backend_util.computeOutAndReduceShapes(e.shape,i),o=s[0],l=s[1],u=x.util.sizeFromShape(l),c=e.as2D(-1,u),h=x.sumOutType(e.dtype);return this.reduce(c,"prod",h).reshape(o)},t.prototype.unsortedSegmentSum=function(e,i,r){var a=0,s=x.backend_util.getAxesPermutation([a],e.rank),o=e;s!=null&&(o=x.transpose(e,s),a=x.backend_util.getInnerMostAxes(1,e.rank)[0]);var l=NL.computeOutShape(o.shape,a,r),u=x.util.sizeFromShape([o.shape[a]]),c=o.as2D(-1,u),h=x.sumOutType(e.dtype),d=this.segOpCompute(c,"unsortedSegmentSum",i,h,r).reshape(l);return s!=null&&(d=x.transpose(d,x.backend_util.getUndoAxesPermutation(s))),d},t.prototype.segOpCompute=function(e,i,r,a,s){var o=e.shape[0],l=e.shape[1],u=NL.segOpComputeOptimalWindowSize(l,s),c={windowSize:u,inSize:l,batchSize:o,numSegments:s},h=new K9(c,i),d=this.compileAndRun(h,[e,r],a);return d.shape[1]===s?d:(r=x.range(0,s).tile([l/u]),this.segOpCompute(d,i,r,a,s))},t.prototype.argMinMaxReduce=function(e,i,r){var a=[i];if(x.backend_util.assertAxesAreInnerMostDims("arg"+r.charAt(0).toUpperCase()+r.slice(1),a,e.rank),!x.env().getBool("WEBGL_PACK_REDUCE")||e.rank<=2){var s=x.backend_util.computeOutAndReduceShapes(e.shape,a),o=s[0],l=s[1],u=x.util.sizeFromShape(l),c=e.as2D(-1,u);return this.argReduce(c,r).reshape(o)}return this.argReducePacked(e,r)},t.prototype.argMin=function(e,i){return this.argMinMaxReduce(e,i,"min")},t.prototype.argMax=function(e,i){return this.argMinMaxReduce(e,i,"max")},t.prototype.cumsum=function(e,i,r,a){if(i!==e.rank-1)throw new Error("WebGL cumsum shader expects an inner-most axis="+(e.rank-1)+" "+("but got axis="+i));for(var s=e.shape[i],o=e,l=0;l<=Math.ceil(Math.log2(s))-1;l++){var u=new MS(e.shape,!1,a),c=u.getCustomSetupFunc(l),h=o;o=this.compileAndRun(u,[o],o.dtype,c),h.dispose()}if(r){var u=new MS(e.shape,r,a),h=o;o=this.compileAndRun(u,[o]),h.dispose()}return o},t.prototype.equal=function(e,i){if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,z5,"bool");var r=new St(I5,e.shape,i.shape);return this.compileAndRun(r,[e,i],"bool")},t.prototype.notEqual=function(e,i){if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,P5,"bool");var r=new St(A5,e.shape,i.shape);return this.compileAndRun(r,[e,i],"bool")},t.prototype.less=function(e,i){var r=this,a=this.tryRunOnCpuOrThrow([e,i],function(){return r.cpuBackend.less(e,i)});if(a)return a;if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,_5,"bool");var s=new St(T5,e.shape,i.shape);return this.compileAndRun(s,[e,i],"bool")},t.prototype.lessEqual=function(e,i){if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,M5,"bool");var r=new St(N5,e.shape,i.shape);return this.compileAndRun(r,[e,i],"bool")},t.prototype.greater=function(e,i){var r=this,a=this.tryRunOnCpuOrThrow([e,i],function(){return r.cpuBackend.greater(e,i)});if(a)return a;if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,H5,"bool");var s=new St(x5,e.shape,i.shape);return this.compileAndRun(s,[e,i],"bool")},t.prototype.greaterEqual=function(e,i){if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,V5,"bool");var r=new St(C5,e.shape,i.shape);return this.compileAndRun(r,[e,i],"bool")},t.prototype.logicalNot=function(e){var i=new Re(e.shape,E6);return this.compileAndRun(i,[e])},t.prototype.logicalAnd=function(e,i){if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,q5,"bool");var r=new St(R5,e.shape,i.shape);return this.compileAndRun(r,[e,i],"bool")},t.prototype.logicalOr=function(e,i){if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,G5,"bool");var r=new St(O5,e.shape,i.shape);return this.compileAndRun(r,[e,i],"bool")},t.prototype.select=function(e,i,r){var a=new $9(e.rank,i.shape,i.rank);return this.compileAndRun(a,[e,i,r],x.upcastType(i.dtype,r.dtype))},t.prototype.where=function(e){x.backend_util.warn("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var i=e.dataSync();return P6(e.shape,i)},t.prototype.topk=function(e,i,r){var a=e.dataSync();return z6(a,e.shape,e.dtype,i,r)},t.prototype.min=function(e,i){x.backend_util.assertAxesAreInnerMostDims("min",i,e.rank);var r=x.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=x.util.sizeFromShape(s),l=e.as2D(-1,o);return this.reduce(l,"min",l.dtype).reshape(a)},t.prototype.minimum=function(e,i){var r=this,a=this.tryRunOnCpuOrThrow([e,i],function(){return r.cpuBackend.minimum(e,i)});if(a)return a;var s=x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ui(j5,e.shape,i.shape):new St(D5,e.shape,i.shape);return this.compileAndRun(s,[e,i])},t.prototype.mod=function(e,i){var r=x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ui(K5,e.shape,i.shape):new St(k5,e.shape,i.shape);return this.compileAndRun(r,[e,i])},t.prototype.maximum=function(e,i){var r=this,a=this.tryRunOnCpuOrThrow([e,i],function(){return r.cpuBackend.maximum(e,i)});if(a)return a;var s=x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ui(Y5,e.shape,i.shape):new St(E5,e.shape,i.shape);return this.compileAndRun(s,[e,i])},t.prototype.all=function(e,i){x.backend_util.assertAxesAreInnerMostDims("all",i,e.rank);var r=x.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=x.util.sizeFromShape(s),l=e.as2D(-1,o);return this.reduce(l,"all",l.dtype).reshape(a)},t.prototype.any=function(e,i){x.backend_util.assertAxesAreInnerMostDims("any",i,e.rank);var r=x.backend_util.computeOutAndReduceShapes(e.shape,i),a=r[0],s=r[1],o=x.util.sizeFromShape(s),l=e.as2D(-1,o);return this.reduce(l,"any",l.dtype).reshape(a)},t.prototype.floorDiv=function(e,i){var r=S5,a="int32";if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,W5,a);var s=new St(r,e.shape,i.shape);return this.compileAndRun(s,[e,i],a)},t.prototype.add=function(e,i){if(e.dtype==="complex64"&&i.dtype==="complex64")return this.complexSeparableBinaryOp(e,i,fp);var r=x.upcastType(e.dtype,i.dtype);if(this.shouldExecuteOnCPU([e,i])){var a=this.texData.get(e.dataId),s=this.texData.get(i.dataId),o=wM(e.shape,i.shape,a.values,s.values,r),l=o[0],u=o[1];return this.makeOutput(u,r,l)}if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,fp,r);var c=new St(fp,e.shape,i.shape);return this.compileAndRun(c,[e,i],r)},t.prototype.packedUnaryOp=function(e,i,r){var a=new Ts(e.shape,i);return this.compileAndRun(a,[e],r)},t.prototype.packedBinaryOp=function(e,i,r,a,s){s===void 0&&(s=!1);var o=new Ui(r,e.shape,i.shape,s);return this.compileAndRun(o,[e,i],a)},t.prototype.complexSeparableBinaryOp=function(e,i,r){var a=this,s=this.texData.get(e.dataId),o=this.texData.get(i.dataId),l=[[s.complexTensors.real,o.complexTensors.real],[s.complexTensors.imag,o.complexTensors.imag]].map(function(d){var p=d[0],f=d[1],m=a.makeComplexComponentTensorInfo(e,p),g=a.makeComplexComponentTensorInfo(i,f),v=new St(r,e.shape,i.shape);return a.compileAndRun(v,[m,g],x.upcastType(p.dtype,f.dtype))}),u=l[0],c=l[1],h=this.complex(u,c);return u.dispose(),c.dispose(),h},t.prototype.makeComplexComponentTensorInfo=function(e,i){return{dataId:i.dataId,dtype:i.dtype,shape:e.shape}},t.prototype.addN=function(e){if(e.length===1)return e[0];if(e.length>x.env().get("WEBGL_MAX_TEXTURES_IN_SHADER")){var i=Math.floor(e.length/2),r=this.addN(e.slice(0,i)),a=this.addN(e.slice(i));return this.addN([r,a])}var s=e.map(function(c){return c.dtype}).reduce(function(c,h){return x.upcastType(c,h)}),o=e.map(function(c){return c.shape}),l=x.env().getBool("WEBGL_PACK"),u=l?new kM(e[0].shape,o):new DM(e[0].shape,o);return this.compileAndRun(u,e,s)},t.prototype.subtract=function(e,i){if(e.dtype==="complex64"&&i.dtype==="complex64")return this.complexSeparableBinaryOp(e,i,mp);var r=x.upcastType(e.dtype,i.dtype);if(this.shouldExecuteOnCPU([e,i])){var a=this.texData.get(e.dataId),s=this.texData.get(i.dataId),o=OM(e.shape,i.shape,a.values,s.values,r),l=o[0],u=o[1];return this.makeOutput(u,r,l)}if(x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(e,i,mp,e.dtype);var c=new St(mp,e.shape,i.shape);return this.compileAndRun(c,[e,i],r)},t.prototype.pow=function(e,i){var r=x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"),a=r?new Ui(U5,e.shape,i.shape):new St(L5,e.shape,i.shape),s=x.upcastType(e.dtype,i.dtype);return this.compileAndRun(a,[e,i],s)},t.prototype.ceil=function(e){if(this.shouldExecuteOnCPU([e])){var i=SM(this.texData.get(e.dataId).values,e.dtype);return this.makeOutput(e.shape,e.dtype,i)}if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,bL,e.dtype);var r=new Re(e.shape,bL);return this.compileAndRun(r,[e])},t.prototype.floor=function(e){if(this.shouldExecuteOnCPU([e])){var i=AM(this.texData.get(e.dataId).values,e.dtype);return this.makeOutput(e.shape,e.dtype,i)}if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,wL,e.dtype);var r=new Re(e.shape,wL);return this.compileAndRun(r,[e])},t.prototype.sign=function(e){var i=new Re(e.shape,u6);return this.compileAndRun(i,[e])},t.prototype.isNaN=function(e){var i=new Re(e.shape,c6);return this.compileAndRun(i,[e],"bool")},t.prototype.isInf=function(e){var i=new Re(e.shape,h6);return this.compileAndRun(i,[e],"bool")},t.prototype.isFinite=function(e){var i=new Re(e.shape,d6);return this.compileAndRun(i,[e],"bool")},t.prototype.round=function(e){var i=new Re(e.shape,p6);return this.compileAndRun(i,[e])},t.prototype.exp=function(e){if(this.shouldExecuteOnCPU([e])){var i=LM(this.texData.get(e.dataId).values,e.dtype);return this.makeOutput(e.shape,e.dtype,i)}if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,SL,e.dtype);var r=new Re(e.shape,SL);return this.compileAndRun(r,[e])},t.prototype.expm1=function(e){if(this.shouldExecuteOnCPU([e])){var i=IM(this.texData.get(e.dataId).values,e.dtype);return this.makeOutput(e.shape,e.dtype,i)}if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,LL,e.dtype);var r=new Re(e.shape,LL);return this.compileAndRun(r,[e])},t.prototype.softmax=function(e,i){var r=x.util.parseAxisParam([i],e.shape),a=x.max(e,r),s=x.backend_util.expandShapeToKeepDim(a.shape,r),o=this.subtract(e,a.reshape(s)),l=this.exp(o),u=this.sum(l,r).reshape(s);return x.div(l,u)},t.prototype.log=function(e){if(this.shouldExecuteOnCPU([e])){var i=TM(this.texData.get(e.dataId).values,e.dtype);return this.makeOutput(e.shape,e.dtype,i)}if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,F6,e.dtype);var r=new Re(e.shape,f6);return this.compileAndRun(r,[e])},t.prototype.log1p=function(e){var i=new Re(e.shape,m6);return this.compileAndRun(i,[e])},t.prototype.sqrt=function(e){var i=new Re(e.shape,g6);return this.compileAndRun(i,[e])},t.prototype.rsqrt=function(e){if(this.shouldExecuteOnCPU([e])){var i=CM(this.texData.get(e.dataId).values,e.dtype);return this.makeOutput(e.shape,e.dtype,i)}var r=new Re(e.shape,v6);return this.compileAndRun(r,[e])},t.prototype.reciprocal=function(e){var i=new Re(e.shape,O6);return this.compileAndRun(i,[e])},t.prototype.relu=function(e){var i;return x.env().getBool("WEBGL_PACK")?i=new Ts(e.shape,IL):i=new Re(e.shape,mL),this.compileAndRun(i,[e])},t.prototype.relu6=function(e){var i;return x.env().getBool("WEBGL_PACK")?i=new Ts(e.shape,AL):i=new Re(e.shape,gL),this.compileAndRun(i,[e])},t.prototype.prelu=function(e,i){var r=x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ui(WS,e.shape,i.shape):new St(FS,e.shape,i.shape);return this.compileAndRun(r,[e,i])},t.prototype.elu=function(e){if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,TL,e.dtype);var i=new Re(e.shape,vL);return this.compileAndRun(i,[e])},t.prototype.eluDer=function(e,i){var r=x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ui(B5,e.shape,i.shape):new St(F5,e.shape,i.shape);return this.compileAndRun(r,[e,i])},t.prototype.selu=function(e){var i=new Re(e.shape,o6);return this.compileAndRun(i,[e])},t.prototype.int=function(e){var i=new Re(e.shape,D6);return this.compileAndRun(i,[e],"int32")},t.prototype.clip=function(e,i,r){var a;x.env().getBool("WEBGL_PACK_CLIP")?a=new X5(e.shape):a=new $5(e.shape);var s=a.getCustomSetupFunc(i,r);return this.compileAndRun(a,[e],null,s)},t.prototype.abs=function(e){if(this.shouldExecuteOnCPU([e])&&e.dtype!=="complex64"){var i=bM(this.texData.get(e.dataId).values);return this.makeOutput(e.shape,e.dtype,i)}if(x.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(e,fL,e.dtype);var r=new Re(e.shape,fL);return this.compileAndRun(r,[e])},t.prototype.complexAbs=function(e){var i=this.texData.get(e.dataId),r=new J5(e.shape),a=[this.makeComplexComponentTensorInfo(e,i.complexTensors.real),this.makeComplexComponentTensorInfo(e,i.complexTensors.imag)];return this.compileAndRun(r,a)},t.prototype.sigmoid=function(e){var i=new Re(e.shape,y6);return this.compileAndRun(i,[e])},t.prototype.softplus=function(e){var i=new Re(e.shape,b6);return this.compileAndRun(i,[e])},t.prototype.asin=function(e){var i=new Re(e.shape,w6);return this.compileAndRun(i,[e])},t.prototype.acos=function(e){var i=new Re(e.shape,S6);return this.compileAndRun(i,[e])},t.prototype.atan=function(e){var i=new Re(e.shape,L6);return this.compileAndRun(i,[e])},t.prototype.sinh=function(e){var i=new Re(e.shape,I6);return this.compileAndRun(i,[e])},t.prototype.cosh=function(e){var i=new Re(e.shape,A6);return this.compileAndRun(i,[e])},t.prototype.tanh=function(e){var i=new Re(e.shape,T6);return this.compileAndRun(i,[e])},t.prototype.asinh=function(e){var i=new Re(e.shape,N6);return this.compileAndRun(i,[e])},t.prototype.acosh=function(e){var i=new Re(e.shape,x6);return this.compileAndRun(i,[e])},t.prototype.atanh=function(e){var i=new Re(e.shape,C6);return this.compileAndRun(i,[e])},t.prototype.erf=function(e){var i=new Re(e.shape,R6);return this.compileAndRun(i,[e])},t.prototype.step=function(e,i){var r=new Re(e.shape,l6(i));return this.compileAndRun(r,[e])},t.prototype.conv2dByMatMul=function(e,i,r,a,s,o){var l=e.shape,u=this.texData.get(e.dataId),c=r.inChannels,h=l[0]*l[1]*l[2],d=r.outChannels,p=r.dataFormat==="channelsLast",f=!1,m=!1,g=(h===1||d===1)&&c>xL,v=l[2]%2!==0&&!!u.isPacked;if(g||!x.env().getBool("WEBGL_LAZILY_UNPACK")||!x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!v){var b=p?l[0]*l[1]*l[2]:l[0]*l[2]*l[3],w=x.reshape(e,[1,b,r.inChannels]),S=x.reshape(i,[1,r.inChannels,r.outChannels]),L=this.fusedBatchMatMul({a:w,b:S,transposeA:f,transposeB:m,bias:a,activation:s,preluActivationWeights:o});return x.reshape(L,r.outShape)}var N=p?l[0]*l[1]*(l[2]+1):l[0]*l[2]*(l[3]+1),C={dataId:e.dataId,shape:[1,N,r.inChannels],dtype:e.dtype},R=u.shape;u.shape=u.shape.slice(),u.shape[u.shape.length-2]++,x.util.assert(Ls(u.shape,C.shape),function(){return"packed reshape "+u.shape+" to "+C.shape+" isn't free"});var D=x.reshape(i,[1,r.inChannels,r.outChannels]),k=this.fusedBatchMatMul({a:C,b:D,transposeA:f,transposeB:m,bias:a,activation:s,preluActivationWeights:o}),W=this.texData.get(k.dataId);return x.util.assert(W.isPacked,function(){return"batchMatMul result is expected to be packed"}),u.shape=R,W.shape=r.outShape,x.engine().makeTensorFromDataId(k.dataId,r.outShape,k.dtype)},t.prototype.conv2dWithIm2Row=function(e,i,r,a,s,o){var l=r.filterWidth,u=r.filterHeight,c=r.inChannels,h=r.outWidth,d=r.outHeight,p=r.dataFormat,f=p==="channelsLast",m=l*u*c,g=d*h,v=[m,g],b=!0,w=!1,S=e.squeeze([0]),L=i.reshape([1,m,-1]),N=new T9(v,S.shape,r),C=this.compileAndRun(N,[S]).reshape([1,v[0],v[1]]),R=a!=null,D=o!=null,k=s?hl(s,!0):null,W=new Sp(C.shape,[1,g,r.outChannels],b,w,R,k,D),F=[C,L];a&&F.push(a),D&&F.push(o);var P=this.compileAndRun(W,F);return f?P.reshape([1,d,h,r.outChannels]):P.reshape([1,r.outChannels,d,h])},t.prototype.fusedConv2d=function(e){var i=e.input,r=e.filter,a=e.convInfo,s=e.bias,o=e.activation,l=e.preluActivationWeights;if(a.filterHeight===1&&a.filterWidth===1&&a.dilationHeight===1&&a.dilationWidth===1&&a.strideHeight===1&&a.strideWidth===1&&(a.padInfo.type==="SAME"||a.padInfo.type==="VALID"))return this.conv2dByMatMul(i,r,a,s,o,l);if(x.env().getBool("WEBGL_CONV_IM2COL")&&i.shape[0]===1)return this.conv2dWithIm2Row(i,r,a,s,o,l);var u=s!=null,c=l!=null,h=o?hl(o,!1):null,d=new US(a,u,h,c),p=[i,r];return s&&p.push(s),l&&p.push(l),this.compileAndRun(d,p)},t.prototype.conv2d=function(e,i,r){if(r.filterHeight===1&&r.filterWidth===1&&r.dilationHeight===1&&r.dilationWidth===1&&r.strideHeight===1&&r.strideWidth===1&&(r.padInfo.type==="SAME"||r.padInfo.type==="VALID"))return this.conv2dByMatMul(e,i,r);if(x.env().getBool("WEBGL_CONV_IM2COL")&&e.shape[0]===1)return this.conv2dWithIm2Row(e,i,r);var a=new US(r);return this.compileAndRun(a,[e,i])},t.prototype.conv2dDerInput=function(e,i,r){var a=new t9(r);return this.compileAndRun(a,[e,i])},t.prototype.conv2dDerFilter=function(e,i,r){var a=new e9(r);return this.compileAndRun(a,[e,i])},t.prototype.fusedDepthwiseConv2D=function(e){var i=e.input,r=e.filter,a=e.convInfo,s=e.bias,o=e.activation,l=e.preluActivationWeights,u=x.env().getBool("WEBGL_PACK_DEPTHWISECONV")&&a.strideWidth<=2&&a.outChannels/a.inChannels===1,c=o?hl(o,u):null,h=[i,r],d=s!=null,p=l!=null;d&&h.push(s),p&&h.push(l);var f;return u?(f=new zS(a,d,c,p),this.compileAndRun(f,h)):(f=new BS(a,d,c,p),this.compileAndRun(f,h))},t.prototype.depthwiseConv2D=function(e,i,r){var a;return x.env().getBool("WEBGL_PACK_DEPTHWISECONV")&&r.strideWidth<=2&&r.outChannels/r.inChannels===1?(a=new zS(r),this.compileAndRun(a,[e,i])):(a=new BS(r),this.compileAndRun(a,[e,i]))},t.prototype.depthwiseConv2DDerInput=function(e,i,r){var a=new a9(r);return this.compileAndRun(a,[e,i])},t.prototype.depthwiseConv2DDerFilter=function(e,i,r){var a=new r9(r);return this.compileAndRun(a,[e,i])},t.prototype.conv3d=function(e,i,r){var a=new s9(r);return this.compileAndRun(a,[e,i])},t.prototype.conv3dDerInput=function(e,i,r){var a=new i9(r);return this.compileAndRun(a,[e,i])},t.prototype.conv3dDerFilter=function(e,i,r){var a=new n9(r);return this.compileAndRun(a,[e,i])},t.prototype.cast=function(e,i){return x.backend_util.castTensor(e,i,this)},t.prototype.unstack=function(e,i){for(var r=e.shape[i],a=new Array(e.rank-1),s=0,o=0;o<e.rank;o++)o!==i&&(a[s++]=e.shape[o]);var l=new Array(e.rank).fill(0),u=e.shape.slice();u[i]=1;for(var c=new Array(r),o=0;o<c.length;o++)l[i]=o,c[o]=this.slice(e,l,u).reshape(a);return c},t.prototype.avgPool3d=function(e,i){var r=new Lp(i,"avg",!1);return this.compileAndRun(r,[e],"float32")},t.prototype.avgPool3dBackprop=function(e,i,r){var a=new w5(r);return this.compileAndRun(a,[e],i.dtype)},t.prototype.maxPool3d=function(e,i){var r=new Lp(i,"max",!1);return this.compileAndRun(r,[e],"float32")},t.prototype.maxPool3dBackprop=function(e,i,r,a){var s=!0,o=new Lp(a,"max",s),l=this.compileAndRun(o,[i]),u=new O9(a),c=this.compileAndRun(u,[e,l],i.dtype);return l.dispose(),c},t.prototype.resizeBilinear=function(e,i,r,a){var s=x.env().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new V9(e.shape,i,r,a):new H9(e.shape,i,r,a);return this.compileAndRun(s,[e],"float32")},t.prototype.resizeBilinearBackprop=function(e,i,r){var a=new M9(e,i,r);return this.compileAndRun(a,[e])},t.prototype.resizeNearestNeighbor=function(e,i,r,a){var s=new G9(e.shape,i,r,a);return this.compileAndRun(s,[e])},t.prototype.resizeNearestNeighborBackprop=function(e,i,r){var a=new q9(e,i,r);return this.compileAndRun(a,[e])},t.prototype.multinomial=function(e,i,r,a){var s=i?e:x.softmax(e),o=s.shape[0],l=s.shape[1],u=new E9(o,l,r),c=u.getCustomSetupFunc(a);return this.compileAndRun(u,[s],"int32",c)},t.prototype.oneHot=function(e,i,r,a){var s=new D9(e.size,i,r,a);return this.compileAndRun(s,[e])},t.prototype.diag=function(e){var i=new h9(e.size);return this.compileAndRun(i,[e])},t.prototype.cropAndResize=function(e,i,r,a,s,o){var l=new o9(e.shape,i.shape,a,s,o);return this.compileAndRun(l,[e,i,r],"float32")},t.prototype.depthToSpace=function(e,i,r){x.util.assert(i>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+i});var a=e.shape[0],s=r==="NHWC"?e.shape[1]:e.shape[2],o=r==="NHWC"?e.shape[2]:e.shape[3],l=r==="NHWC"?e.shape[3]:e.shape[1],u=s*i,c=o*i,h=l/(i*i),d=r==="NHWC"?[a,u,c,h]:[a,h,u,c],p=new c9(d,i,r);return this.compileAndRun(p,[e])},t.prototype.split=function(e,i,r){return U6(e,i,r)},t.prototype.scatterND=function(e,i,r){var a=x.backend_util.calculateShapes(i,e,r),s=a.sliceRank,o=a.numUpdates,l=a.sliceSize,u=a.strides,c=a.outputSize,h=[c/l,l],d=e.reshape([o,s]),p=i.reshape([o,l]);if(c===0)return x.backend_util.reshapeTensor(x.tensor([]),r);var f=x.scalar(0),m=new cL(o,s,d.rank,p.rank,u,h),g=this.compileAndRun(m,[p,d,f]);return g.reshape(r)},t.prototype.sparseToDense=function(e,i,r,a){var s=x.backend_util.calculateShapes(i,e,r),o=s.sliceRank,l=s.numUpdates,u=s.strides,c=s.outputSize,h=!1,d=new cL(l,o,e.rank,i.rank,u,[c,1],h),p=this.compileAndRun(d,[i,e,a]);return p.reshape(r)},t.prototype.fft=function(e){var i=!1;return this.fftImpl(e,i)},t.prototype.ifft=function(e){var i=!0;return this.fftImpl(e,i)},t.prototype.fftImpl=function(e,i){var r=this.texData.get(e.dataId),a=new VS(HS.REAL,e.shape,i),s=new VS(HS.IMAG,e.shape,i),o=[this.makeComplexComponentTensorInfo(e,r.complexTensors.real),this.makeComplexComponentTensorInfo(e,r.complexTensors.imag)],l=this.compileAndRun(a,o),u=this.compileAndRun(s,o),c=this.complex(l,u).as2D(e.shape[0],e.shape[1]);return l.dispose(),u.dispose(),c},t.prototype.gatherND=function(e,i){var r=i.shape,a=r[r.length-1],s=x.backend_util.prepareAndValidate(e,i),o=s[0],l=s[1],u=s[2],c=s[3],h=i.reshape([l,a]),d=e.reshape([e.size/u,u]),p=new b9(a,c,[l,u]),f=this.compileAndRun(p,[d,h]);return f.reshape(o)},t.prototype.fill=function(e,i,r){if(r=r||x.util.inferDtype(i),r==="string"){var a=x.util.getArrayFromDType(r,x.util.sizeFromShape(e));return a.fill(i),x.engine().makeTensor(a,e,r,this)}else{var s=new g9(e,i),o=s.getCustomSetupFunc(i);return this.compileAndRun(s,[],r,o)}},t.prototype.onesLike=function(e){if(e.dtype==="string")throw new Error("onesLike is not supported under string dtype");return this.fill(e.shape,1,e.dtype)},t.prototype.zerosLike=function(e){return this.fill(e.shape,e.dtype==="string"?"":0,e.dtype)},t.prototype.linspace=function(e,i,r){return x.backend_util.linspaceImpl(e,i,r)},t.prototype.makeTensorInfo=function(e,i,r){var a=this.write(r,e,i);return this.texData.get(a).usage=null,{dataId:a,shape:e,dtype:i}},t.prototype.makeOutput=function(e,i,r){var a=this.makeTensorInfo(e,i,r).dataId;return x.engine().makeTensorFromDataId(a,e,i,this)},t.prototype.unpackTensor=function(e){var i=new W6(e.shape);return this.runWebGLProgram(i,[e],e.dtype)},t.prototype.packTensor=function(e){var i=new U9(e.shape),r=!0;return this.runWebGLProgram(i,[e],e.dtype,null,r)},t.prototype.packedReshape=function(e,i){var r=[Lr(e.shape)].concat(Ir(e.shape)),a={dtype:e.dtype,shape:r,dataId:e.dataId},s=[Lr(i)].concat(Ir(i)),o=new uL(s,r),l=!0,u=this.runWebGLProgram(o,[a],e.dtype,null,l);return{dataId:u.dataId,shape:i,dtype:u.dtype}},t.prototype.decode=function(e){var i=this.texData.get(e),r=i.isPacked,a=i.shape,s=i.dtype,o=il(a),l;r?l=new u9(o):l=new l9(o);var u=!0,c=this.runWebGLProgram(l,[{shape:o,dtype:s,dataId:e}],s,null,u);return{dtype:s,shape:a,dataId:c.dataId}},t.prototype.runWebGLProgram=function(e,i,r,a,s){var o=this;s===void 0&&(s=!1);var l=this.makeTensorInfo(e.outputShape,r),u=this.texData.get(l.dataId);if(e.packedOutput&&(u.isPacked=!0),e.outPackingScheme===vs.DENSE){var c=bs(e.outputShape);u.texShape=c.map(function(w){return w*2})}if(e.outTexUsage!=null&&(u.usage=e.outTexUsage),x.util.sizeFromShape(l.shape)===0)return u.values=x.util.getTypedArrayFromDType(l.dtype,0),l;var h=[],d=i.map(function(w){if(w.dtype==="complex64")throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var S=o.texData.get(w.dataId);if(S.texture==null){if(!e.packedInputs&&x.util.sizeFromShape(w.shape)<=x.env().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:w.shape,texData:null,isUniform:!0,uniformValues:S.values};e.packedInputs&&(S.isPacked=!0,S.shape=w.shape)}else if(!!S.isPacked!==!!e.packedInputs)w=S.isPacked?o.unpackTensor(w):o.packTensor(w),h.push(w),S=o.texData.get(w.dataId);else if(S.isPacked&&!Ls(S.shape,w.shape)){var L=w,N=w.shape;w.shape=S.shape,w=o.packedReshape(w,N),h.push(w),S=o.texData.get(w.dataId),L.shape=N}return o.uploadToGPU(w.dataId),{shape:w.shape,texData:S,isUniform:!1}});this.uploadToGPU(l.dataId);var p={shape:l.shape,texData:u,isUniform:!1},f=A9(e,d,p),m=this.getAndSaveBinary(f,function(){return L9(o.gpgpu,e,d,p)}),g=this.activeTimers!=null,v;if(g&&(v=this.startTimer()),I9(this.gpgpu,m,d,p,a),h.forEach(function(w){return o.disposeIntermediateTensorInfo(w)}),g&&(v=this.endTimer(v),this.activeTimers.push({name:e.constructor.name,query:this.getQueryTime(v)})),!x.env().getBool("WEBGL_LAZILY_UNPACK")&&u.isPacked&&s===!1){var b=this.unpackTensor(l);return this.disposeIntermediateTensorInfo(l),b}return l},t.prototype.compileAndRun=function(e,i,r,a,s){s===void 0&&(s=!1),r=r||i[0].dtype;var o=this.runWebGLProgram(e,i,r,a,s);return x.engine().makeTensorFromDataId(o.dataId,o.shape,o.dtype)},t.prototype.getAndSaveBinary=function(e,i){return e in this.binaryCache||(this.binaryCache[e]=i()),this.binaryCache[e]},t.prototype.getTextureManager=function(){return this.textureManager},t.prototype.dispose=function(){var e=this;if(this.disposed)return;if(!x.env().getBool("IS_TEST")){var i=Object.keys(this.binaryCache);i.forEach(function(r){e.gpgpu.deleteProgram(e.binaryCache[r].webGLProgram),delete e.binaryCache[r]})}this.textureManager.dispose(),this.canvas!=null&&typeof HTMLCanvasElement!="undefined"&&this.canvas instanceof HTMLCanvasElement?this.canvas.remove():this.canvas=null,this.gpgpuCreatedLocally&&(this.gpgpu.program=null,this.gpgpu.dispose()),this.disposed=!0},t.prototype.floatPrecision=function(){var e=this;return this.floatPrecisionValue==null&&(this.floatPrecisionValue=x.tidy(function(){if(!x.env().get("WEBGL_RENDER_FLOAT32_ENABLED")){var i=x.env().getBool("DEBUG");x.env().set("DEBUG",!1);var r=e.abs(x.scalar(1e-8)).dataSync()[0];if(x.env().set("DEBUG",i),r>0)return 32}return 16})),this.floatPrecisionValue},t.prototype.epsilon=function(){return this.floatPrecision()===32?_6:M6},t.prototype.uploadToGPU=function(e){var i,r=this.texData.get(e),a=r.shape,s=r.dtype,o=r.values,l=r.texture,u=r.usage,c=r.isPacked;if(l!=null)return;var h=this.activeTimers!=null,d;h&&(d=x.util.now());var p=r.texShape;if(p==null&&(p=vS(a,c),r.texShape=p),o!=null){var f=il(a),m=void 0,g=p[1],v=p[0],b=o instanceof Uint8Array;c?(i=fa(p[0],p[1]),g=i[0],v=i[1],m=new m9(f,[v,g],b)):m=new f9(f,[v,g],b);var w=this.makeTensorInfo([v,g],s);b?this.texData.get(w.dataId).usage=on.PIXELS:this.texData.get(w.dataId).usage=on.UPLOAD,this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(w.dataId),g,v,o);var S=!0,L=this.runWebGLProgram(m,[w],s,null,S),N=this.texData.get(L.dataId);r.texture=N.texture,r.texShape=N.texShape,r.isPacked=N.isPacked,r.usage=N.usage,this.disposeIntermediateTensorInfo(w),this.texData.delete(L.dataId),r.values=null,h&&(this.uploadWaitMs+=x.util.now()-d)}else{var C=this.acquireTexture(p,u,s,c);r.texture=C}},t.prototype.convertAndCacheOnCPU=function(e,i){var r=this.texData.get(e),a=r.dtype;return this.releaseGPUData(e),i!=null&&(r.values=Y6(i,a)),r.values},t.prototype.acquireTexture=function(e,i,r,a){if(this.numBytesInGPU+=this.computeBytes(e,r),!this.warnedAboutMemory&&this.numBytesInGPU>this.numMBBeforeWarning*1024*1024){var s=(this.numBytesInGPU/1024/1024).toFixed(2);this.warnedAboutMemory=!0,console.warn("High memory usage in GPU: "+s+" MB, most likely due to a memory leak")}return this.textureManager.acquireTexture(e,i,a)},t.prototype.computeBytes=function(e,i){return e[0]*e[1]*x.util.bytesPerElement(i)},t.prototype.tryRunOnCpuOrThrow=function(e,i){if(this.shouldExecuteOnCPU(e))try{return i()}catch(r){if(x.env().getBool("IS_TEST"))throw new Error("CPU forwarding failed")}return null},t}(x.KernelBackend);function Y6(n,t){if(t==="float32"||t==="complex64")return n;if(t==="int32"||t==="bool"){for(var e=t==="int32"?new Int32Array(n.length):new Uint8Array(n.length),i=0;i<e.length;++i)e[i]=Math.round(n[i]);return e}else throw new Error("Unknown dtype "+t)}var j6="2.6.0";function RL(){x.env().set("WEBGL_FORCE_F16_TEXTURES",!0)}x.device_util.isBrowser()&&x.registerBackend("webgl",function(){return new CL},2);var K6={forceHalfFloat:RL},OL="if (isnan(x)) return x;",$6=`
|
|
if (isnan(a)) return a;
|
|
if (isnan(b)) return b;
|
|
`,X6=`
|
|
result.r = isNaN.r > 0. ? NAN : result.r;
|
|
result.g = isNaN.g > 0. ? NAN : result.g;
|
|
result.b = isNaN.b > 0. ? NAN : result.b;
|
|
result.a = isNaN.a > 0. ? NAN : result.a;
|
|
`;function dl(n){return function(t){var e=t.inputs,i=t.backend,r=e.x,a=i,s=new Re(r.shape,n);return a.runWebGLProgram(s,[r],r.dtype)}}function Ap(n,t,e,i){return function(r){var a=r.inputs,s=r.backend,o=a,l=o.a,u=o.b,c=s,h=x.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ui(t,l.shape,u.shape,!!e):new St(n,l.shape,u.shape),d=i||l.dtype,p=c.runWebGLProgram(h,[l,u],d);return p}}var J6=$6+`
|
|
return atan(a, b);
|
|
`,Z6=`
|
|
vec4 result = atan(a, b);
|
|
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
|
|
`+X6+`
|
|
return result;
|
|
`,Q6=Ap(J6,Z6),e8={kernelName:x.Atan2,backendName:"webgl",kernelFunc:Q6};function Tp(n){var t=n.inputs,e=n.backend,i=t.x;return e.incRef(i.dataId),{dataId:i.dataId,shape:i.shape,dtype:i.dtype}}var t8={kernelName:x.Identity,backendName:"webgl",kernelFunc:Tp};function n8(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x;ma(r,"avgPool");var a=i.filterSize,s=i.strides,o=i.pad,l=i.dimRoundingMode,u=1;x.util.assert(x.backend_util.eitherStridesOrDilationsAreOne(s,u),function(){return"Error in avgPool: Either strides or dilations must be 1. "+("Got strides "+s+" and dilations '"+u+"'")});var c=x.backend_util.computePool2DInfo(r.shape,a,s,u,o,l);if(c.filterWidth===1&&c.filterHeight===1&&x.util.arraysEqual(c.inShape,c.outShape))return Tp({inputs:{x:r},backend:e});var h=new As(c,"avg",!1);return e.runWebGLProgram(h,[r],"float32")}var i8={kernelName:x.AvgPool,backendName:"webgl",kernelFunc:n8};function r8(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.dy,a=t.input,s=a;ma([r,a],"avgPoolBackprop");var o=i.filterSize,l=i.strides,u=i.pad,c=x.backend_util.computePool2DInfo(s.shape,o,l,1,u),h=new b5(c);return e.runWebGLProgram(h,[r],s.dtype)}var a8={kernelName:x.AvgPoolBackprop,backendName:"webgl",kernelFunc:r8};var s8=function(){function n(t,e,i,r,a,s){this.outputShape=[],this.variableNames=["x","mean","variance"],x.backend_util.assertAndGetBroadcastShape(t,e),x.backend_util.assertAndGetBroadcastShape(t,i);var o="0.0";r!=null&&(x.backend_util.assertAndGetBroadcastShape(t,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");var l="1.0";a!=null&&(x.backend_util.assertAndGetBroadcastShape(t,a),this.variableNames.push("scale"),l="getScaleAtOutCoords()"),this.outputShape=t,this.userCode=`
|
|
void main() {
|
|
float x = getXAtOutCoords();
|
|
float mean = getMeanAtOutCoords();
|
|
float variance = getVarianceAtOutCoords();
|
|
float offset = `+o+`;
|
|
float scale = `+l+`;
|
|
float inv = scale * inversesqrt(variance + float(`+s+`));
|
|
setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));
|
|
}
|
|
`}return n}();var o8=function(){function n(t,e,i,r,a,s){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],x.backend_util.assertAndGetBroadcastShape(t,e),x.backend_util.assertAndGetBroadcastShape(t,i);var o="vec4(0.0)";r!=null&&(x.backend_util.assertAndGetBroadcastShape(t,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");var l="vec4(1.0)";a!=null&&(x.backend_util.assertAndGetBroadcastShape(t,a),this.variableNames.push("scale"),l="getScaleAtOutCoords()"),this.outputShape=t,this.userCode=`
|
|
void main() {
|
|
vec4 offset = `+o+`;
|
|
vec4 scale = `+l+`;
|
|
|
|
vec4 x = getXAtOutCoords();
|
|
vec4 mean = getMeanAtOutCoords();
|
|
vec4 variance = getVarianceAtOutCoords();
|
|
|
|
vec4 inv = scale * inversesqrt(variance + vec4(`+s+`));
|
|
|
|
setOutput((x - mean) * inv + offset);
|
|
}
|
|
`}return n}();var l8=function(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=t.mean,s=t.variance,o=t.offset,l=t.scale;x.util.assert(a.shape.length===s.shape.length,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),x.util.assert(o==null||a.shape.length===o.shape.length,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),x.util.assert(l==null||a.shape.length===l.shape.length,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."});var u=i.varianceEpsilon;u==null&&(u=.001);var c=[r,a,s],h=null;o!=null&&(h=o.shape,c.push(o));var d=null;l!=null&&(d=l.shape,c.push(l));var p=x.env().getBool("WEBGL_PACK_NORMALIZATION")?new o8(r.shape,a.shape,s.shape,h,d,u):new s8(r.shape,a.shape,s.shape,h,d,u),f=e.runWebGLProgram(p,c,c[0].dtype);return f},u8={kernelName:x.FusedBatchNorm,backendName:"webgl",kernelFunc:l8};var c8=OL+`
|
|
return cos(x);
|
|
`,h8=dl(c8),d8={kernelName:x.Cos,backendName:"webgl",kernelFunc:h8};var p8=`
|
|
if (a == b) {
|
|
return 1.0;
|
|
};
|
|
return a / b;`,f8=`
|
|
// vec4 one = vec4(equal(a, b));
|
|
// return one + (vec4(1.0) - one) * a / b;
|
|
vec4 result = a / b;
|
|
if(a.x == b.x) {
|
|
result.x = 1.;
|
|
}
|
|
if(a.y == b.y) {
|
|
result.y = 1.;
|
|
}
|
|
if(a.z == b.z) {
|
|
result.z = 1.;
|
|
}
|
|
if(a.w == b.w) {
|
|
result.w = 1.;
|
|
}
|
|
|
|
return result;
|
|
`,m8=Ap(p8,f8,!0),g8={kernelName:x.Div,backendName:"webgl",kernelFunc:m8};var v8=function(){function n(t){this.variableNames=["Image"],this.outputShape=[];var e=t[2];this.outputShape=t,this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int x = coords[2];
|
|
|
|
int coordX = `+e+` - x;
|
|
float outputValue;
|
|
if(coordX >= 0 && coordX < `+e+`) {
|
|
outputValue = getImage(coords[0], coords[1], coordX, coords[3]);
|
|
} else {
|
|
outputValue = getImage(coords[0], coords[1], coords[2], coords[3]);
|
|
}
|
|
setOutput(outputValue);
|
|
}
|
|
`}return n}();var y8={kernelName:x.FlipLeftRight,backendName:"webgl",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=t.image,r=e,a=new v8(i.shape),s=r.runWebGLProgram(a,[i],i.dtype);return s}};var b8=function(){function n(t){this.variableNames=["A"];var e=Bt(),i=t[0],r=t[1];this.outputShape=t,this.userCode=`
|
|
void main() {
|
|
ivec3 coords = getOutputCoords();
|
|
int texR = coords[0];
|
|
int texC = coords[1];
|
|
int depth = coords[2];
|
|
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(`+r+".0, "+i+`.0);
|
|
|
|
vec4 values = `+e.texture2D+`(A, uv);
|
|
float value;
|
|
if (depth == 0) {
|
|
value = values.r;
|
|
} else if (depth == 1) {
|
|
value = values.g;
|
|
} else if (depth == 2) {
|
|
value = values.b;
|
|
} else if (depth == 3) {
|
|
value = values.a;
|
|
}
|
|
|
|
setOutput(floor(value * 255.0 + 0.5));
|
|
}
|
|
`}return n}();var w8=function(){function n(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var e=Bt(),i=t[0],r=t[1];this.outputShape=t,this.userCode=`
|
|
void main() {
|
|
ivec3 coords = getOutputCoords();
|
|
int texR = coords[0];
|
|
int texC = coords[1];
|
|
int depth = coords[2];
|
|
|
|
vec4 result = vec4(0.);
|
|
|
|
for(int row=0; row<=1; row++) {
|
|
for(int col=0; col<=1; col++) {
|
|
texC = coords[1] + row;
|
|
depth = coords[2] + col;
|
|
|
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
vec2(`+r+".0, "+i+`.0);
|
|
vec4 values = `+e.texture2D+`(A, uv);
|
|
float value;
|
|
if (depth == 0) {
|
|
value = values.r;
|
|
} else if (depth == 1) {
|
|
value = values.g;
|
|
} else if (depth == 2) {
|
|
value = values.b;
|
|
} else if (depth == 3) {
|
|
value = values.a;
|
|
}
|
|
|
|
result[row * 2 + col] = floor(value * 255.0 + 0.5);
|
|
}
|
|
}
|
|
|
|
`+e.output+` = result;
|
|
}
|
|
`}return n}();var L8={kernelName:x.FromPixels,backendName:"webgl",kernelFunc:S8},Sa;function S8(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.pixels,a=i.numChannels,s=typeof HTMLVideoElement!="undefined"&&r instanceof HTMLVideoElement,o=typeof HTMLImageElement!="undefined"&&r instanceof HTMLImageElement,l=s?[r.videoWidth,r.videoHeight]:[r.width,r.height],u=l[0],c=l[1],h=[c,u],d=[c,u,a];(o||s)&&(Sa==null&&(Sa=document.createElement("canvas").getContext("2d")),Sa.canvas.width=u,Sa.canvas.height=c,Sa.drawImage(r,0,0,u,c),r=Sa.canvas);var p=e.makeTensorInfo(h,"int32");e.texData.get(p.dataId).usage=on.PIXELS,e.gpgpu.uploadPixelDataToTexture(e.getTexture(p.dataId),r);var f=x.env().getBool("WEBGL_PACK")?new w8(d):new b8(d),m=e.runWebGLProgram(f,[p],"int32");return e.disposeData(p.dataId),m}function I8(n){for(var t=[];t.length===0||t[t.length-1].outSize!==1;){var e=t.length?t[t.length-1].outSize:n[1],i=x.backend_util.computeOptimalWindowSize(e);t.push({inSize:e,windowSize:i,outSize:Math.ceil(e/i)})}return t}function A8(n,t,e,i){for(var r=I8(n.shape),a=n,s=0;s<r.length;s++){var o=r[s],l=o.inSize,u=o.windowSize,c=o.outSize,h=new lL({windowSize:u,inSize:l,batchSize:n.shape[0],outSize:c},e),d=a;a=i.runWebGLProgram(h,[a],t),d.dataId!==n.dataId&&i.disposeData(d.dataId)}return a}function T8(n,t,e){var i=[Lr(n.shape)].concat(Ir(n.shape)),r={dtype:n.dtype,shape:i,dataId:n.dataId},a=[Lr(t)].concat(Ir(t)),s=new uL(a,i),o=!0,l=e.runWebGLProgram(s,[r],n.dtype,null,o);return{dataId:l.dataId,shape:t,dtype:l.dtype}}function Np(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x,a=i.shape,s=e,o=x.util.sizeFromShape(r.shape),l=x.util.inferFromImplicitShape(a,o),u=x.util.sizeFromShape(l);x.util.assert(o===u,function(){return"The new shape ("+l+") has "+u+" elements and the old "+("shape ("+r.shape+") has "+o+" elements. The new shape and old ")+"shape must have the same number of elements."});var c=s.texData.get(r.dataId);return c.isPacked&&!Ls(r.shape,l)&&!(c.texture!==null&&Ls(c.shape,l))?T8(r,l,s):(s.incRef(r.dataId),{dataId:r.dataId,shape:l,dtype:r.dtype})}var N8={kernelName:x.Reshape,backendName:"webgl",kernelFunc:Np};function x8(n,t,e,i){var r=x.util.sizeFromShape(t),a=x.util.sizeFromShape(n.shape),s=a/r,o=Np({inputs:{x:n},attrs:{shape:[s,r]},backend:i}),l=A8(o,n.dtype,"max",i),u=Np({inputs:{x:l},attrs:{shape:e},backend:i});return i.disposeIntermediateTensorInfo(o),i.disposeIntermediateTensorInfo(l),u}var R8=function(){function n(t,e){this.variableNames=["A"];for(var i=new Array(t.length),r=0;r<i.length;r++)i[r]=t[e[r]];this.outputShape=i,this.rank=i.length;var a=Ze(this.rank),s=C8(e);this.userCode=`
|
|
void main() {
|
|
`+a+` resRC = getOutputCoords();
|
|
setOutput(getA(`+s+`));
|
|
}
|
|
`}return n}();function C8(n){var t=n.length;if(t>6)throw Error("Transpose for rank "+t+" is not yet supported");for(var e=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],i=new Array(t),r=0;r<n.length;r++)i[n[r]]=e[r];return i.join()}var O8=function(){function n(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;for(var i=new Array(t.length),r=0;r<i.length;r++)i[r]=t[e[r]];if(this.outputShape=i,this.rank=i.length,this.rank>6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");for(var a=Ze(this.rank),s=TS("rc",this.rank),o=new Array(this.rank),r=0;r<e.length;r++)o[e[r]]=s[r];var l="vec2("+o.slice(-2).join()+")",u="++"+s[this.rank-1]+" < "+i[this.rank-1],c="getChannel(getA("+o.join()+"), "+l+")";this.userCode=`
|
|
void main() {
|
|
`+a+` rc = getOutputCoords();
|
|
vec4 result = vec4(0.);
|
|
result[0] = `+c+`;
|
|
if(`+u+`) {
|
|
result[1] = `+c+`;
|
|
}
|
|
--`+s[this.rank-1]+`;
|
|
if(++`+s[this.rank-2]+" < "+i[this.rank-2]+`) {
|
|
result[2] = `+c+`;
|
|
if(`+u+`) {
|
|
result[3] = `+c+`;
|
|
}
|
|
}
|
|
setOutput(result);
|
|
}
|
|
`}return n}();function EL(n,t,e){var i=x.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new O8(n.shape,t):new R8(n.shape,t);return e.runWebGLProgram(i,[n],n.dtype)}var E8={kernelName:x.Max,backendName:"webgl",kernelFunc:function(n){var t=n.inputs,e=n.attrs,i=n.backend,r=t.x,a=e,s=a.reductionIndices,o=a.keepDims,l=i,u=r.shape.length,c=x.util.parseAxisParam(s,r.shape),h=c,d=x.backend_util.getAxesPermutation(h,u),p=d!=null,f=l.shouldExecuteOnCPU([r]),m=r;if(p){if(f){for(var g=l.texData.get(m.dataId),v=g.values,b=new Array(u),w=0;w<b.length;w++)b[w]=r.shape[d[w]];var S=AS(v,r.shape,r.dtype,d,b);m=l.makeTensorInfo(b,r.dtype);var L=l.texData.get(m.dataId);L.values=S}else m=EL(r,d,l);h=x.backend_util.getInnerMostAxes(h.length,u)}x.backend_util.assertAxesAreInnerMostDims("max",h,u);var N=x.backend_util.computeOutAndReduceShapes(m.shape,h),C=N[0],R=N[1],D=C;o&&(D=x.backend_util.expandShapeToKeepDim(C,c));var k;if(f){var g=l.texData.get(m.dataId),v=g.values,W=NM(v,x.util.sizeFromShape(R),D,r.dtype);k=l.makeTensorInfo(D,r.dtype);var F=l.texData.get(k.dataId);F.values=W}else k=x8(m,R,D,l);return p&&l.disposeIntermediateTensorInfo(m),k}};function D8(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.x;ma(r,"maxPool");var a=i.filterSize,s=i.strides,o=i.pad,l=i.dimRoundingMode,u=1;x.util.assert(x.backend_util.eitherStridesOrDilationsAreOne(s,u),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+s+" and dilations '"+u+"'")});var c=x.backend_util.computePool2DInfo(r.shape,a,s,u,o,l);if(c.filterWidth===1&&c.filterHeight===1&&x.util.arraysEqual(c.inShape,c.outShape))return Tp({inputs:{x:r},backend:e});var h=new As(c,"max",!1);return e.runWebGLProgram(h,[r],r.dtype)}var k8={kernelName:x.MaxPool,backendName:"webgl",kernelFunc:D8};function F8(n){var t=n.inputs,e=n.backend,i=n.attrs,r=t.dy,a=t.input,s=t.output,o=a;ma([a,s],"maxPoolBackprop");var l=i.filterSize,u=i.strides,c=i.pad,h=i.dimRoundingMode,d=x.backend_util.computePool2DInfo(o.shape,l,u,1,c,h),p=!0,f=new As(d,"max",p),m=e.runWebGLProgram(f,[o],o.dtype),g=new R9(d),v=e.runWebGLProgram(g,[r,m],o.dtype);return e.disposeIntermediateTensorInfo(m),v}var W8={kernelName:x.MaxPoolBackprop,backendName:"webgl",kernelFunc:F8};function U8(n,t,e,i){var r=new As(e,"max",!1),a=i.runWebGLProgram(r,[n],"float32");r=new As(e,"max",!0,!0,t);var s=i.runWebGLProgram(r,[n],"float32");return[a,s]}var B8={kernelName:x.MaxPoolWithArgmax,backendName:"webgl",kernelFunc:function(n){var t=n.inputs,e=n.attrs,i=n.backend,r=t.x,a=e,s=a.filterSize,o=a.strides,l=a.pad,u=a.includeBatchInIndex,c=i;x.util.assert(r.shape.length===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+r.shape.length+"."});var h=[1,1];x.util.assert(x.backend_util.eitherStridesOrDilationsAreOne(o,h),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+o+" and dilations '"+h+"'")});var d=x.backend_util.computePool2DInfo(r.shape,s,o,h,l),p=U8(r,u,d,c),f=p[0],m=p[1];return[f,m]}};var z8={kernelName:x.NonMaxSuppressionV3,backendName:"webgl",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=n.attrs;x.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var r=t,a=r.boxes,s=r.scores,o=i,l=o.maxOutputSize,u=o.iouThreshold,c=o.scoreThreshold,h=e,d=h.readSync(a.dataId),p=h.readSync(s.dataId),f=l,m=u,g=c;return x.kernel_impls.nonMaxSuppressionV3Impl(d,p,f,m,g)}};var P8=x.kernel_impls.nonMaxSuppressionV4Impl,_8={kernelName:x.NonMaxSuppressionV4,backendName:"webgl",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=n.attrs;x.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var r=t,a=r.boxes,s=r.scores,o=i,l=o.maxOutputSize,u=o.iouThreshold,c=o.scoreThreshold,h=o.padToMaxOutputSize,d=e,p=d.readSync(a.dataId),f=d.readSync(s.dataId),m=P8(p,f,l,u,c,h),g=m.selectedIndices,v=m.validOutputs;return[g,v]}};var M8=x.kernel_impls.nonMaxSuppressionV5Impl,H8={kernelName:x.NonMaxSuppressionV5,backendName:"webgl",kernelFunc:function(n){var t=n.inputs,e=n.backend,i=n.attrs;x.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var r=t,a=r.boxes,s=r.scores,o=i,l=o.maxOutputSize,u=o.iouThreshold,c=o.scoreThreshold,h=o.softNmsSigma,d=e,p=d.readSync(a.dataId),f=d.readSync(s.dataId),m=l,g=u,v=c,b=h,w=M8(p,f,m,g,v,b),S=w.selectedIndices,L=w.selectedScores;return[S,L]}};var V8=function(){function n(t,e,i,r){this.variableNames=["Image"],this.outputShape=[];var a=t[1],s=t[2],o=Math.sin(e).toFixed(3),l=Math.cos(e).toFixed(3);this.outputShape=t;var u=x.backend_util.getImageCenter(r,a,s),c=u[0],h=u[1],d=c.toFixed(3),p=h.toFixed(3),f="";typeof i=="number"?f="float outputValue = "+i.toFixed(2)+";":f=`
|
|
vec3 fill = vec3(`+i.join(",")+`);
|
|
float outputValue = fill[coords[3]];`,this.userCode=`
|
|
void main() {
|
|
ivec4 coords = getOutputCoords();
|
|
int x = coords[2];
|
|
int y = coords[1];
|
|
float coordXFloat = (float(x) - `+d+") * "+l+" - (float(y) - "+p+") * "+o+`;
|
|
float coordYFloat = (float(x) - `+d+") * "+o+" + (float(y) - "+p+") * "+l+`;
|
|
int coordX = int(round(coordXFloat + `+d+`));
|
|
int coordY = int(round(coordYFloat + `+p+`));
|
|
`+f+`
|
|
if(coordX >= 0 && coordX < `+s+" && coordY >= 0 && coordY < "+a+`) {
|
|
outputValue = getImage(coords[0], coordY, coordX, coords[3]);
|
|
}
|
|
setOutput(outputValue);
|
|
}
|
|
`}return n}();var q8={kernelName:x.RotateWithOffset,backendName:"webgl",kernelFunc:function(n){var t=n.inputs,e=n.attrs,i=n.backend,r=t.image,a=e,s=a.radians,o=a.fillValue,l=a.center,u=i,c=new V8(r.shape,s,o,l),h=u.runWebGLProgram(c,[r],r.dtype);return h}};var G8=OL+`
|
|
return sin(x);
|
|
`,Y8=dl(G8),j8={kernelName:x.Sin,backendName:"webgl",kernelFunc:Y8};var K8="return x * x;",$8=dl(K8),X8={kernelName:x.Square,backendName:"webgl",kernelFunc:$8};var DL="return (a - b) * (a - b);",J8=Ap(DL,DL),Z8={kernelName:x.SquaredDifference,backendName:"webgl",kernelFunc:J8};var Q8="return tan(x);",e7=dl(Q8),t7={kernelName:x.Tan,backendName:"webgl",kernelFunc:e7};var n7={kernelName:x.Transpose,backendName:"webgl",kernelFunc:function(n){for(var t=n.inputs,e=n.attrs,i=n.backend,r=t.x,a=e.perm,s=i,o=r.shape.length,l=new Array(o),u=0;u<l.length;u++)l[u]=r.shape[a[u]];var c;if(s.shouldExecuteOnCPU([r])){var h=s.texData.get(r.dataId),d=h.values,p=AS(d,r.shape,r.dtype,a,l);c=s.makeTensorInfo(l,r.dtype);var f=s.texData.get(c.dataId);f.values=p}else c=EL(r,a,s);return c}};function i7(n){var t=n.inputs,e=n.attrs,i=n.backend,r=e.axis,a=t.x;ma(a,"unique"),console.warn("WARNING: ","UI might be locked temporarily as data is being downloaded");var s=i.readSync(a.dataId),o=EM(s,r,a.shape,a.dtype),l=o.outputValues,u=o.outputShape,c=o.indices;return[i.makeTensorInfo(u,a.dtype,l),i.makeTensorInfo([c.length],"int32",c)]}var r7={kernelName:x.Unique,backendName:"webgl",kernelFunc:i7};var a7=[e8,i8,a8,u8,d8,g8,y8,L8,t8,E8,k8,W8,B8,z8,_8,H8,N8,q8,j8,X8,Z8,t7,n7,r7];for(var xp=0,kL=a7;xp<kL.length;xp++){var s7=kL[xp];x.registerKernel(s7)}qn.GPGPUContext=sL;qn.MathBackendWebGL=CL;qn.forceHalfFloat=RL;qn.gpgpu_util=w9;qn.setWebGLContext=Q0;qn.version_webgl=j6;qn.webgl=K6;qn.webgl_util=rM});var zt=Le(Nr=>{"use strict";Object.defineProperty(Nr,"__esModule",{value:!0});var Cp=lr(),Rp=Ow(),Op=Gw(),WL=h0(),o7=Z0(),l7=FL();var u7="2.6.0";var c7={"tfjs-core":Cp.version_core,"tfjs-backend-cpu":o7.version_cpu,"tfjs-backend-webgl":l7.version_webgl,"tfjs-data":WL.version_data,"tfjs-layers":Rp.version_layers,"tfjs-converter":Op.version_converter,tfjs:u7};Object.keys(Cp).forEach(function(n){n!=="default"&&Object.defineProperty(Nr,n,{enumerable:!0,get:function(){return Cp[n]}})});Object.keys(Rp).forEach(function(n){n!=="default"&&Object.defineProperty(Nr,n,{enumerable:!0,get:function(){return Rp[n]}})});Object.keys(Op).forEach(function(n){n!=="default"&&Object.defineProperty(Nr,n,{enumerable:!0,get:function(){return Op[n]}})});Nr.data=WL;Nr.version=c7});var _L=Le(pl=>{const ke=zt(),UL=6;function h7(n){const t={strides:[n/16,n/8],anchors:[2,6]},e=[];for(let i=0;i<t.strides.length;i++){const r=t.strides[i],a=Math.floor((n+r-1)/r),s=Math.floor((n+r-1)/r),o=t.anchors[i];for(let l=0;l<a;l++){const u=r*(l+.5);for(let c=0;c<s;c++){const h=r*(c+.5);for(let d=0;d<o;d++)e.push([h,u])}}}return e}const BL=n=>{n.startEndTensor.dispose(),n.startPoint.dispose(),n.endPoint.dispose()},zL=n=>({startEndTensor:n,startPoint:ke.slice(n,[0,0],[-1,2]),endPoint:ke.slice(n,[0,2],[-1,2])}),d7=(n,t)=>{const e=ke.mul(n.startPoint,t),i=ke.mul(n.endPoint,t),r=ke.concat2d([e,i],1);return zL(r)};function p7(n,t,e){const i=ke.slice(n,[0,1],[-1,2]),r=ke.add(i,t),a=ke.slice(n,[0,3],[-1,2]),s=ke.div(a,e),o=ke.div(r,e),l=ke.div(s,2),u=ke.sub(o,l),c=ke.add(o,l),h=ke.mul(u,e),d=ke.mul(c,e),p=1;return ke.concat2d([h,d],p)}function f7(n,t){return ke.tidy(()=>{const e=n.box?n.box:n;return d7(e,t).startEndTensor.squeeze()})}class PL{constructor(n,t){this.blazeFaceModel=n,this.width=t.detector.inputSize,this.height=t.detector.inputSize,this.maxFaces=t.detector.maxFaces,this.anchorsData=h7(t.detector.inputSize),this.anchors=ke.tensor2d(this.anchorsData),this.inputSize=ke.tensor1d([this.width,this.height]),this.iouThreshold=t.detector.iouThreshold,this.scaleFaces=.8,this.scoreThreshold=t.detector.scoreThreshold}async getBoundingBoxes(n){if(!n||n.isDisposedInternal||n.shape.length!==4||n.shape[1]<1||n.shape[2]<1)return null;const[t,e,i]=ke.tidy(()=>{const l=n.resizeBilinear([this.width,this.height]),u=ke.mul(ke.sub(l.div(255),.5),2),c=this.blazeFaceModel.predict(u);let h;if(Array.isArray(c)){const m=c.sort((w,S)=>w.size-S.size),g=ke.concat([m[0],m[2]],2),v=ke.concat([m[1],m[3]],2),b=ke.concat([v,g],1);h=b.squeeze(0)}else h=c.squeeze();const d=p7(h,this.anchors,this.inputSize),p=ke.slice(h,[0,0],[-1,1]),f=ke.sigmoid(p).squeeze();return[h,d,f]}),r=await ke.image.nonMaxSuppressionAsync(e,i,this.maxFaces,this.iouThreshold,this.scoreThreshold),a=await r.array();r.dispose();let s=a.map(l=>ke.slice(e,[l,0],[1,-1]));s=await Promise.all(s.map(async l=>{const u=await l.array();return l.dispose(),u}));const o=[];for(let l=0;l<s.length;l++){const u=s[l],c=ke.tidy(()=>{const h=zL(u),d=a[l],p=this.anchorsData[d],f=ke.slice(t,[d,UL-1],[1,-1]).squeeze().reshape([UL,-1]),m=ke.slice(i,[d],[1]);return{box:h,landmarks:f,probability:m,anchor:p}});o.push(c)}return e.dispose(),i.dispose(),t.dispose(),{boxes:o,scaleFactor:[n.shape[2]/this.width,n.shape[1]/this.height]}}async estimateFaces(n){const t=ke.tidy(()=>(n instanceof ke.Tensor||(n=ke.browser.fromPixels(n)),n.toFloat().expandDims(0))),{boxes:e,scaleFactor:i}=await this.getBoundingBoxes(t);return t.dispose(),Promise.all(e.map(async r=>{const a=f7(r,i),[s,o,l]=await Promise.all([r.landmarks,a,r.probability].map(async f=>f.array())),u=r.anchor,[c,h]=i,d=s.map(f=>[(f[0]+u[0])*c,(f[1]+u[1])*h]),p={topLeft:o.slice(0,2),bottomRight:o.slice(2),landmarks:d,probability:l};return BL(r.box),r.landmarks.dispose(),r.probability.dispose(),a.dispose(),p}))}}async function m7(n){const t=await ke.loadGraphModel(n.detector.modelPath,{fromTFHub:n.detector.modelPath.includes("tfhub.dev")}),e=new PL(t,n);return e}pl.load=m7;pl.BlazeFaceModel=PL;pl.disposeBox=BL});var Dp=Le(Ep=>{Ep.MESH_ANNOTATIONS={silhouette:[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109],lipsUpperOuter:[61,185,40,39,37,0,267,269,270,409,291],lipsLowerOuter:[146,91,181,84,17,314,405,321,375,291],lipsUpperInner:[78,191,80,81,82,13,312,311,310,415,308],lipsLowerInner:[78,95,88,178,87,14,317,402,318,324,308],rightEyeUpper0:[246,161,160,159,158,157,173],rightEyeLower0:[33,7,163,144,145,153,154,155,133],rightEyeUpper1:[247,30,29,27,28,56,190],rightEyeLower1:[130,25,110,24,23,22,26,112,243],rightEyeUpper2:[113,225,224,223,222,221,189],rightEyeLower2:[226,31,228,229,230,231,232,233,244],rightEyeLower3:[143,111,117,118,119,120,121,128,245],rightEyebrowUpper:[156,70,63,105,66,107,55,193],rightEyebrowLower:[35,124,46,53,52,65],rightEyeIris:[473,474,475,476,477],leftEyeUpper0:[466,388,387,386,385,384,398],leftEyeLower0:[263,249,390,373,374,380,381,382,362],leftEyeUpper1:[467,260,259,257,258,286,414],leftEyeLower1:[359,255,339,254,253,252,256,341,463],leftEyeUpper2:[342,445,444,443,442,441,413],leftEyeLower2:[446,261,448,449,450,451,452,453,464],leftEyeLower3:[372,340,346,347,348,349,350,357,465],leftEyebrowUpper:[383,300,293,334,296,336,285,417],leftEyebrowLower:[265,353,276,283,282,295],leftEyeIris:[468,469,470,471,472],midwayBetweenEyes:[168],noseTip:[1],noseBottom:[2],noseRightCorner:[98],noseLeftCorner:[327],rightCheek:[205],leftCheek:[425]};Ep.MESH_TO_IRIS_INDICES_MAP=[{key:"EyeUpper0",indices:[9,10,11,12,13,14,15]},{key:"EyeUpper1",indices:[25,26,27,28,29,30,31]},{key:"EyeUpper2",indices:[41,42,43,44,45,46,47]},{key:"EyeLower0",indices:[0,1,2,3,4,5,6,7,8]},{key:"EyeLower1",indices:[16,17,18,19,20,21,22,23,24]},{key:"EyeLower2",indices:[32,33,34,35,36,37,38,39,40]},{key:"EyeLower3",indices:[54,55,56,57,58,59,60,61,62]},{key:"EyebrowUpper",indices:[63,64,65,66,67,68,69,70]},{key:"EyebrowLower",indices:[48,49,50,51,52,53]}]});var ML=Le(xr=>{const g7=zt();function v7(n,t){const e=[n.startPoint[0]*t[0],n.startPoint[1]*t[1]],i=[n.endPoint[0]*t[0],n.endPoint[1]*t[1]];return{startPoint:e,endPoint:i}}xr.scaleBoxCoordinates=v7;function kp(n){return[Math.abs(n.endPoint[0]-n.startPoint[0]),Math.abs(n.endPoint[1]-n.startPoint[1])]}xr.getBoxSize=kp;function Fp(n){return[n.startPoint[0]+(n.endPoint[0]-n.startPoint[0])/2,n.startPoint[1]+(n.endPoint[1]-n.startPoint[1])/2]}xr.getBoxCenter=Fp;function y7(n,t,e){const i=t.shape[1],r=t.shape[2],a=[[n.startPoint[1]/i,n.startPoint[0]/r,n.endPoint[1]/i,n.endPoint[0]/r]];return g7.image.cropAndResize(t,a,[0],e)}xr.cutBoxFromImageAndResize=y7;function b7(n,t=1.5){const e=Fp(n),i=kp(n),r=[t*i[0]/2,t*i[1]/2],a=[e[0]-r[0],e[1]-r[1]],s=[e[0]+r[0],e[1]+r[1]];return{startPoint:a,endPoint:s,landmarks:n.landmarks}}xr.enlargeBox=b7;function w7(n){const t=Fp(n),e=kp(n),i=Math.max(...e),r=i/2,a=[t[0]-r,t[1]-r],s=[t[0]+r,t[1]+r];return{startPoint:a,endPoint:s,landmarks:n.landmarks}}xr.squarifyBox=w7});var YL=Le(Rn=>{Rn.IDENTITY_MATRIX=[[1,0,0],[0,1,0],[0,0,1]];function HL(n){return n-2*Math.PI*Math.floor((n+Math.PI)/(2*Math.PI))}Rn.normalizeRadians=HL;function S7(n,t){const e=Math.PI/2-Math.atan2(-(t[1]-n[1]),t[0]-n[0]);return HL(e)}Rn.computeRotation=S7;function L7(n){return n*180/Math.PI}Rn.radToDegrees=L7;function VL(n,t){return[[1,0,n],[0,1,t],[0,0,1]]}function La(n,t){let e=0;for(let i=0;i<n.length;i++)e+=n[i]*t[i];return e}Rn.dot=La;function qL(n,t){const e=[];for(let i=0;i<n.length;i++)e.push(n[i][t]);return e}Rn.getColumnFrom2DArr=qL;function GL(n,t){const e=[],i=n.length;for(let r=0;r<i;r++){e.push([]);for(let a=0;a<i;a++)e[r].push(La(n[r],qL(t,a)))}return e}function I7(n,t){const e=Math.cos(n),i=Math.sin(n),r=[[e,-i,0],[i,e,0],[0,0,1]],a=VL(t[0],t[1]),s=GL(a,r),o=VL(-t[0],-t[1]);return GL(s,o)}Rn.buildRotationMatrix=I7;function A7(n){const t=[[n[0][0],n[1][0]],[n[0][1],n[1][1]]],e=[n[0][2],n[1][2]],i=[-La(t[0],e),-La(t[1],e)];return[t[0].concat(i[0]),t[1].concat(i[1]),[0,0,1]]}Rn.invertTransformMatrix=A7;function T7(n,t){return[La(n,t[0]),La(n,t[1])]}Rn.rotatePoint=T7;function N7(n,t){return Math.sqrt((n[0]-t[0])**2+(n[1]-t[1])**2)}Rn.xyDistanceBetweenPoints=N7});var KL=Le(jL=>{const Bi=zt(),Yn=ML(),zi=Dp(),Pi=YL(),x7=468,C7=.25,R7=13,O7=[R7,zi.MESH_ANNOTATIONS.midwayBetweenEyes[0]],E7=3,D7=2,k7=[E7,D7],Wp=zi.MESH_ANNOTATIONS.leftEyeLower0,Up=[Wp[0],Wp[Wp.length-1]],Bp=zi.MESH_ANNOTATIONS.rightEyeLower0,zp=[Bp[0],Bp[Bp.length-1]],F7=3,W7=4,U7=71,Pp=76;function fl(n,t,e,i){for(let r=0;r<zi.MESH_TO_IRIS_INDICES_MAP.length;r++){const{key:a,indices:s}=zi.MESH_TO_IRIS_INDICES_MAP[r],o=zi.MESH_ANNOTATIONS[`${e}${a}`],l=i==null;if(l||i.includes(a))for(let u=0;u<s.length;u++){const c=s[u];n[o[u]]=[t[c][0],t[c][1],(t[c][2]+n[o[u]][2])/2]}}}class B7{constructor(n,t,e,i){this.regionsOfInterest=[],this.runsWithoutFaceDetector=0,this.boundingBoxDetector=n,this.meshDetector=t,this.irisModel=e,this.meshWidth=i.mesh.inputSize,this.meshHeight=i.mesh.inputSize,this.irisSize=i.iris.inputSize,this.irisEnlarge=i.iris.enlargeFactor}transformRawCoords(n,t,e,i){const r=Yn.getBoxSize({startPoint:t.startPoint,endPoint:t.endPoint}),a=[r[0]/this.meshWidth,r[1]/this.meshHeight],s=n.map(d=>[a[0]*(d[0]-this.meshWidth/2),a[1]*(d[1]-this.meshHeight/2),d[2]]),o=Pi.buildRotationMatrix(e,[0,0]),l=s.map(d=>[...Pi.rotatePoint(d,o),d[2]]),u=Pi.invertTransformMatrix(i),c=[...Yn.getBoxCenter({startPoint:t.startPoint,endPoint:t.endPoint}),1],h=[Pi.dot(c,u[0]),Pi.dot(c,u[1])];return l.map(d=>[d[0]+h[0],d[1]+h[1],d[2]])}getLeftToRightEyeDepthDifference(n){const t=n[Up[0]][2],e=n[zp[0]][2];return t-e}getEyeBox(n,t,e,i,r=!1){const a=Yn.squarifyBox(Yn.enlargeBox(this.calculateLandmarksBoundingBox([n[e],n[i]]),this.irisEnlarge)),s=Yn.getBoxSize(a);let o=Bi.image.cropAndResize(t,[[a.startPoint[1]/this.meshHeight,a.startPoint[0]/this.meshWidth,a.endPoint[1]/this.meshHeight,a.endPoint[0]/this.meshWidth]],[0],[this.irisSize,this.irisSize]);return r&&(o=Bi.image.flipLeftRight(o)),{box:a,boxSize:s,crop:o}}getEyeCoords(n,t,e,i=!1){const r=[];for(let a=0;a<Pp;a++){const s=n[a*3],o=n[a*3+1],l=n[a*3+2];r.push([(i?1-s/this.irisSize:s/this.irisSize)*e[0]+t.startPoint[0],o/this.irisSize*e[1]+t.startPoint[1],l])}return{rawCoords:r,iris:r.slice(U7)}}getAdjustedIrisCoords(n,t,e){const i=n[zi.MESH_ANNOTATIONS[`${e}EyeUpper0`][F7]][2],r=n[zi.MESH_ANNOTATIONS[`${e}EyeLower0`][W7]][2],a=(i+r)/2;return t.map((s,o)=>{let l=a;return o===2?l=i:o===4&&(l=r),[s[0],s[1],l]})}async predict(n,t){if(this.skipFrames=t.detector.skipFrames,this.maxFaces=t.detector.maxFaces,this.shouldUpdateRegionsOfInterest()){const{boxes:i,scaleFactor:r}=await this.boundingBoxDetector.getBoundingBoxes(n);if(i.length===0)return this.regionsOfInterest=[],null;const a=i.map(s=>{const o={startPoint:s.box.startPoint.squeeze().arraySync(),endPoint:s.box.endPoint.squeeze().arraySync()};s.box.startPoint.dispose(),s.box.endPoint.dispose();const l=Yn.scaleBoxCoordinates(o,r),u=Yn.enlargeBox(l),c=s.landmarks.arraySync();return s.landmarks.dispose(),s.probability.dispose(),{...u,landmarks:c}});this.updateRegionsOfInterest(a),this.runsWithoutFaceDetector=0}else this.runsWithoutFaceDetector++;const e=Bi.tidy(()=>this.regionsOfInterest.map((i,r)=>{let a=0;const s=i.landmarks.length>=x7;let[o,l]=O7;s===!1&&([o,l]=k7),a=Pi.computeRotation(i.landmarks[o],i.landmarks[l]);const u=Yn.getBoxCenter({startPoint:i.startPoint,endPoint:i.endPoint}),c=[u[0]/n.shape[2],u[1]/n.shape[1]];let h=n,d=Pi.IDENTITY_MATRIX;a!==0&&(h=Bi.image.rotateWithOffset(n,a,0,c),d=Pi.buildRotationMatrix(-a,u));const p={startPoint:i.startPoint,endPoint:i.endPoint},f=Yn.cutBoxFromImageAndResize(p,h,[this.meshHeight,this.meshWidth]).div(255),[,m,g]=this.meshDetector.predict(f),v=Bi.reshape(g,[-1,3]);let b=v.arraySync();if(t.iris.enabled){const{box:N,boxSize:C,crop:R}=this.getEyeBox(b,f,Up[0],Up[1],!0),{box:D,boxSize:k,crop:W}=this.getEyeBox(b,f,zp[0],zp[1]),F=this.irisModel.predict(Bi.concat([R,W])),P=F.dataSync();F.dispose();const H=P.slice(0,Pp*3),{rawCoords:_,iris:j}=this.getEyeCoords(H,N,C,!0),K=P.slice(Pp*3),{rawCoords:q,iris:G}=this.getEyeCoords(K,D,k),Z=this.getLeftToRightEyeDepthDifference(b);Math.abs(Z)<30?(fl(b,_,"left"),fl(b,q,"right")):Z<1?fl(b,_,"left",["EyeUpper0","EyeLower0"]):fl(b,q,"right",["EyeUpper0","EyeLower0"]);const X=this.getAdjustedIrisCoords(b,j,"left"),ee=this.getAdjustedIrisCoords(b,G,"right");b=b.concat(X).concat(ee)}const w=this.transformRawCoords(b,i,a,d);Bi.dispose(b);const S=Yn.enlargeBox(this.calculateLandmarksBoundingBox(w));if(t.mesh.enabled){const N=Bi.tensor2d(w);this.regionsOfInterest[r]={...S,landmarks:N.arraySync()};const C={coords:N,box:S,confidence:m.squeeze(),image:f};return C}const L={coords:null,box:S,confidence:m.squeeze(),image:f};return L}));return e}updateRegionsOfInterest(n){for(let t=0;t<n.length;t++){const e=n[t],i=this.regionsOfInterest[t];let r=0;if(i&&i.startPoint){const[a,s]=e.startPoint,[o,l]=e.endPoint,[u,c]=i.startPoint,[h,d]=i.endPoint,p=Math.max(a,u),f=Math.max(s,c),m=Math.min(o,h),g=Math.min(l,d),v=(m-p)*(g-f),b=(o-a)*(l-s),w=(h-u)*(d-s);r=v/(b+w-v)}r<C7&&(this.regionsOfInterest[t]=e)}this.regionsOfInterest=this.regionsOfInterest.slice(0,n.length)}clearRegionOfInterest(n){this.regionsOfInterest[n]!=null&&(this.regionsOfInterest=[...this.regionsOfInterest.slice(0,n),...this.regionsOfInterest.slice(n+1)])}shouldUpdateRegionsOfInterest(){const n=this.regionsOfInterest.length,t=n===0;return this.maxFaces===1||t?t:n!==this.maxFaces&&this.runsWithoutFaceDetector>=this.skipFrames}calculateLandmarksBoundingBox(n){const t=n.map(a=>a[0]),e=n.map(a=>a[1]),i=[Math.min(...t),Math.min(...e)],r=[Math.max(...t),Math.max(...e)];return{startPoint:i,endPoint:r}}}jL.Pipeline=B7});var XL=Le($L=>{$L.UV_COORDS=[[.499976992607117,.652534008026123],[.500025987625122,.547487020492554],[.499974012374878,.602371990680695],[.482113003730774,.471979022026062],[.500150978565216,.527155995368958],[.499909996986389,.498252987861633],[.499523013830185,.40106201171875],[.289712011814117,.380764007568359],[.499954998493195,.312398016452789],[.499987006187439,.269918978214264],[.500023007392883,.107050001621246],[.500023007392883,.666234016418457],[.5000159740448,.679224014282227],[.500023007392883,.692348003387451],[.499976992607117,.695277988910675],[.499976992607117,.70593398809433],[.499976992607117,.719385027885437],[.499976992607117,.737019002437592],[.499967992305756,.781370997428894],[.499816000461578,.562981009483337],[.473773002624512,.573909997940063],[.104906998574734,.254140973091125],[.365929991006851,.409575998783112],[.338757991790771,.41302502155304],[.311120003461838,.409460008144379],[.274657994508743,.389131009578705],[.393361985683441,.403706014156342],[.345234006643295,.344011008739471],[.370094001293182,.346076011657715],[.319321990013123,.347265005111694],[.297903001308441,.353591024875641],[.24779200553894,.410809993743896],[.396889001131058,.842755019664764],[.280097991228104,.375599980354309],[.106310002505779,.399955987930298],[.2099249958992,.391353011131287],[.355807989835739,.534406006336212],[.471751004457474,.65040397644043],[.474155008792877,.680191993713379],[.439785003662109,.657229006290436],[.414617002010345,.66654098033905],[.450374007225037,.680860996246338],[.428770989179611,.682690978050232],[.374971002340317,.727805018424988],[.486716985702515,.547628998756409],[.485300987958908,.527395009994507],[.257764995098114,.314490020275116],[.401223003864288,.455172002315521],[.429818987846375,.548614978790283],[.421351999044418,.533740997314453],[.276895999908447,.532056987285614],[.483370006084442,.499586999416351],[.33721199631691,.282882988452911],[.296391993761063,.293242990970612],[.169294998049736,.193813979625702],[.447580009698868,.302609980106354],[.392390012741089,.353887975215912],[.354490011930466,.696784019470215],[.067304998636246,.730105042457581],[.442739009857178,.572826027870178],[.457098007202148,.584792017936707],[.381974011659622,.694710969924927],[.392388999462128,.694203019142151],[.277076005935669,.271932005882263],[.422551989555359,.563233017921448],[.385919004678726,.281364023685455],[.383103013038635,.255840003490448],[.331431001424789,.119714021682739],[.229923993349075,.232002973556519],[.364500999450684,.189113974571228],[.229622006416321,.299540996551514],[.173287004232407,.278747975826263],[.472878992557526,.666198015213013],[.446828007698059,.668527007102966],[.422762006521225,.673889994621277],[.445307999849319,.580065965652466],[.388103008270264,.693961024284363],[.403039008378983,.706539988517761],[.403629004955292,.693953037261963],[.460041999816895,.557139039039612],[.431158006191254,.692366003990173],[.452181994915009,.692366003990173],[.475387006998062,.692366003990173],[.465828001499176,.779190003871918],[.472328990697861,.736225962638855],[.473087012767792,.717857003211975],[.473122000694275,.704625964164734],[.473033010959625,.695277988910675],[.427942007780075,.695277988910675],[.426479011774063,.703539967536926],[.423162013292313,.711845993995667],[.4183090031147,.720062971115112],[.390094995498657,.639572978019714],[.013953999616206,.560034036636353],[.499913990497589,.58014702796936],[.413199990987778,.69539999961853],[.409626007080078,.701822996139526],[.468080013990402,.601534962654114],[.422728985548019,.585985004901886],[.463079988956451,.593783974647522],[.37211999297142,.47341400384903],[.334562003612518,.496073007583618],[.411671012639999,.546965003013611],[.242175996303558,.14767599105835],[.290776997804642,.201445996761322],[.327338010072708,.256527006626129],[.399509996175766,.748921036720276],[.441727995872498,.261676013469696],[.429764986038208,.187834024429321],[.412198007106781,.108901023864746],[.288955003023148,.398952007293701],[.218936994671822,.435410976409912],[.41278201341629,.398970007896423],[.257135003805161,.355440020561218],[.427684992551804,.437960982322693],[.448339998722076,.536936044692993],[.178560003638268,.45755398273468],[.247308000922203,.457193970680237],[.286267012357712,.467674970626831],[.332827985286713,.460712015628815],[.368755996227264,.447206974029541],[.398963987827301,.432654976844788],[.476410001516342,.405806005001068],[.189241006970406,.523923993110657],[.228962004184723,.348950982093811],[.490725994110107,.562400996685028],[.404670000076294,.485132992267609],[.019469000399113,.401564002037048],[.426243007183075,.420431017875671],[.396993011236191,.548797011375427],[.266469985246658,.376977026462555],[.439121007919312,.51895797252655],[.032313998788595,.644356966018677],[.419054001569748,.387154996395111],[.462783008813858,.505746960639954],[.238978996872902,.779744982719421],[.198220998048782,.831938028335571],[.107550002634525,.540755033493042],[.183610007166862,.740257024765015],[.134409993886948,.333683013916016],[.385764002799988,.883153975009918],[.490967005491257,.579378008842468],[.382384985685349,.508572995662689],[.174399003386497,.397670984268188],[.318785011768341,.39623498916626],[.343364000320435,.400596976280212],[.396100014448166,.710216999053955],[.187885001301765,.588537991046906],[.430987000465393,.944064974784851],[.318993002176285,.898285031318665],[.266247987747192,.869701027870178],[.500023007392883,.190576016902924],[.499976992607117,.954452991485596],[.366169989109039,.398822009563446],[.393207013607025,.39553701877594],[.410373002290726,.391080021858215],[.194993004202843,.342101991176605],[.388664990663528,.362284004688263],[.365961998701096,.355970978736877],[.343364000320435,.355356991291046],[.318785011768341,.35834002494812],[.301414996385574,.363156020641327],[.058132998645306,.319076001644135],[.301414996385574,.387449026107788],[.499987989664078,.618434011936188],[.415838003158569,.624195992946625],[.445681989192963,.566076993942261],[.465844005346298,.620640993118286],[.49992299079895,.351523995399475],[.288718998432159,.819945991039276],[.335278987884521,.852819979190826],[.440512001514435,.902418971061707],[.128294005990028,.791940987110138],[.408771991729736,.373893976211548],[.455606997013092,.451801002025604],[.499877005815506,.908990025520325],[.375436991453171,.924192011356354],[.11421000212431,.615022003650665],[.448662012815475,.695277988910675],[.4480200111866,.704632043838501],[.447111994028091,.715808033943176],[.444831997156143,.730794012546539],[.430011987686157,.766808986663818],[.406787008047104,.685672998428345],[.400738000869751,.681069016456604],[.392399996519089,.677703022956848],[.367855995893478,.663918972015381],[.247923001646996,.601333022117615],[.452769994735718,.420849978923798],[.43639200925827,.359887003898621],[.416164010763168,.368713974952698],[.413385987281799,.692366003990173],[.228018000721931,.683571994304657],[.468268007040024,.352671027183533],[.411361992359161,.804327011108398],[.499989002943039,.469825029373169],[.479153990745544,.442654013633728],[.499974012374878,.439637005329132],[.432112008333206,.493588984012604],[.499886006116867,.866917014122009],[.49991300702095,.821729004383087],[.456548988819122,.819200992584229],[.344549000263214,.745438992977142],[.37890899181366,.574010014533997],[.374292999505997,.780184984207153],[.319687992334366,.570737957954407],[.357154995203018,.604269981384277],[.295284003019333,.621580958366394],[.447750002145767,.862477004528046],[.410986006259918,.508723020553589],[.31395098567009,.775308012962341],[.354128003120422,.812552988529205],[.324548006057739,.703992962837219],[.189096003770828,.646299958229065],[.279776990413666,.71465802192688],[.1338230073452,.682700991630554],[.336768001317978,.644733011722565],[.429883986711502,.466521978378296],[.455527991056442,.548622965812683],[.437114000320435,.558896005153656],[.467287987470627,.529924988746643],[.414712011814117,.335219979286194],[.37704598903656,.322777986526489],[.344107985496521,.320150971412659],[.312875986099243,.32233202457428],[.283526003360748,.333190023899078],[.241245999932289,.382785975933075],[.102986000478268,.468762993812561],[.267612010240555,.424560010433197],[.297879010438919,.433175981044769],[.333433985710144,.433878004550934],[.366427004337311,.426115989685059],[.396012008190155,.416696012020111],[.420121014118195,.41022801399231],[.007561000064015,.480777025222778],[.432949006557465,.569517970085144],[.458638995885849,.479089021682739],[.473466008901596,.545744001865387],[.476087987422943,.563830018043518],[.468472003936768,.555056989192963],[.433990985155106,.582361996173859],[.483518004417419,.562983989715576],[.482482999563217,.57784903049469],[.42645001411438,.389798998832703],[.438998997211456,.39649498462677],[.450067013502121,.400434017181396],[.289712011814117,.368252992630005],[.276670008897781,.363372981548309],[.517862021923065,.471948027610779],[.710287988185883,.380764007568359],[.526226997375488,.573909997940063],[.895093023777008,.254140973091125],[.634069979190826,.409575998783112],[.661242008209229,.41302502155304],[.688880026340485,.409460008144379],[.725341975688934,.389131009578705],[.606630027294159,.40370500087738],[.654766023159027,.344011008739471],[.629905998706818,.346076011657715],[.680678009986877,.347265005111694],[.702096998691559,.353591024875641],[.75221198797226,.410804986953735],[.602918028831482,.842862963676453],[.719901978969574,.375599980354309],[.893692970275879,.399959981441498],[.790081977844238,.391354024410248],[.643998026847839,.534487962722778],[.528249025344849,.65040397644043],[.525849997997284,.680191040039062],[.560214996337891,.657229006290436],[.585384011268616,.66654098033905],[.549625992774963,.680860996246338],[.57122802734375,.682691991329193],[.624852001667023,.72809898853302],[.513050019741058,.547281980514526],[.51509702205658,.527251958847046],[.742246985435486,.314507007598877],[.598631024360657,.454979002475739],[.570338010787964,.548575043678284],[.578631997108459,.533622980117798],[.723087012767792,.532054007053375],[.516445994377136,.499638974666595],[.662801027297974,.282917976379395],[.70362401008606,.293271005153656],[.830704987049103,.193813979625702],[.552385985851288,.302568018436432],[.607609987258911,.353887975215912],[.645429015159607,.696707010269165],[.932694971561432,.730105042457581],[.557260990142822,.572826027870178],[.542901992797852,.584792017936707],[.6180260181427,.694710969924927],[.607590973377228,.694203019142151],[.722943007946014,.271963000297546],[.577413976192474,.563166975975037],[.614082992076874,.281386971473694],[.616907000541687,.255886018276215],[.668509006500244,.119913995265961],[.770092010498047,.232020974159241],[.635536015033722,.189248979091644],[.77039098739624,.299556016921997],[.826722025871277,.278755009174347],[.527121007442474,.666198015213013],[.553171992301941,.668527007102966],[.577238023281097,.673889994621277],[.554691970348358,.580065965652466],[.611896991729736,.693961024284363],[.59696102142334,.706539988517761],[.596370995044708,.693953037261963],[.539958000183105,.557139039039612],[.568841993808746,.692366003990173],[.547818005084991,.692366003990173],[.52461302280426,.692366003990173],[.534089982509613,.779141008853912],[.527670979499817,.736225962638855],[.526912987232208,.717857003211975],[.526877999305725,.704625964164734],[.526966989040375,.695277988910675],[.572058022022247,.695277988910675],[.573521018028259,.703539967536926],[.57683801651001,.711845993995667],[.581691026687622,.720062971115112],[.609944999217987,.639909982681274],[.986046016216278,.560034036636353],[.5867999792099,.69539999961853],[.590372025966644,.701822996139526],[.531915009021759,.601536989212036],[.577268004417419,.585934996604919],[.536915004253387,.593786001205444],[.627542972564697,.473352015018463],[.665585994720459,.495950996875763],[.588353991508484,.546862006187439],[.757824003696442,.14767599105835],[.709249973297119,.201507985591888],[.672684013843536,.256581008434296],[.600408971309662,.74900496006012],[.55826598405838,.261672019958496],[.570303976535797,.187870979309082],[.588165998458862,.109044015407562],[.711045026779175,.398952007293701],[.781069993972778,.435405015945435],[.587247014045715,.398931980133057],[.742869973182678,.355445981025696],[.572156012058258,.437651991844177],[.55186802148819,.536570012569427],[.821442008018494,.457556009292603],[.752701997756958,.457181990146637],[.71375697851181,.467626988887787],[.66711300611496,.460672974586487],[.631101012229919,.447153985500336],[.6008620262146,.432473003864288],[.523481011390686,.405627012252808],[.810747981071472,.523926019668579],[.771045982837677,.348959028720856],[.509127020835876,.562718033790588],[.595292985439301,.485023975372314],[.980530977249146,.401564002037048],[.573499977588654,.420000016689301],[.602994978427887,.548687994480133],[.733529984951019,.376977026462555],[.560611009597778,.519016981124878],[.967685997486115,.644356966018677],[.580985009670258,.387160003185272],[.537728011608124,.505385041236877],[.760966002941132,.779752969741821],[.801778972148895,.831938028335571],[.892440974712372,.54076099395752],[.816350996494293,.740260004997253],[.865594983100891,.333687007427216],[.614073991775513,.883246004581451],[.508952975273132,.579437971115112],[.617941975593567,.508316040039062],[.825608015060425,.397674977779388],[.681214988231659,.39623498916626],[.656635999679565,.400596976280212],[.603900015354156,.710216999053955],[.81208598613739,.588539004325867],[.56801301240921,.944564998149872],[.681007981300354,.898285031318665],[.733752012252808,.869701027870178],[.633830010890961,.398822009563446],[.606792986392975,.39553701877594],[.589659988880157,.391062021255493],[.805015981197357,.342108011245728],[.611334979534149,.362284004688263],[.634037971496582,.355970978736877],[.656635999679565,.355356991291046],[.681214988231659,.35834002494812],[.698584973812103,.363156020641327],[.941866993904114,.319076001644135],[.698584973812103,.387449026107788],[.584177017211914,.624107003211975],[.554318010807037,.566076993942261],[.534153997898102,.62064003944397],[.711217999458313,.819975018501282],[.664629995822906,.852871000766754],[.559099972248077,.902631998062134],[.871706008911133,.791940987110138],[.591234028339386,.373893976211548],[.544341027736664,.451583981513977],[.624562978744507,.924192011356354],[.88577002286911,.615028977394104],[.551338016986847,.695277988910675],[.551980018615723,.704632043838501],[.552887976169586,.715808033943176],[.555167973041534,.730794012546539],[.569944024085999,.767035007476807],[.593203008174896,.685675978660583],[.599261999130249,.681069016456604],[.607599973678589,.677703022956848],[.631937980651855,.663500010967255],[.752032995223999,.601315021514893],[.547226011753082,.420395016670227],[.563543975353241,.359827995300293],[.583841025829315,.368713974952698],[.586614012718201,.692366003990173],[.771915018558502,.683578014373779],[.531597018241882,.352482974529266],[.588370978832245,.804440975189209],[.52079701423645,.442565023899078],[.567984998226166,.493479013442993],[.543282985687256,.819254994392395],[.655317008495331,.745514988899231],[.621008992195129,.574018001556396],[.625559985637665,.78031200170517],[.680198013782501,.570719003677368],[.64276397228241,.604337990283966],[.704662978649139,.621529996395111],[.552012026309967,.862591981887817],[.589071989059448,.508637011051178],[.685944974422455,.775357007980347],[.645735025405884,.812640011310577],[.675342977046967,.703978002071381],[.810858011245728,.646304965019226],[.72012197971344,.714666962623596],[.866151988506317,.682704985141754],[.663187026977539,.644596993923187],[.570082008838654,.466325998306274],[.544561982154846,.548375964164734],[.562758982181549,.558784961700439],[.531987011432648,.530140042304993],[.585271000862122,.335177004337311],[.622952997684479,.32277899980545],[.655896008014679,.320163011550903],[.687132000923157,.322345972061157],[.716481983661652,.333200991153717],[.758756995201111,.382786989212036],[.897013008594513,.468769013881683],[.732392013072968,.424547016620636],[.70211398601532,.433162987232208],[.66652500629425,.433866024017334],[.633504986763,.426087975502014],[.603875994682312,.416586995124817],[.579657971858978,.409945011138916],[.992439985275269,.480777025222778],[.567192018032074,.569419980049133],[.54136598110199,.478899002075195],[.526564002037048,.546118021011353],[.523913025856018,.563830018043518],[.531529009342194,.555056989192963],[.566035985946655,.582329034805298],[.51631098985672,.563053965568542],[.5174720287323,.577877044677734],[.573594987392426,.389806985855103],[.560697972774506,.395331978797913],[.549755990505219,.399751007556915],[.710287988185883,.368252992630005],[.723330020904541,.363372981548309]]});var JL=Le(z7=>{Sl(z7,{default:()=>P7});var P7=[127,34,139,11,0,37,232,231,120,72,37,39,128,121,47,232,121,128,104,69,67,175,171,148,157,154,155,118,50,101,73,39,40,9,151,108,48,115,131,194,204,211,74,40,185,80,42,183,40,92,186,230,229,118,202,212,214,83,18,17,76,61,146,160,29,30,56,157,173,106,204,194,135,214,192,203,165,98,21,71,68,51,45,4,144,24,23,77,146,91,205,50,187,201,200,18,91,106,182,90,91,181,85,84,17,206,203,36,148,171,140,92,40,39,193,189,244,159,158,28,247,246,161,236,3,196,54,68,104,193,168,8,117,228,31,189,193,55,98,97,99,126,47,100,166,79,218,155,154,26,209,49,131,135,136,150,47,126,217,223,52,53,45,51,134,211,170,140,67,69,108,43,106,91,230,119,120,226,130,247,63,53,52,238,20,242,46,70,156,78,62,96,46,53,63,143,34,227,173,155,133,123,117,111,44,125,19,236,134,51,216,206,205,154,153,22,39,37,167,200,201,208,36,142,100,57,212,202,20,60,99,28,158,157,35,226,113,160,159,27,204,202,210,113,225,46,43,202,204,62,76,77,137,123,116,41,38,72,203,129,142,64,98,240,49,102,64,41,73,74,212,216,207,42,74,184,169,170,211,170,149,176,105,66,69,122,6,168,123,147,187,96,77,90,65,55,107,89,90,180,101,100,120,63,105,104,93,137,227,15,86,85,129,102,49,14,87,86,55,8,9,100,47,121,145,23,22,88,89,179,6,122,196,88,95,96,138,172,136,215,58,172,115,48,219,42,80,81,195,3,51,43,146,61,171,175,199,81,82,38,53,46,225,144,163,110,246,33,7,52,65,66,229,228,117,34,127,234,107,108,69,109,108,151,48,64,235,62,78,191,129,209,126,111,35,143,163,161,246,117,123,50,222,65,52,19,125,141,221,55,65,3,195,197,25,7,33,220,237,44,70,71,139,122,193,245,247,130,33,71,21,162,153,158,159,170,169,150,188,174,196,216,186,92,144,160,161,2,97,167,141,125,241,164,167,37,72,38,12,145,159,160,38,82,13,63,68,71,226,35,111,158,153,154,101,50,205,206,92,165,209,198,217,165,167,97,220,115,218,133,112,243,239,238,241,214,135,169,190,173,133,171,208,32,125,44,237,86,87,178,85,86,179,84,85,180,83,84,181,201,83,182,137,93,132,76,62,183,61,76,184,57,61,185,212,57,186,214,207,187,34,143,156,79,239,237,123,137,177,44,1,4,201,194,32,64,102,129,213,215,138,59,166,219,242,99,97,2,94,141,75,59,235,24,110,228,25,130,226,23,24,229,22,23,230,26,22,231,112,26,232,189,190,243,221,56,190,28,56,221,27,28,222,29,27,223,30,29,224,247,30,225,238,79,20,166,59,75,60,75,240,147,177,215,20,79,166,187,147,213,112,233,244,233,128,245,128,114,188,114,217,174,131,115,220,217,198,236,198,131,134,177,132,58,143,35,124,110,163,7,228,110,25,356,389,368,11,302,267,452,350,349,302,303,269,357,343,277,452,453,357,333,332,297,175,152,377,384,398,382,347,348,330,303,304,270,9,336,337,278,279,360,418,262,431,304,408,409,310,415,407,270,409,410,450,348,347,422,430,434,313,314,17,306,307,375,387,388,260,286,414,398,335,406,418,364,367,416,423,358,327,251,284,298,281,5,4,373,374,253,307,320,321,425,427,411,421,313,18,321,405,406,320,404,405,315,16,17,426,425,266,377,400,369,322,391,269,417,465,464,386,257,258,466,260,388,456,399,419,284,332,333,417,285,8,346,340,261,413,441,285,327,460,328,355,371,329,392,439,438,382,341,256,429,420,360,364,394,379,277,343,437,443,444,283,275,440,363,431,262,369,297,338,337,273,375,321,450,451,349,446,342,467,293,334,282,458,461,462,276,353,383,308,324,325,276,300,293,372,345,447,382,398,362,352,345,340,274,1,19,456,248,281,436,427,425,381,256,252,269,391,393,200,199,428,266,330,329,287,273,422,250,462,328,258,286,384,265,353,342,387,259,257,424,431,430,342,353,276,273,335,424,292,325,307,366,447,345,271,303,302,423,266,371,294,455,460,279,278,294,271,272,304,432,434,427,272,407,408,394,430,431,395,369,400,334,333,299,351,417,168,352,280,411,325,319,320,295,296,336,319,403,404,330,348,349,293,298,333,323,454,447,15,16,315,358,429,279,14,15,316,285,336,9,329,349,350,374,380,252,318,402,403,6,197,419,318,319,325,367,364,365,435,367,397,344,438,439,272,271,311,195,5,281,273,287,291,396,428,199,311,271,268,283,444,445,373,254,339,263,466,249,282,334,296,449,347,346,264,447,454,336,296,299,338,10,151,278,439,455,292,407,415,358,371,355,340,345,372,390,249,466,346,347,280,442,443,282,19,94,370,441,442,295,248,419,197,263,255,359,440,275,274,300,383,368,351,412,465,263,467,466,301,368,389,380,374,386,395,378,379,412,351,419,436,426,322,373,390,388,2,164,393,370,462,461,164,0,267,302,11,12,374,373,387,268,12,13,293,300,301,446,261,340,385,384,381,330,266,425,426,423,391,429,355,437,391,327,326,440,457,438,341,382,362,459,457,461,434,430,394,414,463,362,396,369,262,354,461,457,316,403,402,315,404,403,314,405,404,313,406,405,421,418,406,366,401,361,306,408,407,291,409,408,287,410,409,432,436,410,434,416,411,264,368,383,309,438,457,352,376,401,274,275,4,421,428,262,294,327,358,433,416,367,289,455,439,462,370,326,2,326,370,305,460,455,254,449,448,255,261,446,253,450,449,252,451,450,256,452,451,341,453,452,413,464,463,441,413,414,258,442,441,257,443,442,259,444,443,260,445,444,467,342,445,459,458,250,289,392,290,290,328,460,376,433,435,250,290,392,411,416,433,341,463,464,453,464,465,357,465,412,343,412,399,360,363,440,437,399,456,420,456,363,401,435,288,372,383,353,339,255,249,448,261,255,133,243,190,133,155,112,33,246,247,33,130,25,398,384,286,362,398,414,362,463,341,263,359,467,263,249,255,466,467,260,75,60,166,238,239,79,162,127,139,72,11,37,121,232,120,73,72,39,114,128,47,233,232,128,103,104,67,152,175,148,173,157,155,119,118,101,74,73,40,107,9,108,49,48,131,32,194,211,184,74,185,191,80,183,185,40,186,119,230,118,210,202,214,84,83,17,77,76,146,161,160,30,190,56,173,182,106,194,138,135,192,129,203,98,54,21,68,5,51,4,145,144,23,90,77,91,207,205,187,83,201,18,181,91,182,180,90,181,16,85,17,205,206,36,176,148,140,165,92,39,245,193,244,27,159,28,30,247,161,174,236,196,103,54,104,55,193,8,111,117,31,221,189,55,240,98,99,142,126,100,219,166,218,112,155,26,198,209,131,169,135,150,114,47,217,224,223,53,220,45,134,32,211,140,109,67,108,146,43,91,231,230,120,113,226,247,105,63,52,241,238,242,124,46,156,95,78,96,70,46,63,116,143,227,116,123,111,1,44,19,3,236,51,207,216,205,26,154,22,165,39,167,199,200,208,101,36,100,43,57,202,242,20,99,56,28,157,124,35,113,29,160,27,211,204,210,124,113,46,106,43,204,96,62,77,227,137,116,73,41,72,36,203,142,235,64,240,48,49,64,42,41,74,214,212,207,183,42,184,210,169,211,140,170,176,104,105,69,193,122,168,50,123,187,89,96,90,66,65,107,179,89,180,119,101,120,68,63,104,234,93,227,16,15,85,209,129,49,15,14,86,107,55,9,120,100,121,153,145,22,178,88,179,197,6,196,89,88,96,135,138,136,138,215,172,218,115,219,41,42,81,5,195,51,57,43,61,208,171,199,41,81,38,224,53,225,24,144,110,105,52,66,118,229,117,227,34,234,66,107,69,10,109,151,219,48,235,183,62,191,142,129,126,116,111,143,7,163,246,118,117,50,223,222,52,94,19,141,222,221,65,196,3,197,45,220,44,156,70,139,188,122,245,139,71,162,145,153,159,149,170,150,122,188,196,206,216,92,163,144,161,164,2,167,242,141,241,0,164,37,11,72,12,144,145,160,12,38,13,70,63,71,31,226,111,157,158,154,36,101,205,203,206,165,126,209,217,98,165,97,237,220,218,237,239,241,210,214,169,140,171,32,241,125,237,179,86,178,180,85,179,181,84,180,182,83,181,194,201,182,177,137,132,184,76,183,185,61,184,186,57,185,216,212,186,192,214,187,139,34,156,218,79,237,147,123,177,45,44,4,208,201,32,98,64,129,192,213,138,235,59,219,141,242,97,97,2,141,240,75,235,229,24,228,31,25,226,230,23,229,231,22,230,232,26,231,233,112,232,244,189,243,189,221,190,222,28,221,223,27,222,224,29,223,225,30,224,113,247,225,99,60,240,213,147,215,60,20,166,192,187,213,243,112,244,244,233,245,245,128,188,188,114,174,134,131,220,174,217,236,236,198,134,215,177,58,156,143,124,25,110,7,31,228,25,264,356,368,0,11,267,451,452,349,267,302,269,350,357,277,350,452,357,299,333,297,396,175,377,381,384,382,280,347,330,269,303,270,151,9,337,344,278,360,424,418,431,270,304,409,272,310,407,322,270,410,449,450,347,432,422,434,18,313,17,291,306,375,259,387,260,424,335,418,434,364,416,391,423,327,301,251,298,275,281,4,254,373,253,375,307,321,280,425,411,200,421,18,335,321,406,321,320,405,314,315,17,423,426,266,396,377,369,270,322,269,413,417,464,385,386,258,248,456,419,298,284,333,168,417,8,448,346,261,417,413,285,326,327,328,277,355,329,309,392,438,381,382,256,279,429,360,365,364,379,355,277,437,282,443,283,281,275,363,395,431,369,299,297,337,335,273,321,348,450,349,359,446,467,283,293,282,250,458,462,300,276,383,292,308,325,283,276,293,264,372,447,346,352,340,354,274,19,363,456,281,426,436,425,380,381,252,267,269,393,421,200,428,371,266,329,432,287,422,290,250,328,385,258,384,446,265,342,386,387,257,422,424,430,445,342,276,422,273,424,306,292,307,352,366,345,268,271,302,358,423,371,327,294,460,331,279,294,303,271,304,436,432,427,304,272,408,395,394,431,378,395,400,296,334,299,6,351,168,376,352,411,307,325,320,285,295,336,320,319,404,329,330,349,334,293,333,366,323,447,316,15,315,331,358,279,317,14,316,8,285,9,277,329,350,253,374,252,319,318,403,351,6,419,324,318,325,397,367,365,288,435,397,278,344,439,310,272,311,248,195,281,375,273,291,175,396,199,312,311,268,276,283,445,390,373,339,295,282,296,448,449,346,356,264,454,337,336,299,337,338,151,294,278,455,308,292,415,429,358,355,265,340,372,388,390,466,352,346,280,295,442,282,354,19,370,285,441,295,195,248,197,457,440,274,301,300,368,417,351,465,251,301,389,385,380,386,394,395,379,399,412,419,410,436,322,387,373,388,326,2,393,354,370,461,393,164,267,268,302,12,386,374,387,312,268,13,298,293,301,265,446,340,380,385,381,280,330,425,322,426,391,420,429,437,393,391,326,344,440,438,458,459,461,364,434,394,428,396,262,274,354,457,317,316,402,316,315,403,315,314,404,314,313,405,313,421,406,323,366,361,292,306,407,306,291,408,291,287,409,287,432,410,427,434,411,372,264,383,459,309,457,366,352,401,1,274,4,418,421,262,331,294,358,435,433,367,392,289,439,328,462,326,94,2,370,289,305,455,339,254,448,359,255,446,254,253,449,253,252,450,252,256,451,256,341,452,414,413,463,286,441,414,286,258,441,258,257,442,257,259,443,259,260,444,260,467,445,309,459,250,305,289,290,305,290,460,401,376,435,309,250,392,376,411,433,453,341,464,357,453,465,343,357,412,437,343,399,344,360,440,420,437,456,360,420,363,361,401,288,265,372,353,390,339,249,339,448,255]});var eI=Le(Ns=>{const Cr=zt(),_7=_L(),ZL=Dp(),M7=KL(),H7=XL(),V7=JL().default;class QL{constructor(n,t,e,i){this.pipeline=new M7.Pipeline(n,t,e,i),i&&(this.config=i)}async estimateFaces(n,t){t&&(this.config=t);const e=Cr.tidy(()=>(n instanceof Cr.Tensor||(n=Cr.browser.fromPixels(n)),n.toFloat().expandDims(0))),i=await this.pipeline.predict(e,t);Cr.dispose(e);const r=[];for(const a of i||[]){const s=a.confidence.arraySync();if(s>=this.config.detector.minConfidence){const o=a.coords?a.coords.arraySync():null,l={};if(o&&o.length>0)for(const u in ZL.MESH_ANNOTATIONS)(this.config.iris.enabled||u.includes("Iris")===!1)&&(l[u]=ZL.MESH_ANNOTATIONS[u].map(c=>o[c]));r.push({confidence:s||0,box:a.box?[a.box.startPoint[0],a.box.startPoint[1],a.box.endPoint[0]-a.box.startPoint[0],a.box.endPoint[1]-a.box.startPoint[1]]:0,mesh:o,annotations:l,image:a.image?Cr.clone(a.image):null})}a.confidence.dispose(),a.image.dispose()}return r}}async function q7(n){const t=await Promise.all([_7.load(n),Cr.loadGraphModel(n.mesh.modelPath,{fromTFHub:n.mesh.modelPath.includes("tfhub.dev")}),Cr.loadGraphModel(n.iris.modelPath,{fromTFHub:n.iris.modelPath.includes("tfhub.dev")})]),e=new QL(t[0],t[1],t[2],n);return e}Ns.load=q7;Ns.MediaPipeFaceMesh=QL;Ns.uv_coords=H7;Ns.triangulation=V7});var nI=Le(ml=>{const un=zt(),_i={};let tI={age:0,gender:""},_p=0;async function G7(n,t){const e=un.browser.fromPixels(n),i=un.image.resizeBilinear(e,[t,t]),r=un.cast(un.expandDims(i,0),"float32");return r}async function Y7(n){return _i.age||(_i.age=await un.loadGraphModel(n.face.age.modelPath)),_i.age}async function j7(n){return _i.gender||(_i.gender=await un.loadGraphModel(n.face.gender.modelPath)),_i.gender}async function K7(n,t){if(_p+=1,_p>=t.face.age.skipFrames)return _p=0,tI;let e;if(n instanceof un.Tensor){const r=un.image.resizeBilinear(n,[t.face.age.inputSize,t.face.age.inputSize],!1);e=un.mul(r,[255]),un.dispose(r)}else e=await G7(n,t.face.age.inputSize);const i={};if(t.face.age.enabled){const r=await _i.age.predict(e),a=await r.data();i.age=Math.trunc(10*a[0])/10,un.dispose(r)}if(t.face.gender.enabled){const r=await _i.gender.predict(e),a=await r.data();i.gender=Math.trunc(100*a[0])<50?"female":"male",un.dispose(r)}return un.dispose(e),tI=i,i}ml.predict=K7;ml.loadAge=Y7;ml.loadGender=j7});var aI=Le(Mp=>{const Pt=zt(),$7=["angry","discust","fear","happy","sad","surpise","neutral"],gl={};let iI=[],Hp=0;const rI=1.5;function X7(n,t){const e=Pt.tidy(()=>{const i=Pt.browser.fromPixels(n,1),r=Pt.image.resizeBilinear(i,[t,t]),a=Pt.cast(Pt.expandDims(r,0),"float32");return a});return e}async function J7(n){return gl.emotion||(gl.emotion=await Pt.loadGraphModel(n.face.emotion.modelPath)),gl.emotion}async function Z7(n,t){if(Hp+=1,Hp>=t.face.emotion.skipFrames)return Hp=0,iI;const e=Pt.tidy(()=>{if(n instanceof Pt.Tensor){const r=Pt.image.resizeBilinear(n,[t.face.emotion.inputSize,t.face.emotion.inputSize],!1),[a,s,o]=Pt.split(r,3,3);if(t.face.emotion.useGrayscale){const l=Pt.mul(a,[.2989]),u=Pt.mul(s,[.587]),c=Pt.mul(o,[.114]),h=Pt.addN([l,u,c]);return h}return s}return X7(n,t.face.emotion.inputSize)}),i=[];if(t.face.emotion.enabled){const r=await gl.emotion.predict(e),a=await r.data();for(let s=0;s<a.length;s++)rI*a[s]>t.face.emotion.minConfidence&&i.push({score:Math.min(.99,Math.trunc(100*rI*a[s])/100),emotion:$7[s]});i.sort((s,o)=>o.score-s.score),Pt.dispose(r)}return Pt.dispose(e),iI=i,i}Mp.predict=Z7;Mp.load=J7});var lI=Le(sI=>{const oI=zt();class Q7{constructor(n,t){this.model=n,this.outputStride=t;const e=this.model.inputs[0].shape;oI.util.assert(e[1]===-1&&e[2]===-1,()=>`Input shape [${e[1]}, ${e[2]}] must both be equal to or -1`)}predict(n){return oI.tidy(()=>{const t=this.preprocessInput(n.toFloat()),e=t.expandDims(0),i=this.model.predict(e),r=i.map(s=>s.squeeze([0])),a=this.nameOutputResults(r);return{heatmapScores:a.heatmap.sigmoid(),offsets:a.offsets,displacementFwd:a.displacementFwd,displacementBwd:a.displacementBwd}})}dispose(){this.model.dispose()}}sI.BaseModel=Q7});var Vp=Le(uI=>{const cI=zt(),eH=lI();class tH extends eH.BaseModel{preprocessInput(n){return cI.tidy(()=>cI.div(n,127.5).sub(1))}nameOutputResults(n){const[t,e,i,r]=n;return{offsets:t,heatmap:e,displacementFwd:i,displacementBwd:r}}}uI.MobileNet=tH});var dI=Le(hI=>{function qp(n){return Math.floor(n/2)}class nH{constructor(n,t){this.priorityQueue=new Array(n),this.numberOfElements=-1,this.getElementValue=t}enqueue(n){this.priorityQueue[++this.numberOfElements]=n,this.swim(this.numberOfElements)}dequeue(){const n=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,n}empty(){return this.numberOfElements===-1}size(){return this.numberOfElements+1}all(){return this.priorityQueue.slice(0,this.numberOfElements+1)}max(){return this.priorityQueue[0]}swim(n){for(;n>0&&this.less(qp(n),n);)this.exchange(n,qp(n)),n=qp(n)}sink(n){for(;2*n<=this.numberOfElements;){let t=2*n;if(t<this.numberOfElements&&this.less(t,t+1)&&t++,!this.less(n,t))break;this.exchange(n,t),n=t}}getValueAt(n){return this.getElementValue(this.priorityQueue[n])}less(n,t){return this.getValueAt(n)<this.getValueAt(t)}exchange(n,t){const e=this.priorityQueue[n];this.priorityQueue[n]=this.priorityQueue[t],this.priorityQueue[t]=e}}hI.MaxHeap=nH});var fI=Le(pI=>{const iH=dI();function rH(n,t,e,i,r,a){const[s,o]=a.shape;let l=!0;const u=Math.max(e-r,0),c=Math.min(e+r+1,s);for(let h=u;h<c;++h){const d=Math.max(i-r,0),p=Math.min(i+r+1,o);for(let f=d;f<p;++f)if(a.get(h,f,n)>t){l=!1;break}if(!l)break}return l}function aH(n,t,e){const[i,r,a]=e.shape,s=new iH.MaxHeap(i*r*a,({score:o})=>o);for(let o=0;o<i;++o)for(let l=0;l<r;++l)for(let u=0;u<a;++u){const c=e.get(o,l,u);if(c<n)continue;rH(u,c,o,l,t,e)&&s.enqueue({score:c,part:{heatmapY:o,heatmapX:l,id:u}})}return s}pI.buildPartWithScoreQueue=aH});var xs=Le(On=>{On.partNames=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"];On.NUM_KEYPOINTS=On.partNames.length;On.partIds=On.partNames.reduce((n,t,e)=>(n[t]=e,n),{});const sH=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]];On.poseChain=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]];On.connectedPartIndices=sH.map(([n,t])=>[On.partIds[n],On.partIds[t]]);On.partChannels=["left_face","right_face","right_upper_leg_front","right_lower_leg_back","right_upper_leg_back","left_lower_leg_front","left_upper_leg_front","left_upper_leg_back","left_lower_leg_back","right_feet","right_lower_leg_front","left_feet","torso_front","torso_back","right_upper_arm_front","right_upper_arm_back","right_lower_arm_back","left_lower_arm_front","left_upper_arm_front","left_upper_arm_back","left_lower_arm_back","right_hand","right_lower_arm_front","left_hand"]});var Yp=Le(Mi=>{const oH=xs();function mI(n,t,e,i){return{y:i.get(n,t,e),x:i.get(n,t,e+oH.NUM_KEYPOINTS)}}Mi.getOffsetPoint=mI;function lH(n,t,e){const{heatmapY:i,heatmapX:r,id:a}=n,{y:s,x:o}=mI(i,r,a,e);return{x:n.heatmapX*t+o,y:n.heatmapY*t+s}}Mi.getImageCoords=lH;function uH(n,t){const e=new Array(t);for(let i=0;i<t;i++)e[i]=n;return e}Mi.fillArray=uH;function Gp(n,t,e){return n<t?t:n>e?e:n}Mi.clamp=Gp;function cH(n,t,e,i){const r=e-n,a=i-t;return r*r+a*a}Mi.squaredDistance=cH;function hH(n,t){return{x:n.x+t.x,y:n.y+t.y}}Mi.addVectors=hH;function dH(n,t,e){return{y:Gp(n.y,t,e),x:Gp(n.x,t,e)}}Mi.clampVector=dH});var wI=Le(gI=>{const Cs=xs(),Ia=Yp(),vI=Cs.poseChain.map(([n,t])=>[Cs.partIds[n],Cs.partIds[t]]),jp=vI.map(([,n])=>n),yI=vI.map(([n])=>n);function pH(n,t,e){const i=e.shape[2]/2;return{y:e.get(t.y,t.x,n),x:e.get(t.y,t.x,i+n)}}function Kp(n,t,e,i){return{y:Ia.clamp(Math.round(n.y/t),0,e-1),x:Ia.clamp(Math.round(n.x/t),0,i-1)}}function bI(n,t,e,i,r,a,s,o=2){const[l,u]=i.shape,c=Kp(t.position,a,l,u),h=pH(n,c,s),d=Ia.addVectors(t.position,h);let p=d;for(let g=0;g<o;g++){const v=Kp(p,a,l,u),b=Ia.getOffsetPoint(v.y,v.x,e,r);p=Ia.addVectors({x:v.x*a,y:v.y*a},{x:b.x,y:b.y})}const f=Kp(p,a,l,u),m=i.get(f.y,f.x,e);return{position:p,part:Cs.partNames[e],score:m}}function fH(n,t,e,i,r,a){const s=t.shape[2],o=jp.length,l=new Array(s),{part:u,score:c}=n,h=Ia.getImageCoords(u,i,e);l[u.id]={score:c,part:Cs.partNames[u.id],position:h};for(let d=o-1;d>=0;--d){const p=jp[d],f=yI[d];l[p]&&!l[f]&&(l[f]=bI(d,l[p],f,t,e,i,a))}for(let d=0;d<o;++d){const p=yI[d],f=jp[d];l[p]&&!l[f]&&(l[f]=bI(d,l[p],f,t,e,i,r))}return l}gI.decodePose=fH});var $p=Le(SI=>{const mH=fI(),gH=wI(),LI=Yp();function II(n,t,{x:e,y:i},r){return n.some(({keypoints:a})=>{const s=a[r].position;return LI.squaredDistance(i,e,s.y,s.x)<=t})}function vH(n,t,e){const i=e.reduce((r,{position:a,score:s},o)=>(II(n,t,a,o)||(r+=s),r),0);return i/e.length}const yH=1;function bH(n,t,e,i,r,a,s=.5,o=20){const l=[],u=mH.buildPartWithScoreQueue(s,yH,n),c=o*o;for(;l.length<a&&!u.empty();){const h=u.dequeue(),d=LI.getImageCoords(h.part,r,t);if(II(l,c,d,h.part.id))continue;const p=gH.decodePose(h,n,t,r,e,i),f=vH(l,c,p);l.push({keypoints:p,score:f})}return l}SI.decodeMultiplePoses=bH});var Jp=Le(gn=>{const Aa=zt(),wH=xs();function SH(n,t,e){return n<e||t<e}function LH(n,t){return wH.connectedPartIndices.reduce((e,[i,r])=>(SH(n[i].score,n[r].score,t)||e.push([n[i],n[r]]),e),[])}gn.getAdjacentKeyPoints=LH;const{NEGATIVE_INFINITY:AI,POSITIVE_INFINITY:TI}=Number;function NI(n){return n.reduce(({maxX:t,maxY:e,minX:i,minY:r},{position:{x:a,y:s}})=>({maxX:Math.max(t,a),maxY:Math.max(e,s),minX:Math.min(i,a),minY:Math.min(r,s)}),{maxX:AI,maxY:AI,minX:TI,minY:TI})}gn.getBoundingBox=NI;function IH(n){const{minX:t,minY:e,maxX:i,maxY:r}=NI(n);return[{x:t,y:e},{x:i,y:e},{x:i,y:r},{x:t,y:r}]}gn.getBoundingBoxPoints=IH;async function AH(n){return Promise.all(n.map(t=>t.buffer()))}gn.toTensorBuffers3D=AH;function xI(n,t,e,i=0,r=0){return{score:n.score,keypoints:n.keypoints.map(({score:a,part:s,position:o})=>({score:a,part:s,position:{x:o.x*e+r,y:o.y*t+i}}))}}gn.scalePose=xI;function CI(n,t,e,i=0,r=0){return e===1&&t===1&&i===0&&r===0?n:n.map(a=>xI(a,t,e,i,r))}gn.scalePoses=CI;function RI(n){return n instanceof Aa.Tensor?[n.shape[0],n.shape[1]]:[n.height,n.width]}gn.getInputTensorDimensions=RI;function Xp(n){return n instanceof Aa.Tensor?n:Aa.browser.fromPixels(n)}gn.toInputTensor=Xp;function TH(n,t,e){return Aa.tidy(()=>{const i=Xp(n);return i.resizeBilinear([t,e])})}gn.toResizedInputTensor=TH;function NH(n,[t,e]){const[i,r]=RI(n),a=e/t,s=r/i;let[o,l,u,c]=[0,0,0,0];s<a?(o=0,l=0,u=Math.round(.5*(a*i-r)),c=Math.round(.5*(a*i-r))):(o=Math.round(.5*(1/a*r-i)),l=Math.round(.5*(1/a*r-i)),u=0,c=0);const h=Aa.tidy(()=>{let d=Xp(n);return d=Aa.pad3d(d,[[o,l],[u,c],[0,0]]),d.resizeBilinear([t,e])});return{resized:h,padding:{top:o,left:u,right:c,bottom:l}}}gn.padAndResizeTo=NH;function xH(n,[t,e],[i,r],a){const s=(t+a.top+a.bottom)/i,o=(e+a.left+a.right)/r,l=CI(n,s,o,-a.top,-a.left);return l}gn.scaleAndFlipPoses=xH});var EI=Le(Zp=>{const CH=zt(),RH=Vp(),OH=$p(),vl=Jp();class OI{constructor(n){this.baseModel=n}async estimatePoses(n,t){const e=t.outputStride,[i,r]=vl.getInputTensorDimensions(n),{resized:a,padding:s}=vl.padAndResizeTo(n,[t.inputResolution,t.inputResolution]),{heatmapScores:o,offsets:l,displacementFwd:u,displacementBwd:c}=this.baseModel.predict(a),h=await vl.toTensorBuffers3D([o,l,u,c]),d=h[0],p=h[1],f=h[2],m=h[3],g=await OH.decodeMultiplePoses(d,p,f,m,e,t.maxDetections,t.scoreThreshold,t.nmsRadius),v=vl.scaleAndFlipPoses(g,[i,r],[t.inputResolution,t.inputResolution],s);return o.dispose(),l.dispose(),u.dispose(),c.dispose(),a.dispose(),v}dispose(){this.baseModel.dispose()}}Zp.PoseNet=OI;async function EH(n){const t=await CH.loadGraphModel(n.modelPath),e=new RH.MobileNet(t,n.outputStride);return new OI(e)}async function DH(n){return EH(n)}Zp.load=DH});var kI=Le(tn=>{const kH=Vp(),DI=EI(),FH=$p(),yl=xs(),Rs=Jp();tn.load=DI.load;tn.PoseNet=DI.PoseNet;tn.MobileNet=kH.MobileNet;tn.decodeMultiplePoses=FH.decodeMultiplePoses;tn.partChannels=yl.partChannels;tn.partIds=yl.partIds;tn.partNames=yl.partNames;tn.poseChain=yl.poseChain;tn.getAdjacentKeyPoints=Rs.getAdjacentKeyPoints;tn.getBoundingBox=Rs.getBoundingBox;tn.getBoundingBoxPoints=Rs.getBoundingBoxPoints;tn.scaleAndFlipPoses=Rs.scaleAndFlipPoses;tn.scalePose=Rs.scalePose});var tf=Le(Hi=>{const WH=zt();function Qp(n){return[Math.abs(n.endPoint[0]-n.startPoint[0]),Math.abs(n.endPoint[1]-n.startPoint[1])]}Hi.getBoxSize=Qp;function ef(n){return[n.startPoint[0]+(n.endPoint[0]-n.startPoint[0])/2,n.startPoint[1]+(n.endPoint[1]-n.startPoint[1])/2]}Hi.getBoxCenter=ef;function UH(n,t,e){const i=t.shape[1],r=t.shape[2],a=[[n.startPoint[1]/i,n.startPoint[0]/r,n.endPoint[1]/i,n.endPoint[0]/r]];return WH.image.cropAndResize(t,a,[0],e)}Hi.cutBoxFromImageAndResize=UH;function BH(n,t){const e=[n.startPoint[0]*t[0],n.startPoint[1]*t[1]],i=[n.endPoint[0]*t[0],n.endPoint[1]*t[1]],r=n.palmLandmarks.map(a=>{const s=[a[0]*t[0],a[1]*t[1]];return s});return{startPoint:e,endPoint:i,palmLandmarks:r}}Hi.scaleBoxCoordinates=BH;function zH(n,t=1.5){const e=ef(n),i=Qp(n),r=[t*i[0]/2,t*i[1]/2],a=[e[0]-r[0],e[1]-r[1]],s=[e[0]+r[0],e[1]+r[1]];return{startPoint:a,endPoint:s,palmLandmarks:n.palmLandmarks}}Hi.enlargeBox=zH;function PH(n){const t=ef(n),e=Qp(n),i=Math.max(...e),r=i/2,a=[t[0]-r,t[1]-r],s=[t[0]+r,t[1]+r];return{startPoint:a,endPoint:s,palmLandmarks:n.palmLandmarks}}Hi.squarifyBox=PH;function _H(n,t){const e=[n.endPoint[0]-n.startPoint[0],n.endPoint[1]-n.startPoint[1]],i=[e[0]*t[0],e[1]*t[1]],r=[n.startPoint[0]+i[0],n.startPoint[1]+i[1]],a=[n.endPoint[0]+i[0],n.endPoint[1]+i[1]];return{startPoint:r,endPoint:a,palmLandmarks:n.palmLandmarks}}Hi.shiftBox=_H});var WI=Le(FI=>{const qe=zt(),MH=tf();class HH{constructor(n,t,e){this.model=n,this.width=e.inputSize,this.height=e.inputSize,this.anchors=t.map(i=>[i.x_center,i.y_center]),this.anchorsTensor=qe.tensor2d(this.anchors),this.inputSizeTensor=qe.tensor1d([e.inputSize,e.inputSize]),this.doubleInputSizeTensor=qe.tensor1d([e.inputSize*2,e.inputSize*2])}normalizeBoxes(n){return qe.tidy(()=>{const t=qe.slice(n,[0,0],[-1,2]),e=qe.slice(n,[0,2],[-1,2]),i=qe.add(qe.div(t,this.inputSizeTensor),this.anchorsTensor),r=qe.div(e,this.doubleInputSizeTensor),a=qe.mul(qe.sub(i,r),this.inputSizeTensor),s=qe.mul(qe.add(i,r),this.inputSizeTensor);return qe.concat2d([a,s],1)})}normalizeLandmarks(n,t){return qe.tidy(()=>{const e=qe.add(qe.div(n.reshape([-1,7,2]),this.inputSizeTensor),this.anchors[t]);return qe.mul(e,this.inputSizeTensor)})}async getBoundingBoxes(n){const t=qe.tidy(()=>qe.mul(qe.sub(n,.5),2)),e=this.model.predict(t),i=e.squeeze(),r=qe.tidy(()=>qe.sigmoid(qe.slice(i,[0,0],[-1,1])).squeeze()),a=qe.slice(i,[0,1],[-1,4]),s=this.normalizeBoxes(a),o=await qe.image.nonMaxSuppressionAsync(s,r,this.maxHands,this.iouThreshold,this.scoreThreshold),l=await o.array(),u=[t,e,o,i,s,a,r];if(l.length===0)return u.forEach(h=>h.dispose()),null;const c=qe.tidy(()=>{const h=[];for(const d in l){const p=l[d],f=qe.slice(s,[p,0],[1,-1]),m=qe.slice(i,[p,5],[1,14]),g=qe.tidy(()=>this.normalizeLandmarks(m,p).reshape([-1,2]));h.push({boxes:f,palmLandmarks:g})}return h});return c}async estimateHandBounds(n,t){const e=n.shape[1],i=n.shape[2];this.iouThreshold=t.iouThreshold,this.scoreThreshold=t.scoreThreshold,this.maxHands=t.maxHands;const r=qe.tidy(()=>n.resizeBilinear([this.width,this.height]).div(255)),a=await this.getBoundingBoxes(r);if(r.dispose(),!a||a.length===0)return null;const s=[];for(const o in a){const l=a[o],u=await l.boxes.array(),c=u[0].slice(0,2),h=u[0].slice(2,4),d=await l.palmLandmarks.array();l.boxes.dispose(),l.palmLandmarks.dispose(),s.push(MH.scaleBoxCoordinates({startPoint:c,endPoint:h,palmLandmarks:d},[i/this.width,e/this.height]))}return s}}FI.HandDetector=HH});var BI=Le(UI=>{UI.MESH_ANNOTATIONS={thumb:[1,2,3,4],indexFinger:[5,6,7,8],middleFinger:[9,10,11,12],ringFinger:[13,14,15,16],pinky:[17,18,19,20],palmBase:[0]}});var HI=Le(Vi=>{function zI(n){return n-2*Math.PI*Math.floor((n+Math.PI)/(2*Math.PI))}Vi.normalizeRadians=zI;function VH(n,t){const e=Math.PI/2-Math.atan2(-(t[1]-n[1]),t[0]-n[0]);return zI(e)}Vi.computeRotation=VH;const PI=(n,t)=>[[1,0,n],[0,1,t],[0,0,1]];function Ta(n,t){let e=0;for(let i=0;i<n.length;i++)e+=n[i]*t[i];return e}Vi.dot=Ta;function _I(n,t){const e=[];for(let i=0;i<n.length;i++)e.push(n[i][t]);return e}Vi.getColumnFrom2DArr=_I;function MI(n,t){const e=[],i=n.length;for(let r=0;r<i;r++){e.push([]);for(let a=0;a<i;a++)e[r].push(Ta(n[r],_I(t,a)))}return e}function qH(n,t){const e=Math.cos(n),i=Math.sin(n),r=[[e,-i,0],[i,e,0],[0,0,1]],a=PI(t[0],t[1]),s=MI(a,r),o=PI(-t[0],-t[1]);return MI(s,o)}Vi.buildRotationMatrix=qH;function GH(n){const t=[[n[0][0],n[1][0]],[n[0][1],n[1][1]]],e=[n[0][2],n[1][2]],i=[-Ta(t[0],e),-Ta(t[1],e)];return[t[0].concat(i[0]),t[1].concat(i[1]),[0,0,1]]}Vi.invertTransformMatrix=GH;function YH(n,t){return[Ta(n,t[0]),Ta(n,t[1])]}Vi.rotatePoint=YH});var YI=Le(VI=>{const qI=zt(),jn=tf(),qi=HI(),jH=.8,KH=[0,-.4],$H=[0,-.1],XH=1.65,GI=[0,5,9,13,17,1,2],JH=0,ZH=2;class QH{constructor(n,t,e){this.regionsOfInterest=[],this.runsWithoutHandDetector=0,this.boundingBoxDetector=n,this.meshDetector=t,this.meshWidth=e.inputSize,this.meshHeight=e.inputSize,this.enlargeFactor=e.enlargeFactor}getBoxForPalmLandmarks(n,t){const e=n.map(r=>{const a=[...r,1];return qi.rotatePoint(a,t)}),i=this.calculateLandmarksBoundingBox(e);return jn.enlargeBox(jn.squarifyBox(jn.shiftBox(i,KH)),this.enlargeFactor)}getBoxForHandLandmarks(n){const t=this.calculateLandmarksBoundingBox(n),e=jn.enlargeBox(jn.squarifyBox(jn.shiftBox(t,$H)),XH),i=[];for(let r=0;r<GI.length;r++)i.push(n[GI[r]].slice(0,2));return e.palmLandmarks=i,e}transformRawCoords(n,t,e,i){const r=jn.getBoxSize(t),a=[r[0]/this.meshWidth,r[1]/this.meshHeight],s=n.map(d=>[a[0]*(d[0]-this.meshWidth/2),a[1]*(d[1]-this.meshHeight/2),d[2]]),o=qi.buildRotationMatrix(e,[0,0]),l=s.map(d=>{const p=qi.rotatePoint(d,o);return[...p,d[2]]}),u=qi.invertTransformMatrix(i),c=[...jn.getBoxCenter(t),1],h=[qi.dot(c,u[0]),qi.dot(c,u[1])];return l.map(d=>[d[0]+h[0],d[1]+h[1],d[2]])}async estimateHands(n,t){this.maxContinuousChecks=t.skipFrames,this.detectionConfidence=t.minConfidence,this.maxHands=t.maxHands;const e=this.shouldUpdateRegionsOfInterest();if(e===!0){const r=await this.boundingBoxDetector.estimateHandBounds(n,t);this.regionsOfInterest=[];for(const a in r)this.updateRegionsOfInterest(r[a],!0,a);this.runsWithoutHandDetector=0}else this.runsWithoutHandDetector++;const i=[];if(!this.regionsOfInterest)return i;for(const r in this.regionsOfInterest){const a=this.regionsOfInterest[r][0];if(!a)return i;const s=qi.computeRotation(a.palmLandmarks[JH],a.palmLandmarks[ZH]),o=jn.getBoxCenter(a),l=[o[0]/n.shape[2],o[1]/n.shape[1]],u=qI.image.rotateWithOffset(n,s,0,l),c=qi.buildRotationMatrix(-s,o),h=e?this.getBoxForPalmLandmarks(a.palmLandmarks,c):a,d=jn.cutBoxFromImageAndResize(h,u,[this.meshWidth,this.meshHeight]),p=d.div(255);d.dispose(),u.dispose();const f=this.meshDetector.predict(p),[m,g]=f;p.dispose();const v=m.dataSync()[0];if(m.dispose(),v<t.minConfidence)return g.dispose(),this.regionsOfInterest[r]=[],i;const b=qI.reshape(g,[-1,3]),w=await b.array();g.dispose(),b.dispose();const S=this.transformRawCoords(w,h,s,c),L=this.getBoxForHandLandmarks(S);this.updateRegionsOfInterest(L,!1,r);const N={landmarks:S,confidence:v,box:{topLeft:L.startPoint,bottomRight:L.endPoint}};i.push(N)}return i}calculateLandmarksBoundingBox(n){const t=n.map(a=>a[0]),e=n.map(a=>a[1]),i=[Math.min(...t),Math.min(...e)],r=[Math.max(...t),Math.max(...e)];return{startPoint:i,endPoint:r}}updateRegionsOfInterest(n,t,e){if(t)this.regionsOfInterest[e]=[n];else{const i=this.regionsOfInterest[e][0];let r=0;if(i!=null&&i.startPoint!=null){const[a,s]=n.startPoint,[o,l]=n.endPoint,[u,c]=i.startPoint,[h,d]=i.endPoint,p=Math.max(a,u),f=Math.max(s,c),m=Math.min(o,h),g=Math.min(l,d),v=(m-p)*(g-f),b=(o-a)*(l-s),w=(h-u)*(d-s);r=v/(b+w-v)}this.regionsOfInterest[e][0]=r>jH?i:n}}shouldUpdateRegionsOfInterest(){return!this.regionsOfInterest||this.regionsOfInterest.length===0||this.runsWithoutHandDetector>=this.maxContinuousChecks}}VI.HandPipeline=QH});var $I=Le(nf=>{const Rr=zt(),eV=WI(),jI=BI(),tV=YI();class KI{constructor(n){this.pipeline=n}async estimateHands(n,t){this.maxContinuousChecks=t.skipFrames,this.detectionConfidence=t.minConfidence,this.maxHands=t.maxHands;const e=Rr.tidy(()=>(n instanceof Rr.Tensor||(n=Rr.browser.fromPixels(n)),n.toFloat().expandDims(0))),i=await this.pipeline.estimateHands(e,t);e.dispose();const r=[];if(!i)return r;for(const a of i){if(!a)return[];const s={};for(const o of Object.keys(jI.MESH_ANNOTATIONS))s[o]=jI.MESH_ANNOTATIONS[o].map(l=>a.landmarks[l]);r.push({confidence:a.confidence||0,box:a.box?[a.box.topLeft[0],a.box.topLeft[1],a.box.bottomRight[0]-a.box.topLeft[0],a.box.bottomRight[1]-a.box.topLeft[1]]:0,landmarks:a.landmarks,annotations:s})}return r}}nf.HandPose=KI;async function nV(n){if(Rr.env().features.IS_NODE){const t=require("fs"),e=await t.readFileSync(n.replace("file://",""));return JSON.parse(e)}return Rr.util.fetch(n).then(t=>t.json())}async function iV(n){const[t,e,i]=await Promise.all([nV(n.detector.anchors),Rr.loadGraphModel(n.detector.modelPath,{fromTFHub:n.detector.modelPath.includes("tfhub.dev")}),Rr.loadGraphModel(n.skeleton.modelPath,{fromTFHub:n.skeleton.modelPath.includes("tfhub.dev")})]),r=new eV.HandDetector(e,t,n),a=new tV.HandPipeline(r,i,n),s=new KI(a);return s}nf.load=iV});var XI=Le(rV=>{Sl(rV,{default:()=>aV});var aV={backend:"webgl",console:!0,face:{enabled:!0,detector:{modelPath:"../models/blazeface/back/model.json",inputSize:256,maxFaces:10,skipFrames:10,minConfidence:.5,iouThreshold:.3,scoreThreshold:.7},mesh:{enabled:!0,modelPath:"../models/facemesh/model.json",inputSize:192},iris:{enabled:!0,modelPath:"../models/iris/model.json",enlargeFactor:2.3,inputSize:64},age:{enabled:!0,modelPath:"../models/ssrnet-age/imdb/model.json",inputSize:64,skipFrames:10},gender:{enabled:!0,modelPath:"../models/ssrnet-gender/imdb/model.json"},emotion:{enabled:!0,inputSize:64,minConfidence:.5,skipFrames:10,useGrayscale:!0,modelPath:"../models/emotion/model.json"}},body:{enabled:!0,modelPath:"../models/posenet/model.json",inputResolution:257,outputStride:16,maxDetections:5,scoreThreshold:.7,nmsRadius:20},hand:{enabled:!0,inputSize:256,skipFrames:10,minConfidence:.5,iouThreshold:.3,scoreThreshold:.7,enlargeFactor:1.65,maxHands:2,detector:{anchors:"../models/handdetect/anchors.json",modelPath:"../models/handdetect/model.json"},skeleton:{modelPath:"../models/handskeleton/model.json"}}}});var ZI=Le((XV,JI)=>{JI.exports={name:"@vladmandic/human",version:"0.3.3",description:"human: 3D Face Detection, Iris Tracking and Age & Gender Prediction",sideEffects:!1,main:"dist/human-nobundle.cjs",module:"dist/human.esm.js",browser:"dist/human.esm.js",author:"Vladimir Mandic <mandic00@live.com>",bugs:{url:"https://github.com/vladmandic/human/issues"},homepage:"https://github.com/vladmandic/human#readme",license:"MIT",engines:{node:">=14.0.0"},repository:{type:"git",url:"git+https://github.com/vladmandic/human.git"},dependencies:{},peerDependencies:{},devDependencies:{"@tensorflow/tfjs":"^2.6.0","@tensorflow/tfjs-node":"^2.6.0",esbuild:"^0.7.15",eslint:"^7.10.0","eslint-config-airbnb-base":"^14.2.0","eslint-plugin-import":"^2.22.1","eslint-plugin-json":"^2.1.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1",rimraf:"^3.0.2"},scripts:{start:"node --trace-warnings --trace-uncaught --no-deprecation demo/demo-node.js",lint:"eslint src/*.js demo/*.js","build-iife":"esbuild --bundle --platform=browser --sourcemap --target=esnext --format=iife --minify --external:fs --global-name=human --outfile=dist/human.js src/index.js","build-esm-bundle":"esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:fs --outfile=dist/human.esm.js src/index.js","build-esm-nobundle":"esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:@tensorflow --external:fs --outfile=dist/human.esm-nobundle.js src/index.js","build-node-bundle":"esbuild --bundle --platform=node --sourcemap --target=esnext --format=cjs --minify --outfile=dist/human.cjs src/index.js","build-node-nobundle":"esbuild --bundle --platform=node --sourcemap --target=esnext --format=cjs --external:@tensorflow --outfile=dist/human-nobundle.cjs src/index.js",build:"rimraf dist/* && npm run build-iife && npm run build-esm-bundle && npm run build-esm-nobundle && npm run build-node-bundle && npm run build-node-nobundle && ls -l dist/",update:"npm update --depth 20 && npm dedupe && npm prune && npm audit"},keywords:["tensorflowjs","face-detection","face-geometry","body-tracking","hand-tracking","iris-tracking","age-estimation","emotion-detection","gender-prediction","gesture-recognition"]}});const jt=zt(),QI=eI(),bl=nI(),e2=aI(),t2=kI(),n2=$I(),i2=XI().default,sV=ZI();let Pe;const kt={facemesh:null,posenet:null,handpose:null,iris:null,age:null,gender:null,emotion:null},Kn=()=>typeof performance!="undefined"?performance.now():parseInt(Number(process.hrtime.bigint())/1e3/1e3),wl=(...n)=>{Pe.console&&console.log(...n)};function r2(...n){const t=e=>e&&typeof e=="object";return n.reduce((e,i)=>(Object.keys(i||{}).forEach(r=>{const a=e[r],s=i[r];Array.isArray(a)&&Array.isArray(s)?e[r]=a.concat(...s):t(a)&&t(s)?e[r]=r2(a,s):e[r]=s}),e),{})}function oV(n){if(!n)return"input is not defined";const t=n.naturalWidth||n.videoWidth||n.width||n.shape&&n.shape[1]>0;if(!t||t===0)return"input is empty";if(n.readyState&&n.readyState<=2)return"input is not ready";try{jt.getBackend()}catch{return"backend not loaded"}return null}async function lV(n,t){Pe=r2(i2,t);const e=oV(n);return e?(wl(e,n),{error:e}):new Promise(async i=>{const r=Object.values(kt).filter(h=>h).length;r===0&&wl("Human library starting"),jt.getBackend()!==Pe.backend&&(wl("Human library setting backend:",Pe.backend),await jt.setBackend(Pe.backend),await jt.ready());let a;jt.getBackend()==="webgl"&&(a=jt.env().get("WEBGL_PACK_DEPTHWISECONV"),jt.env().set("WEBGL_PACK_DEPTHWISECONV",!0)),Pe.face.enabled&&!kt.facemesh&&(kt.facemesh=await QI.load(Pe.face)),Pe.body.enabled&&!kt.posenet&&(kt.posenet=await t2.load(Pe.body)),Pe.hand.enabled&&!kt.handpose&&(kt.handpose=await n2.load(Pe.hand)),Pe.face.enabled&&Pe.face.age.enabled&&!kt.age&&(kt.age=await bl.loadAge(Pe)),Pe.face.enabled&&Pe.face.gender.enabled&&!kt.gender&&(kt.gender=await bl.loadGender(Pe)),Pe.face.enabled&&Pe.face.emotion.enabled&&!kt.emotion&&(kt.emotion=await e2.load(Pe));const s={};let o;o=Kn(),jt.engine().startScope();const l=Pe.body.enabled?await kt.posenet.estimatePoses(n,Pe.body):[];jt.engine().endScope(),s.body=Math.trunc(Kn()-o),o=Kn(),jt.engine().startScope();const u=Pe.hand.enabled?await kt.handpose.estimateHands(n,Pe.hand):[];jt.engine().endScope(),s.hand=Math.trunc(Kn()-o);const c=[];if(Pe.face.enabled){o=Kn(),jt.engine().startScope();const h=await kt.facemesh.estimateFaces(n,Pe.face);s.face=Math.trunc(Kn()-o);for(const d of h){if(!d.image||d.image.isDisposedInternal){wl("face object is disposed:",d.image);continue}o=Kn();const p=Pe.face.age.enabled||Pe.face.gender.enabled?await bl.predict(d.image,Pe):{};s.agegender=Math.trunc(Kn()-o),o=Kn();const f=Pe.face.emotion.enabled?await e2.predict(d.image,Pe):{};s.emotion=Math.trunc(Kn()-o),d.image.dispose();const m=d.annotations.leftEyeIris&&d.annotations.rightEyeIris?Math.max(d.annotations.leftEyeIris[3][0]-d.annotations.leftEyeIris[1][0],d.annotations.rightEyeIris[3][0]-d.annotations.rightEyeIris[1][0]):0;c.push({confidence:d.confidence,box:d.box,mesh:d.mesh,annotations:d.annotations,age:p.age,gender:p.gender,emotion:f,iris:m!==0?Math.trunc(100*11.7/m)/100:0})}jt.engine().endScope()}jt.env().set("WEBGL_PACK_DEPTHWISECONV",a),s.total=Object.values(s).reduce((h,d)=>h+d),i({face:c,body:l,hand:u,performance:s})})}exports.detect=lV;exports.defaults=i2;exports.config=Pe;exports.models=kt;exports.facemesh=QI;exports.ssrnet=bl;exports.posenet=t2;exports.handpose=n2;exports.tf=jt;exports.version=sV.version;
|
|
/*! *****************************************************************************
|
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
this file except in compliance with the License. You may obtain a copy of the
|
|
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
and limitations under the License.
|
|
***************************************************************************** */
|
|
/**
|
|
* @license
|
|
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2018 Google LLC
|
|
*
|
|
* Use of this source code is governed by an MIT-style
|
|
* license that can be found in the LICENSE file or at
|
|
* https://opensource.org/licenses/MIT.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
*
|
|
* Use of this source code is governed by an MIT-style
|
|
* license that can be found in the LICENSE file or at
|
|
* https://opensource.org/licenses/MIT.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC
|
|
*
|
|
* Use of this source code is governed by an MIT-style
|
|
* license that can be found in the LICENSE file or at
|
|
* https://opensource.org/licenses/MIT.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the License);
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an AS IS BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* =============================================================================
|
|
*/
|
|
/**
|
|
* @license
|
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* =============================================================================
|
|
*/
|
|
/** @license See the LICENSE file. */
|
|
//# sourceMappingURL=human.cjs.map
|