@magenta/music
Version:
Make music with machine learning, in the browser.
311 lines • 993 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@tensorflow/tfjs"),require("tone")):"function"==typeof define&&define.amd?define(["tf","Tone"],t):"object"==typeof exports?exports.ddsp=t(require("@tensorflow/tfjs"),require("tone")):e.ddsp=t(e.tf,e.Tone)}(self,(function(e,t){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=182)}([function(e,t,n){"use strict";n.d(t,"T",(function(){return U.b})),n.d(t,"Fb",(function(){return Se.a})),n.d(t,"Kb",(function(){return Se.b})),n.d(t,"W",(function(){return Te})),n.d(t,"Y",(function(){return Fe})),n.d(t,"Z",(function(){return V})),n.d(t,"ab",(function(){return X})),n.d(t,"bb",(function(){return Be})),n.d(t,"cb",(function(){return Je})),n.d(t,"db",(function(){return ut})),n.d(t,"eb",(function(){return ct})),n.d(t,"hb",(function(){return ht})),n.d(t,"mb",(function(){return dt})),n.d(t,"nb",(function(){return ft})),n.d(t,"ob",(function(){return pt})),n.d(t,"pb",(function(){return gt})),n.d(t,"rb",(function(){return mt})),n.d(t,"sb",(function(){return bt})),n.d(t,"tb",(function(){return vt})),n.d(t,"ub",(function(){return $t})),n.d(t,"xb",(function(){return _e})),n.d(t,"yb",(function(){return Ot})),n.d(t,"zb",(function(){return kt})),n.d(t,"Bb",(function(){return Rt})),n.d(t,"Cb",(function(){return At})),n.d(t,"Db",(function(){return Tt})),n.d(t,"Eb",(function(){return _t})),n.d(t,"Gb",(function(){return Le.a})),n.d(t,"Ib",(function(){return Nt})),n.d(t,"Mb",(function(){return Bt})),n.d(t,"Nb",(function(){return Et})),n.d(t,"Ob",(function(){return Pt})),n.d(t,"Jb",(function(){return it})),n.d(t,"ib",(function(){return $n})),n.d(t,"Hb",(function(){return On})),n.d(t,"gb",(function(){return kn})),n.d(t,"vb",(function(){return Rn})),n.d(t,"wb",(function(){return Xn.e})),n.d(t,"jb",(function(){return c.b})),n.d(t,"qb",(function(){return qn.a})),n.d(t,"kb",(function(){return r})),n.d(t,"Lb",(function(){return Re})),n.d(t,"X",(function(){return s})),n.d(t,"Ab",(function(){return o})),n.d(t,"fb",(function(){return Br})),n.d(t,"lb",(function(){return i})),n.d(t,"w",(function(){return zr.b})),n.d(t,"k",(function(){return zr.a})),n.d(t,"a",(function(){return z.a})),n.d(t,"b",(function(){return z.d})),n.d(t,"c",(function(){return z.m})),n.d(t,"d",(function(){return z.o})),n.d(t,"e",(function(){return z.r})),n.d(t,"f",(function(){return z.v})),n.d(t,"g",(function(){return z.w})),n.d(t,"h",(function(){return z.y})),n.d(t,"i",(function(){return z.z})),n.d(t,"j",(function(){return z.G})),n.d(t,"l",(function(){return z.R})),n.d(t,"m",(function(){return z.W})),n.d(t,"n",(function(){return z.X})),n.d(t,"o",(function(){return z.Y})),n.d(t,"p",(function(){return z.ab})),n.d(t,"q",(function(){return z.bb})),n.d(t,"s",(function(){return z.eb})),n.d(t,"u",(function(){return z.jb})),n.d(t,"t",(function(){return z.ib})),n.d(t,"v",(function(){return z.kb})),n.d(t,"x",(function(){return z.sb})),n.d(t,"y",(function(){return z.yb})),n.d(t,"z",(function(){return z.zb})),n.d(t,"A",(function(){return z.Cb})),n.d(t,"B",(function(){return z.Db})),n.d(t,"C",(function(){return z.Fb})),n.d(t,"D",(function(){return z.Ib})),n.d(t,"E",(function(){return z.Kb})),n.d(t,"I",(function(){return z.Pb})),n.d(t,"F",(function(){return z.Mb})),n.d(t,"G",(function(){return z.Nb})),n.d(t,"H",(function(){return z.Ob})),n.d(t,"J",(function(){return z.Xb})),n.d(t,"K",(function(){return z.bc})),n.d(t,"M",(function(){return z.jc})),n.d(t,"O",(function(){return z.qc})),n.d(t,"N",(function(){return z.oc})),n.d(t,"Q",(function(){return z.xc})),n.d(t,"P",(function(){return z.wc})),n.d(t,"R",(function(){return z.Ac})),n.d(t,"S",(function(){return z.Cc})),n.d(t,"U",(function(){return z.Gc})),n.d(t,"V",(function(){return z.Hc})),n.d(t,"r",(function(){return z.db})),n.d(t,"L",(function(){return z.hc}));var r={};n.r(r),n.d(r,"copyModel",(function(){return B})),n.d(r,"listModels",(function(){return D})),n.d(r,"moveModel",(function(){return P})),n.d(r,"removeModel",(function(){return L})),n.d(r,"browserFiles",(function(){return J})),n.d(r,"browserHTTPRequest",(function(){return ue})),n.d(r,"concatenateArrayBuffers",(function(){return l.d})),n.d(r,"decodeWeights",(function(){return l.e})),n.d(r,"encodeWeights",(function(){return l.f})),n.d(r,"fromMemory",(function(){return he})),n.d(r,"getLoadHandlers",(function(){return g})),n.d(r,"getModelArtifactsInfoForJSON",(function(){return l.g})),n.d(r,"getSaveHandlers",(function(){return p})),n.d(r,"http",(function(){return ie})),n.d(r,"isHTTPScheme",(function(){return ae})),n.d(r,"loadWeights",(function(){return ne})),n.d(r,"registerLoadRouter",(function(){return f})),n.d(r,"registerSaveRouter",(function(){return d})),n.d(r,"weightsLoaderFactory",(function(){return re})),n.d(r,"withSaveHandler",(function(){return de}));var o={};n.r(o),n.d(o,"assertParamsValid",(function(){return fe})),n.d(o,"maskToAxes",(function(){return pe})),n.d(o,"computeOutShape",(function(){return ge})),n.d(o,"stridesWithElidedDims",(function(){return me})),n.d(o,"getNormalizedAxes",(function(){return ye})),n.d(o,"startIndicesWithElidedDims",(function(){return ve})),n.d(o,"stopIndicesWithElidedDims",(function(){return we})),n.d(o,"stridesForAxis",(function(){return Ce})),n.d(o,"startForAxis",(function(){return Ie})),n.d(o,"stopForAxis",(function(){return Ee})),n.d(o,"isSliceContinous",(function(){return $e})),n.d(o,"computeFlatOffset",(function(){return Oe})),n.d(o,"parseSliceParams",(function(){return ke}));var a={};n.r(a),n.d(a,"segOpComputeOptimalWindowSize",(function(){return _r})),n.d(a,"computeOutShape",(function(){return Nr})),n.d(a,"collectGatherOpShapeInfo",(function(){return Fr}));var s={};n.r(s),n.d(s,"axesAreInnerMostDims",(function(){return Ze})),n.d(s,"combineLocations",(function(){return et})),n.d(s,"computeOutAndReduceShapes",(function(){return tt})),n.d(s,"expandShapeToKeepDim",(function(){return nt})),n.d(s,"assertAxesAreInnerMostDims",(function(){return rt})),n.d(s,"getAxesPermutation",(function(){return ot})),n.d(s,"getUndoAxesPermutation",(function(){return at})),n.d(s,"getInnerMostAxes",(function(){return st})),n.d(s,"getBroadcastDims",(function(){return jt})),n.d(s,"getReductionAxes",(function(){return Dt})),n.d(s,"assertAndGetBroadcastShape",(function(){return Lt})),n.d(s,"assertParamsConsistent",(function(){return je})),n.d(s,"computeOutShape",(function(){return De})),n.d(s,"computeDilation2DInfo",(function(){return Pe})),n.d(s,"computePool2DInfo",(function(){return Me})),n.d(s,"computePool3DInfo",(function(){return Ue})),n.d(s,"computeConv2DInfo",(function(){return Ve})),n.d(s,"computeConv3DInfo",(function(){return ze})),n.d(s,"computeDefaultPad",(function(){return We})),n.d(s,"tupleValuesAreOne",(function(){return Ke})),n.d(s,"eitherStridesOrDilationsAreOne",(function(){return Ye})),n.d(s,"convertConv2DDataFormat",(function(){return Qe})),n.d(s,"getFusedDyActivation",(function(){return Jn})),n.d(s,"getFusedBiasGradient",(function(){return Zn})),n.d(s,"applyActivation",(function(){return er})),n.d(s,"shouldFuse",(function(){return tr})),n.d(s,"PARALLELIZE_THRESHOLD",(function(){return nr})),n.d(s,"computeOptimalWindowSize",(function(){return rr})),n.d(s,"slice_util",(function(){return o})),n.d(s,"upcastType",(function(){return Se.b})),n.d(s,"getImageCenter",(function(){return or})),n.d(s,"getReshaped",(function(){return ar})),n.d(s,"getPermuted",(function(){return sr})),n.d(s,"getReshapedPermuted",(function(){return ir})),n.d(s,"getSliceBeginCoords",(function(){return ur})),n.d(s,"getSliceSize",(function(){return cr})),n.d(s,"prepareAndValidate",(function(){return lr})),n.d(s,"validateUpdateShape",(function(){return hr})),n.d(s,"validateInput",(function(){return dr})),n.d(s,"calculateShapes",(function(){return fr})),n.d(s,"SELU_SCALEALPHA",(function(){return pr})),n.d(s,"SELU_SCALE",(function(){return gr})),n.d(s,"ERF_P",(function(){return mr})),n.d(s,"ERF_A1",(function(){return br})),n.d(s,"ERF_A2",(function(){return xr})),n.d(s,"ERF_A3",(function(){return yr})),n.d(s,"ERF_A4",(function(){return vr})),n.d(s,"ERF_A5",(function(){return wr})),n.d(s,"warn",(function(){return Cr})),n.d(s,"log",(function(){return Ir})),n.d(s,"mergeRealAndImagArrays",(function(){return Er})),n.d(s,"splitRealAndImagArrays",(function(){return $r})),n.d(s,"complexWithEvenIndex",(function(){return Or})),n.d(s,"complexWithOddIndex",(function(){return kr})),n.d(s,"getComplexWithIndex",(function(){return Rr})),n.d(s,"assignToTypedArray",(function(){return Sr})),n.d(s,"exponents",(function(){return Ar})),n.d(s,"exponent",(function(){return Tr})),n.d(s,"prepareSplitSize",(function(){return St})),n.d(s,"segment_util",(function(){return a})),n.d(s,"castTensor",(function(){return jr})),n.d(s,"reshapeTensor",(function(){return Dr})),n.d(s,"linspaceImpl",(function(){return Lr}));var i={};n.r(i),n.d(i,"nonMaxSuppressionV3Impl",(function(){return nn})),n.d(i,"nonMaxSuppressionV4Impl",(function(){return rn})),n.d(i,"nonMaxSuppressionV5Impl",(function(){return on})),n.d(i,"split",(function(){return Pr})),n.d(i,"tile",(function(){return Mr})),n.d(i,"topkImpl",(function(){return Ur})),n.d(i,"whereImpl",(function(){return Vr}));var u=n(6),c=(n(38),n(11)),l=n(17);
/**
* @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.
* =============================================================================
*/
class h{constructor(){this.saveRouters=[],this.loadRouters=[]}static getInstance(){return null==h.instance&&(h.instance=new h),h.instance}static registerSaveRouter(e){h.getInstance().saveRouters.push(e)}static registerLoadRouter(e){h.getInstance().loadRouters.push(e)}static getSaveHandlers(e){return h.getHandlers(e,"save")}static getLoadHandlers(e,t){return h.getHandlers(e,"load",t)}static getHandlers(e,t,n){const r=[];return("load"===t?h.getInstance().loadRouters:h.getInstance().saveRouters).forEach(t=>{const o=t(e,n);null!==o&&r.push(o)}),r}}const d=e=>h.registerSaveRouter(e),f=e=>h.registerLoadRouter(e),p=e=>h.getSaveHandlers(e),g=(e,t)=>h.getLoadHandlers(e,t)
/**
* @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.
* =============================================================================
*/;function m(){if(!Object(c.b)().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");const e="undefined"==typeof window?self:window,t=e.indexedDB||e.mozIndexedDB||e.webkitIndexedDB||e.msIndexedDB||e.shimIndexedDB;if(null==t)throw new Error("The current browser does not appear to support IndexedDB.");return t}function b(e){const t=e.result;t.createObjectStore("models_store",{keyPath:"modelPath"}),t.createObjectStore("model_info_store",{keyPath:"modelPath"})}class x{constructor(e){if(this.indexedDB=m(),null==e||!e)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=e}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return this.databaseAction(this.modelPath,e)}async load(){return this.databaseAction(this.modelPath)}databaseAction(e,t){return new Promise((e,n)=>{const r=this.indexedDB.open("tensorflowjs",1);r.onupgradeneeded=()=>b(r),r.onsuccess=()=>{const o=r.result;if(null==t){const t=o.transaction("models_store","readonly"),r=t.objectStore("models_store").get(this.modelPath);r.onsuccess=()=>{if(null==r.result)return o.close(),n(new Error(`Cannot find model with path '${this.modelPath}' in IndexedDB.`));e(r.result.modelArtifacts)},r.onerror=e=>(o.close(),n(r.error)),t.oncomplete=()=>o.close()}else{const r=Object(l.g)(t),a=o.transaction("model_info_store","readwrite");let s=a.objectStore("model_info_store");const i=s.put({modelPath:this.modelPath,modelArtifactsInfo:r});let u;i.onsuccess=()=>{u=o.transaction("models_store","readwrite");const i=u.objectStore("models_store").put({modelPath:this.modelPath,modelArtifacts:t,modelArtifactsInfo:r});i.onsuccess=()=>e({modelArtifactsInfo:r}),i.onerror=e=>{s=a.objectStore("model_info_store");const t=s.delete(this.modelPath);t.onsuccess=()=>(o.close(),n(i.error)),t.onerror=e=>(o.close(),n(i.error))}},i.onerror=e=>(o.close(),n(i.error)),a.oncomplete=()=>{null==u?o.close():u.oncomplete=()=>o.close()}}},r.onerror=e=>n(r.error)})}}x.URL_SCHEME="indexeddb://";const y=e=>{return Object(c.b)().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(x.URL_SCHEME)?(t=e.slice(x.URL_SCHEME.length),new x(t)):null;var t};h.registerSaveRouter(y),h.registerLoadRouter(y);class v{constructor(){this.indexedDB=m()}async listModels(){return new Promise((e,t)=>{const n=this.indexedDB.open("tensorflowjs",1);n.onupgradeneeded=()=>b(n),n.onsuccess=()=>{const r=n.result,o=r.transaction("model_info_store","readonly"),a=o.objectStore("model_info_store").getAll();a.onsuccess=()=>{const t={};for(const e of a.result)t[e.modelPath]=e.modelArtifactsInfo;e(t)},a.onerror=e=>(r.close(),t(a.error)),o.oncomplete=()=>r.close()},n.onerror=e=>t(n.error)})}async removeModel(e){var t;return e=(t=e).startsWith(x.URL_SCHEME)?t.slice(x.URL_SCHEME.length):t,new Promise((t,n)=>{const r=this.indexedDB.open("tensorflowjs",1);r.onupgradeneeded=()=>b(r),r.onsuccess=()=>{const o=r.result,a=o.transaction("model_info_store","readwrite"),s=a.objectStore("model_info_store"),i=s.get(e);let u;i.onsuccess=()=>{if(null==i.result)return o.close(),n(new Error(`Cannot find model with path '${e}' in IndexedDB.`));{const r=s.delete(e),a=()=>{u=o.transaction("models_store","readwrite");const r=u.objectStore("models_store").delete(e);r.onsuccess=()=>t(i.result.modelArtifactsInfo),r.onerror=e=>n(i.error)};r.onsuccess=a,r.onerror=e=>(a(),o.close(),n(i.error))}},i.onerror=e=>(o.close(),n(i.error)),a.oncomplete=()=>{null==u?o.close():u.oncomplete=()=>o.close()}},r.onerror=e=>n(r.error)})}}var w=n(16);
/**
* @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.
* =============================================================================
*/const C="tensorflowjs_models",I="info",E="model_topology",$="weight_specs",O="weight_data",k="model_metadata";function R(e){return{info:[C,e,I].join("/"),topology:[C,e,E].join("/"),weightSpecs:[C,e,$].join("/"),weightData:[C,e,O].join("/"),modelMetadata:[C,e,k].join("/")}}function S(e){const t=e.split("/");if(t.length<3)throw new Error("Invalid key format: "+e);return t.slice(1,t.length-1).join("/")}class A{constructor(e){if(!Object(c.b)().getBool("IS_BROWSER")||"undefined"==typeof window||void 0===window.localStorage)throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,null==e||!e)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=e,this.keys=R(this.modelPath)}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");{const t=JSON.stringify(e.modelTopology),n=JSON.stringify(e.weightSpecs),r=Object(l.g)(e);try{return this.LS.setItem(this.keys.info,JSON.stringify(r)),this.LS.setItem(this.keys.topology,t),this.LS.setItem(this.keys.weightSpecs,n),this.LS.setItem(this.keys.weightData,Object(l.a)(e.weightData)),this.LS.setItem(this.keys.modelMetadata,JSON.stringify({format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,userDefinedMetadata:e.userDefinedMetadata})),{modelArtifactsInfo:r}}catch(e){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}.`)}}}async load(){const e=JSON.parse(this.LS.getItem(this.keys.info));if(null==e)throw new Error(`In local storage, there is no model with name '${this.modelPath}'`);if("JSON"!==e.modelTopologyType)throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");const t={},n=JSON.parse(this.LS.getItem(this.keys.topology));if(null==n)throw new Error(`In local storage, the topology of model '${this.modelPath}' is missing.`);t.modelTopology=n;const r=JSON.parse(this.LS.getItem(this.keys.weightSpecs));if(null==r)throw new Error(`In local storage, the weight specs of model '${this.modelPath}' are missing.`);t.weightSpecs=r;const o=this.LS.getItem(this.keys.modelMetadata);if(null!=o){const e=JSON.parse(o);t.format=e.format,t.generatedBy=e.generatedBy,t.convertedBy=e.convertedBy,t.userDefinedMetadata=e.userDefinedMetadata}const a=this.LS.getItem(this.keys.weightData);if(null==a)throw new Error(`In local storage, the binary weight values of model '${this.modelPath}' are missing.`);return t.weightData=Object(l.b)(a),t}}A.URL_SCHEME="localstorage://";const T=e=>{return Object(c.b)().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(A.URL_SCHEME)?(t=e.slice(A.URL_SCHEME.length),new A(t)):null;var t};h.registerSaveRouter(T),h.registerLoadRouter(T);class _{constructor(){Object(w.b)(Object(c.b)().getBool("IS_BROWSER"),()=>"Current environment is not a web browser"),Object(w.b)("undefined"==typeof window||void 0!==window.localStorage,()=>"Current browser does not appear to support localStorage"),this.LS=window.localStorage}async listModels(){const e={},t=C+"/",n="/"+I;for(let r=0;r<this.LS.length;++r){const o=this.LS.key(r);if(o.startsWith(t)&&o.endsWith(n)){e[S(o)]=JSON.parse(this.LS.getItem(o))}}return e}async removeModel(e){var t;const n=R(e=(t=e).startsWith(A.URL_SCHEME)?t.slice(A.URL_SCHEME.length):t);if(null==this.LS.getItem(n.info))throw new Error(`Cannot find model at path '${e}'`);const r=JSON.parse(this.LS.getItem(n.info));return this.LS.removeItem(n.info),this.LS.removeItem(n.topology),this.LS.removeItem(n.weightSpecs),this.LS.removeItem(n.weightData),r}}
/**
* @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.
* =============================================================================
*/class N{constructor(){this.managers={}}static getInstance(){return null==N.instance&&(N.instance=new N),N.instance}static registerManager(e,t){Object(w.b)(null!=e,()=>"scheme must not be undefined or null."),e.endsWith("://")&&(e=e.slice(0,e.indexOf("://"))),Object(w.b)(e.length>0,()=>"scheme must not be an empty string.");const n=N.getInstance();Object(w.b)(null==n.managers[e],()=>`A model store manager is already registered for scheme '${e}'.`),n.managers[e]=t}static getManager(e){const t=this.getInstance().managers[e];if(null==t)throw new Error(`Cannot find model manager for scheme '${e}'`);return t}static getSchemes(){return Object.keys(this.getInstance().managers)}}function F(e){if(-1===e.indexOf("://"))throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+N.getSchemes().join(","));return{scheme:e.split("://")[0],path:e.split("://")[1]}}async function j(e,t,n=!1){Object(w.b)(e!==t,()=>`Old path and new path are the same: '${e}'`);const r=h.getLoadHandlers(e);Object(w.b)(r.length>0,()=>`Copying failed because no load handler is found for source URL ${e}.`),Object(w.b)(r.length<2,()=>`Copying failed because more than one (${r.length}) load handlers for source URL ${e}.`);const o=r[0],a=h.getSaveHandlers(t);Object(w.b)(a.length>0,()=>`Copying failed because no save handler is found for destination URL ${t}.`),Object(w.b)(a.length<2,()=>`Copying failed because more than one (${r.length}) save handlers for destination URL ${t}.`);const s=a[0],i=F(e).scheme,u=F(e).path,c=i===F(e).scheme,l=await o.load();n&&c&&await N.getManager(i).removeModel(u);const d=await s.save(l);return n&&!c&&await N.getManager(i).removeModel(u),d.modelArtifactsInfo}async function D(){const e=N.getSchemes(),t={};for(const n of e){const e=await N.getManager(n).listModels();for(const r in e){t[n+"://"+r]=e[r]}}return t}async function L(e){const t=F(e);return N.getManager(t.scheme).removeModel(t.path)}async function B(e,t){return j(e,t,!1)}async function P(e,t){return j(e,t,!0)}
/**
* @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.
* =============================================================================
*/class M{fetch(e,t){return fetch(e,t)}now(){return performance.now()}encode(e,t){if("utf-8"!==t&&"utf8"!==t)throw new Error("Browser's encoder only supports utf-8, but got "+t);return null==this.textEncoder&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(e)}decode(e,t){return new TextDecoder(t).decode(e)}}if(Object(c.b)().get("IS_BROWSER")){Object(c.b)().setPlatform("browser",new M);try{N.registerManager(A.URL_SCHEME,new _)}catch(e){}try{N.registerManager(x.URL_SCHEME,new v)}catch(e){}}n(159);var U=n(5);
/**
* @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.
* =============================================================================
*/
function V(e,t="float32",n){return t=t||"float32",w.c(e),new U.b(e,t,n)}var z=n(1),W=n(3),G=n(4);const X=Object(G.a)({cast_:
/**
* @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.
* =============================================================================
*/
function(e,t){const n=Object(W.a)(e,"x","cast");if(!w.B(t))throw new Error("Failed to cast to unknown dtype "+t);if("string"===t&&"string"!==n.dtype||"string"!==t&&"string"===n.dtype)throw new Error("Only strings can be casted to strings");const r={x:n},o={dtype:t};return u.a.runKernelFunc(e=>e.cast(n,t),r,null,z.v,o)}});
/**
* @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.
* =============================================================================
*/const q=Object(G.a)({clone_:function(e){const t=Object(W.a)(e,"x","clone",null),n={x:t};return u.a.runKernelFunc(()=>u.a.makeTensorFromDataId(t.dataId,t.shape,t.dtype),n,null,z.jb)}});
/**
* @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 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.
* =============================================================================
*/
Object(u.b)();const H={buffer:V,cast:X,clone:q,print:function(e,t=!1){console.log(e.toString(t))}};Object(U.e)(H);function K(e){return new Promise(e=>setTimeout(e)).then(e)}class Y{constructor(e){if(!Object(c.b)().getBool("IS_BROWSER"))throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");e.startsWith(Y.URL_SCHEME)&&(e=e.slice(Y.URL_SCHEME.length)),null!=e&&0!==e.length||(e="model"),this.modelTopologyFileName=e+".json",this.weightDataFileName=e+".weights.bin"}async save(e){if("undefined"==typeof document)throw new Error("Browser downloads are not supported in this environment since `document` is not present");const t=window.URL.createObjectURL(new Blob([e.weightData],{type:"application/octet-stream"}));if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");{const n=[{paths:["./"+this.weightDataFileName],weights:e.weightSpecs}],r={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,weightsManifest:n},o=window.URL.createObjectURL(new Blob([JSON.stringify(r)],{type:"application/json"})),a=null==this.jsonAnchor?document.createElement("a"):this.jsonAnchor;if(a.download=this.modelTopologyFileName,a.href=o,await K(()=>a.dispatchEvent(new MouseEvent("click"))),null!=e.weightData){const e=null==this.weightDataAnchor?document.createElement("a"):this.weightDataAnchor;e.download=this.weightDataFileName,e.href=t,await K(()=>e.dispatchEvent(new MouseEvent("click")))}return{modelArtifactsInfo:Object(l.g)(e)}}}}Y.URL_SCHEME="downloads://";class Q{constructor(e){if(null==e||e.length<1)throw new Error("When calling browserFiles, at least 1 file is required, but received "+e);this.files=e}async load(){const e=this.files[0],t=this.files.slice(1);return new Promise((n,r)=>{const o=new FileReader;o.onload=o=>{const a=JSON.parse(o.target.result),s=a.modelTopology;if(null==s)return void r(new Error("modelTopology field is missing from file "+e.name));0===t.length&&n({modelTopology:s});const i=a.weightsManifest;if(null==i)return void r(new Error("weightManifest field is missing from file "+e.name));let u;try{u=this.checkManifestAndWeightFiles(i,t)}catch(e){return void r(e)}const c=[],h=[],d=[];i.forEach(e=>{e.paths.forEach(e=>{h.push(e),d.push(null)}),c.push(...e.weights)}),i.forEach(e=>{e.paths.forEach(e=>{const t=new FileReader;t.onload=t=>{const r=t.target.result,o=h.indexOf(e);d[o]=r,-1===d.indexOf(null)&&n({modelTopology:s,weightSpecs:c,weightData:Object(l.d)(d),format:a.format,generatedBy:a.generatedBy,convertedBy:a.convertedBy,userDefinedMetadata:a.userDefinedMetadata})},t.onerror=t=>r(`Failed to weights data from file of path '${e}'.`),t.readAsArrayBuffer(u[e])})})},o.onerror=t=>r(`Failed to read model topology and weights manifest JSON from file '${e.name}'. BrowserFiles supports loading Keras-style tf.Model artifacts only.`),o.readAsText(e)})}checkManifestAndWeightFiles(e,t){const n=[],r=t.map(e=>Object(l.c)(e.name)),o={};for(const a of e)a.paths.forEach(e=>{const a=Object(l.c)(e);if(-1!==n.indexOf(a))throw new Error(`Duplicate file basename found in weights manifest: '${a}'`);if(n.push(a),-1===r.indexOf(a))throw new Error(`Weight file with basename '${a}' is not provided.`);o[e]=t[r.indexOf(a)]});if(n.length!==t.length)throw new Error(`Mismatch in the number of files in weights manifest (${n.length}) and the number of weight files provided (${t.length}).`);return o}}function J(e){return new Q(e)}
/**
* @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.
* =============================================================================
*/function Z(e,t,n,r){!function(e){Object(w.b)(null!=e&&Array.isArray(e)&&e.length>0,()=>"promises must be a none empty array")}(e),function(e,t){Object(w.b)(e>=0&&e<=1,()=>"Progress fraction must be in range [0, 1], but got startFraction "+e),Object(w.b)(t>=0&&t<=1,()=>"Progress fraction must be in range [0, 1], but got endFraction "+t),Object(w.b)(t>=e,()=>`startFraction must be no more than endFraction, but got startFraction ${e} and endFraction `+t)}(n=null==n?0:n,r=null==r?1:r);let o=0;return Promise.all(e.map(a=>(a.then(a=>{const s=n+ ++o/e.length*(r-n);return t(s),a}),a)))}h.registerSaveRouter(e=>Object(c.b)().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(Y.URL_SCHEME)?function(e="model"){return new Y(e)}(e.slice(Y.URL_SCHEME.length)):null);var ee=n(41);
/**
* @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.
* =============================================================================
*/async function te(e,t){null==t&&(t={});const n=null==t.fetchFunc?Object(c.b)().platform.fetch:t.fetchFunc,r=e.map(e=>n(e,t.requestInit,{isBinary:!0})),o=(null==t.onProgress?await Promise.all(r):await Z(r,t.onProgress,0,.5)).map(e=>e.arrayBuffer());return null==t.onProgress?await Promise.all(o):await Z(o,t.onProgress,.5,1)}async function ne(e,t="",n,r){return re(e=>te(e,{requestInit:r}))(e,t,n)}function re(e){return async(t,n="",r)=>{const o=t.map(()=>!1),a={},s=null!=r?r.map(()=>!1):[],i=[];if(t.forEach((e,t)=>{let n=0;e.weights.forEach(e=>{const u="quantization"in e?e.quantization.dtype:e.dtype,c=ee.a[u]*w.N(e.shape),l=()=>{o[t]=!0,null==a[t]&&(a[t]=[]),a[t].push({manifestEntry:e,groupOffset:n,sizeBytes:c})};null!=r?r.forEach((t,n)=>{t===e.name&&(l(),s[n]=!0)}):l(),i.push(e.name),n+=c})}),!s.every(e=>e)){const e=r.filter((e,t)=>!s[t]);throw new Error("Could not find weights in manifest with names: "+e.join(", ")+". \nManifest JSON has weights with names: "+i.join(", ")+".")}const u=o.reduce((e,t,n)=>(t&&e.push(n),e),[]),c=[];u.forEach(e=>{t[e].paths.forEach(e=>{const t=n+(n.endsWith("/")?"":"/")+e;c.push(t)})});const h=await e(c),d={};let f=0;return u.forEach(e=>{const n=t[e].paths.length;let r=0;for(let e=0;e<n;e++)r+=h[f+e].byteLength;const o=new ArrayBuffer(r),s=new Uint8Array(o);let i=0;for(let e=0;e<n;e++){const t=new Uint8Array(h[f+e]);s.set(t,i),i+=t.byteLength}a[e].forEach(e=>{const t=o.slice(e.groupOffset,e.groupOffset+e.sizeBytes),n=Object(l.e)(t,[e.manifestEntry]);for(const e in n)d[e]=n[e]}),f+=n}),d}}
/**
* @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.
* =============================================================================
*/class oe{constructor(e,t){if(this.DEFAULT_METHOD="POST",null==t&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,null!=t.fetchFunc?(Object(w.b)("function"==typeof t.fetchFunc,()=>"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=t.fetchFunc):this.fetch=Object(c.b)().platform.fetch,Object(w.b)(null!=e&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&Object(w.b)(2===e.length,()=>`URL paths for http must have a length of 2, (actual length is ${e.length}).`),this.path=e,null!=t.requestInit&&null!=t.requestInit.body)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");const t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;const n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],r={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,userDefinedMetadata:e.userDefinedMetadata,weightsManifest:n};t.body.append("model.json",new Blob([JSON.stringify(r)],{type:"application/json"}),"model.json"),null!=e.weightData&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:"application/octet-stream"}),"model.weights.bin");const o=await this.fetch(this.path,t);if(o.ok)return{modelArtifactsInfo:Object(l.g)(e),responses:[o]};throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+o.status+".")}async load(){const e=await this.fetch(this.path,this.requestInit);if(!e.ok)throw new Error(`Request to ${this.path} failed with status code `+e.status+". Please verify this URL points to the model JSON of the model to load.");let t;try{t=await e.json()}catch(e){let t=`Failed to parse model JSON of response from ${this.path}.`;throw this.path.endsWith(".pb")?t+=" 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.":t+=" Please make sure the server is serving valid JSON for this request.",new Error(t)}const n=t.modelTopology,r=t.weightsManifest,o=t.generatedBy,a=t.convertedBy,s=t.format,i=t.userDefinedMetadata;if(null==n&&null==r)throw new Error(`The JSON from HTTP path ${this.path} contains neither model topology or manifest for weights.`);let u,c;if(null!=r){const e=await this.loadWeights(r);[u,c]=e}const l={modelTopology:n,weightSpecs:u,weightData:c,userDefinedMetadata:i,generatedBy:o,convertedBy:a,format:s},h=t.modelInitializer;return h&&(l.modelInitializer=h),l}async loadWeights(e){const t=Array.isArray(this.path)?this.path[1]:this.path,[n,r]=function(e){const t=e.lastIndexOf("/"),n=e.lastIndexOf("?"),r=e.substring(0,t),o=n>t?e.substring(n):"";return[r+"/",o]}(t),o=this.weightPathPrefix||n,a=[];for(const t of e)a.push(...t.weights);const s=[],i=[];for(const t of e)for(const e of t.paths)null!=this.weightUrlConverter?i.push(this.weightUrlConverter(e)):s.push(o+e+r);this.weightUrlConverter&&s.push(...await Promise.all(i));const u=await te(s,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[a,Object(l.d)(u)]}}function ae(e){return null!=e.match(oe.URL_SCHEME_REGEX)}oe.URL_SCHEME_REGEX=/^https?:\/\//;const se=(e,t)=>{if("undefined"==typeof fetch&&(null==t||null==t.fetchFunc))return null;{let n=!0;if(n=Array.isArray(e)?e.every(e=>ae(e)):ae(e),n)return ie(e,t)}return null};function ie(e,t){return new oe(e,t)}function ue(e,t){return ie(e,t)}
/**
* @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.
* =============================================================================
*/h.registerSaveRouter(se),h.registerLoadRouter(se);class ce{constructor(e){this.modelArtifacts=e}async load(){return this.modelArtifacts}}class le{constructor(e){this.saveHandler=e}async save(e){return this.saveHandler(e)}}function he(e,t,n,r){if(1===arguments.length){return null!=e.modelTopology||null!=e.weightSpecs?new ce(e):(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 ce({modelTopology:e}))}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 ce({modelTopology:e,weightSpecs:t,weightData:n,trainingConfig:r})}function de(e){return new le(e)}
/**
* @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 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.
* =============================================================================
*/function fe(e,t,n){const r=e.shape.length;w.b(r===t.length,()=>`Error in slice${r}D: Length of begin ${t} must match the rank of the array (${r}).`),w.b(r===n.length,()=>`Error in slice${r}D: Length of size ${n} must match the rank of the array (${r}).`);for(let o=0;o<r;++o)w.b(t[o]+n[o]<=e.shape[o],()=>`Error in slice${r}D: begin[${o}] + size[${o}] (${t[o]+n[o]}) would overflow input.shape[${o}] (${e.shape[o]})`)}function pe(e){const t=[];let n=0;for(;e>0;)1&e&&t.push(n),e/=2,n++;return t}function ge(e,t,n){const r=[];for(let o=0;o<e.length;o++)r[o]=Math.ceil((t[o]-e[o])/n[o]);return r}function me(e,t,n,r){const o=[...e];for(let e=o.length;e<r.length;e++)o.push(1);for(let e=0;e<n;e++)0===e?o[t]=1:(o.splice(t,0,1),o.pop());return o}function be(e,t,n){return n<=e?n:n-(t-1)}function xe(e,t){const n=[];for(let r=0;r<e;r++)n.push(t+r);return n}function ye(e,t,n,r,o,a,s,i,u){const c=e.length;let l=new Array(c),h=new Array(c),d=new Array(c);if(t.length&&n>0){const u=t[0],c=n+1;l=ve(s,u,c,r,e),h=we(i,u,c,o,e),d=me(a,u,c,e)}else for(let t=0;t<c;t++)l[t]=Ie(s,r,a,e,t,u),h[t]=Ee(i,o,a,e,t,u),d[t]=Ce(a,t,u);return{begin:l,end:h,strides:d}}function ve(e,t,n,r,o){const a=[...o],s=xe(n,t);for(let o=0;o<a.length;o++)if(s.indexOf(o)>-1)a[o]=0;else{const s=be(t,n,o);let i=r[s];e&1<<s&&(i=0),a[o]=i}return a}function we(e,t,n,r,o){const a=[...o],s=xe(n,t);for(let o=0;o<a.length;o++)if(s.indexOf(o)>-1)a[o]=Number.MAX_SAFE_INTEGER;else{const s=be(t,n,o);let i=r[s];e&1<<s&&(i=Number.MAX_SAFE_INTEGER),a[o]=i}for(let e=0;e<a.length;e++){const t=o[e];a[e]<0&&(a[e]+=t),a[e]=w.i(0,a[e],o[e])}return a}function Ce(e,t,n){let r=e[t];return(n&1<<t||null==r)&&(r=1),r}function Ie(e,t,n,r,o,a){let s=t[o];const i=n[o]||1;(e&1<<o||a&1<<o||null==s)&&(s=i>0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);const u=r[o];return s<0&&(s+=u),s=w.i(0,s,u-1),s}function Ee(e,t,n,r,o,a){let s=t[o];const i=n[o]||1;(e&1<<o||a&1<<o||null==s)&&(s=i>0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);const u=r[o];return s<0&&(s+=u),s=i>0?w.i(0,s,u):w.i(-1,s,u-1),s}function $e(e,t,n){let r=n.length;for(let e=0;e<n.length;e++)if(n[e]>1){r=e;break}for(let o=r+1;o<n.length;o++)if(t[o]>0||n[o]!==e[o])return!1;return!0}function Oe(e,t){let n=e.length>0?e[e.length-1]:1;for(let r=0;r<e.length-1;r++)n+=e[r]*t[r];return n}function ke(e,t,n){let r;const o=e.shape.length;let a;return r="number"==typeof t?[t,...new Array(o-1).fill(0)]:t.length<o?t.concat(new Array(o-t.length).fill(0)):t.slice(),r.forEach(e=>{w.b(-1!==e,()=>"slice() does not support negative begin indexing.")}),a=null==n?new Array(o).fill(-1):"number"==typeof n?[n,...new Array(o-1).fill(-1)]:n.length<o?n.concat(new Array(o-n.length).fill(-1)):n,a=a.map((t,n)=>t>=0?t:(w.b(-1===t,()=>`Negative size values should be exactly -1 but got ${t} for the slice() size at index ${n}.`),e.shape[n]-r[n])),[r,a]}var Re=n(7),Se=n(27),Ae=n(14);const Te=Object(G.a)({add_:
/**
* @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.
* =============================================================================
*/
function(e,t){let n=Object(W.a)(e,"a","add"),r=Object(W.a)(t,"b","add");[n,r]=Object(Ae.b)(n,r);const o={a:n,b:r};return u.a.runKernelFunc((e,t)=>{const o=e.add(n,r);return t([n,r]),o},o,null,z.d)}});
/**
* @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.
* =============================================================================
*/const _e=Object(G.a)({reshape_:function(e,t){const n=Object(W.a)(e,"x","reshape",null),r={x:n},o={shape:t};return u.a.runKernelFunc((e,r)=>(t=w.s(t,n.size),w.b(n.size===w.N(t),()=>"new shape and old shape must have the same number of elements."),r([n]),e.reshape(n,t)),r,null,z.bc,o)}});function Ne(e){return null==e?null:0===e.rank?_e(e,[e.size]):1===e.rank?e:2===e.rank?_e(e,[1,1,e.shape[0],e.shape[1]]):3===e.rank?_e(e,[1,e.shape[0],e.shape[1],e.shape[2]]):e}const Fe=Object(G.a)({batchNorm_:
/**
* @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.
* =============================================================================
*/
function(e,t,n,r,o,a){null==a&&(a=.001);const s=Object(W.a)(e,"x","batchNorm"),i=Object(W.a)(t,"mean","batchNorm"),c=Object(W.a)(n,"variance","batchNorm");let l,h;null!=o&&(l=Object(W.a)(o,"scale","batchNorm")),null!=r&&(h=Object(W.a)(r,"offset","batchNorm")),w.b(i.rank===c.rank,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),w.b(null==h||i.rank===h.rank,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),w.b(null==l||i.rank===l.rank,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");const d=function(e){let t;return t=0===e.rank||1===e.rank?_e(e,[1,1,1,e.size]):2===e.rank?_e(e,[1,1,e.shape[0],e.shape[1]]):3===e.rank?_e(e,[1,e.shape[0],e.shape[1],e.shape[2]]):e,t}(s),f={x:d,scale:l,offset