From 3c66210fd8a55fd8ce42bbfb207acb3a1bb12dbf Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 31 Aug 2021 14:50:16 -0400 Subject: [PATCH] full rebuild --- CHANGELOG.md | 5 +++-- 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 +++++++++++++++++++------------------- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab85bffb..2c6808fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # @vladmandic/human -Version: **2.1.4** +Version: **2.1.5** 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,11 +9,12 @@ Repository: **** ## Changelog -### **HEAD -> main** 2021/08/31 mandic00@live.com +### **2.1.5** 2021/08/31 mandic00@live.com ### **origin/main** 2021/08/31 mandic00@live.com +- dynamically generate default wasm path - implement finger poses in hand detection and gestures - implemented movenet-multipose model diff --git a/dist/human.esm-nobundle.js b/dist/human.esm-nobundle.js index fea8a7d9..959357d0 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 ue="2.1.4";var R0,Z0,F0,M0,T0,w0,s5,X0,a5,i5,x5,y5,l5=class{constructor(A){e0(this,R0,void 0);e0(this,Z0,void 0);e0(this,F0,void 0);e0(this,M0,void 0);e0(this,T0,void 0);e0(this,w0,void 0);this.setCanvas=A=>vA(A);this.analyze=(...A)=>{if(!G(this,Z0))return;let t=this.tf.engine().state.numTensors,r=G(this,R0);n0(this,R0,t);let o=t-r;o!==0&&M(...A,o)};e0(this,s5,A=>{if(!G(this,F0))return null;if(!A)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(A instanceof n.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(t){return"backend not loaded"}return null});e0(this,X0,async(A=!1)=>{var t;if(this.config.backend&&this.config.backend.length>0&&A||this.tf.getBackend()!==this.config.backend){let r=L();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"&&ge();let o=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&M("available backends:",o),o.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"),i=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&M(`wasm execution: ${a?"SIMD":"no SIMD"} ${i?"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",!0),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 o=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&M(`gl version:${o.getParameter(o.VERSION)} renderer:${o.getParameter(o.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(L()-r)}});this.next=A=>kA(A||this.result);e0(this,a5,async A=>{if(this.config.cacheSensitivity===0)return!1;let t=32;if(!A.shape[1]||!A.shape[2])return!1;let r=n.image.resizeBilinear(A,[Math.trunc(A.shape[1]/t),Math.trunc(A.shape[2]/t)]),o=await r.data(),a=0;for(let y=0;y10*this.config.cacheSensitivity?0:i),s});e0(this,i5,async()=>{let A=(o,a="application/octet-stream")=>fetch(`data:${a};base64,${o}`).then(i=>i.blob()),t,r;switch(this.config.warmup){case"face":t=await A(o5);break;case"full":t=await A(r5);break;default:t=null}if(t){let o=await createImageBitmap(t);r=await this.detect(o,this.config),o.close()}return r});e0(this,x5,async()=>new Promise(A=>{let t,r=0;switch(this.config.warmup){case"face":r=256,t="data:image/jpeg;base64,"+o5;break;case"full":case"body":r=1200,t="data:image/jpeg;base64,"+r5;break;default:t=null}let o=new Image;o.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");a.width=o.naturalWidth,a.height=o.naturalHeight;let i=a.getContext("2d");i==null||i.drawImage(o,0,0);let s=await this.detect(a,this.config);A(s)},t?o.src=t:A(null)}));e0(this,y5,async()=>{let A=o=>Buffer.from(o,"base64"),t;if(this.config.warmup==="face"&&(t=A(o5)),(this.config.warmup==="body"||this.config.warmup==="full")&&(t=A(r5)),!t)return null;let r;if(typeof n.node!="undefined"){let o=n.node.decodeJpeg(t),a=o.expandDims(0);this.tf.dispose(o),r=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&M("Warmup tfjs-node not loaded");return r});l5.version=ue,Object.defineProperty(this,"version",{value:ue}),m5.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${n.version_core}/dist/`,this.config=U(m5,A||{}),this.tf=n,this.draw=me,this.state="idle",n0(this,R0,0),n0(this,Z0,!1),n0(this,F0,!1),n0(this,M0,!0),n0(this,w0,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=>g0(t,this.config),this.faceTriangulation=Ne,this.faceUVMap=Oe,this.sysinfo=be(),n0(this,T0,1)}similarity(A,t){return E5(A,t)}segmentation(A,t){return hA(A,t,this.config)}enhance(A){return R5(A)}match(A,t,r=0){return He(A,t,r)}async load(A){this.state="load";let t=L();A&&(this.config=U(this.config,A)),G(this,M0)&&(this.config.debug&&M(`version: ${l5.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 G(this,X0).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 pA(this),G(this,M0)&&(this.config.debug&&M("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),n0(this,M0,!1));let r=Math.trunc(L()-t);r>(this.performance.load||0)&&(this.performance.load=r)}async detect(A,t){return new Promise(async r=>{this.state="config";let o,a;this.config=U(this.config,t),this.state="check";let i=G(this,s5).call(this,A);i&&(M(i,A),r({error:i}));let s=L();await G(this,X0).call(this),await this.load(),o=L();let y=g0(A,this.config);if(this.performance.image=Math.trunc(L()-o),this.analyze("Get Image:"),this.config.segmentation.enabled&&y&&y.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",o=L(),await le(y),a=Math.trunc(L()-o),a>0&&(this.performance.segmentation=a),y.canvas&&(n.dispose(y.tensor),y=g0(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}o=L(),this.config.skipFrame=await G(this,a5).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(L()-o),this.analyze("Check Changed:");let x=[],l=[],c=[],d=[];this.config.async?(x=this.config.face.enabled?ce(this,y.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",o=L(),x=this.config.face.enabled?await ce(this,y.tensor):[],a=Math.trunc(L()-o),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?V5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?D5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?Q5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?Ae(y.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",o=L(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await V5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await D5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?await Q5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?await Ae(y.tensor,this.config):[]),a=Math.trunc(L()-o),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(c=this.config.hand.enabled?U5(y.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",o=L(),c=this.config.hand.enabled?await U5(y.tensor,this.config):[],a=Math.trunc(L()-o),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?d=this.config.object.enabled?re(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(d=this.config.object.enabled?xe(y.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",o=L(),this.config.object.modelPath.includes("nanodet")?d=this.config.object.enabled?await re(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(d=this.config.object.enabled?await xe(y.tensor,this.config):[]),a=Math.trunc(L()-o),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([x,l,c,d]=await Promise.all([x,l,c,d]));let m=[];this.config.gesture.enabled&&(o=L(),m=[...gA(x),...bA(l),...TA(c),...MA(x)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(L()-o)),this.performance.total=Math.trunc(L()-s),this.state="idle",this.result={face:x,body:l,hand:c,gesture:m,object:d,performance:this.performance,canvas:y.canvas,timestamp:Date.now(),get persons(){var T;return SA(x,l,c,m,(T=y==null?void 0:y.tensor)==null?void 0:T.shape)}},n.dispose(y.tensor),r(this.result)})}async warmup(A){let t=L();if(A&&(this.config=U(this.config,A)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let r;typeof createImageBitmap=="function"?r=await G(this,i5).call(this):typeof Image!="undefined"?r=await G(this,x5).call(this):r=await G(this,y5).call(this);let o=L();return this.config.debug&&M("Warmup",this.config.warmup,Math.round(o-t),"ms",r),r}},Wt=l5;R0=new WeakMap,Z0=new WeakMap,F0=new WeakMap,M0=new WeakMap,T0=new WeakMap,w0=new WeakMap,s5=new WeakMap,X0=new WeakMap,a5=new WeakMap,i5=new WeakMap,x5=new WeakMap,y5=new WeakMap;export{Wt as Human,Wt as default}; +2Q==`;var ue="2.1.5";var R0,Z0,F0,M0,T0,w0,s5,X0,a5,i5,x5,y5,l5=class{constructor(A){e0(this,R0,void 0);e0(this,Z0,void 0);e0(this,F0,void 0);e0(this,M0,void 0);e0(this,T0,void 0);e0(this,w0,void 0);this.setCanvas=A=>vA(A);this.analyze=(...A)=>{if(!G(this,Z0))return;let t=this.tf.engine().state.numTensors,r=G(this,R0);n0(this,R0,t);let o=t-r;o!==0&&M(...A,o)};e0(this,s5,A=>{if(!G(this,F0))return null;if(!A)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(A instanceof n.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(t){return"backend not loaded"}return null});e0(this,X0,async(A=!1)=>{var t;if(this.config.backend&&this.config.backend.length>0&&A||this.tf.getBackend()!==this.config.backend){let r=L();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"&&ge();let o=Object.keys(this.tf.engine().registryFactory);if(this.config.debug&&M("available backends:",o),o.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"),i=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&M(`wasm execution: ${a?"SIMD":"no SIMD"} ${i?"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",!0),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 o=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&M(`gl version:${o.getParameter(o.VERSION)} renderer:${o.getParameter(o.RENDERER)}`)}this.tf.enableProdMode(),await this.tf.ready(),this.performance.backend=Math.trunc(L()-r)}});this.next=A=>kA(A||this.result);e0(this,a5,async A=>{if(this.config.cacheSensitivity===0)return!1;let t=32;if(!A.shape[1]||!A.shape[2])return!1;let r=n.image.resizeBilinear(A,[Math.trunc(A.shape[1]/t),Math.trunc(A.shape[2]/t)]),o=await r.data(),a=0;for(let y=0;y10*this.config.cacheSensitivity?0:i),s});e0(this,i5,async()=>{let A=(o,a="application/octet-stream")=>fetch(`data:${a};base64,${o}`).then(i=>i.blob()),t,r;switch(this.config.warmup){case"face":t=await A(o5);break;case"full":t=await A(r5);break;default:t=null}if(t){let o=await createImageBitmap(t);r=await this.detect(o,this.config),o.close()}return r});e0(this,x5,async()=>new Promise(A=>{let t,r=0;switch(this.config.warmup){case"face":r=256,t="data:image/jpeg;base64,"+o5;break;case"full":case"body":r=1200,t="data:image/jpeg;base64,"+r5;break;default:t=null}let o=new Image;o.onload=async()=>{let a=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");a.width=o.naturalWidth,a.height=o.naturalHeight;let i=a.getContext("2d");i==null||i.drawImage(o,0,0);let s=await this.detect(a,this.config);A(s)},t?o.src=t:A(null)}));e0(this,y5,async()=>{let A=o=>Buffer.from(o,"base64"),t;if(this.config.warmup==="face"&&(t=A(o5)),(this.config.warmup==="body"||this.config.warmup==="full")&&(t=A(r5)),!t)return null;let r;if(typeof n.node!="undefined"){let o=n.node.decodeJpeg(t),a=o.expandDims(0);this.tf.dispose(o),r=await this.detect(a,this.config),this.tf.dispose(a)}else this.config.debug&&M("Warmup tfjs-node not loaded");return r});l5.version=ue,Object.defineProperty(this,"version",{value:ue}),m5.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${n.version_core}/dist/`,this.config=U(m5,A||{}),this.tf=n,this.draw=me,this.state="idle",n0(this,R0,0),n0(this,Z0,!1),n0(this,F0,!1),n0(this,M0,!0),n0(this,w0,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=>g0(t,this.config),this.faceTriangulation=Ne,this.faceUVMap=Oe,this.sysinfo=be(),n0(this,T0,1)}similarity(A,t){return E5(A,t)}segmentation(A,t){return hA(A,t,this.config)}enhance(A){return R5(A)}match(A,t,r=0){return He(A,t,r)}async load(A){this.state="load";let t=L();A&&(this.config=U(this.config,A)),G(this,M0)&&(this.config.debug&&M(`version: ${l5.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 G(this,X0).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 pA(this),G(this,M0)&&(this.config.debug&&M("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),n0(this,M0,!1));let r=Math.trunc(L()-t);r>(this.performance.load||0)&&(this.performance.load=r)}async detect(A,t){return new Promise(async r=>{this.state="config";let o,a;this.config=U(this.config,t),this.state="check";let i=G(this,s5).call(this,A);i&&(M(i,A),r({error:i}));let s=L();await G(this,X0).call(this),await this.load(),o=L();let y=g0(A,this.config);if(this.performance.image=Math.trunc(L()-o),this.analyze("Get Image:"),this.config.segmentation.enabled&&y&&y.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",o=L(),await le(y),a=Math.trunc(L()-o),a>0&&(this.performance.segmentation=a),y.canvas&&(n.dispose(y.tensor),y=g0(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}o=L(),this.config.skipFrame=await G(this,a5).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(L()-o),this.analyze("Check Changed:");let x=[],l=[],c=[],d=[];this.config.async?(x=this.config.face.enabled?ce(this,y.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",o=L(),x=this.config.face.enabled?await ce(this,y.tensor):[],a=Math.trunc(L()-o),a>0&&(this.performance.face=a)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?V5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?D5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?Q5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?Ae(y.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",o=L(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await V5(y.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await D5(y.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?l=this.config.body.enabled?await Q5(y.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(l=this.config.body.enabled?await Ae(y.tensor,this.config):[]),a=Math.trunc(L()-o),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(c=this.config.hand.enabled?U5(y.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",o=L(),c=this.config.hand.enabled?await U5(y.tensor,this.config):[],a=Math.trunc(L()-o),a>0&&(this.performance.hand=a)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(this.config.object.modelPath.includes("nanodet")?d=this.config.object.enabled?re(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(d=this.config.object.enabled?xe(y.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",o=L(),this.config.object.modelPath.includes("nanodet")?d=this.config.object.enabled?await re(y.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(d=this.config.object.enabled?await xe(y.tensor,this.config):[]),a=Math.trunc(L()-o),a>0&&(this.performance.object=a)),this.analyze("End Object:"),this.config.async&&([x,l,c,d]=await Promise.all([x,l,c,d]));let m=[];this.config.gesture.enabled&&(o=L(),m=[...gA(x),...bA(l),...TA(c),...MA(x)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(L()-o)),this.performance.total=Math.trunc(L()-s),this.state="idle",this.result={face:x,body:l,hand:c,gesture:m,object:d,performance:this.performance,canvas:y.canvas,timestamp:Date.now(),get persons(){var T;return SA(x,l,c,m,(T=y==null?void 0:y.tensor)==null?void 0:T.shape)}},n.dispose(y.tensor),r(this.result)})}async warmup(A){let t=L();if(A&&(this.config=U(this.config,A)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let r;typeof createImageBitmap=="function"?r=await G(this,i5).call(this):typeof Image!="undefined"?r=await G(this,x5).call(this):r=await G(this,y5).call(this);let o=L();return this.config.debug&&M("Warmup",this.config.warmup,Math.round(o-t),"ms",r),r}},Wt=l5;R0=new WeakMap,Z0=new WeakMap,F0=new WeakMap,M0=new WeakMap,T0=new WeakMap,w0=new WeakMap,s5=new WeakMap,X0=new WeakMap,a5=new WeakMap,i5=new WeakMap,x5=new WeakMap,y5=new WeakMap;export{Wt as Human,Wt as default}; //# sourceMappingURL=human.esm-nobundle.js.map diff --git a/dist/human.esm.js b/dist/human.esm.js index 74e61674..1016802e 100644 --- a/dist/human.esm.js +++ b/dist/human.esm.js @@ -5336,7 +5336,7 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var Jy="2.1.4";var xu,yd,xd,li,ui,bu,t0,bd,n0,s0,r0,a0,o0=class{constructor(t){as(this,xu,void 0);as(this,yd,void 0);as(this,xd,void 0);as(this,li,void 0);as(this,ui,void 0);as(this,bu,void 0);this.setCanvas=t=>q8(t);this.analyze=(...t)=>{if(!mn(this,yd))return;let n=this.tf.engine().state.numTensors,s=mn(this,xu);Ds(this,xu,n);let r=n-s;r!==0&&ue(...t,r)};as(this,t0,t=>{if(!mn(this,xd))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ge))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});as(this,bd,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ye();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"&&Uk();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",!0),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(Ye()-s)}});this.next=t=>eI(t||this.result);as(this,n0,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});as(this,s0,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(Qf);break;case"full":n=await t(e0);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});as(this,r0,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Qf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+e0;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)}));as(this,a0,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Qf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(e0)),!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});o0.version=Jy,Object.defineProperty(this,"version",{value:Jy}),Fm.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${Dx}/dist/`,this.config=gn(Fm,t||{}),this.tf=id,this.draw=Yy,this.state="idle",Ds(this,xu,0),Ds(this,yd,!1),Ds(this,xd,!1),Ds(this,li,!0),Ds(this,bu,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=>ii(n,this.config),this.faceTriangulation=s8,this.faceUVMap=r8,this.sysinfo=f5(),Ds(this,ui,1)}similarity(t,n){return ly(t,n)}segmentation(t,n){return B8(t,n,this.config)}enhance(t){return uy(t)}match(t,n,s=0){return o8(t,n,s)}async load(t){this.state="load";let n=Ye();t&&(this.config=gn(this.config,t)),mn(this,li)&&(this.config.debug&&ue(`version: ${o0.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 mn(this,bd).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 W8(this),mn(this,li)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ds(this,li,!1));let s=Math.trunc(Ye()-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=gn(this.config,n),this.state="check";let o=mn(this,t0).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ye();await mn(this,bd).call(this),await this.load(),r=Ye();let l=ii(t,this.config);if(this.performance.image=Math.trunc(Ye()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ye(),await qy(l),a=Math.trunc(Ye()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=ii(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=Ye(),this.config.skipFrame=await mn(this,n0).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(Ye()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?Xy(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ye(),u=this.config.face.enabled?await Xy(this,l.tensor):[],a=Math.trunc(Ye()-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?by(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?Ey(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?$y(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?My(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ye(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await by(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await Ey(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await $y(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await My(l.tensor,this.config):[]),a=Math.trunc(Ye()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?Ty(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ye(),d=this.config.hand.enabled?await Ty(l.tensor,this.config):[],a=Math.trunc(Ye()-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?Wy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?Gy(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ye(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Wy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await Gy(l.tensor,this.config):[]),a=Math.trunc(Ye()-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=Ye(),p=[...U8(u),...V8(c),...G8(d),...H8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ye()-r)),this.performance.total=Math.trunc(Ye()-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 Q8(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=Ye();if(t&&(this.config=gn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await mn(this,s0).call(this):typeof Image!="undefined"?s=await mn(this,r0).call(this):s=await mn(this,a0).call(this);let r=Ye();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}},_le=o0;xu=new WeakMap,yd=new WeakMap,xd=new WeakMap,li=new WeakMap,ui=new WeakMap,bu=new WeakMap,t0=new WeakMap,bd=new WeakMap,n0=new WeakMap,s0=new WeakMap,r0=new WeakMap,a0=new WeakMap;export{_le as Human,_le as default}; +2Q==`;var Jy="2.1.5";var xu,yd,xd,li,ui,bu,t0,bd,n0,s0,r0,a0,o0=class{constructor(t){as(this,xu,void 0);as(this,yd,void 0);as(this,xd,void 0);as(this,li,void 0);as(this,ui,void 0);as(this,bu,void 0);this.setCanvas=t=>q8(t);this.analyze=(...t)=>{if(!mn(this,yd))return;let n=this.tf.engine().state.numTensors,s=mn(this,xu);Ds(this,xu,n);let r=n-s;r!==0&&ue(...t,r)};as(this,t0,t=>{if(!mn(this,xd))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ge))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});as(this,bd,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ye();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"&&Uk();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",!0),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(Ye()-s)}});this.next=t=>eI(t||this.result);as(this,n0,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});as(this,s0,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(Qf);break;case"full":n=await t(e0);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});as(this,r0,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Qf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+e0;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)}));as(this,a0,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Qf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(e0)),!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});o0.version=Jy,Object.defineProperty(this,"version",{value:Jy}),Fm.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${Dx}/dist/`,this.config=gn(Fm,t||{}),this.tf=id,this.draw=Yy,this.state="idle",Ds(this,xu,0),Ds(this,yd,!1),Ds(this,xd,!1),Ds(this,li,!0),Ds(this,bu,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=>ii(n,this.config),this.faceTriangulation=s8,this.faceUVMap=r8,this.sysinfo=f5(),Ds(this,ui,1)}similarity(t,n){return ly(t,n)}segmentation(t,n){return B8(t,n,this.config)}enhance(t){return uy(t)}match(t,n,s=0){return o8(t,n,s)}async load(t){this.state="load";let n=Ye();t&&(this.config=gn(this.config,t)),mn(this,li)&&(this.config.debug&&ue(`version: ${o0.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 mn(this,bd).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 W8(this),mn(this,li)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ds(this,li,!1));let s=Math.trunc(Ye()-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=gn(this.config,n),this.state="check";let o=mn(this,t0).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ye();await mn(this,bd).call(this),await this.load(),r=Ye();let l=ii(t,this.config);if(this.performance.image=Math.trunc(Ye()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ye(),await qy(l),a=Math.trunc(Ye()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=ii(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=Ye(),this.config.skipFrame=await mn(this,n0).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(Ye()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?Xy(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ye(),u=this.config.face.enabled?await Xy(this,l.tensor):[],a=Math.trunc(Ye()-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?by(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?Ey(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?$y(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?My(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ye(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await by(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await Ey(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await $y(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await My(l.tensor,this.config):[]),a=Math.trunc(Ye()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?Ty(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ye(),d=this.config.hand.enabled?await Ty(l.tensor,this.config):[],a=Math.trunc(Ye()-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?Wy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?Gy(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ye(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Wy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await Gy(l.tensor,this.config):[]),a=Math.trunc(Ye()-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=Ye(),p=[...U8(u),...V8(c),...G8(d),...H8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ye()-r)),this.performance.total=Math.trunc(Ye()-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 Q8(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=Ye();if(t&&(this.config=gn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await mn(this,s0).call(this):typeof Image!="undefined"?s=await mn(this,r0).call(this):s=await mn(this,a0).call(this);let r=Ye();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}},_le=o0;xu=new WeakMap,yd=new WeakMap,xd=new WeakMap,li=new WeakMap,ui=new WeakMap,bu=new WeakMap,t0=new WeakMap,bd=new WeakMap,n0=new WeakMap,s0=new WeakMap,r0=new WeakMap,a0=new WeakMap;export{_le as Human,_le as default}; /** * @license * Copyright 2017 Google LLC. All Rights Reserved. diff --git a/dist/human.js b/dist/human.js index d2a79730..a291f5a3 100644 --- a/dist/human.js +++ b/dist/human.js @@ -5336,7 +5336,7 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var Qy="2.1.4";var xu,yd,xd,li,ui,bu,t0,bd,n0,s0,r0,a0,o0=class{constructor(t){as(this,xu,void 0);as(this,yd,void 0);as(this,xd,void 0);as(this,li,void 0);as(this,ui,void 0);as(this,bu,void 0);this.setCanvas=t=>q8(t);this.analyze=(...t)=>{if(!mn(this,yd))return;let n=this.tf.engine().state.numTensors,s=mn(this,xu);Ds(this,xu,n);let r=n-s;r!==0&&ue(...t,r)};as(this,t0,t=>{if(!mn(this,xd))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ge))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});as(this,bd,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ye();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"&&Uk();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",!0),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(Ye()-s)}});this.next=t=>eI(t||this.result);as(this,n0,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});as(this,s0,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(Qf);break;case"full":n=await t(e0);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});as(this,r0,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Qf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+e0;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)}));as(this,a0,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Qf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(e0)),!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});o0.version=Qy,Object.defineProperty(this,"version",{value:Qy}),Om.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${Dx}/dist/`,this.config=gn(Om,t||{}),this.tf=id,this.draw=Jy,this.state="idle",Ds(this,xu,0),Ds(this,yd,!1),Ds(this,xd,!1),Ds(this,li,!0),Ds(this,bu,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=>ii(n,this.config),this.faceTriangulation=s8,this.faceUVMap=r8,this.sysinfo=f5(),Ds(this,ui,1)}similarity(t,n){return uy(t,n)}segmentation(t,n){return B8(t,n,this.config)}enhance(t){return cy(t)}match(t,n,s=0){return o8(t,n,s)}async load(t){this.state="load";let n=Ye();t&&(this.config=gn(this.config,t)),mn(this,li)&&(this.config.debug&&ue(`version: ${o0.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 mn(this,bd).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 W8(this),mn(this,li)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ds(this,li,!1));let s=Math.trunc(Ye()-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=gn(this.config,n),this.state="check";let o=mn(this,t0).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ye();await mn(this,bd).call(this),await this.load(),r=Ye();let l=ii(t,this.config);if(this.performance.image=Math.trunc(Ye()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ye(),await Xy(l),a=Math.trunc(Ye()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=ii(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=Ye(),this.config.skipFrame=await mn(this,n0).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(Ye()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?Ky(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ye(),u=this.config.face.enabled?await Ky(this,l.tensor):[],a=Math.trunc(Ye()-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?vy(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?Ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?Fy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?zy(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ye(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await vy(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await Ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await Fy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await zy(l.tensor,this.config):[]),a=Math.trunc(Ye()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?Ny(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ye(),d=this.config.hand.enabled?await Ny(l.tensor,this.config):[],a=Math.trunc(Ye()-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?Vy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?jy(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ye(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Vy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await jy(l.tensor,this.config):[]),a=Math.trunc(Ye()-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=Ye(),p=[...U8(u),...V8(c),...G8(d),...H8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ye()-r)),this.performance.total=Math.trunc(Ye()-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 Q8(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=Ye();if(t&&(this.config=gn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await mn(this,s0).call(this):typeof Image!="undefined"?s=await mn(this,r0).call(this):s=await mn(this,a0).call(this);let r=Ye();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}},tI=o0;xu=new WeakMap,yd=new WeakMap,xd=new WeakMap,li=new WeakMap,ui=new WeakMap,bu=new WeakMap,t0=new WeakMap,bd=new WeakMap,n0=new WeakMap,s0=new WeakMap,r0=new WeakMap,a0=new WeakMap;return Dle;})(); +2Q==`;var Qy="2.1.5";var xu,yd,xd,li,ui,bu,t0,bd,n0,s0,r0,a0,o0=class{constructor(t){as(this,xu,void 0);as(this,yd,void 0);as(this,xd,void 0);as(this,li,void 0);as(this,ui,void 0);as(this,bu,void 0);this.setCanvas=t=>q8(t);this.analyze=(...t)=>{if(!mn(this,yd))return;let n=this.tf.engine().state.numTensors,s=mn(this,xu);Ds(this,xu,n);let r=n-s;r!==0&&ue(...t,r)};as(this,t0,t=>{if(!mn(this,xd))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Ge))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});as(this,bd,async(t=!1)=>{var n;if(this.config.backend&&this.config.backend.length>0&&t||this.tf.getBackend()!==this.config.backend){let s=Ye();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"&&Uk();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",!0),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(Ye()-s)}});this.next=t=>eI(t||this.result);as(this,n0,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});as(this,s0,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(Qf);break;case"full":n=await t(e0);break;default:n=null}if(n){let r=await createImageBitmap(n);s=await this.detect(r,this.config),r.close()}return s});as(this,r0,async()=>new Promise(t=>{let n,s=0;switch(this.config.warmup){case"face":s=256,n="data:image/jpeg;base64,"+Qf;break;case"full":case"body":s=1200,n="data:image/jpeg;base64,"+e0;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)}));as(this,a0,async()=>{let t=r=>Buffer.from(r,"base64"),n;if(this.config.warmup==="face"&&(n=t(Qf)),(this.config.warmup==="body"||this.config.warmup==="full")&&(n=t(e0)),!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});o0.version=Qy,Object.defineProperty(this,"version",{value:Qy}),Om.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${Dx}/dist/`,this.config=gn(Om,t||{}),this.tf=id,this.draw=Jy,this.state="idle",Ds(this,xu,0),Ds(this,yd,!1),Ds(this,xd,!1),Ds(this,li,!0),Ds(this,bu,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=>ii(n,this.config),this.faceTriangulation=s8,this.faceUVMap=r8,this.sysinfo=f5(),Ds(this,ui,1)}similarity(t,n){return uy(t,n)}segmentation(t,n){return B8(t,n,this.config)}enhance(t){return cy(t)}match(t,n,s=0){return o8(t,n,s)}async load(t){this.state="load";let n=Ye();t&&(this.config=gn(this.config,t)),mn(this,li)&&(this.config.debug&&ue(`version: ${o0.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 mn(this,bd).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 W8(this),mn(this,li)&&(this.config.debug&&ue("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),Ds(this,li,!1));let s=Math.trunc(Ye()-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=gn(this.config,n),this.state="check";let o=mn(this,t0).call(this,t);o&&(ue(o,t),s({error:o}));let i=Ye();await mn(this,bd).call(this),await this.load(),r=Ye();let l=ii(t,this.config);if(this.performance.image=Math.trunc(Ye()-r),this.analyze("Get Image:"),this.config.segmentation.enabled&&l&&l.tensor&&(this.analyze("Start Segmentation:"),this.state="run:segmentation",r=Ye(),await Xy(l),a=Math.trunc(Ye()-r),a>0&&(this.performance.segmentation=a),l.canvas&&(K(l.tensor),l=ii(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=Ye(),this.config.skipFrame=await mn(this,n0).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(Ye()-r),this.analyze("Check Changed:");let u=[],c=[],d=[],h=[];this.config.async?(u=this.config.face.enabled?Ky(this,l.tensor):[],this.performance.face&&delete this.performance.face):(this.state="run:face",r=Ye(),u=this.config.face.enabled?await Ky(this,l.tensor):[],a=Math.trunc(Ye()-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?vy(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?Ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?Fy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?zy(l.tensor,this.config):[]),this.performance.body&&delete this.performance.body):(this.state="run:body",r=Ye(),this.config.body.modelPath.includes("posenet")?c=this.config.body.enabled?await vy(l.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?c=this.config.body.enabled?await Ry(l.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")?c=this.config.body.enabled?await Fy(l.tensor,this.config):[]:this.config.body.modelPath.includes("movenet")&&(c=this.config.body.enabled?await zy(l.tensor,this.config):[]),a=Math.trunc(Ye()-r),a>0&&(this.performance.body=a)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(d=this.config.hand.enabled?Ny(l.tensor,this.config):[],this.performance.hand&&delete this.performance.hand):(this.state="run:hand",r=Ye(),d=this.config.hand.enabled?await Ny(l.tensor,this.config):[],a=Math.trunc(Ye()-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?Vy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?jy(l.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(this.state="run:object",r=Ye(),this.config.object.modelPath.includes("nanodet")?h=this.config.object.enabled?await Vy(l.tensor,this.config):[]:this.config.object.modelPath.includes("centernet")&&(h=this.config.object.enabled?await jy(l.tensor,this.config):[]),a=Math.trunc(Ye()-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=Ye(),p=[...U8(u),...V8(c),...G8(d),...H8(u)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=Math.trunc(Ye()-r)),this.performance.total=Math.trunc(Ye()-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 Q8(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=Ye();if(t&&(this.config=gn(this.config,t)),!this.config.warmup||this.config.warmup==="none")return{error:"null"};let s;typeof createImageBitmap=="function"?s=await mn(this,s0).call(this):typeof Image!="undefined"?s=await mn(this,r0).call(this):s=await mn(this,a0).call(this);let r=Ye();return this.config.debug&&ue("Warmup",this.config.warmup,Math.round(r-n),"ms",s),s}},tI=o0;xu=new WeakMap,yd=new WeakMap,xd=new WeakMap,li=new WeakMap,ui=new WeakMap,bu=new WeakMap,t0=new WeakMap,bd=new WeakMap,n0=new WeakMap,s0=new WeakMap,r0=new WeakMap,a0=new WeakMap;return Dle;})(); /** * @license * Copyright 2017 Google LLC. All Rights Reserved. diff --git a/dist/human.node-gpu.js b/dist/human.node-gpu.js index 8628f576..0accc47c 100644 --- a/dist/human.node-gpu.js +++ b/dist/human.node-gpu.js @@ -11807,7 +11807,7 @@ lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ 2Q==`; // package.json -var version = "2.1.4"; +var version = "2.1.5"; // 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 15216ea1..9c83961c 100644 --- a/dist/human.node-wasm.js +++ b/dist/human.node-wasm.js @@ -11808,7 +11808,7 @@ lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ 2Q==`; // package.json -var version = "2.1.4"; +var version = "2.1.5"; // 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 7968aae6..270f65c1 100644 --- a/dist/human.node.js +++ b/dist/human.node.js @@ -11807,7 +11807,7 @@ lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ 2Q==`; // package.json -var version = "2.1.4"; +var version = "2.1.5"; // 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 032fad3f..3ce6325b 100644 --- a/server/build.log +++ b/server/build.log @@ -1,22 +1,22 @@ -2021-08-31 14:47:11 INFO:  @vladmandic/human version 2.1.4 -2021-08-31 14:47:11 INFO:  User: vlado Platform: linux Arch: x64 Node: v16.5.0 -2021-08-31 14:47:11 INFO:  Toolchain: {"tfjs":"3.9.0","esbuild":"0.12.24","typescript":"4.4.2","typedoc":"0.21.9","eslint":"7.32.0"} -2021-08-31 14:47:11 INFO:  Clean: ["dist/*","types/*","typedoc/*"] -2021-08-31 14:47:11 INFO:  Build: file startup all type: production config: {"minifyWhitespace":true,"minifyIdentifiers":true,"minifySyntax":true} -2021-08-31 14:47:11 STATE: target: node type: tfjs: {"imports":1,"importBytes":102,"outputBytes":1303,"outputFiles":"dist/tfjs.esm.js"} -2021-08-31 14:47:11 STATE: target: node type: node: {"imports":47,"importBytes":457046,"outputBytes":397286,"outputFiles":"dist/human.node.js"} -2021-08-31 14:47:11 STATE: target: nodeGPU type: tfjs: {"imports":1,"importBytes":110,"outputBytes":1311,"outputFiles":"dist/tfjs.esm.js"} -2021-08-31 14:47:12 STATE: target: nodeGPU type: node: {"imports":47,"importBytes":457054,"outputBytes":397290,"outputFiles":"dist/human.node-gpu.js"} -2021-08-31 14:47:12 STATE: target: nodeWASM type: tfjs: {"imports":1,"importBytes":149,"outputBytes":1378,"outputFiles":"dist/tfjs.esm.js"} -2021-08-31 14:47:12 STATE: target: nodeWASM type: node: {"imports":47,"importBytes":457121,"outputBytes":397362,"outputFiles":"dist/human.node-wasm.js"} -2021-08-31 14:47:12 STATE: target: browserNoBundle type: tfjs: {"imports":1,"importBytes":2168,"outputBytes":1242,"outputFiles":"dist/tfjs.esm.js"} -2021-08-31 14:47:12 STATE: target: browserNoBundle type: esm: {"imports":47,"importBytes":456985,"outputBytes":255646,"outputFiles":"dist/human.esm-nobundle.js"} -2021-08-31 14:47:12 STATE: target: browserBundle type: tfjs: {"modules":1174,"moduleBytes":8150347,"imports":7,"importBytes":2168,"outputBytes":2343932,"outputFiles":"dist/tfjs.esm.js"} -2021-08-31 14:47:12 STATE: target: browserBundle type: iife: {"imports":47,"importBytes":2799675,"outputBytes":1391880,"outputFiles":"dist/human.js"} -2021-08-31 14:47:13 STATE: target: browserBundle type: esm: {"imports":47,"importBytes":2799675,"outputBytes":1391872,"outputFiles":"dist/human.esm.js"} -2021-08-31 14:47:13 INFO:  Running Linter: ["server/","src/","tfjs/","test/","demo/"] -2021-08-31 14:47:36 INFO:  Linter complete: files: 84 errors: 0 warnings: 0 -2021-08-31 14:47:36 INFO:  Generate ChangeLog: ["/home/vlado/dev/human/CHANGELOG.md"] -2021-08-31 14:47:36 INFO:  Generate Typings: ["src/human.ts"] outDir: ["types"] -2021-08-31 14:47:50 INFO:  Generate TypeDocs: ["src/human.ts"] outDir: ["typedoc"] -2021-08-31 14:48:05 INFO:  Documentation generated at /home/vlado/dev/human/typedoc 1 +2021-08-31 14:49:10 INFO:  @vladmandic/human version 2.1.5 +2021-08-31 14:49:10 INFO:  User: vlado Platform: linux Arch: x64 Node: v16.5.0 +2021-08-31 14:49:10 INFO:  Toolchain: {"tfjs":"3.9.0","esbuild":"0.12.24","typescript":"4.4.2","typedoc":"0.21.9","eslint":"7.32.0"} +2021-08-31 14:49:10 INFO:  Clean: ["dist/*","types/*","typedoc/*"] +2021-08-31 14:49:10 INFO:  Build: file startup all type: production config: {"minifyWhitespace":true,"minifyIdentifiers":true,"minifySyntax":true} +2021-08-31 14:49:10 STATE: target: node type: tfjs: {"imports":1,"importBytes":102,"outputBytes":1303,"outputFiles":"dist/tfjs.esm.js"} +2021-08-31 14:49:10 STATE: target: node type: node: {"imports":47,"importBytes":457046,"outputBytes":397286,"outputFiles":"dist/human.node.js"} +2021-08-31 14:49:10 STATE: target: nodeGPU type: tfjs: {"imports":1,"importBytes":110,"outputBytes":1311,"outputFiles":"dist/tfjs.esm.js"} +2021-08-31 14:49:11 STATE: target: nodeGPU type: node: {"imports":47,"importBytes":457054,"outputBytes":397290,"outputFiles":"dist/human.node-gpu.js"} +2021-08-31 14:49:11 STATE: target: nodeWASM type: tfjs: {"imports":1,"importBytes":149,"outputBytes":1378,"outputFiles":"dist/tfjs.esm.js"} +2021-08-31 14:49:11 STATE: target: nodeWASM type: node: {"imports":47,"importBytes":457121,"outputBytes":397362,"outputFiles":"dist/human.node-wasm.js"} +2021-08-31 14:49:11 STATE: target: browserNoBundle type: tfjs: {"imports":1,"importBytes":2168,"outputBytes":1242,"outputFiles":"dist/tfjs.esm.js"} +2021-08-31 14:49:11 STATE: target: browserNoBundle type: esm: {"imports":47,"importBytes":456985,"outputBytes":255646,"outputFiles":"dist/human.esm-nobundle.js"} +2021-08-31 14:49:11 STATE: target: browserBundle type: tfjs: {"modules":1174,"moduleBytes":8150347,"imports":7,"importBytes":2168,"outputBytes":2343932,"outputFiles":"dist/tfjs.esm.js"} +2021-08-31 14:49:12 STATE: target: browserBundle type: iife: {"imports":47,"importBytes":2799675,"outputBytes":1391880,"outputFiles":"dist/human.js"} +2021-08-31 14:49:12 STATE: target: browserBundle type: esm: {"imports":47,"importBytes":2799675,"outputBytes":1391872,"outputFiles":"dist/human.esm.js"} +2021-08-31 14:49:12 INFO:  Running Linter: ["server/","src/","tfjs/","test/","demo/"] +2021-08-31 14:49:35 INFO:  Linter complete: files: 84 errors: 0 warnings: 0 +2021-08-31 14:49:35 INFO:  Generate ChangeLog: ["/home/vlado/dev/human/CHANGELOG.md"] +2021-08-31 14:49:35 INFO:  Generate Typings: ["src/human.ts"] outDir: ["types"] +2021-08-31 14:49:50 INFO:  Generate TypeDocs: ["src/human.ts"] outDir: ["typedoc"] +2021-08-31 14:50:03 INFO:  Documentation generated at /home/vlado/dev/human/typedoc 1