2020-10-16 02:20:37 +02:00
|
|
|
var je=Object.defineProperty;var y=(e,t)=>()=>(t||(t={exports:{}},e(t.exports,t)),t.exports),S0=e=>je(e,"__esModule",{value:!0}),Ue=(e,t)=>{S0(e);for(var n in t)je(e,n,{get:t[n],enumerable:!0})};var Xe=y(oe=>{const f=require("@tensorflow/tfjs"),B0={strides:[8,16],anchors:[2,6]},We=6;function T0(e,t){const n=[];for(let o=0;o<t.strides.length;o++){const i=t.strides[o],s=Math.floor((e+i-1)/i),r=Math.floor((e+i-1)/i),c=t.anchors[o];for(let a=0;a<s;a++){const d=i*(a+.5);for(let u=0;u<r;u++){const h=i*(u+.5);for(let l=0;l<c;l++)n.push([h,d])}}}return n}const Ke=e=>{e.startEndTensor.dispose(),e.startPoint.dispose(),e.endPoint.dispose()},Ge=e=>({startEndTensor:e,startPoint:f.slice(e,[0,0],[-1,2]),endPoint:f.slice(e,[0,2],[-1,2])}),_0=(e,t)=>{const n=f.mul(e.startPoint,t),o=f.mul(e.endPoint,t),i=f.concat2d([n,o],1);return Ge(i)};function k0(e,t,n){const o=f.slice(e,[0,1],[-1,2]),i=f.add(o,t),s=f.slice(e,[0,3],[-1,2]),r=f.div(s,n),c=f.div(i,n),a=f.div(r,2),d=f.sub(c,a),u=f.add(c,a),h=f.mul(d,n),l=f.mul(u,n),p=1;return f.concat2d([h,l],p)}function z0(e,t){return f.tidy(()=>{const n=e.box?e.box:e;return _0(n,t).startEndTensor.squeeze()})}class Ye{constructor(e,t){this.blazeFaceModel=e,this.width=t.detector.inputSize,this.height=t.detector.inputSize,this.anchorSize=t.detector.anchorSize,this.maxFaces=t.detector.maxFaces,this.anchorsData=T0(t.detector.anchorSize,B0),this.anchors=f.tensor2d(this.anchorsData),this.inputSize=f.tensor1d([this.width,this.height]),this.iouThreshold=t.detector.iouThreshold,this.scaleFaces=.8,this.scoreThreshold=t.detector.scoreThreshold}async getBoundingBoxes(e){const[t,n,o]=f.tidy(()=>{const a=e.resizeBilinear([this.width,this.height]),d=f.mul(f.sub(a.div(255),.5),2),u=this.blazeFaceModel.predict(d);let h;if(Array.isArray(u)){const w=u.sort((N,C)=>N.size-C.size),E=f.concat([w[0],w[2]],2),P=f.concat([w[1],w[3]],2),x=f.concat([P,E],1);h=x.squeeze(0)}else h=u.squeeze();const l=k0(h,this.anchors,this.inputSize),p=f.slice(h,[0,0],[-1,1]),m=f.sigmoid(p).squeeze();return[h,l,m]}),i=await f.image.nonMaxSuppressionAsync(n,o,this.maxFaces,this.iouThreshold,this.scoreThreshold),s=await i.array();i.dispose();let r=s.map(a=>f.slice(n,[a,0],[1,-1]));r=await Promise.all(r.map(async a=>{const d=await a.array();return a.dispose(),d}));const c=[];for(let a=0;a<r.length;a++){const d=r[a],u=f.tidy(()=>{const h=Ge(d),l=s[a],p=this.anchorsData[l],m=f.slice(t,[l,We-1],[1,-1]).squeeze().reshape([We,-1]),w=f.slice(o,[l],[1]);return{box:h,landmarks:m,probability:w,anchor:p}});c.push(u)}return n.dispose(),o.dispose(),t.dispose(),{boxes:c,scaleFactor:[e.shape[2]/this.width,e.shape[1]/this.height]}}async estimateFaces(e){const t=f.tidy(()=>(e instanceof f.Tensor||(e=f.browser.fromPixels(e)),e.toFloat().expandDims(0))),{boxes:n,scaleFactor:o}=await this.getBoundingBoxes(t);return t.dispose(),Promise.all(n.map(async i=>{const s=z0(i,o),[r,c,a]=await Promise.all([i.landmarks,s,i.probability].map(async m=>m.array())),d=i.anchor,[u,h]=o,l=r.map(m=>[(m[0]+d[0])*u,(m[1]+d[1])*h]),p={topLeft:c.slice(0,2),bottomRight:c.slice(2),landmarks:l,probability:a};return Ke(i.box),i.landmarks.dispose(),i.probability.dispose(),s.dispose(),p}))}}async function A0(e){const t=await f.loadGraphModel(e.detector.modelPath,{fromTFHub:e.detector.modelPath.includes("tfhub.dev")}),n=new Ye(t,e);return n}oe.load=A0;oe.BlazeFaceModel=Ye;oe.disposeBox=Ke});var ue=y(he=>{he.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,1
|