From ed4c2c6efad7be551089d8334a6bac4fd1586c5f Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Thu, 19 Aug 2021 17:28:07 -0400 Subject: [PATCH] update todo --- CHANGELOG.md | 8 +++++-- TODO.md | 4 ++++ dist/human.esm-nobundle.js | 2 +- dist/human.esm.js | 2 +- dist/human.js | 2 +- dist/human.node-gpu.js | 2 +- dist/human.node-wasm.js | 2 +- dist/human.node.js | 2 +- server/build.log | 44 +++++++++++++++++++------------------- 9 files changed, 38 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3929c42b..5b2b42ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # @vladmandic/human -Version: **2.1.3** +Version: **2.1.4** Description: **Human: AI-powered 3D Face Detection & Rotation Tracking, Face Description & Recognition, Body Pose Tracking, 3D Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction, Gesture Recognition** Author: **Vladimir Mandic ** @@ -9,7 +9,11 @@ Repository: **** ## Changelog -### **HEAD -> main** 2021/08/18 mandic00@live.com +### **2.1.4** 2021/08/19 mandic00@live.com + +- add static type definitions to main class + +### **origin/main** 2021/08/18 mandic00@live.com - rebuild full - improve face box caching diff --git a/TODO.md b/TODO.md index 47eb58a0..130cc989 100644 --- a/TODO.md +++ b/TODO.md @@ -7,6 +7,10 @@ WebGL shader optimizations for faster load and initial detection - Implement WebGL uniforms for shaders: - Fix shader packing: +MoveNet MultiPose Model: + +- Implementation is ready, but model is 2x size and 0.5x performance +
## Exploring diff --git a/dist/human.esm-nobundle.js b/dist/human.esm-nobundle.js index 9903b742..f45bb1e4 100644 --- a/dist/human.esm-nobundle.js +++ b/dist/human.esm-nobundle.js @@ -730,5 +730,5 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var ye="2.1.3";var b0,S0,k0,d0,c0,g0,Q0,W0,_0,$0,A5,e5,s2=class{constructor(e){K(this,b0,void 0);K(this,S0,void 0);K(this,k0,void 0);K(this,d0,void 0);K(this,c0,void 0);K(this,g0,void 0);this.analyze=(...e)=>{if(!X(this,S0))return;let t=this.tf.engine().state.numTensors,r=X(this,b0);_(this,b0,t);let n=t-r;n!==0&&M(...e,n)};K(this,Q0,e=>{if(!X(this,k0))return null;if(!e)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(e instanceof o.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(t){return"backend not loaded"}return null});K(this,W0,async(e=!1)=>{var t;if(this.config.backend&&this.config.backend.length>0&&e||this.tf.getBackend()!==this.config.backend){let r=I();if(this.state="backend",this.config.backend&&this.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&this.config.debug&&M("running inside web worker"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(M("override: backend set to tensorflow while running in browser"),this.config.backend="humangl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="humangl")&&(M("override: backend set to webgl while running in nodejs"),this.config.backend="tensorflow"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")M("override: backend set to webgpu but browser does not support webgpu"),this.config.backend="humangl";else{let a=await navigator.gpu.requestAdapter();this.config.debug&&M("enumerated webgpu adapter:",a)}this.config.backend==="humangl"&&xA();let n=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&M("available backends:",n),n.includes(this.config.backend)||(M(`error: backend ${this.config.backend} not found in registry`),this.config.backend=this.tf.ENV.flags.IS_NODE?"tensorflow":"humangl",M(`override: using backend ${this.config.backend} instead`)),this.config.debug&&M("setting backend:",this.config.backend),this.config.backend==="wasm"){if(this.config.debug&&M("wasm path:",this.config.wasmPath),typeof((t=this.tf)==null?void 0:t.setWasmPaths)!="undefined")this.tf.setWasmPaths(this.config.wasmPath);else throw new Error("Human: WASM backend is not loaded");let a=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),x=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&M(`wasm execution: ${a?"SIMD":"no SIMD"} ${x?"multithreaded":"singlethreaded"}`),this.config.debug&&!a&&M("warning: wasm simd support is not enabled")}try{await this.tf.setBackend(this.config.backend)}catch(a){M("error: cannot set backend:",this.config.backend,a)}}if(this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_CPU_FORWARD",!0),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!1),this.tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS",!0),typeof this.config.deallocate!="undefined"&&this.config.deallocate&&(M("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",0));let n=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&M(`gl version:${n.getParameter(n.VERSION)} renderer:${n.getParameter(n.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(I()-r)}});this.next=e=>xe(e||this.result);K(this,_0,async e=>{if(this.config.cacheSensitivity===0)return!1;let t=32;if(!e.shape[1]||!e.shape[2])return!1;let r=o.image.resizeBilinear(e,[Math.trunc(e.shape[1]/t),Math.trunc(e.shape[2]/t)]),n=await r.data(),a=0;for(let y=0;y10*this.config.cacheSensitivity?0:x),s});K(this,$0,async()=>{let e=(n,a="application/octet-stream")=>fetch(`data:${a};base64,${n}`).then(x=>x.blob()),t,r;switch(this.config.warmup){case"face":t=await e(D0);break;case"full":t=await e(K0);break;default:t=null}if(t){let n=await createImageBitmap(t);r=await this.detect(n,this.config),n.close()}return r});K(this,A5,async()=>new Promise(e=>{let t,r=0;switch(this.config.warmup){case"face":r=256,t="data:image/jpeg;base64,"+D0;break;case"full":case"body":r=1200,t="data:image/jpeg;base64,"+K0;break;default:t=null}let n=new Image;n.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");a.width=n.naturalWidth,a.height=n.naturalHeight;let x=a.getContext("2d");x==null||x.drawImage(n,0,0);let s=await this.detect(a,this.config);e(s)},t?n.src=t:e(null)}));K(this,e5,async()=>{let e=n=>Buffer.from(n,"base64"),t;if(this.config.warmup==="face"&&(t=e(D0)),(this.config.warmup==="body"||this.config.warmup==="full")&&(t=e(K0)),!t)return null;let r;if(typeof o.node!="undefined"){let n=o.node.decodeJpeg(t),a=n.expandDims(0);this.tf.dispose(n),r=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&M("Warmup tfjs-node not loaded");return r});this.config=C(aA,e||{}),this.tf=o,this.draw=nA,this.version=ye,this.state="idle",_(this,b0,0),_(this,S0,!1),_(this,k0,!1),_(this,d0,!0),_(this,g0,0),this.performance={backend:0,load:0,image:0,frames:0,cached:0,changed:0,total:0,draw:0},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,movenet:null,handpose:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,centernet:null,faceres:null,segmentation:null},this.result={face:[],body:[],hand:[],gesture:[],object:[],performance:{},timestamp:0,persons:[]},this.image=t=>l0(t,this.config),this.faceTriangulation=PA,this.faceUVMap=vA,this.sysinfo=iA(),_(this,c0,1)}similarity(e,t){return m5(e,t)}segmentation(e,t){return QA(e,t,this.config)}enhance(e){return u5(e)}match(e,t,r=0){return EA(e,t,r)}async load(e){this.state="load";let t=I();e&&(this.config=C(this.config,e)),X(this,d0)&&(this.config.debug&&M(`version: ${this.version}`),this.config.debug&&M(`tfjs version: ${this.tf.version_core}`),this.config.debug&&M("platform:",this.sysinfo.platform),this.config.debug&&M("agent:",this.sysinfo.agent),await X(this,W0).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&M("configuration:",this.config),this.config.debug&&M("tf flags:",this.tf.ENV.flags))),await _A(this),X(this,d0)&&(this.config.debug&&M("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),_(this,d0,!1));let r=Math.trunc(I()-t);r>(this.performance.load||0)&&(this.performance.load=r)}async detect(e,t){return new Promise(async r=>{this.state="config";let n,a;this.config=C(this.config,t),this.state="check";let x=X(this,Q0).call(this,e);x&&(M(x,e),r({error:x}));let s=I();await X(this,W0).call(this),await this.load(),n=I();let y=l0(e,this.config);if(this.performance.image=Math.trunc(I()-n),this.analyze("Get Image:"),this.config.segmentation.enabled&&y&&y.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",n=I(),await AA(y),a=Math.trunc(I()-n),a>0&&(this.performance.segmentation=a),y.canvas&&(o.dispose(y.tensor),y=l0(y.canvas,this.config)),this.analyze("End Segmentation:")),!y||!y.tensor){M("could not convert input to tensor"),r({error:"could not convert input to tensor"});return}n=I(),this.config.skipFrame=await X(this,_0).call(this,y.tensor),this.performance.frames||(this.performance.frames=0),this.performance.cached||(this.performance.cached=0),this.performance.frames++,this.config.skipFrame&&this.performance.cached++,this.performance.changed=Math.trunc(I()-n),this.analyze("Check Changed:");let i=[],l=[],d=[],c=[];this.config.async?(i=this.config.face.enabled?eA(this,y.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",n=I(),i=this.config.face.enabled?await eA(this,y.tensor):[],a=Math.trunc(I()-n),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?R5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?O5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?Z5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?G5(y.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",n=I(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await R5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await O5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?await Z5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?await G5(y.tensor,this.config):[]),a=Math.trunc(I()-n),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?I5(y.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",n=I(),d=this.config.hand.enabled?await I5(y.tensor,this.config):[],a=Math.trunc(I()-n),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?c=this.config.object.enabled?Y5(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(c=this.config.object.enabled?_5(y.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",n=I(),this.config.object.modelPath.includes("nanodet")?c=this.config.object.enabled?await Y5(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(c=this.config.object.enabled?await _5(y.tensor,this.config):[]),a=Math.trunc(I()-n),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([i,l,d,c]=await Promise.all([i,l,d,c]));let u=[];this.config.gesture.enabled&&(n=I(),u=[...Ae(i),...$A(l),...te(d),...ee(i)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(I()-n)),this.performance.total=Math.trunc(I()-s),this.state="idle",this.result={face:i,body:l,hand:d,gesture:u,object:c,performance:this.performance,canvas:y.canvas,timestamp:Date.now(),get persons(){var P;return ie(i,l,d,u,(P=y==null?void 0:y.tensor)==null?void 0:P.shape)}},o.dispose(y.tensor),r(this.result)})}async warmup(e){let t=I();if(e&&(this.config=C(this.config,e)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let r;typeof createImageBitmap=="function"?r=await X(this,$0).call(this):typeof Image!="undefined"?r=await X(this,A5).call(this):r=await X(this,e5).call(this);let n=I();return this.config.debug&&M("Warmup",this.config.warmup,Math.round(n-t),"ms",r),r}};b0=new WeakMap,S0=new WeakMap,k0=new WeakMap,d0=new WeakMap,c0=new WeakMap,g0=new WeakMap,Q0=new WeakMap,W0=new WeakMap,_0=new WeakMap,$0=new WeakMap,A5=new WeakMap,e5=new WeakMap;export{s2 as Human,s2 as default}; +2Q==`;var ye="2.1.4";var b0,S0,k0,d0,c0,g0,Q0,W0,_0,$0,A5,e5,s2=class{constructor(e){K(this,b0,void 0);K(this,S0,void 0);K(this,k0,void 0);K(this,d0,void 0);K(this,c0,void 0);K(this,g0,void 0);this.analyze=(...e)=>{if(!X(this,S0))return;let t=this.tf.engine().state.numTensors,r=X(this,b0);_(this,b0,t);let n=t-r;n!==0&&M(...e,n)};K(this,Q0,e=>{if(!X(this,k0))return null;if(!e)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(e instanceof o.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(t){return"backend not loaded"}return null});K(this,W0,async(e=!1)=>{var t;if(this.config.backend&&this.config.backend.length>0&&e||this.tf.getBackend()!==this.config.backend){let r=I();if(this.state="backend",this.config.backend&&this.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&this.config.debug&&M("running inside web worker"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(M("override: backend set to tensorflow while running in browser"),this.config.backend="humangl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="humangl")&&(M("override: backend set to webgl while running in nodejs"),this.config.backend="tensorflow"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")M("override: backend set to webgpu but browser does not support webgpu"),this.config.backend="humangl";else{let a=await navigator.gpu.requestAdapter();this.config.debug&&M("enumerated webgpu adapter:",a)}this.config.backend==="humangl"&&xA();let n=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&M("available backends:",n),n.includes(this.config.backend)||(M(`error: backend ${this.config.backend} not found in registry`),this.config.backend=this.tf.ENV.flags.IS_NODE?"tensorflow":"humangl",M(`override: using backend ${this.config.backend} instead`)),this.config.debug&&M("setting backend:",this.config.backend),this.config.backend==="wasm"){if(this.config.debug&&M("wasm path:",this.config.wasmPath),typeof((t=this.tf)==null?void 0:t.setWasmPaths)!="undefined")this.tf.setWasmPaths(this.config.wasmPath);else throw new Error("Human: WASM backend is not loaded");let a=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),x=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&M(`wasm execution: ${a?"SIMD":"no SIMD"} ${x?"multithreaded":"singlethreaded"}`),this.config.debug&&!a&&M("warning: wasm simd support is not enabled")}try{await this.tf.setBackend(this.config.backend)}catch(a){M("error: cannot set backend:",this.config.backend,a)}}if(this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_CPU_FORWARD",!0),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!1),this.tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS",!0),typeof this.config.deallocate!="undefined"&&this.config.deallocate&&(M("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",0));let n=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&M(`gl version:${n.getParameter(n.VERSION)} renderer:${n.getParameter(n.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(I()-r)}});this.next=e=>xe(e||this.result);K(this,_0,async e=>{if(this.config.cacheSensitivity===0)return!1;let t=32;if(!e.shape[1]||!e.shape[2])return!1;let r=o.image.resizeBilinear(e,[Math.trunc(e.shape[1]/t),Math.trunc(e.shape[2]/t)]),n=await r.data(),a=0;for(let y=0;y10*this.config.cacheSensitivity?0:x),s});K(this,$0,async()=>{let e=(n,a="application/octet-stream")=>fetch(`data:${a};base64,${n}`).then(x=>x.blob()),t,r;switch(this.config.warmup){case"face":t=await e(D0);break;case"full":t=await e(K0);break;default:t=null}if(t){let n=await createImageBitmap(t);r=await this.detect(n,this.config),n.close()}return r});K(this,A5,async()=>new Promise(e=>{let t,r=0;switch(this.config.warmup){case"face":r=256,t="data:image/jpeg;base64,"+D0;break;case"full":case"body":r=1200,t="data:image/jpeg;base64,"+K0;break;default:t=null}let n=new Image;n.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");a.width=n.naturalWidth,a.height=n.naturalHeight;let x=a.getContext("2d");x==null||x.drawImage(n,0,0);let s=await this.detect(a,this.config);e(s)},t?n.src=t:e(null)}));K(this,e5,async()=>{let e=n=>Buffer.from(n,"base64"),t;if(this.config.warmup==="face"&&(t=e(D0)),(this.config.warmup==="body"||this.config.warmup==="full")&&(t=e(K0)),!t)return null;let r;if(typeof o.node!="undefined"){let n=o.node.decodeJpeg(t),a=n.expandDims(0);this.tf.dispose(n),r=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&M("Warmup tfjs-node not loaded");return r});this.config=C(aA,e||{}),this.tf=o,this.draw=nA,this.version=ye,this.state="idle",_(this,b0,0),_(this,S0,!1),_(this,k0,!1),_(this,d0,!0),_(this,g0,0),this.performance={backend:0,load:0,image:0,frames:0,cached:0,changed:0,total:0,draw:0},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,movenet:null,handpose:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,centernet:null,faceres:null,segmentation:null},this.result={face:[],body:[],hand:[],gesture:[],object:[],performance:{},timestamp:0,persons:[]},this.image=t=>l0(t,this.config),this.faceTriangulation=PA,this.faceUVMap=vA,this.sysinfo=iA(),_(this,c0,1)}similarity(e,t){return m5(e,t)}segmentation(e,t){return QA(e,t,this.config)}enhance(e){return u5(e)}match(e,t,r=0){return EA(e,t,r)}async load(e){this.state="load";let t=I();e&&(this.config=C(this.config,e)),X(this,d0)&&(this.config.debug&&M(`version: ${this.version}`),this.config.debug&&M(`tfjs version: ${this.tf.version_core}`),this.config.debug&&M("platform:",this.sysinfo.platform),this.config.debug&&M("agent:",this.sysinfo.agent),await X(this,W0).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&M("configuration:",this.config),this.config.debug&&M("tf flags:",this.tf.ENV.flags))),await _A(this),X(this,d0)&&(this.config.debug&&M("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),_(this,d0,!1));let r=Math.trunc(I()-t);r>(this.performance.load||0)&&(this.performance.load=r)}async detect(e,t){return new Promise(async r=>{this.state="config";let n,a;this.config=C(this.config,t),this.state="check";let x=X(this,Q0).call(this,e);x&&(M(x,e),r({error:x}));let s=I();await X(this,W0).call(this),await this.load(),n=I();let y=l0(e,this.config);if(this.performance.image=Math.trunc(I()-n),this.analyze("Get Image:"),this.config.segmentation.enabled&&y&&y.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",n=I(),await AA(y),a=Math.trunc(I()-n),a>0&&(this.performance.segmentation=a),y.canvas&&(o.dispose(y.tensor),y=l0(y.canvas,this.config)),this.analyze("End Segmentation:")),!y||!y.tensor){M("could not convert input to tensor"),r({error:"could not convert input to tensor"});return}n=I(),this.config.skipFrame=await X(this,_0).call(this,y.tensor),this.performance.frames||(this.performance.frames=0),this.performance.cached||(this.performance.cached=0),this.performance.frames++,this.config.skipFrame&&this.performance.cached++,this.performance.changed=Math.trunc(I()-n),this.analyze("Check Changed:");let i=[],l=[],d=[],c=[];this.config.async?(i=this.config.face.enabled?eA(this,y.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",n=I(),i=this.config.face.enabled?await eA(this,y.tensor):[],a=Math.trunc(I()-n),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?R5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?O5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?Z5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?G5(y.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",n=I(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await R5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await O5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?await Z5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?await G5(y.tensor,this.config):[]),a=Math.trunc(I()-n),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?I5(y.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",n=I(),d=this.config.hand.enabled?await I5(y.tensor,this.config):[],a=Math.trunc(I()-n),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?c=this.config.object.enabled?Y5(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(c=this.config.object.enabled?_5(y.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",n=I(),this.config.object.modelPath.includes("nanodet")?c=this.config.object.enabled?await Y5(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(c=this.config.object.enabled?await _5(y.tensor,this.config):[]),a=Math.trunc(I()-n),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([i,l,d,c]=await Promise.all([i,l,d,c]));let u=[];this.config.gesture.enabled&&(n=I(),u=[...Ae(i),...$A(l),...te(d),...ee(i)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(I()-n)),this.performance.total=Math.trunc(I()-s),this.state="idle",this.result={face:i,body:l,hand:d,gesture:u,object:c,performance:this.performance,canvas:y.canvas,timestamp:Date.now(),get persons(){var P;return ie(i,l,d,u,(P=y==null?void 0:y.tensor)==null?void 0:P.shape)}},o.dispose(y.tensor),r(this.result)})}async warmup(e){let t=I();if(e&&(this.config=C(this.config,e)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let r;typeof createImageBitmap=="function"?r=await X(this,$0).call(this):typeof Image!="undefined"?r=await X(this,A5).call(this):r=await X(this,e5).call(this);let n=I();return this.config.debug&&M("Warmup",this.config.warmup,Math.round(n-t),"ms",r),r}};b0=new WeakMap,S0=new WeakMap,k0=new WeakMap,d0=new WeakMap,c0=new WeakMap,g0=new WeakMap,Q0=new WeakMap,W0=new WeakMap,_0=new WeakMap,$0=new WeakMap,A5=new WeakMap,e5=new WeakMap;export{s2 as Human,s2 as default}; //# sourceMappingURL=human.esm-nobundle.js.map diff --git a/dist/human.esm.js b/dist/human.esm.js index acf7a7f6..034f8539 100644 --- a/dist/human.esm.js +++ b/dist/human.esm.js @@ -5338,7 +5338,7 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var k8="2.1.3";var uu,id,ld,Ko,Zo,cu,Hf,ud,Gf,jf,qf,Xf,Uie=class{constructor(t){ts(this,uu,void 0);ts(this,id,void 0);ts(this,ld,void 0);ts(this,Ko,void 0);ts(this,Zo,void 0);ts(this,cu,void 0);this.analyze=(...t)=>{if(!hn(this,id))return;let n=this.tf.engine().state.numTensors,s=hn(this,uu);Ss(this,uu,n);let r=n-s;r!==0&&ue(...t,r)};ts(this,Hf,t=>{if(!hn(this,ld))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ue))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ts(this,ud,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ke();if(this.state="backend",this.config.backend&&this.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&this.config.debug&&ue("running inside web worker"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(ue("override: backend set to tensorflow while running in browser"),this.config.backend="humangl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="humangl")&&(ue("override: backend set to webgl while running in nodejs"),this.config.backend="tensorflow"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")ue("override: backend set to webgpu but browser does not support webgpu"),this.config.backend="humangl";else{let a=await navigator.gpu.requestAdapter();this.config.debug&&ue("enumerated webgpu adapter:",a)}this.config.backend==="humangl"&&wk();let r=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&ue("available backends:",r),r.includes(this.config.backend)||(ue(`error: backend ${this.config.backend} not found in registry`),this.config.backend=this.tf.ENV.flags.IS_NODE?"tensorflow":"humangl",ue(`override: using backend ${this.config.backend} instead`)),this.config.debug&&ue("setting backend:",this.config.backend),this.config.backend==="wasm"){if(this.config.debug&&ue("wasm path:",this.config.wasmPath),typeof((n=this.tf)==null?void 0:n.setWasmPaths)!="undefined")this.tf.setWasmPaths(this.config.wasmPath);else throw new Error("Human: WASM backend is not loaded");let a=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),o=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&ue(`wasm execution: ${a?"SIMD":"no SIMD"} ${o?"multithreaded":"singlethreaded"}`),this.config.debug&&!a&&ue("warning: wasm simd support is not enabled")}try{await this.tf.setBackend(this.config.backend)}catch(a){ue("error: cannot set backend:",this.config.backend,a)}}if(this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_CPU_FORWARD",!0),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!1),this.tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS",!0),typeof this.config.deallocate!="undefined"&&this.config.deallocate&&(ue("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",0));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&ue(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(Ke()-s)}});this.next=t=>w8(t||this.result);ts(this,Gf,async t=>{if(this.config.cacheSensitivity===0)return!1;let n=32;if(!t.shape[1]||!t.shape[2])return!1;let s=_e.resizeBilinear(t,[Math.trunc(t.shape[1]/n),Math.trunc(t.shape[2]/n)]),r=await s.data(),a=0;for(let l=0;l10*this.config.cacheSensitivity?0:o),i});ts(this,jf,async()=>{let t=(r,a="application/octet-stream")=>fetch(`data:${a};base64,${r}`).then(o=>o.blob()),n,s;switch(this.config.warmup){case"face":n=await t(Vf);break;case"full":n=await t(Uf);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});ts(this,qf,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Vf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+Uf;break;default:n=null}let r=new Image;r.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(s,s):document.createElement("canvas");a.width=r.naturalWidth,a.height=r.naturalHeight;let o=a.getContext("2d");o==null||o.drawImage(r,0,0);let i=await this.detect(a,this.config);t(i)},n?r.src=n:t(null)}));ts(this,Xf,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Vf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(Uf)),!n)return null;let s;if(typeof void 0!="undefined"){let r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r),s=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&ue("Warmup tfjs-node not loaded");return s});this.config=pn(Yy,t||{}),this.tf=Yc,this.draw=Oy,this.version=k8,this.state="idle",Ss(this,uu,0),Ss(this,id,!1),Ss(this,ld,!1),Ss(this,Ko,!0),Ss(this,cu,0),this.performance={backend:0,load:0,image:0,frames:0,cached:0,changed:0,total:0,draw:0},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,movenet:null,handpose:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,centernet:null,faceres:null,segmentation:null},this.result={face:[],body:[],hand:[],gesture:[],object:[],performance:{},timestamp:0,persons:[]},this.image=n=>Xo(n,this.config),this.faceTriangulation=Pk,this.faceUVMap=Mk,this.sysinfo=Jy(),Ss(this,Zo,1)}similarity(t,n){return j1(t,n)}segmentation(t,n){return c8(t,n,this.config)}enhance(t){return q1(t)}match(t,n,s=0){return Lk(t,n,s)}async load(t){this.state="load";let n=Ke();t&&(this.config=pn(this.config,t)),hn(this,Ko)&&(this.config.debug&&ue(`version: ${this.version}`),this.config.debug&&ue(`tfjs version: ${this.tf.version_core}`),this.config.debug&&ue("platform:",this.sysinfo.platform),this.config.debug&&ue("agent:",this.sysinfo.agent),await hn(this,ud).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&ue("configuration:",this.config),this.config.debug&&ue("tf flags:",this.tf.ENV.flags))),await d8(this),hn(this,Ko)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ss(this,Ko,!1));let s=Math.trunc(Ke()-n);s>(this.performance.load||0)&&(this.performance.load=s)}async detect(t,n){return new Promise(async s=>{this.state="config";let r,a;this.config=pn(this.config,n),this.state="check";let o=hn(this,Hf).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ke();await hn(this,ud).call(this),await this.load(),r=Ke();let l=Xo(t,this.config);if(this.performance.image=Math.trunc(Ke()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ke(),await _y(l),a=Math.trunc(Ke()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=Xo(l.canvas,this.config)),this.analyze("End Segmentation:")),!l||!l.tensor){ue("could not convert input to tensor"),s({error:"could not convert input to tensor"});return}r=Ke(),this.config.skipFrame=await hn(this,Gf).call(this,l.tensor),this.performance.frames||(this.performance.frames=0),this.performance.cached||(this.performance.cached=0),this.performance.frames++,this.config.skipFrame&&this.performance.cached++,this.performance.changed=Math.trunc(Ke()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?$y(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ke(),u=this.config.face.enabled?await $y(this,l.tensor):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?hy(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?Ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?vy(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ke(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await hy(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await Ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await vy(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?cy(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ke(),d=this.config.hand.enabled?await cy(l.tensor,this.config):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?Sy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?Ey(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ke(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Sy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await Ey(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([u,c,d,h]=await Promise.all([u,c,d,h]));let p=[];this.config.gesture.enabled&&(r=Ke(),p=[...p8(u),...h8(c),...m8(d),...f8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ke()-r)),this.performance.total=Math.trunc(Ke()-i),this.state="idle",this.result={face:u,body:c,hand:d,gesture:p,object:h,performance:this.performance,canvas:l.canvas,timestamp:Date.now(),get persons(){var f;return v8(u,c,d,p,(f=l==null?void 0:l.tensor)==null?void 0:f.shape)}},K(l.tensor),s(this.result)})}async warmup(t){let n=Ke();if(t&&(this.config=pn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await hn(this,jf).call(this):typeof Image!="undefined"?s=await hn(this,qf).call(this):s=await hn(this,Xf).call(this);let r=Ke();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}};uu=new WeakMap,id=new WeakMap,ld=new WeakMap,Ko=new WeakMap,Zo=new WeakMap,cu=new WeakMap,Hf=new WeakMap,ud=new WeakMap,Gf=new WeakMap,jf=new WeakMap,qf=new WeakMap,Xf=new WeakMap;export{Uie as Human,Uie as default}; +2Q==`;var k8="2.1.4";var uu,id,ld,Ko,Zo,cu,Hf,ud,Gf,jf,qf,Xf,Uie=class{constructor(t){ts(this,uu,void 0);ts(this,id,void 0);ts(this,ld,void 0);ts(this,Ko,void 0);ts(this,Zo,void 0);ts(this,cu,void 0);this.analyze=(...t)=>{if(!hn(this,id))return;let n=this.tf.engine().state.numTensors,s=hn(this,uu);Ss(this,uu,n);let r=n-s;r!==0&&ue(...t,r)};ts(this,Hf,t=>{if(!hn(this,ld))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ue))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ts(this,ud,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ke();if(this.state="backend",this.config.backend&&this.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&this.config.debug&&ue("running inside web worker"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(ue("override: backend set to tensorflow while running in browser"),this.config.backend="humangl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="humangl")&&(ue("override: backend set to webgl while running in nodejs"),this.config.backend="tensorflow"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")ue("override: backend set to webgpu but browser does not support webgpu"),this.config.backend="humangl";else{let a=await navigator.gpu.requestAdapter();this.config.debug&&ue("enumerated webgpu adapter:",a)}this.config.backend==="humangl"&&wk();let r=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&ue("available backends:",r),r.includes(this.config.backend)||(ue(`error: backend ${this.config.backend} not found in registry`),this.config.backend=this.tf.ENV.flags.IS_NODE?"tensorflow":"humangl",ue(`override: using backend ${this.config.backend} instead`)),this.config.debug&&ue("setting backend:",this.config.backend),this.config.backend==="wasm"){if(this.config.debug&&ue("wasm path:",this.config.wasmPath),typeof((n=this.tf)==null?void 0:n.setWasmPaths)!="undefined")this.tf.setWasmPaths(this.config.wasmPath);else throw new Error("Human: WASM backend is not loaded");let a=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),o=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&ue(`wasm execution: ${a?"SIMD":"no SIMD"} ${o?"multithreaded":"singlethreaded"}`),this.config.debug&&!a&&ue("warning: wasm simd support is not enabled")}try{await this.tf.setBackend(this.config.backend)}catch(a){ue("error: cannot set backend:",this.config.backend,a)}}if(this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_CPU_FORWARD",!0),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!1),this.tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS",!0),typeof this.config.deallocate!="undefined"&&this.config.deallocate&&(ue("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",0));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&ue(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(Ke()-s)}});this.next=t=>w8(t||this.result);ts(this,Gf,async t=>{if(this.config.cacheSensitivity===0)return!1;let n=32;if(!t.shape[1]||!t.shape[2])return!1;let s=_e.resizeBilinear(t,[Math.trunc(t.shape[1]/n),Math.trunc(t.shape[2]/n)]),r=await s.data(),a=0;for(let l=0;l10*this.config.cacheSensitivity?0:o),i});ts(this,jf,async()=>{let t=(r,a="application/octet-stream")=>fetch(`data:${a};base64,${r}`).then(o=>o.blob()),n,s;switch(this.config.warmup){case"face":n=await t(Vf);break;case"full":n=await t(Uf);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});ts(this,qf,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Vf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+Uf;break;default:n=null}let r=new Image;r.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(s,s):document.createElement("canvas");a.width=r.naturalWidth,a.height=r.naturalHeight;let o=a.getContext("2d");o==null||o.drawImage(r,0,0);let i=await this.detect(a,this.config);t(i)},n?r.src=n:t(null)}));ts(this,Xf,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Vf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(Uf)),!n)return null;let s;if(typeof void 0!="undefined"){let r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r),s=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&ue("Warmup tfjs-node not loaded");return s});this.config=pn(Yy,t||{}),this.tf=Yc,this.draw=Oy,this.version=k8,this.state="idle",Ss(this,uu,0),Ss(this,id,!1),Ss(this,ld,!1),Ss(this,Ko,!0),Ss(this,cu,0),this.performance={backend:0,load:0,image:0,frames:0,cached:0,changed:0,total:0,draw:0},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,movenet:null,handpose:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,centernet:null,faceres:null,segmentation:null},this.result={face:[],body:[],hand:[],gesture:[],object:[],performance:{},timestamp:0,persons:[]},this.image=n=>Xo(n,this.config),this.faceTriangulation=Pk,this.faceUVMap=Mk,this.sysinfo=Jy(),Ss(this,Zo,1)}similarity(t,n){return j1(t,n)}segmentation(t,n){return c8(t,n,this.config)}enhance(t){return q1(t)}match(t,n,s=0){return Lk(t,n,s)}async load(t){this.state="load";let n=Ke();t&&(this.config=pn(this.config,t)),hn(this,Ko)&&(this.config.debug&&ue(`version: ${this.version}`),this.config.debug&&ue(`tfjs version: ${this.tf.version_core}`),this.config.debug&&ue("platform:",this.sysinfo.platform),this.config.debug&&ue("agent:",this.sysinfo.agent),await hn(this,ud).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&ue("configuration:",this.config),this.config.debug&&ue("tf flags:",this.tf.ENV.flags))),await d8(this),hn(this,Ko)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ss(this,Ko,!1));let s=Math.trunc(Ke()-n);s>(this.performance.load||0)&&(this.performance.load=s)}async detect(t,n){return new Promise(async s=>{this.state="config";let r,a;this.config=pn(this.config,n),this.state="check";let o=hn(this,Hf).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ke();await hn(this,ud).call(this),await this.load(),r=Ke();let l=Xo(t,this.config);if(this.performance.image=Math.trunc(Ke()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ke(),await _y(l),a=Math.trunc(Ke()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=Xo(l.canvas,this.config)),this.analyze("End Segmentation:")),!l||!l.tensor){ue("could not convert input to tensor"),s({error:"could not convert input to tensor"});return}r=Ke(),this.config.skipFrame=await hn(this,Gf).call(this,l.tensor),this.performance.frames||(this.performance.frames=0),this.performance.cached||(this.performance.cached=0),this.performance.frames++,this.config.skipFrame&&this.performance.cached++,this.performance.changed=Math.trunc(Ke()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?$y(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ke(),u=this.config.face.enabled?await $y(this,l.tensor):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?hy(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?Ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?vy(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ke(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await hy(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await Ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await vy(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?cy(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ke(),d=this.config.hand.enabled?await cy(l.tensor,this.config):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?Sy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?Ey(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ke(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Sy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await Ey(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([u,c,d,h]=await Promise.all([u,c,d,h]));let p=[];this.config.gesture.enabled&&(r=Ke(),p=[...p8(u),...h8(c),...m8(d),...f8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ke()-r)),this.performance.total=Math.trunc(Ke()-i),this.state="idle",this.result={face:u,body:c,hand:d,gesture:p,object:h,performance:this.performance,canvas:l.canvas,timestamp:Date.now(),get persons(){var f;return v8(u,c,d,p,(f=l==null?void 0:l.tensor)==null?void 0:f.shape)}},K(l.tensor),s(this.result)})}async warmup(t){let n=Ke();if(t&&(this.config=pn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await hn(this,jf).call(this):typeof Image!="undefined"?s=await hn(this,qf).call(this):s=await hn(this,Xf).call(this);let r=Ke();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}};uu=new WeakMap,id=new WeakMap,ld=new WeakMap,Ko=new WeakMap,Zo=new WeakMap,cu=new WeakMap,Hf=new WeakMap,ud=new WeakMap,Gf=new WeakMap,jf=new WeakMap,qf=new WeakMap,Xf=new WeakMap;export{Uie as Human,Uie as default}; /** * @license * Copyright 2017 Google LLC. All Rights Reserved. diff --git a/dist/human.js b/dist/human.js index c9165b4b..d1a3e2ce 100644 --- a/dist/human.js +++ b/dist/human.js @@ -5338,7 +5338,7 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var k8="2.1.3";var uu,id,ld,Ko,Zo,cu,Hf,ud,Gf,jf,qf,Xf,I8=class{constructor(t){ts(this,uu,void 0);ts(this,id,void 0);ts(this,ld,void 0);ts(this,Ko,void 0);ts(this,Zo,void 0);ts(this,cu,void 0);this.analyze=(...t)=>{if(!hn(this,id))return;let n=this.tf.engine().state.numTensors,s=hn(this,uu);Ss(this,uu,n);let r=n-s;r!==0&&ue(...t,r)};ts(this,Hf,t=>{if(!hn(this,ld))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ue))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ts(this,ud,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ke();if(this.state="backend",this.config.backend&&this.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&this.config.debug&&ue("running inside web worker"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(ue("override: backend set to tensorflow while running in browser"),this.config.backend="humangl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="humangl")&&(ue("override: backend set to webgl while running in nodejs"),this.config.backend="tensorflow"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")ue("override: backend set to webgpu but browser does not support webgpu"),this.config.backend="humangl";else{let a=await navigator.gpu.requestAdapter();this.config.debug&&ue("enumerated webgpu adapter:",a)}this.config.backend==="humangl"&&wk();let r=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&ue("available backends:",r),r.includes(this.config.backend)||(ue(`error: backend ${this.config.backend} not found in registry`),this.config.backend=this.tf.ENV.flags.IS_NODE?"tensorflow":"humangl",ue(`override: using backend ${this.config.backend} instead`)),this.config.debug&&ue("setting backend:",this.config.backend),this.config.backend==="wasm"){if(this.config.debug&&ue("wasm path:",this.config.wasmPath),typeof((n=this.tf)==null?void 0:n.setWasmPaths)!="undefined")this.tf.setWasmPaths(this.config.wasmPath);else throw new Error("Human: WASM backend is not loaded");let a=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),o=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&ue(`wasm execution: ${a?"SIMD":"no SIMD"} ${o?"multithreaded":"singlethreaded"}`),this.config.debug&&!a&&ue("warning: wasm simd support is not enabled")}try{await this.tf.setBackend(this.config.backend)}catch(a){ue("error: cannot set backend:",this.config.backend,a)}}if(this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_CPU_FORWARD",!0),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!1),this.tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS",!0),typeof this.config.deallocate!="undefined"&&this.config.deallocate&&(ue("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",0));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&ue(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(Ke()-s)}});this.next=t=>w8(t||this.result);ts(this,Gf,async t=>{if(this.config.cacheSensitivity===0)return!1;let n=32;if(!t.shape[1]||!t.shape[2])return!1;let s=_e.resizeBilinear(t,[Math.trunc(t.shape[1]/n),Math.trunc(t.shape[2]/n)]),r=await s.data(),a=0;for(let l=0;l10*this.config.cacheSensitivity?0:o),i});ts(this,jf,async()=>{let t=(r,a="application/octet-stream")=>fetch(`data:${a};base64,${r}`).then(o=>o.blob()),n,s;switch(this.config.warmup){case"face":n=await t(Vf);break;case"full":n=await t(Uf);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});ts(this,qf,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Vf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+Uf;break;default:n=null}let r=new Image;r.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(s,s):document.createElement("canvas");a.width=r.naturalWidth,a.height=r.naturalHeight;let o=a.getContext("2d");o==null||o.drawImage(r,0,0);let i=await this.detect(a,this.config);t(i)},n?r.src=n:t(null)}));ts(this,Xf,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Vf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(Uf)),!n)return null;let s;if(typeof void 0!="undefined"){let r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r),s=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&ue("Warmup tfjs-node not loaded");return s});this.config=pn(Yy,t||{}),this.tf=Yc,this.draw=Py,this.version=k8,this.state="idle",Ss(this,uu,0),Ss(this,id,!1),Ss(this,ld,!1),Ss(this,Ko,!0),Ss(this,cu,0),this.performance={backend:0,load:0,image:0,frames:0,cached:0,changed:0,total:0,draw:0},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,movenet:null,handpose:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,centernet:null,faceres:null,segmentation:null},this.result={face:[],body:[],hand:[],gesture:[],object:[],performance:{},timestamp:0,persons:[]},this.image=n=>Xo(n,this.config),this.faceTriangulation=Pk,this.faceUVMap=Mk,this.sysinfo=Jy(),Ss(this,Zo,1)}similarity(t,n){return q1(t,n)}segmentation(t,n){return c8(t,n,this.config)}enhance(t){return X1(t)}match(t,n,s=0){return Lk(t,n,s)}async load(t){this.state="load";let n=Ke();t&&(this.config=pn(this.config,t)),hn(this,Ko)&&(this.config.debug&&ue(`version: ${this.version}`),this.config.debug&&ue(`tfjs version: ${this.tf.version_core}`),this.config.debug&&ue("platform:",this.sysinfo.platform),this.config.debug&&ue("agent:",this.sysinfo.agent),await hn(this,ud).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&ue("configuration:",this.config),this.config.debug&&ue("tf flags:",this.tf.ENV.flags))),await d8(this),hn(this,Ko)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ss(this,Ko,!1));let s=Math.trunc(Ke()-n);s>(this.performance.load||0)&&(this.performance.load=s)}async detect(t,n){return new Promise(async s=>{this.state="config";let r,a;this.config=pn(this.config,n),this.state="check";let o=hn(this,Hf).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ke();await hn(this,ud).call(this),await this.load(),r=Ke();let l=Xo(t,this.config);if(this.performance.image=Math.trunc(Ke()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ke(),await $y(l),a=Math.trunc(Ke()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=Xo(l.canvas,this.config)),this.analyze("End Segmentation:")),!l||!l.tensor){ue("could not convert input to tensor"),s({error:"could not convert input to tensor"});return}r=Ke(),this.config.skipFrame=await hn(this,Gf).call(this,l.tensor),this.performance.frames||(this.performance.frames=0),this.performance.cached||(this.performance.cached=0),this.performance.frames++,this.config.skipFrame&&this.performance.cached++,this.performance.changed=Math.trunc(Ke()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?Fy(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ke(),u=this.config.face.enabled?await Fy(this,l.tensor):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?py(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?gy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?wy(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ke(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await py(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await gy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await wy(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?dy(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ke(),d=this.config.hand.enabled?await dy(l.tensor,this.config):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?Cy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?Ry(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ke(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Cy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await Ry(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([u,c,d,h]=await Promise.all([u,c,d,h]));let p=[];this.config.gesture.enabled&&(r=Ke(),p=[...p8(u),...h8(c),...m8(d),...f8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ke()-r)),this.performance.total=Math.trunc(Ke()-i),this.state="idle",this.result={face:u,body:c,hand:d,gesture:p,object:h,performance:this.performance,canvas:l.canvas,timestamp:Date.now(),get persons(){var f;return v8(u,c,d,p,(f=l==null?void 0:l.tensor)==null?void 0:f.shape)}},K(l.tensor),s(this.result)})}async warmup(t){let n=Ke();if(t&&(this.config=pn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await hn(this,jf).call(this):typeof Image!="undefined"?s=await hn(this,qf).call(this):s=await hn(this,Xf).call(this);let r=Ke();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}};uu=new WeakMap,id=new WeakMap,ld=new WeakMap,Ko=new WeakMap,Zo=new WeakMap,cu=new WeakMap,Hf=new WeakMap,ud=new WeakMap,Gf=new WeakMap,jf=new WeakMap,qf=new WeakMap,Xf=new WeakMap;return Hie;})(); +2Q==`;var k8="2.1.4";var uu,id,ld,Ko,Zo,cu,Hf,ud,Gf,jf,qf,Xf,I8=class{constructor(t){ts(this,uu,void 0);ts(this,id,void 0);ts(this,ld,void 0);ts(this,Ko,void 0);ts(this,Zo,void 0);ts(this,cu,void 0);this.analyze=(...t)=>{if(!hn(this,id))return;let n=this.tf.engine().state.numTensors,s=hn(this,uu);Ss(this,uu,n);let r=n-s;r!==0&&ue(...t,r)};ts(this,Hf,t=>{if(!hn(this,ld))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ue))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ts(this,ud,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ke();if(this.state="backend",this.config.backend&&this.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&this.config.debug&&ue("running inside web worker"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(ue("override: backend set to tensorflow while running in browser"),this.config.backend="humangl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="humangl")&&(ue("override: backend set to webgl while running in nodejs"),this.config.backend="tensorflow"),this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")ue("override: backend set to webgpu but browser does not support webgpu"),this.config.backend="humangl";else{let a=await navigator.gpu.requestAdapter();this.config.debug&&ue("enumerated webgpu adapter:",a)}this.config.backend==="humangl"&&wk();let r=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&ue("available backends:",r),r.includes(this.config.backend)||(ue(`error: backend ${this.config.backend} not found in registry`),this.config.backend=this.tf.ENV.flags.IS_NODE?"tensorflow":"humangl",ue(`override: using backend ${this.config.backend} instead`)),this.config.debug&&ue("setting backend:",this.config.backend),this.config.backend==="wasm"){if(this.config.debug&&ue("wasm path:",this.config.wasmPath),typeof((n=this.tf)==null?void 0:n.setWasmPaths)!="undefined")this.tf.setWasmPaths(this.config.wasmPath);else throw new Error("Human: WASM backend is not loaded");let a=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),o=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&ue(`wasm execution: ${a?"SIMD":"no SIMD"} ${o?"multithreaded":"singlethreaded"}`),this.config.debug&&!a&&ue("warning: wasm simd support is not enabled")}try{await this.tf.setBackend(this.config.backend)}catch(a){ue("error: cannot set backend:",this.config.backend,a)}}if(this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_CPU_FORWARD",!0),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!1),this.tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS",!0),typeof this.config.deallocate!="undefined"&&this.config.deallocate&&(ue("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",0));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&ue(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(Ke()-s)}});this.next=t=>w8(t||this.result);ts(this,Gf,async t=>{if(this.config.cacheSensitivity===0)return!1;let n=32;if(!t.shape[1]||!t.shape[2])return!1;let s=_e.resizeBilinear(t,[Math.trunc(t.shape[1]/n),Math.trunc(t.shape[2]/n)]),r=await s.data(),a=0;for(let l=0;l10*this.config.cacheSensitivity?0:o),i});ts(this,jf,async()=>{let t=(r,a="application/octet-stream")=>fetch(`data:${a};base64,${r}`).then(o=>o.blob()),n,s;switch(this.config.warmup){case"face":n=await t(Vf);break;case"full":n=await t(Uf);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});ts(this,qf,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Vf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+Uf;break;default:n=null}let r=new Image;r.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(s,s):document.createElement("canvas");a.width=r.naturalWidth,a.height=r.naturalHeight;let o=a.getContext("2d");o==null||o.drawImage(r,0,0);let i=await this.detect(a,this.config);t(i)},n?r.src=n:t(null)}));ts(this,Xf,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Vf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(Uf)),!n)return null;let s;if(typeof void 0!="undefined"){let r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r),s=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&ue("Warmup tfjs-node not loaded");return s});this.config=pn(Yy,t||{}),this.tf=Yc,this.draw=Py,this.version=k8,this.state="idle",Ss(this,uu,0),Ss(this,id,!1),Ss(this,ld,!1),Ss(this,Ko,!0),Ss(this,cu,0),this.performance={backend:0,load:0,image:0,frames:0,cached:0,changed:0,total:0,draw:0},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,movenet:null,handpose:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,centernet:null,faceres:null,segmentation:null},this.result={face:[],body:[],hand:[],gesture:[],object:[],performance:{},timestamp:0,persons:[]},this.image=n=>Xo(n,this.config),this.faceTriangulation=Pk,this.faceUVMap=Mk,this.sysinfo=Jy(),Ss(this,Zo,1)}similarity(t,n){return q1(t,n)}segmentation(t,n){return c8(t,n,this.config)}enhance(t){return X1(t)}match(t,n,s=0){return Lk(t,n,s)}async load(t){this.state="load";let n=Ke();t&&(this.config=pn(this.config,t)),hn(this,Ko)&&(this.config.debug&&ue(`version: ${this.version}`),this.config.debug&&ue(`tfjs version: ${this.tf.version_core}`),this.config.debug&&ue("platform:",this.sysinfo.platform),this.config.debug&&ue("agent:",this.sysinfo.agent),await hn(this,ud).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&ue("configuration:",this.config),this.config.debug&&ue("tf flags:",this.tf.ENV.flags))),await d8(this),hn(this,Ko)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ss(this,Ko,!1));let s=Math.trunc(Ke()-n);s>(this.performance.load||0)&&(this.performance.load=s)}async detect(t,n){return new Promise(async s=>{this.state="config";let r,a;this.config=pn(this.config,n),this.state="check";let o=hn(this,Hf).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ke();await hn(this,ud).call(this),await this.load(),r=Ke();let l=Xo(t,this.config);if(this.performance.image=Math.trunc(Ke()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ke(),await $y(l),a=Math.trunc(Ke()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=Xo(l.canvas,this.config)),this.analyze("End Segmentation:")),!l||!l.tensor){ue("could not convert input to tensor"),s({error:"could not convert input to tensor"});return}r=Ke(),this.config.skipFrame=await hn(this,Gf).call(this,l.tensor),this.performance.frames||(this.performance.frames=0),this.performance.cached||(this.performance.cached=0),this.performance.frames++,this.config.skipFrame&&this.performance.cached++,this.performance.changed=Math.trunc(Ke()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?Fy(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ke(),u=this.config.face.enabled?await Fy(this,l.tensor):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?py(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?gy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?wy(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ke(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await ay(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await py(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await gy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await wy(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?dy(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ke(),d=this.config.hand.enabled?await dy(l.tensor,this.config):[],a=Math.trunc(Ke()-r),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?Cy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?Ry(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ke(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Cy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await Ry(l.tensor,this.config):[]),a=Math.trunc(Ke()-r),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([u,c,d,h]=await Promise.all([u,c,d,h]));let p=[];this.config.gesture.enabled&&(r=Ke(),p=[...p8(u),...h8(c),...m8(d),...f8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ke()-r)),this.performance.total=Math.trunc(Ke()-i),this.state="idle",this.result={face:u,body:c,hand:d,gesture:p,object:h,performance:this.performance,canvas:l.canvas,timestamp:Date.now(),get persons(){var f;return v8(u,c,d,p,(f=l==null?void 0:l.tensor)==null?void 0:f.shape)}},K(l.tensor),s(this.result)})}async warmup(t){let n=Ke();if(t&&(this.config=pn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await hn(this,jf).call(this):typeof Image!="undefined"?s=await hn(this,qf).call(this):s=await hn(this,Xf).call(this);let r=Ke();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}};uu=new WeakMap,id=new WeakMap,ld=new WeakMap,Ko=new WeakMap,Zo=new WeakMap,cu=new WeakMap,Hf=new WeakMap,ud=new WeakMap,Gf=new WeakMap,jf=new WeakMap,qf=new WeakMap,Xf=new WeakMap;return Hie;})(); /** * @license * Copyright 2017 Google LLC. All Rights Reserved. diff --git a/dist/human.node-gpu.js b/dist/human.node-gpu.js index dbfdee3f..e75687fa 100644 --- a/dist/human.node-gpu.js +++ b/dist/human.node-gpu.js @@ -11357,7 +11357,7 @@ lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ 2Q==`; // package.json -var version = "2.1.3"; +var version = "2.1.4"; // src/human.ts var _numTensors, _analyzeMemoryLeaks, _checkSanity, _firstRun, _lastInputSum, _lastCacheDiff, _sanity, _checkBackend, _skipFrame, _warmupBitmap, _warmupCanvas, _warmupNode; diff --git a/dist/human.node-wasm.js b/dist/human.node-wasm.js index facc649d..efd7b683 100644 --- a/dist/human.node-wasm.js +++ b/dist/human.node-wasm.js @@ -11358,7 +11358,7 @@ lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ 2Q==`; // package.json -var version = "2.1.3"; +var version = "2.1.4"; // src/human.ts var _numTensors, _analyzeMemoryLeaks, _checkSanity, _firstRun, _lastInputSum, _lastCacheDiff, _sanity, _checkBackend, _skipFrame, _warmupBitmap, _warmupCanvas, _warmupNode; diff --git a/dist/human.node.js b/dist/human.node.js index c6ecec8a..6780bd0a 100644 --- a/dist/human.node.js +++ b/dist/human.node.js @@ -11357,7 +11357,7 @@ lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ 2Q==`; // package.json -var version = "2.1.3"; +var version = "2.1.4"; // src/human.ts var _numTensors, _analyzeMemoryLeaks, _checkSanity, _firstRun, _lastInputSum, _lastCacheDiff, _sanity, _checkBackend, _skipFrame, _warmupBitmap, _warmupCanvas, _warmupNode; diff --git a/server/build.log b/server/build.log index c523a30f..5864bafc 100644 --- a/server/build.log +++ b/server/build.log @@ -1,22 +1,22 @@ -2021-08-19 16:13:34 INFO:  @vladmandic/human version 2.1.3 -2021-08-19 16:13:34 INFO:  User: vlado Platform: linux Arch: x64 Node: v16.5.0 -2021-08-19 16:13:34 INFO:  Toolchain: {"tfjs":"3.8.0","esbuild":"0.12.21","typescript":"4.3.5","typedoc":"0.21.6","eslint":"7.32.0"} -2021-08-19 16:13:34 INFO:  Clean: ["dist/*","types/*","typedoc/*"] -2021-08-19 16:13:34 INFO:  Build: file startup all type: production config: {"minifyWhitespace":true,"minifyIdentifiers":true,"minifySyntax":true} -2021-08-19 16:13:34 STATE: target: node type: tfjs: {"imports":1,"importBytes":102,"outputBytes":1303,"outputFiles":"dist/tfjs.esm.js"} -2021-08-19 16:13:34 STATE: target: node type: node: {"imports":42,"importBytes":437161,"outputBytes":379821,"outputFiles":"dist/human.node.js"} -2021-08-19 16:13:34 STATE: target: nodeGPU type: tfjs: {"imports":1,"importBytes":110,"outputBytes":1311,"outputFiles":"dist/tfjs.esm.js"} -2021-08-19 16:13:34 STATE: target: nodeGPU type: node: {"imports":42,"importBytes":437169,"outputBytes":379825,"outputFiles":"dist/human.node-gpu.js"} -2021-08-19 16:13:34 STATE: target: nodeWASM type: tfjs: {"imports":1,"importBytes":149,"outputBytes":1378,"outputFiles":"dist/tfjs.esm.js"} -2021-08-19 16:13:34 STATE: target: nodeWASM type: node: {"imports":42,"importBytes":437236,"outputBytes":379897,"outputFiles":"dist/human.node-wasm.js"} -2021-08-19 16:13:34 STATE: target: browserNoBundle type: tfjs: {"imports":1,"importBytes":2168,"outputBytes":1242,"outputFiles":"dist/tfjs.esm.js"} -2021-08-19 16:13:34 STATE: target: browserNoBundle type: esm: {"imports":42,"importBytes":437100,"outputBytes":249180,"outputFiles":"dist/human.esm-nobundle.js"} -2021-08-19 16:13:35 STATE: target: browserBundle type: tfjs: {"modules":1170,"moduleBytes":4145868,"imports":7,"importBytes":2168,"outputBytes":2334701,"outputFiles":"dist/tfjs.esm.js"} -2021-08-19 16:13:35 STATE: target: browserBundle type: iife: {"imports":42,"importBytes":2770559,"outputBytes":1379548,"outputFiles":"dist/human.js"} -2021-08-19 16:13:35 STATE: target: browserBundle type: esm: {"imports":42,"importBytes":2770559,"outputBytes":1379540,"outputFiles":"dist/human.esm.js"} -2021-08-19 16:13:35 INFO:  Running Linter: ["server/","src/","tfjs/","test/","demo/"] -2021-08-19 16:13:59 INFO:  Linter complete: files: 77 errors: 0 warnings: 0 -2021-08-19 16:13:59 INFO:  Generate ChangeLog: ["/home/vlado/dev/human/CHANGELOG.md"] -2021-08-19 16:13:59 INFO:  Generate Typings: ["src/human.ts"] outDir: ["types"] -2021-08-19 16:14:13 INFO:  Generate TypeDocs: ["src/human.ts"] outDir: ["typedoc"] -2021-08-19 16:14:29 INFO:  Documentation generated at /home/vlado/dev/human/typedoc 1 +2021-08-19 16:17:06 INFO:  @vladmandic/human version 2.1.4 +2021-08-19 16:17:06 INFO:  User: vlado Platform: linux Arch: x64 Node: v16.5.0 +2021-08-19 16:17:06 INFO:  Toolchain: {"tfjs":"3.8.0","esbuild":"0.12.21","typescript":"4.3.5","typedoc":"0.21.6","eslint":"7.32.0"} +2021-08-19 16:17:06 INFO:  Clean: ["dist/*","types/*","typedoc/*"] +2021-08-19 16:17:06 INFO:  Build: file startup all type: production config: {"minifyWhitespace":true,"minifyIdentifiers":true,"minifySyntax":true} +2021-08-19 16:17:06 STATE: target: node type: tfjs: {"imports":1,"importBytes":102,"outputBytes":1303,"outputFiles":"dist/tfjs.esm.js"} +2021-08-19 16:17:07 STATE: target: node type: node: {"imports":42,"importBytes":437161,"outputBytes":379821,"outputFiles":"dist/human.node.js"} +2021-08-19 16:17:07 STATE: target: nodeGPU type: tfjs: {"imports":1,"importBytes":110,"outputBytes":1311,"outputFiles":"dist/tfjs.esm.js"} +2021-08-19 16:17:07 STATE: target: nodeGPU type: node: {"imports":42,"importBytes":437169,"outputBytes":379825,"outputFiles":"dist/human.node-gpu.js"} +2021-08-19 16:17:07 STATE: target: nodeWASM type: tfjs: {"imports":1,"importBytes":149,"outputBytes":1378,"outputFiles":"dist/tfjs.esm.js"} +2021-08-19 16:17:07 STATE: target: nodeWASM type: node: {"imports":42,"importBytes":437236,"outputBytes":379897,"outputFiles":"dist/human.node-wasm.js"} +2021-08-19 16:17:07 STATE: target: browserNoBundle type: tfjs: {"imports":1,"importBytes":2168,"outputBytes":1242,"outputFiles":"dist/tfjs.esm.js"} +2021-08-19 16:17:07 STATE: target: browserNoBundle type: esm: {"imports":42,"importBytes":437100,"outputBytes":249180,"outputFiles":"dist/human.esm-nobundle.js"} +2021-08-19 16:17:07 STATE: target: browserBundle type: tfjs: {"modules":1170,"moduleBytes":4145868,"imports":7,"importBytes":2168,"outputBytes":2334701,"outputFiles":"dist/tfjs.esm.js"} +2021-08-19 16:17:08 STATE: target: browserBundle type: iife: {"imports":42,"importBytes":2770559,"outputBytes":1379548,"outputFiles":"dist/human.js"} +2021-08-19 16:17:08 STATE: target: browserBundle type: esm: {"imports":42,"importBytes":2770559,"outputBytes":1379540,"outputFiles":"dist/human.esm.js"} +2021-08-19 16:17:08 INFO:  Running Linter: ["server/","src/","tfjs/","test/","demo/"] +2021-08-19 16:17:30 INFO:  Linter complete: files: 77 errors: 0 warnings: 0 +2021-08-19 16:17:31 INFO:  Generate ChangeLog: ["/home/vlado/dev/human/CHANGELOG.md"] +2021-08-19 16:17:31 INFO:  Generate Typings: ["src/human.ts"] outDir: ["types"] +2021-08-19 16:17:45 INFO:  Generate TypeDocs: ["src/human.ts"] outDir: ["typedoc"] +2021-08-19 16:17:59 INFO:  Documentation generated at /home/vlado/dev/human/typedoc 1