!function(t,e){"object"==typeofexports&&"undefined"!=typeofmodule?e(exports,require("@tensorflow/tfjs-core"),require("@tensorflow/tfjs-converter")):"function"==typeofdefine&&define.amd?define(["exports","@tensorflow/tfjs-core","@tensorflow/tfjs-converter"],e):e(t.blazeface={},t.tf,t.tf)}(this,function(t,e,n){"use strict";functionr(t,e,n,r){returnnew(n||(n=Promise))(function(o,i){functions(t){try{c(r.next(t))}catch(t){i(t)}}functiona(t){try{c(r.throw(t))}catch(t){i(t)}}functionc(t){vare;t.done?o(t.value):(e=t.value,einstanceofn?e:newn(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})}functiono(t,e){varn,r,o,i,s={label:0,sent:function(){if(1&o[0])throwo[1];returno[1]},trys:[],ops:[]};returni={next:a(0),throw:a(1),return:a(2)},"function"==typeofSymbol&&(i[Symbol.iterator]=function(){returnthis}),i;functiona(i){returnfunction(a){returnfunction(i){if(n)thrownewTypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)returno;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case0:case1:o=i;break;case4:returns.label++,{value:i[1],done:!1};case5:s.label++,r=i[1],i=[0];continue;case7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throwi[1];return{value:i[0]?i[1]:void0,done:!0}}([i,a])}}}vari=function(t){return{startEndTensor:t,startPoint:e.slice(t,[0,0],[-1,2]),endPoint:e.slice(t,[0,2],[-1,2])}},s=function(t,n){varr=e.mul(t.startPoint,n),o=e.mul(t.endPoint,n),s=e.concat2d([r,o],1);returni(s)},a={strides:[8,16],anchors:[2,6]};functionc(t,n){varr,o,i;if(t.topLeftinstanceofe.Tensor&&t.bottomRightinstanceofe.Tensor){vars=e.tidy(function(){return[e.concat([e.slice(e.sub(n-1,t.topLeft),0,1),e.slice(t.topLeft,1,1)]),e.concat([e.sub(n-1,e.slice(t.bottomRight,0,1)),e.slice(t.bottomRight,1,1)])]});r=s[0],o=s[1],null!=t.landmarks&&(i=e.tidy(function(){varr=e.sub(e.tensor1d([n-1,0]),t.landmarks),o=e.tensor1d([1,-1]);returne.mul(r,o)}))}else{vara=t.topLeft,c=a[0],u=a[1],l=t.bottomRight,d=l[0],f=l[1];r=[n-1-c,u],o=[n-1-d,f],null!=t.landmarks&&(i=t.landmarks.map(function(t){return[n-1-t[0],t[1]]}))}varh={topLeft:r,bottomRight:o};returnnull!=i&&(h.landmarks=i),null!=t.probability&&(h.probability=t.probabilityinstanceofe.Tensor?t.probability.clone():t.probability),h}functionu(t,n){returne.tidy(function(){varr;returnr=t.hasOwnProperty("box")?t.box:t,e.squeeze(s(r,n).startEndTensor)})}varl=function(){functiont(t,n,r,o,i,s){this.blazeFaceModel=t,this.width=n,this.height=r,this.maxFaces=o,this.anchorsData=function(t,e,n){for(varr=[],o=0;o<n.strides.length;o++)for(vari=n.strides[o],s=Math.floor((e+i-1)/i),a=Math.floor((t+i-1)/i),c=n.anchors[o],u=0;u<s;u++)for(varl=i*(u+.5),d=0;d<a;d++)for(varf=i*(d+.5),h=0;h<c;h++)r.push([f,l]);returnr}(n,r,a),this.anchors=e.tensor2d(this.anchorsData),this.inputSizeData=[n,r],this.inputSize=e.tensor1d([n,r]),this.iouThreshold=i,this.scoreThreshold=s}returnt.prototype.getBoundingBoxes=function(t,n,s){returnvoid0===s&&(s=!0),r(this,void0,void0,function(){vara,c,u,l,d,f,h,p,b,v,m,y,w,g,x=this;returno(this,function(T){switch(T.label){case0:returna=e.tidy(function(){varn,r,o,i,s,a,c,u,l,d,f,h,p,b=e.image.resizeBilinear(t,[x.width,x.height]),v=e.mul(e.sub(e.div(b,255),.5),2),m=x.blazeFaceModel.predict(v),y=e.squeeze(m),w=(n=y,r=x.anchors,o=x.inputSize,i=e.slice(n,[0,1],[-1,2]),s=e.add(i,r),a=e.slice(n,[0,3],[-1,2]),c=e.div(a,o),u=e.div(s,o),l=e.div(c,2),d=e.sub(u,l),f=e.add(u,l),h=e.mul(d,o),p=e.mul(f,o),e.concat2d([h,p],1)),g=e.slice(y,[0,0],[-1,1]);return[y,w,e.squeeze(e.sigmoid(g))]}),c=a[0],u=a[1],l=a[2],d=console.warn,console.warn=function(){},f=e.image.nonMaxSuppression(u,l,this.maxFaces,this.iouThreshold,this.scoreThreshold),console.warn=d,[4,f.array()];case1:returnh=T.sent(),f.dispose(),p=h.map(function(t){returne.slice(u,[t,0],[1,-1])}),n?[3,3]:[4,Promise.all(p.map(function(t){returnr(x,void0,void0,function(){vare;returno(this,function(n){switch(n.label){case0:return[4,t.array()];case1:returne=n.sent(),t.dispose(),[2,e]}})})}))];case2:p=T.sent(),T.label=3;case3:for(b=t.shape[1],v=t.shape[2],m=n?e.div([v,b],this.inputSize):[v/this.inputSizeData[0],b/this.inputSizeData[1]],y=[],w=function(t){varr=p[t],o=e.tidy(function(){varo=rinstanceofe.Tensor?i(r):i(e.tensor2d(r));if(!s)returno;vara,u=h[t];returna=n?e.slice(x.anchors,[u,0],[1,2]):x.anchorsData[u],{box:o,landmarks:e.reshape(e.squeeze(e.slice(c,[u,5],[1,-1])),[6,-1]),probability:e.slice(l,[u],[1]),anchor:a}});y.push(o)},g=0;g<p.length;g++)w(g);returnu.dispose(),l.dispose(),c.dispose(),[2,{boxes:y,scaleFactor:m}]}})})},t.prototype.estimateFaces=function(t,n,i,s){returnvoid0===n&&(n=!1),void0===i&&(i=!1),void0===s&&(s=!0),r(this,void0,void0,function(){vara,l,d,f,h,p,b=this;returno(this,function(v){switch(v.label){case0:returna=function(t){returntinstanceofe.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),l=a[1],d=e.tidy(function(){returntinstanceofe.Tensor||(t=e.browser.fromPixels(t)),e.expandDims(e.cast(t,"float32"),0)}),[4,this.getBoundingBoxes(d,n,s)];case1:returnf=v.sent(),h=f.boxes,p=f.scaleFactor,d.dispose(),n?[2,h.map(function(t){varn=u(t,p),r={topLeft:e.slice(n,[0],[2]),bottomRight:e.slice(n,[2],[2])};if(s){varo=t,a=o.landmarks,d=o.probability,f=o.anchor,h=e.mul(e.add(a,f),p);r.landmarks=h,r.probability=d}returni&&(r=c(r,l)),r})]:[2,Promise.all(h.map(function(t){returnr(b,void0,void0,function(){vare,n,a,d,f,h,b,v,m,y,w,g=this;returno(this,function(x){switch(x.label){case0:returne=u(t,p),s?[3,2]:[4,e.array()];case1:returnf=x.sent(),n={topLeft:f.slice(0,2),bottomRight:f.slice(2)},[3,4];case2:return[4,Promise.all([t.landmarks,e,t.probability].map(function(t){returnr(g,void0,void0,function(){returno(this,function(e){return[2,t.array()]})})}))];case3:a=x.sent(),d=a[0],f=a[1],h=a[2],b=t.anchor,m=(v=p)[0],y=v[1],w=d.map(function(t){return[(t[0]+b[0])*m,(t[1]+b[1])*y]}),n={topLeft:f.slice(0,2),bottomRight:f.slice(2),landmarks:w,probability:h},(T=t.box).startEndTensor.dispose(),T.startPoint.dispose(),T.endPoint.dispose(),t.landmarks.dispose(),t.probability.dispose(),x.label=4;case4:returne.dispose(),i&&(n=c(n,l)),[2,n]}varT})})}))]}})})},t}(),d="https://tfhub.dev/tensorflow/tfjs-model/blazeface/1/default/1";t.load=function(t){vare=void0===t?{}:t,i=e.maxFaces,s=void0===i?10:i,a=e.inputWidth,c=void0===a?128:a,u=e.inputHeight,f=void0===u?128:u,h=e.iouThreshold,p=void0===h?.3:h,b=e.scoreThreshold,v=void0===b?.75:b,m=e.modelUrl;returnr(this,void0,void0,function(){vart;returno(this,function(e){switch(e.label){case0:returnnull==m?[3,2]:[4,n.loadGraphModel(m)];case1:returnt=e.sent(),[3,4];case2:return[4,n.loadGraphModel(d,{fromTFHub:!0})];case3:t=e.sent(),e.label=4;case4:return[2,newl(t,c,f,s,p,v)]}})})},t.BlazeFaceModel=l,Object.defineProperty(t,"__esModule",{value:!0})});