diff --git a/CHANGELOG.md b/CHANGELOG.md index 003ccd77..5def568a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # @vladmandic/human -Version: **1.2.5** +Version: **1.3.0** Description: **Human: AI-powered 3D Face Detection, Face Description & Recognition, Body Pose Tracking, Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction & Gesture Recognition** Author: **Vladimir Mandic ** @@ -9,14 +9,13 @@ Repository: **** ## Changelog -### **HEAD -> main** 2021/03/29 mandic00@live.com +### **HEAD -> main** 2021/03/30 mandic00@live.com +- initial work on face3d three.js demo - enable buffering - new icons - new serve module and demo structure - -### **origin/main** 2021/03/28 mandic00@live.com - +- move gl flags to correct location - minor rotation calculation fix - remove debug output - new face rotation calculations diff --git a/dist/human.esm-nobundle.js b/dist/human.esm-nobundle.js index 3464c51d..923decee 100644 --- a/dist/human.esm-nobundle.js +++ b/dist/human.esm-nobundle.js @@ -731,5 +731,5 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var i0="1.2.5";var ye,pe,ue,ce,$e,be,et,tt,nt,hn=class{constructor(e={}){ye.set(this,void 0);pe.set(this,void 0);ue.set(this,void 0);ce.set(this,void 0);this.analyze=(...e)=>{if(!L(this,pe))return;let n=this.tf.engine().state.numTensors,c=L(this,ye);te(this,ye,n);let r=n-c;r!==0&&P(...e,r)};$e.set(this,e=>{if(!L(this,ue))return null;if(!e)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(e instanceof A.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});be.set(this,async(e=!1)=>{if(this.config.backend&&this.config.backend!==""&&e||this.tf.getBackend()!==this.config.backend){let n=M();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&P("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&P("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let c=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),r=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&P(`wasm execution: ${c?"SIMD":"no SIMD"} ${r?"multithreaded":"singlethreaded"}`),c||P("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&y1();try{await this.tf.setBackend(this.config.backend)}catch(c){P("error: cannot set backend:",this.config.backend,c)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(P("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let c=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&P(`gl version:${c.getParameter(c.VERSION)} renderer:${c.getParameter(c.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(M()-n)}});et.set(this,async()=>{let e=(r,_="application/octet-stream")=>fetch(`data:${_};base64,${r}`).then(o=>o.blob()),n,c;switch(this.config.warmup){case"face":n=await e(Ge);break;case"full":n=await e(Qe);break;default:n=null}if(n){let r=await createImageBitmap(n);c=await this.detect(r,this.config),r.close()}return c});tt.set(this,async()=>new Promise(e=>{let n,c=0;switch(this.config.warmup){case"face":c=256,n="data:image/jpeg;base64,"+Ge;break;case"full":case"body":c=1200,n="data:image/jpeg;base64,"+Qe;break;default:n=null}let r=new Image;r.onload=async()=>{let _=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(c,c):document.createElement("canvas");_.width=r.naturalWidth,_.height=r.naturalHeight;let o=_.getContext("2d");o==null||o.drawImage(r,0,0);let s=await this.detect(_,this.config);e(s)},n?r.src=n:e(null)}));nt.set(this,async()=>{let e=o=>Buffer.from(o,"base64"),n=this.config.warmup==="face"?e(Ge):e(Qe),c=A.node.decodeJpeg(n),r=c.expandDims(0);this.tf.dispose(c);let _=await this.detect(r,this.config);return this.tf.dispose(r),_});this.tf=A,this.draw=_1,this.version=i0,this.config=Ae(S,e),this.state="idle",te(this,ye,0),te(this,pe,!1),te(this,ue,!1),te(this,ce,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>A1(n,this.config),this.classes={facemesh:Mt,age:ct,gender:_t,emotion:at,faceres:ft,body:this.config.body.modelPath.includes("posenet")?Lt:Dt,hand:Yt,nanodet:t1},this.faceTriangulation=v1,this.faceUVMap=z1,this.sysinfo=x1()}profileData(){return this.config.profile?Te:{}}similarity(e,n){return this.config.face.description.enabled?pt(e,n):this.config.face.embedding.enabled?w1(e,n):0}enhance(e){return ut(e)}match(e,n,c=0){return l1(e,n,c)}async load(e={}){this.state="load";let n=M();e&&(this.config=Ae(this.config,e)),L(this,ce)&&(this.config.debug&&P(`version: ${this.version}`),this.config.debug&&P(`tfjs version: ${this.tf.version_core}`),this.config.debug&&P("platform:",this.sysinfo.platform),this.config.debug&&P("agent:",this.sysinfo.agent),await L(this,be).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&P("configuration:",this.config),this.config.debug&&P("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?Et(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?At(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?it(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?wt(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?lt(this.config):null),this.models.handpose||(this.config.hand.enabled?Ut(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?Xt(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?Gt(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?$t(this.config):null),this.models.nanodet||(this.config.object.enabled?r1(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?mt(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await Et(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await At(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await it(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await wt(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await lt(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await Ut(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await Xt(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await Gt(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await $t(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await r1(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await mt(this.config))),L(this,ce)&&(this.config.debug&&P("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),te(this,ce,!1));let c=Math.trunc(M()-n);c>(this.perf.load||0)&&(this.perf.load=c)}async detect(e,n={}){return new Promise(async c=>{var x,m,p,v;this.state="config";let r;this.config=Ae(this.config,n),this.state="check";let _=L(this,$e).call(this,e);_&&(P(_,e),c({error:_}));let o=M();await L(this,be).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),r=M();let s=A1(e,this.config);if(!s||!s.tensor){P("could not convert input to tensor"),c({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(M()-r),this.analyze("Get Image:");let h,i,y,a,w;this.config.async?(y=this.config.face.enabled?bt(this,s.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",r=M(),y=this.config.face.enabled?await bt(this,s.tensor):[],w=Math.trunc(M()-r),w>0&&(this.perf.face=w)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?h=this.config.body.enabled?(x=this.models.posenet)==null?void 0:x.estimatePoses(s.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?h=this.config.body.enabled?Qt(s.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(h=this.config.body.enabled?e1(s.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",r=M(),this.config.body.modelPath.includes("posenet")?h=this.config.body.enabled?await((m=this.models.posenet)==null?void 0:m.estimatePoses(s.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?h=this.config.body.enabled?await Qt(s.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(h=this.config.body.enabled?await e1(s.tensor,this.config):[]),w=Math.trunc(M()-r),w>0&&(this.perf.body=w)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(i=this.config.hand.enabled?(p=this.models.handpose)==null?void 0:p.estimateHands(s.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",r=M(),i=this.config.hand.enabled?await((v=this.models.handpose)==null?void 0:v.estimateHands(s.tensor,this.config)):[],w=Math.trunc(M()-r),w>0&&(this.perf.hand=w)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(a=this.config.object.enabled?c1(s.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",r=M(),a=this.config.object.enabled?await c1(s.tensor,this.config):[],w=Math.trunc(M()-r),w>0&&(this.perf.object=w)),this.analyze("End Object:"),this.config.async&&([y,h,i,a]=await Promise.all([y,h,i,a])),s.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let u=[];this.config.gesture.enabled&&(r=M(),u=[...t0(y),...e0(h),...r0(i),...n0(y)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(M()-r)),this.perf.total=Math.trunc(M()-o),this.state="idle";let b={face:y,body:h,hand:i,gesture:u,object:a,performance:this.perf,canvas:s.canvas};c(b)})}async warmup(e={}){let n=M();e&&(this.config=Ae(this.config,e));let c=this.config.videoOptimized;this.config.videoOptimized=!1;let r;typeof createImageBitmap=="function"?r=await L(this,et).call(this):typeof Image!="undefined"?r=await L(this,tt).call(this):r=await L(this,nt).call(this),this.config.videoOptimized=c;let _=M();return this.config.debug&&P("Warmup",this.config.warmup,Math.round(_-n),"ms",r),r}};ye=new WeakMap,pe=new WeakMap,ue=new WeakMap,ce=new WeakMap,$e=new WeakMap,be=new WeakMap,et=new WeakMap,tt=new WeakMap,nt=new WeakMap;export{hn as Human,hn as default}; +2Q==`;var i0="1.3.0";var ye,pe,ue,ce,$e,be,et,tt,nt,hn=class{constructor(e={}){ye.set(this,void 0);pe.set(this,void 0);ue.set(this,void 0);ce.set(this,void 0);this.analyze=(...e)=>{if(!L(this,pe))return;let n=this.tf.engine().state.numTensors,c=L(this,ye);te(this,ye,n);let r=n-c;r!==0&&P(...e,r)};$e.set(this,e=>{if(!L(this,ue))return null;if(!e)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(e instanceof A.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});be.set(this,async(e=!1)=>{if(this.config.backend&&this.config.backend!==""&&e||this.tf.getBackend()!==this.config.backend){let n=M();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&P("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&P("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let c=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),r=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&P(`wasm execution: ${c?"SIMD":"no SIMD"} ${r?"multithreaded":"singlethreaded"}`),c||P("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&y1();try{await this.tf.setBackend(this.config.backend)}catch(c){P("error: cannot set backend:",this.config.backend,c)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(P("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let c=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&P(`gl version:${c.getParameter(c.VERSION)} renderer:${c.getParameter(c.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(M()-n)}});et.set(this,async()=>{let e=(r,_="application/octet-stream")=>fetch(`data:${_};base64,${r}`).then(o=>o.blob()),n,c;switch(this.config.warmup){case"face":n=await e(Ge);break;case"full":n=await e(Qe);break;default:n=null}if(n){let r=await createImageBitmap(n);c=await this.detect(r,this.config),r.close()}return c});tt.set(this,async()=>new Promise(e=>{let n,c=0;switch(this.config.warmup){case"face":c=256,n="data:image/jpeg;base64,"+Ge;break;case"full":case"body":c=1200,n="data:image/jpeg;base64,"+Qe;break;default:n=null}let r=new Image;r.onload=async()=>{let _=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(c,c):document.createElement("canvas");_.width=r.naturalWidth,_.height=r.naturalHeight;let o=_.getContext("2d");o==null||o.drawImage(r,0,0);let s=await this.detect(_,this.config);e(s)},n?r.src=n:e(null)}));nt.set(this,async()=>{let e=o=>Buffer.from(o,"base64"),n=this.config.warmup==="face"?e(Ge):e(Qe),c=A.node.decodeJpeg(n),r=c.expandDims(0);this.tf.dispose(c);let _=await this.detect(r,this.config);return this.tf.dispose(r),_});this.tf=A,this.draw=_1,this.version=i0,this.config=Ae(S,e),this.state="idle",te(this,ye,0),te(this,pe,!1),te(this,ue,!1),te(this,ce,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>A1(n,this.config),this.classes={facemesh:Mt,age:ct,gender:_t,emotion:at,faceres:ft,body:this.config.body.modelPath.includes("posenet")?Lt:Dt,hand:Yt,nanodet:t1},this.faceTriangulation=v1,this.faceUVMap=z1,this.sysinfo=x1()}profileData(){return this.config.profile?Te:{}}similarity(e,n){return this.config.face.description.enabled?pt(e,n):this.config.face.embedding.enabled?w1(e,n):0}enhance(e){return ut(e)}match(e,n,c=0){return l1(e,n,c)}async load(e={}){this.state="load";let n=M();e&&(this.config=Ae(this.config,e)),L(this,ce)&&(this.config.debug&&P(`version: ${this.version}`),this.config.debug&&P(`tfjs version: ${this.tf.version_core}`),this.config.debug&&P("platform:",this.sysinfo.platform),this.config.debug&&P("agent:",this.sysinfo.agent),await L(this,be).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&P("configuration:",this.config),this.config.debug&&P("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?Et(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?At(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?it(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?wt(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?lt(this.config):null),this.models.handpose||(this.config.hand.enabled?Ut(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?Xt(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?Gt(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?$t(this.config):null),this.models.nanodet||(this.config.object.enabled?r1(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?mt(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await Et(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await At(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await it(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await wt(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await lt(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await Ut(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await Xt(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await Gt(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await $t(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await r1(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await mt(this.config))),L(this,ce)&&(this.config.debug&&P("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),te(this,ce,!1));let c=Math.trunc(M()-n);c>(this.perf.load||0)&&(this.perf.load=c)}async detect(e,n={}){return new Promise(async c=>{var x,m,p,v;this.state="config";let r;this.config=Ae(this.config,n),this.state="check";let _=L(this,$e).call(this,e);_&&(P(_,e),c({error:_}));let o=M();await L(this,be).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),r=M();let s=A1(e,this.config);if(!s||!s.tensor){P("could not convert input to tensor"),c({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(M()-r),this.analyze("Get Image:");let h,i,y,a,w;this.config.async?(y=this.config.face.enabled?bt(this,s.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",r=M(),y=this.config.face.enabled?await bt(this,s.tensor):[],w=Math.trunc(M()-r),w>0&&(this.perf.face=w)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?h=this.config.body.enabled?(x=this.models.posenet)==null?void 0:x.estimatePoses(s.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?h=this.config.body.enabled?Qt(s.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(h=this.config.body.enabled?e1(s.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",r=M(),this.config.body.modelPath.includes("posenet")?h=this.config.body.enabled?await((m=this.models.posenet)==null?void 0:m.estimatePoses(s.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?h=this.config.body.enabled?await Qt(s.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(h=this.config.body.enabled?await e1(s.tensor,this.config):[]),w=Math.trunc(M()-r),w>0&&(this.perf.body=w)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(i=this.config.hand.enabled?(p=this.models.handpose)==null?void 0:p.estimateHands(s.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",r=M(),i=this.config.hand.enabled?await((v=this.models.handpose)==null?void 0:v.estimateHands(s.tensor,this.config)):[],w=Math.trunc(M()-r),w>0&&(this.perf.hand=w)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(a=this.config.object.enabled?c1(s.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",r=M(),a=this.config.object.enabled?await c1(s.tensor,this.config):[],w=Math.trunc(M()-r),w>0&&(this.perf.object=w)),this.analyze("End Object:"),this.config.async&&([y,h,i,a]=await Promise.all([y,h,i,a])),s.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let u=[];this.config.gesture.enabled&&(r=M(),u=[...t0(y),...e0(h),...r0(i),...n0(y)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(M()-r)),this.perf.total=Math.trunc(M()-o),this.state="idle";let b={face:y,body:h,hand:i,gesture:u,object:a,performance:this.perf,canvas:s.canvas};c(b)})}async warmup(e={}){let n=M();e&&(this.config=Ae(this.config,e));let c=this.config.videoOptimized;this.config.videoOptimized=!1;let r;typeof createImageBitmap=="function"?r=await L(this,et).call(this):typeof Image!="undefined"?r=await L(this,tt).call(this):r=await L(this,nt).call(this),this.config.videoOptimized=c;let _=M();return this.config.debug&&P("Warmup",this.config.warmup,Math.round(_-n),"ms",r),r}};ye=new WeakMap,pe=new WeakMap,ue=new WeakMap,ce=new WeakMap,$e=new WeakMap,be=new WeakMap,et=new WeakMap,tt=new WeakMap,nt=new WeakMap;export{hn as Human,hn as default}; //# sourceMappingURL=human.esm-nobundle.js.map diff --git a/dist/human.esm.js b/dist/human.esm.js index 66724b3b..ffb8222e 100644 --- a/dist/human.esm.js +++ b/dist/human.esm.js @@ -4889,7 +4889,7 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var A4="1.2.5";var Jl,qc,Xc,$i,W0,Kc,B0,V0,U0,Oae=class{constructor(t={}){Jl.set(this,void 0);qc.set(this,void 0);Xc.set(this,void 0);$i.set(this,void 0);this.analyze=(...t)=>{if(!Jn(this,qc))return;let n=this.tf.engine().state.numTensors,r=Jn(this,Jl);rs(this,Jl,n);let a=n-r;a!==0&&Ne(...t,a)};W0.set(this,t=>{if(!Jn(this,Xc))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof We))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});Kc.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=Ye();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&Ne("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&Ne("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let r=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),a=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&Ne(`wasm execution: ${r?"SIMD":"no SIMD"} ${a?"multithreaded":"singlethreaded"}`),r||Ne("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&x6();try{await this.tf.setBackend(this.config.backend)}catch(r){Ne("error: cannot set backend:",this.config.backend,r)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(Ne("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&Ne(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(Ye()-n)}});B0.set(this,async()=>{let t=(a,s="application/octet-stream")=>fetch(`data:${s};base64,${a}`).then(i=>i.blob()),n,r;switch(this.config.warmup){case"face":n=await t(P0);break;case"full":n=await t(L0);break;default:n=null}if(n){let a=await createImageBitmap(n);r=await this.detect(a,this.config),a.close()}return r});V0.set(this,async()=>new Promise(t=>{let n,r=0;switch(this.config.warmup){case"face":r=256,n="data:image/jpeg;base64,"+P0;break;case"full":case"body":r=1200,n="data:image/jpeg;base64,"+L0;break;default:n=null}let a=new Image;a.onload=async()=>{let s=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");s.width=a.naturalWidth,s.height=a.naturalHeight;let i=s.getContext("2d");i==null||i.drawImage(a,0,0);let o=await this.detect(s,this.config);t(o)},n?a.src=n:t(null)}));U0.set(this,async()=>{let t=i=>Buffer.from(i,"base64"),n=this.config.warmup==="face"?t(P0):t(L0),r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r);let s=await this.detect(a,this.config);return this.tf.dispose(a),s});this.tf=xh,this.draw=kg,this.version=A4,this.config=qi(ht,t),this.state="idle",rs(this,Jl,0),rs(this,qc,!1),rs(this,Xc,!1),rs(this,$i,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vg(n,this.config),this.classes={facemesh:H2,age:_2,gender:k2,emotion:C2,faceres:D2,body:this.config.body.modelPath.includes("posenet")?rg:fg,hand:cg,nanodet:xg},this.faceTriangulation=R6,this.faceUVMap=M6,this.sysinfo=Lg()}profileData(){return this.config.profile?c0:{}}similarity(t,n){return this.config.face.description.enabled?z2(t,n):this.config.face.embedding.enabled?w6(t,n):0}enhance(t){return P2(t)}match(t,n,r=0){return b6(t,n,r)}async load(t={}){this.state="load";let n=Ye();t&&(this.config=qi(this.config,t)),Jn(this,$i)&&(this.config.debug&&Ne(`version: ${this.version}`),this.config.debug&&Ne(`tfjs version: ${this.tf.version_core}`),this.config.debug&&Ne("platform:",this.sysinfo.platform),this.config.debug&&Ne("agent:",this.sysinfo.agent),await Jn(this,Kc).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&Ne("configuration:",this.config),this.config.debug&&Ne("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?q2(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?v2(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?T2(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?M2(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?F2(this.config):null),this.models.handpose||(this.config.hand.enabled?pg(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?sg(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?mg(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?yg(this.config):null),this.models.nanodet||(this.config.object.enabled?bg(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?O2(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await q2(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await v2(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await T2(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await M2(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await F2(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await pg(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await sg(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await mg(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await yg(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await bg(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await O2(this.config))),Jn(this,$i)&&(this.config.debug&&Ne("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),rs(this,$i,!1));let r=Math.trunc(Ye()-n);r>(this.perf.load||0)&&(this.perf.load=r)}async detect(t,n={}){return new Promise(async r=>{var m,A,y,g;this.state="config";let a;this.config=qi(this.config,n),this.state="check";let s=Jn(this,W0).call(this,t);s&&(Ne(s,t),r({error:s}));let i=Ye();await Jn(this,Kc).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),a=Ye();let o=vg(t,this.config);if(!o||!o.tensor){Ne("could not convert input to tensor"),r({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(Ye()-a),this.analyze("Get Image:");let l,c,u,h,d;this.config.async?(u=this.config.face.enabled?L2(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",a=Ye(),u=this.config.face.enabled?await L2(this,o.tensor):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.face=d)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?(m=this.models.posenet)==null?void 0:m.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?gg(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",a=Ye(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await((A=this.models.posenet)==null?void 0:A.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?await gg(o.tensor,this.config):[]),d=Math.trunc(Ye()-a),d>0&&(this.perf.body=d)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(c=this.config.hand.enabled?(y=this.models.handpose)==null?void 0:y.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",a=Ye(),c=this.config.hand.enabled?await((g=this.models.handpose)==null?void 0:g.estimateHands(o.tensor,this.config)):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.hand=d)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(h=this.config.object.enabled?_g(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",a=Ye(),h=this.config.object.enabled?await _g(o.tensor,this.config):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.object=d)),this.analyze("End Object:"),this.config.async&&([u,l,c,h]=await Promise.all([u,l,c,h])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let p=[];this.config.gesture.enabled&&(a=Ye(),p=[...o4(u),...i4(l),...u4(c),...l4(u)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(Ye()-a)),this.perf.total=Math.trunc(Ye()-i),this.state="idle";let f={face:u,body:l,hand:c,gesture:p,object:h,performance:this.perf,canvas:o.canvas};r(f)})}async warmup(t={}){let n=Ye();t&&(this.config=qi(this.config,t));let r=this.config.videoOptimized;this.config.videoOptimized=!1;let a;typeof createImageBitmap=="function"?a=await Jn(this,B0).call(this):typeof Image!="undefined"?a=await Jn(this,V0).call(this):a=await Jn(this,U0).call(this),this.config.videoOptimized=r;let s=Ye();return this.config.debug&&Ne("Warmup",this.config.warmup,Math.round(s-n),"ms",a),a}};Jl=new WeakMap,qc=new WeakMap,Xc=new WeakMap,$i=new WeakMap,W0=new WeakMap,Kc=new WeakMap,B0=new WeakMap,V0=new WeakMap,U0=new WeakMap;export{Oae as Human,Oae as default}; +2Q==`;var A4="1.3.0";var Jl,qc,Xc,$i,W0,Kc,B0,V0,U0,Oae=class{constructor(t={}){Jl.set(this,void 0);qc.set(this,void 0);Xc.set(this,void 0);$i.set(this,void 0);this.analyze=(...t)=>{if(!Jn(this,qc))return;let n=this.tf.engine().state.numTensors,r=Jn(this,Jl);rs(this,Jl,n);let a=n-r;a!==0&&Ne(...t,a)};W0.set(this,t=>{if(!Jn(this,Xc))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof We))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});Kc.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=Ye();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&Ne("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&Ne("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let r=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),a=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&Ne(`wasm execution: ${r?"SIMD":"no SIMD"} ${a?"multithreaded":"singlethreaded"}`),r||Ne("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&x6();try{await this.tf.setBackend(this.config.backend)}catch(r){Ne("error: cannot set backend:",this.config.backend,r)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(Ne("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&Ne(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(Ye()-n)}});B0.set(this,async()=>{let t=(a,s="application/octet-stream")=>fetch(`data:${s};base64,${a}`).then(i=>i.blob()),n,r;switch(this.config.warmup){case"face":n=await t(P0);break;case"full":n=await t(L0);break;default:n=null}if(n){let a=await createImageBitmap(n);r=await this.detect(a,this.config),a.close()}return r});V0.set(this,async()=>new Promise(t=>{let n,r=0;switch(this.config.warmup){case"face":r=256,n="data:image/jpeg;base64,"+P0;break;case"full":case"body":r=1200,n="data:image/jpeg;base64,"+L0;break;default:n=null}let a=new Image;a.onload=async()=>{let s=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");s.width=a.naturalWidth,s.height=a.naturalHeight;let i=s.getContext("2d");i==null||i.drawImage(a,0,0);let o=await this.detect(s,this.config);t(o)},n?a.src=n:t(null)}));U0.set(this,async()=>{let t=i=>Buffer.from(i,"base64"),n=this.config.warmup==="face"?t(P0):t(L0),r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r);let s=await this.detect(a,this.config);return this.tf.dispose(a),s});this.tf=xh,this.draw=kg,this.version=A4,this.config=qi(ht,t),this.state="idle",rs(this,Jl,0),rs(this,qc,!1),rs(this,Xc,!1),rs(this,$i,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vg(n,this.config),this.classes={facemesh:H2,age:_2,gender:k2,emotion:C2,faceres:D2,body:this.config.body.modelPath.includes("posenet")?rg:fg,hand:cg,nanodet:xg},this.faceTriangulation=R6,this.faceUVMap=M6,this.sysinfo=Lg()}profileData(){return this.config.profile?c0:{}}similarity(t,n){return this.config.face.description.enabled?z2(t,n):this.config.face.embedding.enabled?w6(t,n):0}enhance(t){return P2(t)}match(t,n,r=0){return b6(t,n,r)}async load(t={}){this.state="load";let n=Ye();t&&(this.config=qi(this.config,t)),Jn(this,$i)&&(this.config.debug&&Ne(`version: ${this.version}`),this.config.debug&&Ne(`tfjs version: ${this.tf.version_core}`),this.config.debug&&Ne("platform:",this.sysinfo.platform),this.config.debug&&Ne("agent:",this.sysinfo.agent),await Jn(this,Kc).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&Ne("configuration:",this.config),this.config.debug&&Ne("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?q2(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?v2(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?T2(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?M2(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?F2(this.config):null),this.models.handpose||(this.config.hand.enabled?pg(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?sg(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?mg(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?yg(this.config):null),this.models.nanodet||(this.config.object.enabled?bg(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?O2(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await q2(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await v2(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await T2(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await M2(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await F2(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await pg(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await sg(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await mg(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await yg(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await bg(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await O2(this.config))),Jn(this,$i)&&(this.config.debug&&Ne("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),rs(this,$i,!1));let r=Math.trunc(Ye()-n);r>(this.perf.load||0)&&(this.perf.load=r)}async detect(t,n={}){return new Promise(async r=>{var m,A,y,g;this.state="config";let a;this.config=qi(this.config,n),this.state="check";let s=Jn(this,W0).call(this,t);s&&(Ne(s,t),r({error:s}));let i=Ye();await Jn(this,Kc).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),a=Ye();let o=vg(t,this.config);if(!o||!o.tensor){Ne("could not convert input to tensor"),r({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(Ye()-a),this.analyze("Get Image:");let l,c,u,h,d;this.config.async?(u=this.config.face.enabled?L2(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",a=Ye(),u=this.config.face.enabled?await L2(this,o.tensor):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.face=d)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?(m=this.models.posenet)==null?void 0:m.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?gg(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",a=Ye(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await((A=this.models.posenet)==null?void 0:A.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?await gg(o.tensor,this.config):[]),d=Math.trunc(Ye()-a),d>0&&(this.perf.body=d)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(c=this.config.hand.enabled?(y=this.models.handpose)==null?void 0:y.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",a=Ye(),c=this.config.hand.enabled?await((g=this.models.handpose)==null?void 0:g.estimateHands(o.tensor,this.config)):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.hand=d)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(h=this.config.object.enabled?_g(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",a=Ye(),h=this.config.object.enabled?await _g(o.tensor,this.config):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.object=d)),this.analyze("End Object:"),this.config.async&&([u,l,c,h]=await Promise.all([u,l,c,h])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let p=[];this.config.gesture.enabled&&(a=Ye(),p=[...o4(u),...i4(l),...u4(c),...l4(u)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(Ye()-a)),this.perf.total=Math.trunc(Ye()-i),this.state="idle";let f={face:u,body:l,hand:c,gesture:p,object:h,performance:this.perf,canvas:o.canvas};r(f)})}async warmup(t={}){let n=Ye();t&&(this.config=qi(this.config,t));let r=this.config.videoOptimized;this.config.videoOptimized=!1;let a;typeof createImageBitmap=="function"?a=await Jn(this,B0).call(this):typeof Image!="undefined"?a=await Jn(this,V0).call(this):a=await Jn(this,U0).call(this),this.config.videoOptimized=r;let s=Ye();return this.config.debug&&Ne("Warmup",this.config.warmup,Math.round(s-n),"ms",a),a}};Jl=new WeakMap,qc=new WeakMap,Xc=new WeakMap,$i=new WeakMap,W0=new WeakMap,Kc=new WeakMap,B0=new WeakMap,V0=new WeakMap,U0=new WeakMap;export{Oae as Human,Oae as default}; /** * @license * Copyright 2017 Google LLC. All Rights Reserved. diff --git a/dist/human.js b/dist/human.js index b5365df6..332cf6fc 100644 --- a/dist/human.js +++ b/dist/human.js @@ -4889,7 +4889,7 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var A4="1.2.5";var Jl,qc,Xc,$i,W0,Kc,B0,V0,U0,y4=class{constructor(t={}){Jl.set(this,void 0);qc.set(this,void 0);Xc.set(this,void 0);$i.set(this,void 0);this.analyze=(...t)=>{if(!Qn(this,qc))return;let n=this.tf.engine().state.numTensors,r=Qn(this,Jl);rs(this,Jl,n);let a=n-r;a!==0&&Ne(...t,a)};W0.set(this,t=>{if(!Qn(this,Xc))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof We))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});Kc.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=Ye();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&Ne("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&Ne("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let r=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),a=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&Ne(`wasm execution: ${r?"SIMD":"no SIMD"} ${a?"multithreaded":"singlethreaded"}`),r||Ne("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&x6();try{await this.tf.setBackend(this.config.backend)}catch(r){Ne("error: cannot set backend:",this.config.backend,r)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(Ne("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&Ne(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(Ye()-n)}});B0.set(this,async()=>{let t=(a,s="application/octet-stream")=>fetch(`data:${s};base64,${a}`).then(i=>i.blob()),n,r;switch(this.config.warmup){case"face":n=await t(P0);break;case"full":n=await t(L0);break;default:n=null}if(n){let a=await createImageBitmap(n);r=await this.detect(a,this.config),a.close()}return r});V0.set(this,async()=>new Promise(t=>{let n,r=0;switch(this.config.warmup){case"face":r=256,n="data:image/jpeg;base64,"+P0;break;case"full":case"body":r=1200,n="data:image/jpeg;base64,"+L0;break;default:n=null}let a=new Image;a.onload=async()=>{let s=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");s.width=a.naturalWidth,s.height=a.naturalHeight;let i=s.getContext("2d");i==null||i.drawImage(a,0,0);let o=await this.detect(s,this.config);t(o)},n?a.src=n:t(null)}));U0.set(this,async()=>{let t=i=>Buffer.from(i,"base64"),n=this.config.warmup==="face"?t(P0):t(L0),r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r);let s=await this.detect(a,this.config);return this.tf.dispose(a),s});this.tf=xh,this.draw=kg,this.version=A4,this.config=qi(ht,t),this.state="idle",rs(this,Jl,0),rs(this,qc,!1),rs(this,Xc,!1),rs(this,$i,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vg(n,this.config),this.classes={facemesh:H2,age:_2,gender:k2,emotion:C2,faceres:D2,body:this.config.body.modelPath.includes("posenet")?rg:fg,hand:cg,nanodet:xg},this.faceTriangulation=R6,this.faceUVMap=M6,this.sysinfo=Lg()}profileData(){return this.config.profile?c0:{}}similarity(t,n){return this.config.face.description.enabled?z2(t,n):this.config.face.embedding.enabled?w6(t,n):0}enhance(t){return P2(t)}match(t,n,r=0){return b6(t,n,r)}async load(t={}){this.state="load";let n=Ye();t&&(this.config=qi(this.config,t)),Qn(this,$i)&&(this.config.debug&&Ne(`version: ${this.version}`),this.config.debug&&Ne(`tfjs version: ${this.tf.version_core}`),this.config.debug&&Ne("platform:",this.sysinfo.platform),this.config.debug&&Ne("agent:",this.sysinfo.agent),await Qn(this,Kc).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&Ne("configuration:",this.config),this.config.debug&&Ne("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?q2(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?v2(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?T2(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?M2(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?F2(this.config):null),this.models.handpose||(this.config.hand.enabled?pg(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?sg(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?mg(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?yg(this.config):null),this.models.nanodet||(this.config.object.enabled?bg(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?O2(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await q2(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await v2(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await T2(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await M2(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await F2(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await pg(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await sg(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await mg(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await yg(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await bg(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await O2(this.config))),Qn(this,$i)&&(this.config.debug&&Ne("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),rs(this,$i,!1));let r=Math.trunc(Ye()-n);r>(this.perf.load||0)&&(this.perf.load=r)}async detect(t,n={}){return new Promise(async r=>{var m,A,y,g;this.state="config";let a;this.config=qi(this.config,n),this.state="check";let s=Qn(this,W0).call(this,t);s&&(Ne(s,t),r({error:s}));let i=Ye();await Qn(this,Kc).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),a=Ye();let o=vg(t,this.config);if(!o||!o.tensor){Ne("could not convert input to tensor"),r({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(Ye()-a),this.analyze("Get Image:");let l,c,u,h,d;this.config.async?(u=this.config.face.enabled?L2(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",a=Ye(),u=this.config.face.enabled?await L2(this,o.tensor):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.face=d)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?(m=this.models.posenet)==null?void 0:m.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?gg(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",a=Ye(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await((A=this.models.posenet)==null?void 0:A.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?await gg(o.tensor,this.config):[]),d=Math.trunc(Ye()-a),d>0&&(this.perf.body=d)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(c=this.config.hand.enabled?(y=this.models.handpose)==null?void 0:y.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",a=Ye(),c=this.config.hand.enabled?await((g=this.models.handpose)==null?void 0:g.estimateHands(o.tensor,this.config)):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.hand=d)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(h=this.config.object.enabled?_g(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",a=Ye(),h=this.config.object.enabled?await _g(o.tensor,this.config):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.object=d)),this.analyze("End Object:"),this.config.async&&([u,l,c,h]=await Promise.all([u,l,c,h])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let p=[];this.config.gesture.enabled&&(a=Ye(),p=[...o4(u),...i4(l),...u4(c),...l4(u)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(Ye()-a)),this.perf.total=Math.trunc(Ye()-i),this.state="idle";let f={face:u,body:l,hand:c,gesture:p,object:h,performance:this.perf,canvas:o.canvas};r(f)})}async warmup(t={}){let n=Ye();t&&(this.config=qi(this.config,t));let r=this.config.videoOptimized;this.config.videoOptimized=!1;let a;typeof createImageBitmap=="function"?a=await Qn(this,B0).call(this):typeof Image!="undefined"?a=await Qn(this,V0).call(this):a=await Qn(this,U0).call(this),this.config.videoOptimized=r;let s=Ye();return this.config.debug&&Ne("Warmup",this.config.warmup,Math.round(s-n),"ms",a),a}};Jl=new WeakMap,qc=new WeakMap,Xc=new WeakMap,$i=new WeakMap,W0=new WeakMap,Kc=new WeakMap,B0=new WeakMap,V0=new WeakMap,U0=new WeakMap;return zae;})(); +2Q==`;var A4="1.3.0";var Jl,qc,Xc,$i,W0,Kc,B0,V0,U0,y4=class{constructor(t={}){Jl.set(this,void 0);qc.set(this,void 0);Xc.set(this,void 0);$i.set(this,void 0);this.analyze=(...t)=>{if(!Qn(this,qc))return;let n=this.tf.engine().state.numTensors,r=Qn(this,Jl);rs(this,Jl,n);let a=n-r;a!==0&&Ne(...t,a)};W0.set(this,t=>{if(!Qn(this,Xc))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof We))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});Kc.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=Ye();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&Ne("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&Ne("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let r=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),a=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&Ne(`wasm execution: ${r?"SIMD":"no SIMD"} ${a?"multithreaded":"singlethreaded"}`),r||Ne("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&x6();try{await this.tf.setBackend(this.config.backend)}catch(r){Ne("error: cannot set backend:",this.config.backend,r)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(Ne("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let r=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&Ne(`gl version:${r.getParameter(r.VERSION)} renderer:${r.getParameter(r.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(Ye()-n)}});B0.set(this,async()=>{let t=(a,s="application/octet-stream")=>fetch(`data:${s};base64,${a}`).then(i=>i.blob()),n,r;switch(this.config.warmup){case"face":n=await t(P0);break;case"full":n=await t(L0);break;default:n=null}if(n){let a=await createImageBitmap(n);r=await this.detect(a,this.config),a.close()}return r});V0.set(this,async()=>new Promise(t=>{let n,r=0;switch(this.config.warmup){case"face":r=256,n="data:image/jpeg;base64,"+P0;break;case"full":case"body":r=1200,n="data:image/jpeg;base64,"+L0;break;default:n=null}let a=new Image;a.onload=async()=>{let s=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(r,r):document.createElement("canvas");s.width=a.naturalWidth,s.height=a.naturalHeight;let i=s.getContext("2d");i==null||i.drawImage(a,0,0);let o=await this.detect(s,this.config);t(o)},n?a.src=n:t(null)}));U0.set(this,async()=>{let t=i=>Buffer.from(i,"base64"),n=this.config.warmup==="face"?t(P0):t(L0),r=(void 0).decodeJpeg(n),a=r.expandDims(0);this.tf.dispose(r);let s=await this.detect(a,this.config);return this.tf.dispose(a),s});this.tf=xh,this.draw=kg,this.version=A4,this.config=qi(ht,t),this.state="idle",rs(this,Jl,0),rs(this,qc,!1),rs(this,Xc,!1),rs(this,$i,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vg(n,this.config),this.classes={facemesh:H2,age:_2,gender:k2,emotion:C2,faceres:D2,body:this.config.body.modelPath.includes("posenet")?rg:fg,hand:cg,nanodet:xg},this.faceTriangulation=R6,this.faceUVMap=M6,this.sysinfo=Lg()}profileData(){return this.config.profile?c0:{}}similarity(t,n){return this.config.face.description.enabled?z2(t,n):this.config.face.embedding.enabled?w6(t,n):0}enhance(t){return P2(t)}match(t,n,r=0){return b6(t,n,r)}async load(t={}){this.state="load";let n=Ye();t&&(this.config=qi(this.config,t)),Qn(this,$i)&&(this.config.debug&&Ne(`version: ${this.version}`),this.config.debug&&Ne(`tfjs version: ${this.tf.version_core}`),this.config.debug&&Ne("platform:",this.sysinfo.platform),this.config.debug&&Ne("agent:",this.sysinfo.agent),await Qn(this,Kc).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&Ne("configuration:",this.config),this.config.debug&&Ne("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?q2(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?v2(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?T2(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?M2(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?F2(this.config):null),this.models.handpose||(this.config.hand.enabled?pg(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?sg(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?mg(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?yg(this.config):null),this.models.nanodet||(this.config.object.enabled?bg(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?O2(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await q2(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await v2(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await T2(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await M2(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await F2(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await pg(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await sg(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await mg(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await yg(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await bg(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await O2(this.config))),Qn(this,$i)&&(this.config.debug&&Ne("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),rs(this,$i,!1));let r=Math.trunc(Ye()-n);r>(this.perf.load||0)&&(this.perf.load=r)}async detect(t,n={}){return new Promise(async r=>{var m,A,y,g;this.state="config";let a;this.config=qi(this.config,n),this.state="check";let s=Qn(this,W0).call(this,t);s&&(Ne(s,t),r({error:s}));let i=Ye();await Qn(this,Kc).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),a=Ye();let o=vg(t,this.config);if(!o||!o.tensor){Ne("could not convert input to tensor"),r({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(Ye()-a),this.analyze("Get Image:");let l,c,u,h,d;this.config.async?(u=this.config.face.enabled?L2(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",a=Ye(),u=this.config.face.enabled?await L2(this,o.tensor):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.face=d)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?(m=this.models.posenet)==null?void 0:m.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?gg(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",a=Ye(),this.config.body.modelPath.includes("posenet")?l=this.config.body.enabled?await((A=this.models.posenet)==null?void 0:A.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?l=this.config.body.enabled?await Ag(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(l=this.config.body.enabled?await gg(o.tensor,this.config):[]),d=Math.trunc(Ye()-a),d>0&&(this.perf.body=d)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(c=this.config.hand.enabled?(y=this.models.handpose)==null?void 0:y.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",a=Ye(),c=this.config.hand.enabled?await((g=this.models.handpose)==null?void 0:g.estimateHands(o.tensor,this.config)):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.hand=d)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(h=this.config.object.enabled?_g(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",a=Ye(),h=this.config.object.enabled?await _g(o.tensor,this.config):[],d=Math.trunc(Ye()-a),d>0&&(this.perf.object=d)),this.analyze("End Object:"),this.config.async&&([u,l,c,h]=await Promise.all([u,l,c,h])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let p=[];this.config.gesture.enabled&&(a=Ye(),p=[...o4(u),...i4(l),...u4(c),...l4(u)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(Ye()-a)),this.perf.total=Math.trunc(Ye()-i),this.state="idle";let f={face:u,body:l,hand:c,gesture:p,object:h,performance:this.perf,canvas:o.canvas};r(f)})}async warmup(t={}){let n=Ye();t&&(this.config=qi(this.config,t));let r=this.config.videoOptimized;this.config.videoOptimized=!1;let a;typeof createImageBitmap=="function"?a=await Qn(this,B0).call(this):typeof Image!="undefined"?a=await Qn(this,V0).call(this):a=await Qn(this,U0).call(this),this.config.videoOptimized=r;let s=Ye();return this.config.debug&&Ne("Warmup",this.config.warmup,Math.round(s-n),"ms",a),a}};Jl=new WeakMap,qc=new WeakMap,Xc=new WeakMap,$i=new WeakMap,W0=new WeakMap,Kc=new WeakMap,B0=new WeakMap,V0=new WeakMap,U0=new WeakMap;return zae;})(); /** * @license * Copyright 2017 Google LLC. All Rights Reserved. diff --git a/dist/human.node-gpu.js b/dist/human.node-gpu.js index 2c0cdc0b..4b7da27d 100644 --- a/dist/human.node-gpu.js +++ b/dist/human.node-gpu.js @@ -731,5 +731,5 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var Z0="1.2.5";var Me,Ne,Oe,me,l1,ke,d1,f1,m1,V0=class{constructor(t={}){Me.set(this,void 0);Ne.set(this,void 0);Oe.set(this,void 0);me.set(this,void 0);this.analyze=(...t)=>{if(!U(this,Ne))return;let n=this.tf.engine().state.numTensors,c=U(this,Me);le(this,Me,n);let r=n-c;r!==0&&g(...t,r)};l1.set(this,t=>{if(!U(this,Oe))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Rt.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ke.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=M();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&g("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&g("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let c=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),r=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&g(`wasm execution: ${c?"SIMD":"no SIMD"} ${r?"multithreaded":"singlethreaded"}`),c||g("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&It();try{await this.tf.setBackend(this.config.backend)}catch(c){g("error: cannot set backend:",this.config.backend,c)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(g("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let c=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&g(`gl version:${c.getParameter(c.VERSION)} renderer:${c.getParameter(c.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(M()-n)}});d1.set(this,async()=>{let t=(r,A="application/octet-stream")=>fetch(`data:${A};base64,${r}`).then(_=>_.blob()),n,c;switch(this.config.warmup){case"face":n=await t(y1);break;case"full":n=await t(w1);break;default:n=null}if(n){let r=await createImageBitmap(n);c=await this.detect(r,this.config),r.close()}return c});f1.set(this,async()=>new Promise(t=>{let n,c=0;switch(this.config.warmup){case"face":c=256,n="data:image/jpeg;base64,"+y1;break;case"full":case"body":c=1200,n="data:image/jpeg;base64,"+w1;break;default:n=null}let r=new Image;r.onload=async()=>{let A=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(c,c):document.createElement("canvas");A.width=r.naturalWidth,A.height=r.naturalHeight;let _=A.getContext("2d");_==null||_.drawImage(r,0,0);let o=await this.detect(A,this.config);t(o)},n?r.src=n:t(null)}));m1.set(this,async()=>{let t=_=>Buffer.from(_,"base64"),n=this.config.warmup==="face"?t(y1):t(w1),c=Rt.node.decodeJpeg(n),r=c.expandDims(0);this.tf.dispose(c);let A=await this.detect(r,this.config);return this.tf.dispose(r),A});this.tf=Rt,this.draw=zt,this.version=Z0,this.config=pe(j,t),this.state="idle",le(this,Me,0),le(this,Ne,!1),le(this,Oe,!1),le(this,me,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vt(n,this.config),this.classes={facemesh:B1,age:g1,gender:P1,emotion:E1,faceres:k1,body:this.config.body.modelPath.includes("posenet")?ct:dt,hand:at,nanodet:bt},this.faceTriangulation=Ut,this.faceUVMap=Dt,this.sysinfo=Nt()}profileData(){return this.config.profile?Ve:{}}similarity(t,n){return this.config.face.description.enabled?Z1(t,n):this.config.face.embedding.enabled?Zt(t,n):0}enhance(t){return V1(t)}match(t,n,c=0){return Vt(t,n,c)}async load(t={}){this.state="load";let n=M();t&&(this.config=pe(this.config,t)),U(this,me)&&(this.config.debug&&g(`version: ${this.version}`),this.config.debug&&g(`tfjs version: ${this.tf.version_core}`),this.config.debug&&g("platform:",this.sysinfo.platform),this.config.debug&&g("agent:",this.sysinfo.agent),await U(this,ke).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&g("configuration:",this.config),this.config.debug&&g("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?K1(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?T1(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?R1(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?W1(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?N1(this.config):null),this.models.handpose||(this.config.hand.enabled?lt(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?_t(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?ft(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?pt(this.config):null),this.models.nanodet||(this.config.object.enabled?Tt(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?I1(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await K1(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await T1(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await R1(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await W1(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await N1(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await lt(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await _t(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await ft(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await pt(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await Tt(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await I1(this.config))),U(this,me)&&(this.config.debug&&g("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),le(this,me,!1));let c=Math.trunc(M()-n);c>(this.perf.load||0)&&(this.perf.load=c)}async detect(t,n={}){return new Promise(async c=>{var a,d,f,T;this.state="config";let r;this.config=pe(this.config,n),this.state="check";let A=U(this,l1).call(this,t);A&&(g(A,t),c({error:A}));let _=M();await U(this,ke).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),r=M();let o=vt(t,this.config);if(!o||!o.tensor){g("could not convert input to tensor"),c({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(M()-r),this.analyze("Get Image:");let s,h,x,i,y;this.config.async?(x=this.config.face.enabled?L1(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",r=M(),x=this.config.face.enabled?await L1(this,o.tensor):[],y=Math.trunc(M()-r),y>0&&(this.perf.face=y)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?(a=this.models.posenet)==null?void 0:a.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?ut(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",r=M(),this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?await((d=this.models.posenet)==null?void 0:d.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?await mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?await ut(o.tensor,this.config):[]),y=Math.trunc(M()-r),y>0&&(this.perf.body=y)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(h=this.config.hand.enabled?(f=this.models.handpose)==null?void 0:f.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",r=M(),h=this.config.hand.enabled?await((T=this.models.handpose)==null?void 0:T.estimateHands(o.tensor,this.config)):[],y=Math.trunc(M()-r),y>0&&(this.perf.hand=y)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(i=this.config.object.enabled?Pt(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",r=M(),i=this.config.object.enabled?await Pt(o.tensor,this.config):[],y=Math.trunc(M()-r),y>0&&(this.perf.object=y)),this.analyze("End Object:"),this.config.async&&([x,s,h,i]=await Promise.all([x,s,h,i])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let m=[];this.config.gesture.enabled&&(r=M(),m=[...R0(x),...M0(s),...S0(h),...E0(x)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(M()-r)),this.perf.total=Math.trunc(M()-_),this.state="idle";let p={face:x,body:s,hand:h,gesture:m,object:i,performance:this.perf,canvas:o.canvas};c(p)})}async warmup(t={}){let n=M();t&&(this.config=pe(this.config,t));let c=this.config.videoOptimized;this.config.videoOptimized=!1;let r;typeof createImageBitmap=="function"?r=await U(this,d1).call(this):typeof Image!="undefined"?r=await U(this,f1).call(this):r=await U(this,m1).call(this),this.config.videoOptimized=c;let A=M();return this.config.debug&&g("Warmup",this.config.warmup,Math.round(A-n),"ms",r),r}};Me=new WeakMap,Ne=new WeakMap,Oe=new WeakMap,me=new WeakMap,l1=new WeakMap,ke=new WeakMap,d1=new WeakMap,f1=new WeakMap,m1=new WeakMap;0&&(module.exports={Human}); +2Q==`;var Z0="1.3.0";var Me,Ne,Oe,me,l1,ke,d1,f1,m1,V0=class{constructor(t={}){Me.set(this,void 0);Ne.set(this,void 0);Oe.set(this,void 0);me.set(this,void 0);this.analyze=(...t)=>{if(!U(this,Ne))return;let n=this.tf.engine().state.numTensors,c=U(this,Me);le(this,Me,n);let r=n-c;r!==0&&g(...t,r)};l1.set(this,t=>{if(!U(this,Oe))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Rt.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ke.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=M();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&g("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&g("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let c=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),r=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&g(`wasm execution: ${c?"SIMD":"no SIMD"} ${r?"multithreaded":"singlethreaded"}`),c||g("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&It();try{await this.tf.setBackend(this.config.backend)}catch(c){g("error: cannot set backend:",this.config.backend,c)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(g("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let c=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&g(`gl version:${c.getParameter(c.VERSION)} renderer:${c.getParameter(c.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(M()-n)}});d1.set(this,async()=>{let t=(r,A="application/octet-stream")=>fetch(`data:${A};base64,${r}`).then(_=>_.blob()),n,c;switch(this.config.warmup){case"face":n=await t(y1);break;case"full":n=await t(w1);break;default:n=null}if(n){let r=await createImageBitmap(n);c=await this.detect(r,this.config),r.close()}return c});f1.set(this,async()=>new Promise(t=>{let n,c=0;switch(this.config.warmup){case"face":c=256,n="data:image/jpeg;base64,"+y1;break;case"full":case"body":c=1200,n="data:image/jpeg;base64,"+w1;break;default:n=null}let r=new Image;r.onload=async()=>{let A=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(c,c):document.createElement("canvas");A.width=r.naturalWidth,A.height=r.naturalHeight;let _=A.getContext("2d");_==null||_.drawImage(r,0,0);let o=await this.detect(A,this.config);t(o)},n?r.src=n:t(null)}));m1.set(this,async()=>{let t=_=>Buffer.from(_,"base64"),n=this.config.warmup==="face"?t(y1):t(w1),c=Rt.node.decodeJpeg(n),r=c.expandDims(0);this.tf.dispose(c);let A=await this.detect(r,this.config);return this.tf.dispose(r),A});this.tf=Rt,this.draw=zt,this.version=Z0,this.config=pe(j,t),this.state="idle",le(this,Me,0),le(this,Ne,!1),le(this,Oe,!1),le(this,me,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vt(n,this.config),this.classes={facemesh:B1,age:g1,gender:P1,emotion:E1,faceres:k1,body:this.config.body.modelPath.includes("posenet")?ct:dt,hand:at,nanodet:bt},this.faceTriangulation=Ut,this.faceUVMap=Dt,this.sysinfo=Nt()}profileData(){return this.config.profile?Ve:{}}similarity(t,n){return this.config.face.description.enabled?Z1(t,n):this.config.face.embedding.enabled?Zt(t,n):0}enhance(t){return V1(t)}match(t,n,c=0){return Vt(t,n,c)}async load(t={}){this.state="load";let n=M();t&&(this.config=pe(this.config,t)),U(this,me)&&(this.config.debug&&g(`version: ${this.version}`),this.config.debug&&g(`tfjs version: ${this.tf.version_core}`),this.config.debug&&g("platform:",this.sysinfo.platform),this.config.debug&&g("agent:",this.sysinfo.agent),await U(this,ke).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&g("configuration:",this.config),this.config.debug&&g("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?K1(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?T1(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?R1(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?W1(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?N1(this.config):null),this.models.handpose||(this.config.hand.enabled?lt(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?_t(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?ft(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?pt(this.config):null),this.models.nanodet||(this.config.object.enabled?Tt(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?I1(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await K1(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await T1(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await R1(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await W1(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await N1(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await lt(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await _t(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await ft(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await pt(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await Tt(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await I1(this.config))),U(this,me)&&(this.config.debug&&g("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),le(this,me,!1));let c=Math.trunc(M()-n);c>(this.perf.load||0)&&(this.perf.load=c)}async detect(t,n={}){return new Promise(async c=>{var a,d,f,T;this.state="config";let r;this.config=pe(this.config,n),this.state="check";let A=U(this,l1).call(this,t);A&&(g(A,t),c({error:A}));let _=M();await U(this,ke).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),r=M();let o=vt(t,this.config);if(!o||!o.tensor){g("could not convert input to tensor"),c({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(M()-r),this.analyze("Get Image:");let s,h,x,i,y;this.config.async?(x=this.config.face.enabled?L1(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",r=M(),x=this.config.face.enabled?await L1(this,o.tensor):[],y=Math.trunc(M()-r),y>0&&(this.perf.face=y)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?(a=this.models.posenet)==null?void 0:a.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?ut(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",r=M(),this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?await((d=this.models.posenet)==null?void 0:d.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?await mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?await ut(o.tensor,this.config):[]),y=Math.trunc(M()-r),y>0&&(this.perf.body=y)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(h=this.config.hand.enabled?(f=this.models.handpose)==null?void 0:f.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",r=M(),h=this.config.hand.enabled?await((T=this.models.handpose)==null?void 0:T.estimateHands(o.tensor,this.config)):[],y=Math.trunc(M()-r),y>0&&(this.perf.hand=y)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(i=this.config.object.enabled?Pt(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",r=M(),i=this.config.object.enabled?await Pt(o.tensor,this.config):[],y=Math.trunc(M()-r),y>0&&(this.perf.object=y)),this.analyze("End Object:"),this.config.async&&([x,s,h,i]=await Promise.all([x,s,h,i])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let m=[];this.config.gesture.enabled&&(r=M(),m=[...R0(x),...M0(s),...S0(h),...E0(x)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(M()-r)),this.perf.total=Math.trunc(M()-_),this.state="idle";let p={face:x,body:s,hand:h,gesture:m,object:i,performance:this.perf,canvas:o.canvas};c(p)})}async warmup(t={}){let n=M();t&&(this.config=pe(this.config,t));let c=this.config.videoOptimized;this.config.videoOptimized=!1;let r;typeof createImageBitmap=="function"?r=await U(this,d1).call(this):typeof Image!="undefined"?r=await U(this,f1).call(this):r=await U(this,m1).call(this),this.config.videoOptimized=c;let A=M();return this.config.debug&&g("Warmup",this.config.warmup,Math.round(A-n),"ms",r),r}};Me=new WeakMap,Ne=new WeakMap,Oe=new WeakMap,me=new WeakMap,l1=new WeakMap,ke=new WeakMap,d1=new WeakMap,f1=new WeakMap,m1=new WeakMap;0&&(module.exports={Human}); //# sourceMappingURL=human.node-gpu.js.map diff --git a/dist/human.node.js b/dist/human.node.js index 8c910063..f82f288f 100644 --- a/dist/human.node.js +++ b/dist/human.node.js @@ -731,5 +731,5 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`;var Z0="1.2.5";var Me,Ne,Oe,me,l1,ke,d1,f1,m1,V0=class{constructor(t={}){Me.set(this,void 0);Ne.set(this,void 0);Oe.set(this,void 0);me.set(this,void 0);this.analyze=(...t)=>{if(!U(this,Ne))return;let n=this.tf.engine().state.numTensors,c=U(this,Me);le(this,Me,n);let r=n-c;r!==0&&g(...t,r)};l1.set(this,t=>{if(!U(this,Oe))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Rt.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ke.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=M();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&g("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&g("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let c=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),r=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&g(`wasm execution: ${c?"SIMD":"no SIMD"} ${r?"multithreaded":"singlethreaded"}`),c||g("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&It();try{await this.tf.setBackend(this.config.backend)}catch(c){g("error: cannot set backend:",this.config.backend,c)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(g("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let c=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&g(`gl version:${c.getParameter(c.VERSION)} renderer:${c.getParameter(c.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(M()-n)}});d1.set(this,async()=>{let t=(r,A="application/octet-stream")=>fetch(`data:${A};base64,${r}`).then(_=>_.blob()),n,c;switch(this.config.warmup){case"face":n=await t(y1);break;case"full":n=await t(w1);break;default:n=null}if(n){let r=await createImageBitmap(n);c=await this.detect(r,this.config),r.close()}return c});f1.set(this,async()=>new Promise(t=>{let n,c=0;switch(this.config.warmup){case"face":c=256,n="data:image/jpeg;base64,"+y1;break;case"full":case"body":c=1200,n="data:image/jpeg;base64,"+w1;break;default:n=null}let r=new Image;r.onload=async()=>{let A=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(c,c):document.createElement("canvas");A.width=r.naturalWidth,A.height=r.naturalHeight;let _=A.getContext("2d");_==null||_.drawImage(r,0,0);let o=await this.detect(A,this.config);t(o)},n?r.src=n:t(null)}));m1.set(this,async()=>{let t=_=>Buffer.from(_,"base64"),n=this.config.warmup==="face"?t(y1):t(w1),c=Rt.node.decodeJpeg(n),r=c.expandDims(0);this.tf.dispose(c);let A=await this.detect(r,this.config);return this.tf.dispose(r),A});this.tf=Rt,this.draw=zt,this.version=Z0,this.config=pe(j,t),this.state="idle",le(this,Me,0),le(this,Ne,!1),le(this,Oe,!1),le(this,me,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vt(n,this.config),this.classes={facemesh:B1,age:g1,gender:P1,emotion:E1,faceres:k1,body:this.config.body.modelPath.includes("posenet")?ct:dt,hand:at,nanodet:bt},this.faceTriangulation=Ut,this.faceUVMap=Dt,this.sysinfo=Nt()}profileData(){return this.config.profile?Ve:{}}similarity(t,n){return this.config.face.description.enabled?Z1(t,n):this.config.face.embedding.enabled?Zt(t,n):0}enhance(t){return V1(t)}match(t,n,c=0){return Vt(t,n,c)}async load(t={}){this.state="load";let n=M();t&&(this.config=pe(this.config,t)),U(this,me)&&(this.config.debug&&g(`version: ${this.version}`),this.config.debug&&g(`tfjs version: ${this.tf.version_core}`),this.config.debug&&g("platform:",this.sysinfo.platform),this.config.debug&&g("agent:",this.sysinfo.agent),await U(this,ke).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&g("configuration:",this.config),this.config.debug&&g("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?K1(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?T1(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?R1(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?W1(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?N1(this.config):null),this.models.handpose||(this.config.hand.enabled?lt(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?_t(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?ft(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?pt(this.config):null),this.models.nanodet||(this.config.object.enabled?Tt(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?I1(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await K1(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await T1(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await R1(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await W1(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await N1(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await lt(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await _t(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await ft(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await pt(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await Tt(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await I1(this.config))),U(this,me)&&(this.config.debug&&g("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),le(this,me,!1));let c=Math.trunc(M()-n);c>(this.perf.load||0)&&(this.perf.load=c)}async detect(t,n={}){return new Promise(async c=>{var a,d,f,T;this.state="config";let r;this.config=pe(this.config,n),this.state="check";let A=U(this,l1).call(this,t);A&&(g(A,t),c({error:A}));let _=M();await U(this,ke).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),r=M();let o=vt(t,this.config);if(!o||!o.tensor){g("could not convert input to tensor"),c({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(M()-r),this.analyze("Get Image:");let s,h,x,i,y;this.config.async?(x=this.config.face.enabled?L1(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",r=M(),x=this.config.face.enabled?await L1(this,o.tensor):[],y=Math.trunc(M()-r),y>0&&(this.perf.face=y)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?(a=this.models.posenet)==null?void 0:a.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?ut(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",r=M(),this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?await((d=this.models.posenet)==null?void 0:d.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?await mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?await ut(o.tensor,this.config):[]),y=Math.trunc(M()-r),y>0&&(this.perf.body=y)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(h=this.config.hand.enabled?(f=this.models.handpose)==null?void 0:f.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",r=M(),h=this.config.hand.enabled?await((T=this.models.handpose)==null?void 0:T.estimateHands(o.tensor,this.config)):[],y=Math.trunc(M()-r),y>0&&(this.perf.hand=y)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(i=this.config.object.enabled?Pt(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",r=M(),i=this.config.object.enabled?await Pt(o.tensor,this.config):[],y=Math.trunc(M()-r),y>0&&(this.perf.object=y)),this.analyze("End Object:"),this.config.async&&([x,s,h,i]=await Promise.all([x,s,h,i])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let m=[];this.config.gesture.enabled&&(r=M(),m=[...R0(x),...M0(s),...S0(h),...E0(x)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(M()-r)),this.perf.total=Math.trunc(M()-_),this.state="idle";let p={face:x,body:s,hand:h,gesture:m,object:i,performance:this.perf,canvas:o.canvas};c(p)})}async warmup(t={}){let n=M();t&&(this.config=pe(this.config,t));let c=this.config.videoOptimized;this.config.videoOptimized=!1;let r;typeof createImageBitmap=="function"?r=await U(this,d1).call(this):typeof Image!="undefined"?r=await U(this,f1).call(this):r=await U(this,m1).call(this),this.config.videoOptimized=c;let A=M();return this.config.debug&&g("Warmup",this.config.warmup,Math.round(A-n),"ms",r),r}};Me=new WeakMap,Ne=new WeakMap,Oe=new WeakMap,me=new WeakMap,l1=new WeakMap,ke=new WeakMap,d1=new WeakMap,f1=new WeakMap,m1=new WeakMap;0&&(module.exports={Human}); +2Q==`;var Z0="1.3.0";var Me,Ne,Oe,me,l1,ke,d1,f1,m1,V0=class{constructor(t={}){Me.set(this,void 0);Ne.set(this,void 0);Oe.set(this,void 0);me.set(this,void 0);this.analyze=(...t)=>{if(!U(this,Ne))return;let n=this.tf.engine().state.numTensors,c=U(this,Me);le(this,Me,n);let r=n-c;r!==0&&g(...t,r)};l1.set(this,t=>{if(!U(this,Oe))return null;if(!t)return"input is not defined";if(this.tf.ENV.flags.IS_NODE&&!(t instanceof Rt.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});ke.set(this,async(t=!1)=>{if(this.config.backend&&this.config.backend!==""&&t||this.tf.getBackend()!==this.config.backend){let n=M();if(this.state="backend",this.config.backend&&this.config.backend!==""){if(this.tf.ENV.flags.IS_BROWSER&&this.config.backend==="tensorflow"&&(this.config.backend="webgl"),this.tf.ENV.flags.IS_NODE&&(this.config.backend==="webgl"||this.config.backend==="wasm")&&(this.config.backend="tensorflow"),this.config.debug&&g("setting backend:",this.config.backend),this.config.backend==="wasm"){this.config.debug&&g("wasm path:",this.config.wasmPath),this.tf.setWasmPaths(this.config.wasmPath);let c=await this.tf.env().getAsync("WASM_HAS_SIMD_SUPPORT"),r=await this.tf.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT");this.config.debug&&g(`wasm execution: ${c?"SIMD":"no SIMD"} ${r?"multithreaded":"singlethreaded"}`),c||g("warning: wasm simd support is not enabled")}this.config.backend==="humangl"&&It();try{await this.tf.setBackend(this.config.backend)}catch(c){g("error: cannot set backend:",this.config.backend,c)}}if(this.tf.enableProdMode(),this.tf.getBackend()==="webgl"||this.tf.getBackend()==="humangl"){this.tf.ENV.set("CHECK_COMPUTATION_FOR_ERRORS",!1),this.tf.ENV.set("WEBGL_PACK_DEPTHWISECONV",!0),this.config.deallocate&&(g("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",this.config.deallocate),this.tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD",this.config.deallocate?0:-1));let c=await this.tf.backend().getGPGPUContext().gl;this.config.debug&&g(`gl version:${c.getParameter(c.VERSION)} renderer:${c.getParameter(c.RENDERER)}`)}await this.tf.ready(),this.perf.backend=Math.trunc(M()-n)}});d1.set(this,async()=>{let t=(r,A="application/octet-stream")=>fetch(`data:${A};base64,${r}`).then(_=>_.blob()),n,c;switch(this.config.warmup){case"face":n=await t(y1);break;case"full":n=await t(w1);break;default:n=null}if(n){let r=await createImageBitmap(n);c=await this.detect(r,this.config),r.close()}return c});f1.set(this,async()=>new Promise(t=>{let n,c=0;switch(this.config.warmup){case"face":c=256,n="data:image/jpeg;base64,"+y1;break;case"full":case"body":c=1200,n="data:image/jpeg;base64,"+w1;break;default:n=null}let r=new Image;r.onload=async()=>{let A=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(c,c):document.createElement("canvas");A.width=r.naturalWidth,A.height=r.naturalHeight;let _=A.getContext("2d");_==null||_.drawImage(r,0,0);let o=await this.detect(A,this.config);t(o)},n?r.src=n:t(null)}));m1.set(this,async()=>{let t=_=>Buffer.from(_,"base64"),n=this.config.warmup==="face"?t(y1):t(w1),c=Rt.node.decodeJpeg(n),r=c.expandDims(0);this.tf.dispose(c);let A=await this.detect(r,this.config);return this.tf.dispose(r),A});this.tf=Rt,this.draw=zt,this.version=Z0,this.config=pe(j,t),this.state="idle",le(this,Me,0),le(this,Ne,!1),le(this,Oe,!1),le(this,me,!0),this.perf={},this.models={face:null,posenet:null,blazepose:null,efficientpose:null,handpose:null,iris:null,age:null,gender:null,emotion:null,embedding:null,nanodet:null,faceres:null},this.image=n=>vt(n,this.config),this.classes={facemesh:B1,age:g1,gender:P1,emotion:E1,faceres:k1,body:this.config.body.modelPath.includes("posenet")?ct:dt,hand:at,nanodet:bt},this.faceTriangulation=Ut,this.faceUVMap=Dt,this.sysinfo=Nt()}profileData(){return this.config.profile?Ve:{}}similarity(t,n){return this.config.face.description.enabled?Z1(t,n):this.config.face.embedding.enabled?Zt(t,n):0}enhance(t){return V1(t)}match(t,n,c=0){return Vt(t,n,c)}async load(t={}){this.state="load";let n=M();t&&(this.config=pe(this.config,t)),U(this,me)&&(this.config.debug&&g(`version: ${this.version}`),this.config.debug&&g(`tfjs version: ${this.tf.version_core}`),this.config.debug&&g("platform:",this.sysinfo.platform),this.config.debug&&g("agent:",this.sysinfo.agent),await U(this,ke).call(this,!0),this.tf.ENV.flags.IS_BROWSER&&(this.config.debug&&g("configuration:",this.config),this.config.debug&&g("tf flags:",this.tf.ENV.flags))),this.config.async?[this.models.face,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.handpose,this.models.posenet,this.models.blazepose,this.models.efficientpose,this.models.nanodet,this.models.faceres]=await Promise.all([this.models.face||(this.config.face.enabled?K1(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?T1(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?R1(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?W1(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?N1(this.config):null),this.models.handpose||(this.config.hand.enabled?lt(this.config):null),this.models.posenet||(this.config.body.enabled&&this.config.body.modelPath.includes("posenet")?_t(this.config):null),this.models.blazepose||(this.config.body.enabled&&this.config.body.modelPath.includes("blazepose")?ft(this.config):null),this.models.efficientpose||(this.config.body.enabled&&this.config.body.modelPath.includes("efficientpose")?pt(this.config):null),this.models.nanodet||(this.config.object.enabled?Tt(this.config):null),this.models.faceres||(this.config.face.enabled&&this.config.face.description.enabled?I1(this.config):null)]):(this.config.face.enabled&&!this.models.face&&(this.models.face=await K1(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await T1(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await R1(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await W1(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await N1(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await lt(this.config)),this.config.body.enabled&&!this.models.posenet&&this.config.body.modelPath.includes("posenet")&&(this.models.posenet=await _t(this.config)),this.config.body.enabled&&!this.models.blazepose&&this.config.body.modelPath.includes("blazepose")&&(this.models.blazepose=await ft(this.config)),this.config.body.enabled&&!this.models.efficientpose&&this.config.body.modelPath.includes("efficientpose")&&(this.models.efficientpose=await pt(this.config)),this.config.object.enabled&&!this.models.nanodet&&(this.models.nanodet=await Tt(this.config)),this.config.face.enabled&&this.config.face.description.enabled&&!this.models.faceres&&(this.models.faceres=await I1(this.config))),U(this,me)&&(this.config.debug&&g("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),le(this,me,!1));let c=Math.trunc(M()-n);c>(this.perf.load||0)&&(this.perf.load=c)}async detect(t,n={}){return new Promise(async c=>{var a,d,f,T;this.state="config";let r;this.config=pe(this.config,n),this.state="check";let A=U(this,l1).call(this,t);A&&(g(A,t),c({error:A}));let _=M();await U(this,ke).call(this),await this.load(),this.config.scoped&&this.tf.engine().startScope(),this.analyze("Start Scope:"),r=M();let o=vt(t,this.config);if(!o||!o.tensor){g("could not convert input to tensor"),c({error:"could not convert input to tensor"});return}this.perf.image=Math.trunc(M()-r),this.analyze("Get Image:");let s,h,x,i,y;this.config.async?(x=this.config.face.enabled?L1(this,o.tensor):[],this.perf.face&&delete this.perf.face):(this.state="run:face",r=M(),x=this.config.face.enabled?await L1(this,o.tensor):[],y=Math.trunc(M()-r),y>0&&(this.perf.face=y)),this.analyze("Start Body:"),this.config.async?(this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?(a=this.models.posenet)==null?void 0:a.estimatePoses(o.tensor,this.config):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?ut(o.tensor,this.config):[]),this.perf.body&&delete this.perf.body):(this.state="run:body",r=M(),this.config.body.modelPath.includes("posenet")?s=this.config.body.enabled?await((d=this.models.posenet)==null?void 0:d.estimatePoses(o.tensor,this.config)):[]:this.config.body.modelPath.includes("blazepose")?s=this.config.body.enabled?await mt(o.tensor,this.config):[]:this.config.body.modelPath.includes("efficientpose")&&(s=this.config.body.enabled?await ut(o.tensor,this.config):[]),y=Math.trunc(M()-r),y>0&&(this.perf.body=y)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.config.async?(h=this.config.hand.enabled?(f=this.models.handpose)==null?void 0:f.estimateHands(o.tensor,this.config):[],this.perf.hand&&delete this.perf.hand):(this.state="run:hand",r=M(),h=this.config.hand.enabled?await((T=this.models.handpose)==null?void 0:T.estimateHands(o.tensor,this.config)):[],y=Math.trunc(M()-r),y>0&&(this.perf.hand=y)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.config.async?(i=this.config.object.enabled?Pt(o.tensor,this.config):[],this.perf.object&&delete this.perf.object):(this.state="run:object",r=M(),i=this.config.object.enabled?await Pt(o.tensor,this.config):[],y=Math.trunc(M()-r),y>0&&(this.perf.object=y)),this.analyze("End Object:"),this.config.async&&([x,s,h,i]=await Promise.all([x,s,h,i])),o.tensor.dispose(),this.config.scoped&&this.tf.engine().endScope(),this.analyze("End Scope:");let m=[];this.config.gesture.enabled&&(r=M(),m=[...R0(x),...M0(s),...S0(h),...E0(x)],this.config.async?this.perf.gesture&&delete this.perf.gesture:this.perf.gesture=Math.trunc(M()-r)),this.perf.total=Math.trunc(M()-_),this.state="idle";let p={face:x,body:s,hand:h,gesture:m,object:i,performance:this.perf,canvas:o.canvas};c(p)})}async warmup(t={}){let n=M();t&&(this.config=pe(this.config,t));let c=this.config.videoOptimized;this.config.videoOptimized=!1;let r;typeof createImageBitmap=="function"?r=await U(this,d1).call(this):typeof Image!="undefined"?r=await U(this,f1).call(this):r=await U(this,m1).call(this),this.config.videoOptimized=c;let A=M();return this.config.debug&&g("Warmup",this.config.warmup,Math.round(A-n),"ms",r),r}};Me=new WeakMap,Ne=new WeakMap,Oe=new WeakMap,me=new WeakMap,l1=new WeakMap,ke=new WeakMap,d1=new WeakMap,f1=new WeakMap,m1=new WeakMap;0&&(module.exports={Human}); //# sourceMappingURL=human.node.js.map diff --git a/package.json b/package.json index a367a3be..d751d913 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vladmandic/human", - "version": "1.2.5", + "version": "1.3.0", "description": "Human: AI-powered 3D Face Detection, Face Description & Recognition, Body Pose Tracking, Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction & Gesture Recognition", "sideEffects": false, "main": "dist/human.node.js",