2020-10-18 15:21:53 +02:00
|
|
|
var Ve=Object.defineProperty;var b=(e,t)=>()=>(t||(t={exports:{}},e(t.exports,t)),t.exports),B0=e=>Ve(e,"__esModule",{value:!0}),Xe=(e,t)=>{B0(e);for(var n in t)Ve(e,n,{get:t[n],enumerable:!0})};var Je=b(se=>{const g=require("@tensorflow/tfjs"),Ge=6;function T0(e){const t={strides:[e/16,e/8],anchors:[2,6]},n=[];for(let o=0;o<t.strides.length;o++){const s=t.strides[o],i=Math.floor((e+s-1)/s),r=Math.floor((e+s-1)/s),a=t.anchors[o];for(let d=0;d<i;d++){const c=s*(d+.5);for(let h=0;h<r;h++){const p=s*(h+.5);for(let l=0;l<a;l++)n.push([p,c])}}}return n}const Qe=e=>{e.startEndTensor.dispose(),e.startPoint.dispose(),e.endPoint.dispose()},Ze=e=>({startEndTensor:e,startPoint:g.slice(e,[0,0],[-1,2]),endPoint:g.slice(e,[0,2],[-1,2])}),k0=(e,t)=>{const n=g.mul(e.startPoint,t),o=g.mul(e.endPoint,t),s=g.concat2d([n,o],1);return Ze(s)};function _0(e,t,n){const o=g.slice(e,[0,1],[-1,2]),s=g.add(o,t),i=g.slice(e,[0,3],[-1,2]),r=g.div(i,n),a=g.div(s,n),d=g.div(r,2),c=g.sub(a,d),h=g.add(a,d),p=g.mul(c,n),l=g.mul(h,n),m=1;return g.concat2d([p,l],m)}function N0(e,t){return g.tidy(()=>{const n=e.box?e.box:e;return k0(n,t).startEndTensor.squeeze()})}class $e{constructor(e,t){this.blazeFaceModel=e,this.width=t.detector.inputSize,this.height=t.detector.inputSize,this.maxFaces=t.detector.maxFaces,this.anchorsData=T0(t.detector.inputSize),this.anchors=g.tensor2d(this.anchorsData),this.inputSize=g.tensor1d([this.width,this.height]),this.iouThreshold=t.detector.iouThreshold,this.scaleFaces=.8,this.scoreThreshold=t.detector.scoreThreshold}async getBoundingBoxes(e){if(!e||e.isDisposedInternal||e.shape.length!==4||e.shape[1]<1||e.shape[2]<1)return null;const[t,n,o]=g.tidy(()=>{const c=e.resizeBilinear([this.width,this.height]),h=g.mul(g.sub(c.div(255),.5),2),p=this.blazeFaceModel.predict(h);let l;if(Array.isArray(p)){const P=p.sort((D,F)=>D.size-F.size),M=g.concat([P[0],P[2]],2),y=g.concat([P[1],P[3]],2),z=g.concat([y,M],1);l=z.squeeze(0)}else l=p.squeeze();const m=_0(l,this.anchors,this.inputSize),u=g.slice(l,[0,0],[-1,1]),w=g.sigmoid(u).squeeze();return[l,m,w]}),s=await g.image.nonMaxSuppressionAsync(n,o,this.maxFaces,this.iouThreshold,this.scoreThreshold),i=await s.array();s.dispose();const r=i.map(c=>g.slice(n,[c,0],[1,-1])),a=await Promise.all(r.map(async c=>{const h=await c.array();return c.dispose(),h})),d=[];for(let c=0;c<a.length;c++){const h=a[c],p=Ze(h),l=i[c],m=this.anchorsData[l],u=g.slice(t,[l,Ge-1],[1,-1]),w=u.squeeze(),P=w.reshape([Ge,-1]),M=g.slice(o,[l],[1]),y={box:p,landmarks:P,probability:M,anchor:m};d.push(y),u.dispose(),w.dispose()}return t.dispose(),n.dispose(),o.dispose(),t.dispose(),{boxes:d,scaleFactor:[e.shape[2]/this.width,e.shape[1]/this.height]}}async estimateFaces(e){const{boxes:t,scaleFactor:n}=await this.getBoundingBoxes(e);return Promise.all(t.map(async o=>{const s=N0(o,n),[i,r,a]=await Promise.all([o.landmarks,s,o.probability].map(async m=>m.array())),d=o.anchor,[c,h]=n,p=i.map(m=>[(m[0]+d[0])*c,(m[1]+d[1])*h]),l={topLeft:r.slice(0,2),bottomRight:r.slice(2),landmarks:p,probability:a};return Qe(o.box),o.landmarks.dispose(),o.probability.dispose(),s.dispose(),l}))}}async function z0(e){const t=await g.loadGraphModel(e.detector.modelPath,{fromTFHub:e.detector.modelPath.includes("tfhub.dev")}),n=new $e(t,e);return n}se.load=z0;se.BlazeFaceModel=$e;se.disposeBox=Qe});var pe=b(me=>{me.MESH_ANNOTATIONS={silhouette:[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109],lipsUpperOuter:[61,185,40,39,37,0,267,269,270,409,291],lipsLowerOuter:[146,91,181,84,17,314,405,321,375,291],lipsUpperInner:[78,191,80,81,82,13,312,311,310,415,308],lipsLowerInner:[78,95,88,178,87,14,317,402,318,324,308],rightEyeUpper0:[246,161,160,159,158,157,173],rightEyeLower0:[33,7,163,144,145,153,154,155,133],rightEyeUpper1:[247,30,29,27,28,56,190],rightEyeLower1:[130,25,110,24,23,22,26,112,243],rightEyeUpper2:[113,225,224,223,222,221,189],rightEyeLower2:[226,31,228,229,230,231,232,233,244],rightEyeLower3:[143,111,117,118,119,120,121,128,245],rightEyebrowUpper:[156,70,63,
|