human/dist/human.esm-nobundle.js

10 lines
207 KiB
JavaScript
Raw Normal View History

2020-11-03 15:34:36 +01:00
var Ge=Object.defineProperty,S0=e=>Ge(e,"__esModule",{value:!0}),b=(e,t)=>()=>(t||(t={exports:{}},e(t.exports,t)),t.exports),Ye=(e,t)=>{S0(e);for(var n in t)Ge(e,n,{get:t[n],enumerable:!0})},Je=b(ce=>{const v=require("@tensorflow/tfjs"),Ke=6;function I0(e){const t={strides:[e/16,e/8],anchors:[2,6]},n=[];for(let r=0;r<t.strides.length;r++){const c=t.strides[r],_=Math.floor((e+c-1)/c),s=Math.floor((e+c-1)/c),h=t.anchors[r];for(let i=0;i<_;i++){const x=c*(i+.5);for(let a=0;a<s;a++){const d=c*(a+.5);for(let y=0;y<h;y++)n.push([d,x])}}}return n}const Ve=e=>{e.startEndTensor.dispose(),e.startPoint.dispose(),e.endPoint.dispose()},Qe=e=>({startEndTensor:e,startPoint:v.slice(e,[0,0],[-1,2]),endPoint:v.slice(e,[0,2],[-1,2])}),Ze=(e,t)=>{const n=v.mul(e.startPoint,t),r=v.mul(e.endPoint,t),c=v.concat2d([n,r],1);return Qe(c)};function R0(e,t,n){const r=v.slice(e,[0,1],[-1,2]),c=v.add(r,t),_=v.slice(e,[0,3],[-1,2]),s=v.div(_,n),h=v.div(c,n),i=v.div(s,2),x=v.sub(h,i),a=v.add(h,i),d=v.mul(x,n),y=v.mul(a,n),o=1;return v.concat2d([d,y],o)}function k0(e,t){return v.tidy(()=>{const n=e.box?e.box:e;return Ze(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=I0(t.detector.inputSize),this.anchors=v.tensor2d(this.anchorsData),this.inputSize=v.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,r]=v.tidy(()=>{const x=e.resizeBilinear([this.width,this.height]),a=v.mul(v.sub(x.div(255),.5),2),d=this.blazeFaceModel.predict(a);let y;if(Array.isArray(d)){const P=d.sort((A,l)=>A.size-l.size),T=v.concat([P[0],P[2]],2),g=v.concat([P[1],P[3]],2),B=v.concat([g,T],1);y=B.squeeze(0)}else y=d.squeeze();const o=R0(y,this.anchors,this.inputSize),m=v.slice(y,[0,0],[-1,1]),p=v.sigmoid(m).squeeze();return[y,o,p]}),c=await v.image.nonMaxSuppressionAsync(n,r,this.maxFaces,this.iouThreshold,this.scoreThreshold),_=c.arraySync();c.dispose();const s=_.map(x=>v.slice(n,[x,0],[1,-1])),h=s.map(x=>{const a=x.arraySync();return x.dispose(),a}),i=[];for(let x=0;x<h.length;x++){const a=h[x],d=Qe(a),y=_[x],o=this.anchorsData[y],m=v.slice(t,[y,Ke-1],[1,-1]),p=m.squeeze(),P=p.reshape([Ke,-1]),T=v.slice(r,[y],[1]),g={box:d,landmarks:P,probability:T,anchor:o};i.push(g),m.dispose(),p.dispose()}return t.dispose(),n.dispose(),r.dispose(),t.dispose(),{boxes:i,scaleFactor:[e.shape[2]/this.width,e.shape[1]/this.height]}}async estimateFaces(e){const{boxes:t,scaleFactor:n}=await this.getBoundingBoxes(e),r=[];for(const c of t){const _=c.landmarks.arraySync(),s=k0(c,n),h=Ze.arraySync(),i=c.probability.arraySync(),x=c.anchor,[a,d]=n,y=_.map(m=>[(m[0]+x[0])*a,(m[1]+x[1])*d]),o={topLeft:h.slice(0,2),bottomRight:h.slice(2),landmarks:y,probability:i};Ve(c.box),c.landmarks.dispose(),c.probability.dispose(),s.dispose(),r.push(o)}return r}}async function B0(e){const t=await v.loadGraphModel(e.detector.modelPath,{fromTFHub:e.detector.modelPath.includes("tfhub.dev")}),n=new $e(t,e);return n}ce.load=B0;ce.BlazeFaceModel=$e;ce.disposeBox=Ve}),ae=b(we=>{we.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,105,66,107,55,193],rightEyebrowLower:[35,124,46,53,52,65
`),A.FRAGMENT_IDENTITY=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","void main(void) {","gl_FragColor = texture2D(texture, vUv);","}"].join(`
`);let l={};l.colorMatrix=function(u){const w=new Float32Array(u);w[4]/=255,w[9]/=255,w[14]/=255,w[19]/=255;const f=w[18]===1&&w[3]===0&&w[8]===0&&w[13]===0&&w[15]===0&&w[16]===0&&w[17]===0&&w[19]===0?l.colorMatrix.SHADER.WITHOUT_ALPHA:l.colorMatrix.SHADER.WITH_ALPHA,M=g(f);o.uniform1fv(M.uniform.m,w),T()},l.colorMatrix.SHADER={},l.colorMatrix.SHADER.WITH_ALPHA=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform float m[20];","void main(void) {","vec4 c = texture2D(texture, vUv);","gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4];","gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9];","gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14];","gl_FragColor.a = m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19];","}"].join(`
`),l.colorMatrix.SHADER.WITHOUT_ALPHA=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform float m[20];","void main(void) {","vec4 c = texture2D(texture, vUv);","gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[4];","gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[9];","gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14];","gl_FragColor.a = c.a;","}"].join(`
`),l.brightness=function(u){const w=(u||0)+1;l.colorMatrix([w,0,0,0,0,0,w,0,0,0,0,0,w,0,0,0,0,0,1,0])},l.saturation=function(u){const w=(u||0)*2/3+1,f=(w-1)*-.5;l.colorMatrix([w,f,f,0,0,f,w,f,0,0,f,f,w,0,0,0,0,0,1,0])},l.desaturate=function(){l.saturation(-1)},l.contrast=function(u){const w=(u||0)+1,f=-128*(w-1);l.colorMatrix([w,0,0,0,f,0,w,0,0,f,0,0,w,0,f,0,0,0,1,0])},l.negative=function(){l.contrast(-2)},l.hue=function(u){u=(u||0)/180*Math.PI;const w=Math.cos(u),f=Math.sin(u),M=.213,R=.715,D=.072;l.colorMatrix([M+w*(1-M)+f*-M,R+w*-R+f*-R,D+w*-D+f*(1-D),0,0,M+w*-M+f*.143,R+w*(1-R)+f*.14,D+w*-D+f*-.283,0,0,M+w*-M+f*-(1-M),R+w*-R+f*R,D+w*(1-D)+f*D,0,0,0,0,0,1,0])},l.desaturateLuminance=function(){l.colorMatrix([.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,0,0,0,1,0])},l.sepia=function(){l.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},l.brownie=function(){l.colorMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0])},l.vintagePinhole=function(){l.colorMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0])},l.kodachrome=function(){l.colorMatrix([1.1285582396593525,-.3967382283601348,-.03992559172921793,0,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982807460946,0,0,0,1,0])},l.technicolor=function(){l.colorMatrix([1.9125277891456083,-.8545344976951645,-.09155508482755585,0,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,0,0,0,1,0])},l.polaroid=function(){l.colorMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0])},l.shiftToBGR=function(){l.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},l.convolution=function(u){const w=new Float32Array(u),f=1/h,M=1/i,R=g(l.convolution.SHADER);o.uniform1fv(R.uniform.m,w),o.uniform2f(R.uniform.px,f,M),T()},l.convolution.SHADER=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform vec2 px;","uniform float m[9];","void main(void) {","vec4 c11 = texture2D(texture, vUv - px);","vec4 c12 = texture2D(texture, vec2(vUv.x, vUv.y - px.y));","vec4 c13 = texture2D(texture, vec2(vUv.x + px.x, vUv.y - px.y));","vec4 c21 = texture2D(texture, vec2(vUv.x - px.x, vUv.y) );","vec4 c22 = texture2D(texture, vUv);","vec4 c23 = texture2D(texture, vec2(vUv.x + px.x, vUv.y) );","vec4 c31 = texture2D(texture, vec2(vUv.x - px.x, vUv.y + px.y) );","vec4 c32 = texture2D(texture, vec2(vUv.x, vUv.y + px.y) );","vec4 c33 = texture2D(texture, vUv + px );","gl_FragColor = ","c11 * m[0] + c12 * m[1] + c22 * m[2] +","c21 * m[3] + c22 * m[4] + c23 * m[5] +","c31 * m[6] + c32 * m[7] + c33 * m[8];","gl_FragColor.a = c22.a;","}"].join(`
`),l.detectEdges=function(){l.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},l.sobelX=function(){l.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},l.sobelY=function(){l.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},l.sharpen=function(u){const w=u||1;l.convolution.call(this,[0,-1*w,0,-1*w,1+4*w,-1*w,0,-1*w,0])},l.emboss=function(u){const w=u||1;l.convolution.call(this,[-2*w,-1*w,0,-1*w,1,1*w,0,1*w,2*w])},l.blur=function(u){const w=u/7/h,f=u/7/i,M=g(l.blur.SHADER);o.uniform2f(M.uniform.px,0,f),T(B.INTERMEDIATE),o.uniform2f(M.uniform.px,w,0),T()},l.blur.SHADER=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform vec2 px;","void main(void) {","gl_FragColor = vec4(0.0);","gl_FragColor += texture2D(texture, vUv + vec2(-7.0*px.x, -7.0*px.y))*0.0044299121055113265;","gl_FragColor += texture2D(texture, vUv + vec2(-6.0*px.x, -6.0*px.y))*0.00895781211794;","gl_FragColor += texture2D(texture, vUv + vec2(-5.0*px.x, -5.0*px.y))*0.0215963866053;","gl_FragColor += texture2D(texture, vUv + vec2(-4.0*px.x, -4.0*px.y))*0.0443683338718;","gl_FragColor += texture2D(texture, vUv + vec2(-3.0*px.x, -3.0*px.y))*0.0776744219933;","gl_FragColor += texture2D(texture, vUv + vec2(-2.0*px.x, -2.0*px.y))*0.115876621105;","gl_FragColor += texture2D(texture, vUv + vec2(-1.0*px.x, -1.0*px.y))*0.147308056121;","gl_FragColor += texture2D(texture, vUv )*0.159576912161;","gl_FragColor += texture2D(texture, vUv + vec2( 1.0*px.x, 1.0*px.y))*0.147308056121;","gl_FragColor += texture2D(texture, vUv + vec2( 2.0*px.x, 2.0*px.y))*0.115876621105;","gl_FragColor += texture2D(texture, vUv + vec2( 3.0*px.x, 3.0*px.y))*0.0776744219933;","gl_FragColor += texture2D(texture, vUv + vec2( 4.0*px.x, 4.0*px.y))*0.0443683338718;","gl_FragColor += texture2D(texture, vUv + vec2( 5.0*px.x, 5.0*px.y))*0.0215963866053;","gl_FragColor += texture2D(texture, vUv + vec2( 6.0*px.x, 6.0*px.y))*0.00895781211794;","gl_FragColor += texture2D(texture, vUv + vec2( 7.0*px.x, 7.0*px.y))*0.0044299121055113265;","}"].join(`
`),l.pixelate=function(u){const w=u/h,f=u/i,M=g(l.pixelate.SHADER);o.uniform2f(M.uniform.size,w,f),T()},l.pixelate.SHADER=["precision highp float;","varying vec2 vUv;","uniform vec2 size;","uniform sampler2D texture;","vec2 pixelate(vec2 coord, vec2 size) {","return floor( coord / size ) * size;","}","void main(void) {","gl_FragColor = vec4(0.0);","vec2 coord = pixelate(vUv, size);","gl_FragColor += texture2D(texture, coord);","}"].join(`
`)};y0.Canvas=vn}),a0=b(En=>{Ye(En,{default:()=>Pn});var Pn={backend:"webgl",console:!0,async:!1,profile:!1,deallocate:!1,scoped:!1,videoOptimized:!0,filter:{enabled:!0,width:0,height:0,return:!0,brightness:0,contrast:0,sharpness:0,blur:0,saturation:0,hue:0,negative:!1,sepia:!1,vintage:!1,kodachrome:!1,technicolor:!1,polaroid:!1,pixelate:0},face:{enabled:!0,detector:{modelPath:"../models/blazeface-back.json",inputSize:256,maxFaces:10,skipFrames:10,minConfidence:.5,iouThreshold:.3,scoreThreshold:.7},mesh:{enabled:!0,modelPath:"../models/facemesh.json",inputSize:192},iris:{enabled:!0,modelPath:"../models/iris.json",enlargeFactor:2.3,inputSize:64},age:{enabled:!0,modelPath:"../models/ssrnet-age-imdb.json",inputSize:64,skipFrames:10},gender:{enabled:!0,minConfidence:.8,modelPath:"../models/ssrnet-gender-imdb.json"},emotion:{enabled:!0,inputSize:64,minConfidence:.5,skipFrames:10,modelPath:"../models/emotion.json"}},body:{enabled:!0,modelPath:"../models/posenet.json",inputResolution:257,outputStride:16,maxDetections:10,scoreThreshold:.7,nmsRadius:20},hand:{enabled:!0,inputSize:256,skipFrames:10,minConfidence:.5,iouThreshold:.3,scoreThreshold:.7,enlargeFactor:1.65,maxHands:10,detector:{modelPath:"../models/handdetect.json"},skeleton:{modelPath:"../models/handskeleton.json"}}}}),l0=b((i5,d0)=>{d0.exports={name:"@vladmandic/human",version:"0.6.2",description:"human: 3D Face Detection, Iris Tracking and Age & Gender Prediction",sideEffects:!1,main:"dist/human.node.js",module:"dist/human.esm.js",browser:"dist/human.esm.js",author:"Vladimir Mandic <mandic00@live.com>",bugs:{url:"https://github.com/vladmandic/human/issues"},homepage:"https://github.com/vladmandic/human#readme",license:"MIT",engines:{node:">=14.0.0"},repository:{type:"git",url:"git+https://github.com/vladmandic/human.git"},dependencies:{},peerDependencies:{},devDependencies:{"@tensorflow/tfjs":"^2.7.0","@tensorflow/tfjs-node":"^2.7.0","@vladmandic/pilogger":"^0.2.7",dayjs:"^1.9.4",esbuild:"^0.7.22",eslint:"^7.12.1","eslint-config-airbnb-base":"^14.2.0","eslint-plugin-import":"^2.22.1","eslint-plugin-json":"^2.1.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1",rimraf:"^3.0.2",seedrandom:"^3.0.5","simple-git":"^2.21.0"},scripts:{start:"node --trace-warnings --unhandled-rejections=strict --trace-uncaught --no-deprecation src/node.js",lint:"eslint src/*.js demo/*.js","build-iife":"esbuild --bundle --minify --platform=browser --sourcemap --target=esnext --format=iife --external:fs --global-name=Human --metafile=dist/human.json --outfile=dist/human.js src/human.js","build-esm-bundle":"esbuild --bundle --minify --platform=browser --sourcemap --target=esnext --format=esm --external:fs --metafile=dist/human.esm.json --outfile=dist/human.esm.js src/human.js","build-esm-nobundle":"esbuild --bundle --minify --platform=browser --sourcemap --target=esnext --format=esm --external:@tensorflow --external:fs --metafile=dist/human.esm-nobundle.json --outfile=dist/human.esm-nobundle.js src/human.js","build-node":"esbuild --bundle --minify --platform=node --sourcemap --target=esnext --format=cjs --metafile=dist/human.node.json --outfile=dist/human.node.js src/human.js","build-node-nobundle":"esbuild --bundle --minify --platform=node --sourcemap --target=esnext --format=cjs --external:@tensorflow --metafile=dist/human.node.json --outfile=dist/human.node-nobundle.js src/human.js",build:"rimraf dist/* && npm run build-iife && npm run build-esm-bundle && npm run build-esm-nobundle && npm run build-node && npm run build-node-nobundle && ls -l dist/",update:"npm update --depth 20 --force && npm dedupe && npm prune && npm audit",changelog:"node changelog.js"},keywords:["tensorflowjs","face-detection","face-geometry","body-tracking","hand-tracking","iris-tracking","age-estimation","emotion-detection","gender-prediction","gesture-recognition"]}});const S=require("@tensorflow/tfjs"),u0=a1(),ie=f1(),He=g1(),f0=W1(),m0=x0(),Tn=w0(),Mn=he(),xe=a0().default,Sn=l0();let p0=!0;const In={face:{detector:{skipFrames:0},age:{skipFrames:0},emotion:{skipFrames:0}},hand:{skipFrames:0}},I=()=>
2020-10-15 14:16:34 +02:00
//# sourceMappingURL=human.esm-nobundle.js.map