import{slice,add,div,sub,mul,concat2d,Tensor,tidy,concat,tensor1d,squeeze,tensor2d,image,sigmoid,reshape,browser,expandDims,cast}from"@tensorflow/tfjs-core";import{loadGraphModel}from"@tensorflow/tfjs-converter";function__awaiter(e,t,r,n){returnnew(r||(r=Promise))(function(o,i){functiona(e){try{c(n.next(e))}catch(e){i(e)}}functions(e){try{c(n.throw(e))}catch(e){i(e)}}functionc(e){vart;e.done?o(e.value):(t=e.value,tinstanceofr?t:newr(function(e){e(t)})).then(a,s)}c((n=n.apply(e,t||[])).next())})}function__generator(e,t){varr,n,o,i,a={label:0,sent:function(){if(1&o[0])throwo[1];returno[1]},trys:[],ops:[]};returni={next:s(0),throw:s(1),return:s(2)},"function"==typeofSymbol&&(i[Symbol.iterator]=function(){returnthis}),i;functions(i){returnfunction(s){returnfunction(i){if(r)thrownewTypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)returno;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case0:case1:o=i;break;case4:returna.label++,{value:i[1],done:!1};case5:a.label++,n=i[1],i=[0];continue;case7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throwi[1];return{value:i[0]?i[1]:void0,done:!0}}([i,s])}}}vardisposeBox=function(e){e.startEndTensor.dispose(),e.startPoint.dispose(),e.endPoint.dispose()},createBox=function(e){return{startEndTensor:e,startPoint:slice(e,[0,0],[-1,2]),endPoint:slice(e,[0,2],[-1,2])}},scaleBox=function(e,t){varr=mul(e.startPoint,t),n=mul(e.endPoint,t),o=concat2d([r,n],1);returncreateBox(o)},NUM_LANDMARKS=6;functiongenerateAnchors(e,t,r){for(varn=[],o=0;o<r.strides.length;o++)for(vari=r.strides[o],a=Math.floor((t+i-1)/i),s=Math.floor((e+i-1)/i),c=r.anchors[o],l=0;l<a;l++)for(varu=i*(l+.5),d=0;d<s;d++)for(varh=i*(d+.5),f=0;f<c;f++)n.push([h,u]);returnn}functiondecodeBounds(e,t,r){varn=slice(e,[0,1],[-1,2]),o=add(n,t),i=slice(e,[0,3],[-1,2]),a=div(i,r),s=div(o,r),c=div(a,2),l=sub(s,c),u=add(s,c),d=mul(l,r),h=mul(u,r);returnconcat2d([d,h],1)}functiongetInputTensorDimensions(e){returneinstanceofTensor?[e.shape[0],e.shape[1]]:[e.height,e.width]}functionflipFaceHorizontal(e,t){varr,n,o;if(e.topLeftinstanceofTensor&&e.bottomRightinstanceofTensor){vari=tidy(function(){return[concat([slice(sub(t-1,e.topLeft),0,1),slice(e.topLeft,1,1)]),concat([sub(t-1,slice(e.bottomRight,0,1)),slice(e.bottomRight,1,1)])]});r=i[0],n=i[1],null!=e.landmarks&&(o=tidy(function(){varr=sub(tensor1d([t-1,0]),e.landmarks),n=tensor1d([1,-1]);returnmul(r,n)}))}else{vara=e.topLeft,s=a[0],c=a[1],l=e.bottomRight,u=l[0],d=l[1];r=[t-1-s,c],n=[t-1-u,d],null!=e.landmarks&&(o=e.landmarks.map(function(e){return[t-1-e[0],e[1]]}))}varh={topLeft:r,bottomRight:n};returnnull!=o&&(h.landmarks=o),null!=e.probability&&(h.probability=e.probabilityinstanceofTensor?e.probability.clone():e.probability),h}functionscaleBoxFromPrediction(e,t){returntidy(function(){varr;returnr=e.hasOwnProperty("box")?e.box:e,squeeze(scaleBox(r,t).startEndTensor)})}varBlazeFaceModel=function(){functione(e,t,r,n,o,i){this.blazeFaceModel=e,this.width=t,this.height=r,this.maxFaces=n;vara={strides:[t/16,t/8],anchors:[2,6]};this.anchorsData=generateAnchors(t,r,a),this.anchors=tensor2d(this.anchorsData),this.inputSize=tensor1d([t,r]),this.iouThreshold=o,this.scoreThreshold=i}returne.prototype.resizeAspectRatio=function(e,t,r){varn=e.shape[2],o=e.shape[1];if(!t||!r)return{ratio:1,image:e};vari=Math.min(t/n,r/o),a=Math.round(n*i),s=Math.round(o*i);return{ratio:i,image:image.resizeBilinear(e,[s,a])}},e.prototype.getBoundingBoxes=function(e,t,r){returnvoid0===r&&(r=!0),__awaiter(this,void0,void0,function(){varn,o,i,a,s,c,l,u,d,h,f,p,b,m=this;return__generator(this,function(v){switch(v.la