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 Cb(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(wn(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;v1?zh(r,[1,a]):r}):i.cell.stateSize>1?[zh(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}),Kt({},r,e,i)},t.fromConfig=function(e,i,r){r===void 0&&(r={});var a=i.cell,s=Ln(a,r);return new e(Object.assign(i,{cell:s}))},t.className="RNN",t}(De);y.serialization.registerClass(Oi);var aa=function(n){Q(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t}(De),vd=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,At(i.units,"units"),i.activation=Ri(e.activation==null?i.DEFAULT_ACTIVATION:e.activation),i.useBias=e.useBias==null?!0:e.useBias,i.kernelInitializer=et(e.kernelInitializer||i.DEFAULT_KERNEL_INITIALIZER),i.recurrentInitializer=et(e.recurrentInitializer||i.DEFAULT_RECURRENT_INITIALIZER),i.biasInitializer=et(e.biasInitializer||i.DEFAULT_BIAS_INITIALIZER),i.kernelRegularizer=tt(e.kernelRegularizer),i.recurrentRegularizer=tt(e.recurrentRegularizer),i.biasRegularizer=tt(e.biasRegularizer),i.kernelConstraint=bt(e.kernelConstraint),i.recurrentConstraint=bt(e.recurrentConstraint),i.biasConstraint=bt(e.biasConstraint),i.dropout=ea([1,Ti([0,e.dropout==null?0:e.dropout])]),i.recurrentDropout=ea([1,Ti([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=Ye(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;01){for(var s=[0],o=2;o1)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;l1){var S=wn(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(wn(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;r1)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 _h(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);s3||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;li){s=r-i;for(var o=[],l=0;l0){var d=void 0;i>r?d=i+r-3:d=i-1;for(var p=[],l=d;l3||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 os(s,e[o].shape.length)}):a=[os(this.axes,i.shape.length),os(this.axes,r.shape.length)],this.normalize&&(i=Ro(i,a[0]),r=Ro(r,a[1])),Z4(i,r,a)},t.prototype.interpretAxes=function(e,i){var r;return Array.isArray(this.axes)?r=this.axes:r=[os(this.axes,e.length),os(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}(pr);y.serialization.registerClass(jb);var $b=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 Io(a.shape,0,r.stddev).add(a)},o=ts(s,function(){return a},i.training||!1);return o})},t.className="GaussianNoise",t}(De);y.serialization.registerClass($b);var Xb=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(Io(a.shape,1,o))};return ts(s,function(){return a},i.training||!1)}return a})},t.className="GaussianDropout",t}(De);y.serialization.registerClass(Xb);var Jb=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=Za(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 ts(s,function(){return xe(e)},i.training||!1)}return e})},t.className="AlphaDropout",t}(De);y.serialization.registerClass(Jb);function ls(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 Q4(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=ls(n,s,o,e,t,r);return[l,s,o]})}function eF(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=wn(0,n.rank);u=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 Tt({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=wn(0,l),c=r.axis>=0?r.axis:r.axis+l;u.splice(c,1);var h=or(1,l);h[c]=o[c];var d=u.slice();d.sort();var p=!y.util.arraysEqual(d,wn(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 ls(s,L,N,C,R,r.epsilon)}else return ls(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=tF(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:at(this.betaInitializer),gammaInitializer:at(this.gammaInitializer),movingMeanInitializer:at(this.movingMeanInitializer),movingVarianceInitializer:at(this.movingVarianceInitializer),betaRegularizer:Ke(this.betaRegularizer),gammaRegularizer:Ke(this.gammaRegularizer),betaConstraint:yt(this.betaConstraint),gammaConstraint:yt(this.gammaConstraint)},i=n.prototype.getConfig.call(this);return Object.assign(e,i),e},t.className="BatchNormalization",t}(De);y.serialization.registerClass(Zb);var Qb=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=i)throw new Error("Invalid axis: "+o)}if(this.axis.length!==Ii(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=or(1,o),p=0,f=r.axis;p=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 nF(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(ew);function Mo(n,t,e,i,r,a){return y.tidy(function(){ct(r),cy(a),rn(i),e==null&&(e=[1,1]),i==null&&(i="valid"),r==null&&(r=bn()),a==null&&(a="max"),n=fd(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 tw(n,t,e,i,r,a){return y.tidy(function(){ct(r),cy(a),rn(i),e==null&&(e=[1,1,1]),i==null&&(i="valid"),r==null&&(r=bn()),a==null&&(a="max"),n=vb(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 nw=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(At(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 At(i.strides,"strides"),i.padding=e.padding==null?"valid":e.padding,rn(i.padding),i.inputSpec=[new Tt({ndim:3})],i}return t.prototype.computeOutputShape=function(e){e=Ye(e);var i=In(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=Qa(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),iw=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 ct(s),rn(a),Mo(e,i,r,a,s,"max")},t.className="MaxPooling1D",t}(nw);y.serialization.registerClass(iw);var rw=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 ct(s),rn(a),Mo(e,i,r,a,s,"avg")},t.className="AveragePooling1D",t}(nw);y.serialization.registerClass(rw);var aw=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 At(i.poolSize,"poolSize"),At(i.strides,"strides"),i.padding=e.padding==null?"valid":e.padding,i.dataFormat=e.dataFormat==null?"channelsLast":e.dataFormat,ct(i.dataFormat),rn(i.padding),i.inputSpec=[new Tt({ndim:4})],i}return t.prototype.computeOutputShape=function(e){e=Ye(e);var i=this.dataFormat==="channelsFirst"?e[2]:e[1],r=this.dataFormat==="channelsFirst"?e[3]:e[2];return i=In(i,this.poolSize[0],this.padding,this.strides[0]),r=In(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),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 ct(s),rn(a),Mo(e,i,r,a,s,"max")},t.className="MaxPooling2D",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 ct(s),rn(a),Mo(e,i,r,a,s,"avg")},t.className="AveragePooling2D",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,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 At(i.poolSize,"poolSize"),At(i.strides,"strides"),i.padding=e.padding==null?"valid":e.padding,i.dataFormat=e.dataFormat==null?"channelsLast":e.dataFormat,ct(i.dataFormat),rn(i.padding),i.inputSpec=[new Tt({ndim:5})],i}return t.prototype.computeOutputShape=function(e){e=Ye(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=In(i,this.poolSize[0],this.padding,this.strides[0]),r=In(r,this.poolSize[1],this.padding,this.strides[1]),a=In(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),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 ct(s),rn(a),tw(e,i,r,a,s,"max")},t.className="MaxPooling3D",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 ct(s),rn(a),tw(e,i,r,a,s,"avg")},t.className="AveragePooling3D",t}(lw);y.serialization.registerClass(cw);var hw=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.inputSpec=[new Tt({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),dw=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}(hw);y.serialization.registerClass(dw);var pw=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}(hw);y.serialization.registerClass(pw);var fw=function(n){Q(t,n);function t(e){var i=n.call(this,e)||this;return i.dataFormat=e.dataFormat==null?"channelsLast":e.dataFormat,ct(i.dataFormat),i.inputSpec=[new Tt({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),mw=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}(fw);y.serialization.registerClass(mw);var gw=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}(fw);y.serialization.registerClass(gw);var vw=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=Ln(a,r);delete i.layer;var o={layer:s};return Object.assign(o,i),new e(o)},t}(De),yw=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=Ye(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=Ye(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=Cb(a,e,[],!1,null,null,!1,!0),o=s[1];return o})},t.className="TimeDistributed",t}(vw);y.serialization.registerClass(yw);function iF(n){Zr(jk,"BidirectionalMergeMode",n)}var rF="concat",bw=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=Ln(a),r.goBackwards=!(r.goBackwards===!0);var s={};if(s.className=e.layer.getClassName(),s.config=r,i.backwardLayer=Ln(s),i.forwardLayer.name="forward_"+i.forwardLayer.name,i.backwardLayer.name="backward_"+i.backwardLayer.name,i.mergeMode=e.mergeMode===void 0?rF:e.mergeMode,iF(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()):Vt(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=xb(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 Tt({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 Sn,d=0,p=o;dt}var Nw=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=Ho:i.mode==="max"||i.monitor.indexOf("acc")!==-1?i.monitorFunc=Tw:i.monitorFunc=Ho,i.monitorFunc===Ho&&(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===Ho?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,Ni(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}(Aw);function UW(n){return new Nw(n)}var BW={earlyStopping:UW};$e.Callback=Aw;$e.CallbackList=Wy;$e.CustomCallback=By;$e.EarlyStopping=Nw;$e.History=Uy;$e.InputSpec=Tt;$e.LayerVariable=Oy;$e.LayersModel=xi;$e.RNN=Oi;$e.Sequential=hd;$e.SymbolicTensor=Sn;$e.callbacks=BW;$e.constraints=qk;$e.initializers=A3;$e.input=sb;$e.layers=fW;$e.loadLayersModel=E4;$e.metrics=OW;$e.model=R4;$e.models=EW;$e.registerCallbackConstructor=D4;$e.regularizers=WW;$e.sequential=O4;$e.version_layers=ad});var Hw=Ae(fr=>{"use strict";Object.defineProperty(fr,"__esModule",{value:!0});var B=sr();var Cw=Object.assign||function(t){for(var e,i=1,r=arguments.length;i0&&a[a.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]0?Object.keys(h).forEach(function(g){var v=ri(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=Ow(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=Td(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Td(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"string[]":o=kd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=kd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"number":o=xd(t.attr,a.tfName,a.defaultValue||0),o===void 0&&!!a.tfDeprecatedName&&(o=xd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"number[]":o=Dd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Dd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"bool":o=Nd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Nd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"bool[]":o=Wd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Wd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"shape":o=Ed(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Ed(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"dtype":o=Rd(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Rd(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"dtype[]":o=Od(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Od(t.attr,a.tfDeprecatedName,a.defaultValue));break;case"func":o=Ew(t.attr,a.tfName,a.defaultValue),o===void 0&&!!a.tfDeprecatedName&&(o=Ew(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=ri(d.name)[0],f={name:p,op:"Placeholder",inputs:[],inputNames:[],category:"graph",inputParams:{},attrParams:{dtype:{value:Cd(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=ri(f)[0];p.inputs.push(s[m]),s[m].children.push(p)})});var c=t.ret;t.signature.outputArg.forEach(function(d){var p=ri(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 bU(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 kw(n,t){var e=Array.isArray(n)?String.fromCharCode.apply(null,n):bU(n);return t?e:e.toLowerCase()}function Td(n,t,e,i){i===void 0&&(i=!1);var r=n[t];return r!=null?kw(r.s,i):e}function Nd(n,t,e){var i=n[t];return i?i.b:e}function xd(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 Cd(n){typeof n=="string"&&(n=Tn[n]);switch(n){case Tn.DT_FLOAT:return"float32";case Tn.DT_INT32:case Tn.DT_INT64:case Tn.DT_INT8:case Tn.DT_UINT8:return"int32";case Tn.DT_BOOL:return"bool";case Tn.DT_DOUBLE:return"float32";case Tn.DT_STRING:return"string";default:return null}}function Ew(n,t,e){var i=n[t];return i&&i.func?i.func.name:e}function Rd(n,t,e){var i=n[t];return i&&i.type?Cd(i.type):e}function Od(n,t,e){var i=n[t];return i&&i.list&&i.list.type?i.list.type.map(function(r){return Cd(r)}):e}function Fw(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 Ed(n,t,e){var i=n[t];return i&&i.shape?Fw(i.shape):e}function Dd(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 kd(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 kw(a,i)}):e}function Fd(n,t,e){var i=n[t];return i&&i.list&&i.list.shape?i.list.shape.map(function(r){return Fw(r)}):e}function Wd(n,t,e){var i=n[t];return i&&i.list&&i.list.b?i.list.b:e}var wU=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 qt(t,this.tensorMap,this.context)},n.prototype.getAttr=function(t,e){var i=this.node.rawAttrs[t];if(i.tensor!=null)return qt(t,this.tensorMap,this.context);if(i.i!=null||i.f!=null)return xd(this.node.rawAttrs,t,e);if(i.s!=null)return Td(this.node.rawAttrs,t,e);if(i.b!=null)return Nd(this.node.rawAttrs,t,e);if(i.shape!=null)return Ed(this.node.rawAttrs,t,e);if(i.type!=null)return Rd(this.node.rawAttrs,t,e);if(i.list!=null){if(i.list.i!=null||i.list.f!=null)return Dd(this.node.rawAttrs,t,e);if(i.list.s!=null)return kd(this.node.rawAttrs,t,e);if(i.list.shape!=null)return Fd(this.node.rawAttrs,t,e);if(i.list.b!=null)return Wd(this.node.rawAttrs,t,e);if(i.list.type!=null)return Od(this.node.rawAttrs,t,e)}return e},n}();var SU=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 LU=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(qt(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 pn(n,t,e){e===void 0&&(e=""),B.util.assert(IU(n,t),function(){return e+(" Shapes "+n+" and "+t+" must match")})}function IU(n,t){if(n.length!==t.length)return!1;for(var e=0;e=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),pn(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.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
+`+("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);mt?1:0}function Lo(n,t){return-1*Mk(n,t)}function Ai(n){if(n==null)return n;for(var t=[],e=0,i=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 "+(iy(n)+".")})}function iy(n){return n===null?"null":Array.isArray(n)?"["+n.map(function(t){return iy(t)}).join(",")+"]":typeof n=="string"?'"'+n+'"':""+n}function Vk(n,t){var e=y.util.now(),i,r=function(){for(var a=[],s=0;s0){var e=n+"_"+t;return ea.set(e,1),e}else return n}var e3=new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);function py(n){return!!n.match(e3)}function t3(n){return n===parseInt(n.toString(),10)}function Ti(n,t,e){t==null&&(t=0),e==null&&(e=n.length);for(var i=1,r=t;r= 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?Hh(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?Hh(n.rank,i,Sn()):null,activation:e}).reshape(f)}}function yy(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 ts(n){return y.mul(n,n)}function Hh(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(Hh(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 by(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 ns(n,t,e){return e===void 0&&(e=!1),e?n():t()}var l3=["fanIn","fanOut","fanAvg"],u3=["normal","uniform","truncatedNormal"];function c3(n){Qr(l3,"FanMode",n)}function h3(n){Qr(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),wy=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(wy);var Vh=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(Vh);var Sy=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(Sy);var Ly=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(Ly);var Iy=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 Ao(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(Iy);var Ay=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(Ay);var Ty=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(Ty);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=Ti(n,2);e=n[1]*r,i=n[0]*r}else if(t==="channelsLast"){var r=Ti(n,0,n.length-2);e=n[n.length-2]*r,i=n[n.length-1]*r}}else{var a=Ti(n);e=Math.sqrt(a),i=Math.sqrt(a)}return[e,i]}var $t=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($t);var qh=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 $t.className},t.className="GlorotUniform",t}($t);y.serialization.registerClass(qh);var Gh=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 $t.className},t.className="GlorotNormal",t}($t);y.serialization.registerClass(Gh);var Yh=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 $t.className},t.className="HeNormal",t}($t);y.serialization.registerClass(Yh);var jh=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 $t.className},t.className="HeUniform",t}($t);y.serialization.registerClass(jh);var Kh=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 $t.className},t.className="LeCunNormal",t}($t);y.serialization.registerClass(Kh);var $h=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 $t.className},t.className="LeCunNormal",t}($t);y.serialization.registerClass($h);var Ny=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=Ao(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(Ny);var xy={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 Cy(n,t){return t===void 0&&(t={}),Xa(n,y.serialization.SerializationMap.getMap().classNameMap,t,"initializer")}function st(n){return Wh(n)}function tt(n){if(typeof n=="string"){var t=n in xy?xy[n]:n;if(t==="GlorotNormal")return new Gh;if(t==="GlorotUniform")return new qh;if(t==="HeNormal")return new Yh;if(t==="HeUniform")return new jh;if(t==="LeCunNormal")return new Kh;if(t==="LeCunUniform")return new $h;var e={};return e.className=t,e.config={},Cy(e)}else return n instanceof fn?n:Cy(n)}function p3(){return new wy}function f3(){return new Vh}function m3(n){return new Sy(n)}function g3(n){return new Ly(n)}function v3(n){return new Iy(n)}function y3(n){return new Ay(n)}function b3(n){return new Ty(n)}function w3(n){return new $t(n)}function S3(n){return new qh(n)}function L3(n){return new Gh(n)}function I3(n){return new Yh(n)}function A3(n){return new jh(n)}function T3(n){return new Kh(n)}function N3(n){return new $h(n)}function x3(n){return new Ny(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 Ry(){return R3++}var To={};function No(n){return n===void 0&&(n=""),n in To||(To[n]=0),To[n]+=1,n+To[n].toString()}function Xh(n){return Array.isArray(n)&&Array.isArray(n[0])}function xo(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 Co(n){for(var t=0,e=0,i=n;e1)throw new Ii("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 Ii("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 Ii("Layer "+this.name+" has no inbound nodes.");if(this.inboundNodes.length>1)throw new Ii("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=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;p0&&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 Ii("The layer "+this.name+" has never been called and thus has no defined output shape.");for(var e=[],i=0,r=this.inboundNodes;i0)&&(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;a0?[4,Promise.all(t)]:[3,2];case 1:for(o=u.sent(),l=0;l=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 My(n,t,e,i,r,a,s,o,l){var u=new By,c=[new U3].concat(_y.createCallbacks(t));n!=null&&c.push.apply(c,n),c.push(u);var h=new Uy(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),Xa(n,y.serialization.SerializationMap.getMap().classNameMap,t,"layer",e)}function Oo(n,t){return y.tidy(function(){n.dtype!=="float32"&&(n=n.asType("float32"));var e=y.sum(ts(n),t,!0),i=y.fill(e.shape,yt()),r=y.sqrt(y.maximum(e,i));return y.div(n,r)})}function dr(n,t){return y.tidy(function(){return y.mean(ts(y.sub(t,n)),-1)})}function Eo(n,t){return y.tidy(function(){return y.mean(y.abs(y.sub(t,n)),-1)})}function ia(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(ts(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(ts(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 rs(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 Do(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 rs(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 ko(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 Qh(n,t){return y.tidy(function(){var e=Oo(n,-1),i=Oo(t,-1),r=y.mul(e,i);return y.neg(y.sum(r,-1))})}var Fo={meanSquaredError:dr,meanAbsoluteError:Eo,meanAbsolutePercentageError:ia,meanSquaredLogarithmicError:B3,squaredHinge:z3,hinge:P3,categoricalHinge:_3,logcosh:M3,categoricalCrossentropy:rs,sparseCategoricalCrossentropy:Do,binaryCrossentropy:ko,kullbackLeiblerDivergence:V3,poisson:q3,cosineProximity:Qh};function ed(n){if(typeof n=="string"){if(n in Fo)return Fo[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 td(n,t){return y.tidy(function(){var e=y.mul(.5,y.onesLike(t)),i=Qa(y.greater(t,e),n.dtype);return y.mean(y.equal(n,i),-1)})}function nd(n,t){return y.tidy(function(){return Qa(y.equal(y.argMax(n,-1),y.argMax(t,-1)),"float32")})}function Hy(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 Vy(n,t){return y.tidy(function(){var e=Hy(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=Hy(n,t),i=G3(n,t),r=e.add(i);return y.where(y.greater(r,0),e.div(r),0).cast("float32")})}function qy(n,t){return ko(n,t)}function Gy(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=dr,$3=dr,X3=Eo,J3=Eo,Z3=ia,Q3=ia,id=rs,e4=Qh,Yy=Do,Wo={binaryAccuracy:td,categoricalAccuracy:nd,precision:Vy,categoricalCrossentropy:id,sparseCategoricalCrossentropy:Yy,mse:K3,MSE:$3,mae:X3,MAE:J3,mape:Z3,MAPE:Q3,cosine:e4};function t4(n){if(typeof n=="string"&&n in Wo)return Wo[n];if(typeof n!="string"&&n!=null)return n;throw new M("Unknown metric "+n)}function Uo(n){if(_n(n!==null,"Unknown LossOrMetricFn "+n),typeof n=="string")return n;for(var t=void 0,e=0,i=Object.keys(Fo);ejy&&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 <= "+(jy+"."))}}function rd(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;e1||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;l0&&(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()];Bo(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;s0&&e.indexOf(l)===-1)continue;for(var u=0;ui.maxNumTensors&&(i.maxNumTensors=w),w0,function(){return"Expected at least one fetch, got none"});var e=[],i={};if(n.length===1){var r=Jy(n[0],t);e=r.sorted,i=r.recipientMap}else for(var a=new Set,s=0,o=n;s0;){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;d1 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=0;)ft.splice(ft.indexOf(_t),1);L.push(_t)},C=[],R=[],D=0,k=i.outputs;Dcn?1:0});for(var he=0,ye=le;he0)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;i0)throw new M(v.length+" of "+a+" weights are not set: "+(""+v))}Zh(d)},t.prototype.updatedConfig=function(){var e=this.getConfig(),i={};return i.className=this.getClassName(),i.config=e,i.kerasVersion="tfjs-layers "+sd,i.backend="TensorFlow.js",i},t.prototype.toJSON=function(e,i){i===void 0&&(i=!0);var r=ad(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 ra,s=0;s1)for(var c=0,h=u;c