webrtc-streamer 0.6.5 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC. All Rights Reserved.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ * =============================================================================
16
+ */
17
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@tensorflow/tfjs-core"),require("@tensorflow/tfjs-converter")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-core","@tensorflow/tfjs-converter"],e):e(t.bodyPix={},t.tf,t.tf)}(this,function(t,e,n){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function a(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}u((r=r.apply(t,e||[])).next())})}function s(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function u(t){var n=t.shape[2],r=e.argMax(t,2),o=e.reshape(r,[-1]);return e.oneHot(o,n)}function f(t,n){return e.tidy(function(){return e.cast(e.greater(t,e.scalar(n)),"int32")})}function d(t,n){var r=n.shape,o=r[0],i=r[1],a=r[2];return e.tidy(function(){var r,s,f=u(n),d=e.expandDims(e.range(0,a,1,"int32"),1),l=e.cast(e.matMul(f,d),"int32"),c=e.reshape(l,[o,i]),h=e.add(c,e.scalar(1,"int32"));return e.sub((r=h,s=t,e.mul(r,s)),e.scalar(1,"int32"))})}var l=function(){function t(t,n){this.model=t,this.outputStride=n;var r=this.model.inputs[0].shape;e.util.assert(-1===r[1]&&-1===r[2],function(){return"Input shape ["+r[1]+", "+r[2]+"] must both be equal to or -1"})}return t.prototype.predict=function(t){var n=this;return e.tidy(function(){var r=n.preprocessInput(e.cast(t,"float32")),o=e.expandDims(r,0),i=n.model.predict(o).map(function(t){return e.squeeze(t,[0])}),a=n.nameOutputResults(i);return{heatmapScores:e.sigmoid(a.heatmap),offsets:a.offsets,displacementFwd:a.displacementFwd,displacementBwd:a.displacementBwd,segmentation:a.segmentation,partHeatmaps:a.partHeatmaps,longOffsets:a.longOffsets,partOffsets:a.partOffsets}})},t.prototype.dispose=function(){this.model.dispose()},t}(),c=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return o(n,t),n.prototype.preprocessInput=function(t){return e.tidy(function(){return e.sub(e.div(t,127.5),1)})},n.prototype.nameOutputResults=function(t){return{offsets:t[0],segmentation:t[1],partHeatmaps:t[2],longOffsets:t[3],heatmap:t[4],displacementFwd:t[5],displacementBwd:t[6],partOffsets:t[7]}},n}(l),h=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],p=h.length,m=h.reduce(function(t,e,n){return t[e]=n,t},{});[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]].map(function(t){var e=t[0],n=t[1];return[m[e],m[n]]});function g(t,e,n){var r=t[0],o=t[1],i=e[0],a=e[1],s=n.top,u=n.bottom;return[a/(n.left+n.right+o),i/(s+u+r)]}function v(t,e,n,r){return{y:r.get(t,e,n),x:r.get(t,e,n+p)}}function w(t,e,n){var r=v(t.heatmapY,t.heatmapX,t.id,n),o=r.y,i=r.x;return{x:t.heatmapX*e+i,y:t.heatmapY*e+o}}function y(t,e,n){return t<e?e:t>n?n:t}function b(t,e){return{x:t.x+e.x,y:t.y+e.y}}function x(t,e,n){void 0===n&&(n=.3);for(var r=0,o=0,i=0;i<t.length;i++)e.keypoints[i].score>n&&(o+=1,r+=Math.pow(t[i].x-e.keypoints[i].position.x,2)+Math.pow(t[i].y-e.keypoints[i].position.y,2));return 0===o?r=1/0:r/=o,r}function S(t,e,n,r,o,i,a){for(var s=a[0],u=a[1],f=n(t),d=f.y*r+f.x,l=o[p*(2*d)+e],c=o[p*(2*d+1)+e],h=t.y+l,m=t.x+c,g=0;g<i;g++){h=Math.min(h,s-1);var v=n({x:m=Math.min(m,u-1),y:h}),w=v.y*r+v.x;h+=l=o[p*(2*w)+e],m+=c=o[p*(2*w+1)+e]}return{x:m,y:h}}function k(t,e,n,r,o,i,a,s,u,f){for(var d=o[0],l=o[1],c=i[0],h=i[1],p=s[0],m=s[1],g=[],v=function(t){return function(t,e,n,r){var o=e[0],i=e[1],a=n[0],s=n[1],u=Math.round(((o+t.y+1)*s-1)/r);return{x:Math.round(((i+t.x+1)*a-1)/r),y:u}}(t,[d,l],[c,h],u)},w=0;w<r;w++){var y=S(t,w,v,a,e,f,[p,m]);g.push(y)}for(var b=-1,k=1/0,M=0;M<n.length;M++){var E=x(g,n[M]);E<k&&(b=M,k=E)}return b}function M(t,e){var n=t[0],r=t[1];return[Math.round((r-1)/e+1),Math.round((n-1)/e+1)]}function E(t,n,r,o,i,a,s,u,f,d,l){for(var c=s[0],h=s[1],m=t.shape,v=m[0],w=m[1],y=n.shape.slice(0,2),b=y[0],x=y[1],S=e.reshape(n,[b,x,2,p]),k=new Float32Array(l*p*3).fill(0),M=0;M<r.length;M++)for(var E=M*p*3,_=r[M],O=0;O<p;O++){var P=_.keypoints[O],A=E+3*O;k[A]=P.score,k[A+1]=P.position.y,k[A+2]=P.position.x}var I=g([o,i],[c,h],u),R=I[0],H=I[1],T=e.tensor(k,[l,p,3]),B=u.top,F=u.left,D={variableNames:["segmentation","longOffsets","poses"],outputShape:[v,w],userCode:"\n int convertToPositionInOutput(int pos, int pad, float scale, int stride) {\n return round(((float(pos + pad) + 1.0) * scale - 1.0) / float(stride));\n }\n\n float convertToPositionInOutputFloat(\n int pos, int pad, float scale, int stride) {\n return ((float(pos + pad) + 1.0) * scale - 1.0) / float(stride);\n }\n\n float dist(float x1, float y1, float x2, float y2) {\n return pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0);\n }\n\n float sampleLongOffsets(float h, float w, int d, int k) {\n float fh = fract(h);\n float fw = fract(w);\n int clH = int(ceil(h));\n int clW = int(ceil(w));\n int flH = int(floor(h));\n int flW = int(floor(w));\n float o11 = getLongOffsets(flH, flW, d, k);\n float o12 = getLongOffsets(flH, clW, d, k);\n float o21 = getLongOffsets(clH, flW, d, k);\n float o22 = getLongOffsets(clH, clW, d, k);\n float o1 = mix(o11, o12, fw);\n float o2 = mix(o21, o22, fw);\n return mix(o1, o2, fh);\n }\n\n int findNearestPose(int h, int w) {\n float prob = getSegmentation(h, w);\n if (prob < 1.0) {\n return -1;\n }\n\n // Done(Tyler): convert from output space h/w to strided space.\n float stridedH = convertToPositionInOutputFloat(\n h, "+B+", "+H+", "+a+");\n float stridedW = convertToPositionInOutputFloat(\n w, "+F+", "+R+", "+a+");\n\n float minDist = 1000000.0;\n int iMin = -1;\n for (int i = 0; i < "+l+"; i++) {\n float curDistSum = 0.0;\n int numKpt = 0;\n for (int k = 0; k < "+p+"; k++) {\n float dy = sampleLongOffsets(stridedH, stridedW, 0, k);\n float dx = sampleLongOffsets(stridedH, stridedW, 1, k);\n\n float y = float(h) + dy;\n float x = float(w) + dx;\n\n for (int s = 0; s < "+f+"; s++) {\n int yRounded = round(min(y, float("+(o-1)+")));\n int xRounded = round(min(x, float("+(i-1)+")));\n\n float yStrided = convertToPositionInOutputFloat(\n yRounded, "+B+", "+H+", "+a+");\n float xStrided = convertToPositionInOutputFloat(\n xRounded, "+F+", "+R+", "+a+");\n\n float dy = sampleLongOffsets(yStrided, xStrided, 0, k);\n float dx = sampleLongOffsets(yStrided, xStrided, 1, k);\n\n y = y + dy;\n x = x + dx;\n }\n\n float poseScore = getPoses(i, k, 0);\n float poseY = getPoses(i, k, 1);\n float poseX = getPoses(i, k, 2);\n if (poseScore > "+d+") {\n numKpt = numKpt + 1;\n curDistSum = curDistSum + dist(x, y, poseX, poseY);\n }\n }\n if (numKpt > 0 && curDistSum / float(numKpt) < minDist) {\n minDist = curDistSum / float(numKpt);\n iMin = i;\n }\n }\n return iMin;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int nearestPose = findNearestPose(coords[0], coords[1]);\n setOutput(float(nearestPose));\n }\n "};return e.backend().compileAndRun(D,[t,S,T])}function _(){return"webgl"===e.getBackend()}function O(t,n,r,o,i,u,f,d,l,c,h,p){var m=f[0],v=f[1];return void 0===l&&(l=.2),void 0===c&&(c=8),void 0===h&&(h=.3),void 0===p&&(p=10),a(this,void 0,void 0,function(){var a,f,w,y,b;return s(this,function(s){switch(s.label){case 0:return a=r.filter(function(t){return t.score>=l}),_()?(w=e.tidy(function(){var r=E(t,n,a,o,i,u,[m,v],d,c,h,p),s=e.engine().makeTensorFromDataId(r.dataId,r.shape,r.dtype);return a.map(function(t,n){return function(t,n){return e.tidy(function(){return e.cast(e.equal(t,e.scalar(n)),"int32")})}(s,n)})}),[4,Promise.all(w.map(function(t){return t.data()}))]):[3,2];case 1:return f=s.sent(),w.forEach(function(t){return t.dispose()}),[3,5];case 2:return[4,t.data()];case 3:return y=s.sent(),[4,n.data()];case 4:b=s.sent(),f=function(t,e,n,r,o,i,a,s,u,f){var d=a[0],l=a[1];void 0===f&&(f=5);for(var c=n.map(function(t){return new Uint8Array(r*o).fill(0)}),h=s.top,p=s.left,m=g([r,o],[d,l],s),v=m[0],w=m[1],y=M([d,l],i)[0],b=0;b<r;b+=1)for(var x=0;x<o;x+=1){var S=b*o+x;if(1===t[S]){var E=k({x:x,y:b},e,n,f,[h,p],[v,w],y,[r,o],i,u);E>=0&&(c[E][S]=1)}}return c}(y,b,a,o,i,u,[m,v],d,c),s.label=5;case 5:return[2,f.map(function(t,e){return{data:t,pose:a[e],width:i,height:o}})]}})})}function P(t,n,r,o,i,u,f,d,l,c,h,p,m){var v=d[0],w=d[1];return void 0===c&&(c=.2),void 0===h&&(h=8),void 0===p&&(p=.3),void 0===m&&(m=10),a(this,void 0,void 0,function(){var a,d,y,b,x,S;return s(this,function(s){switch(s.label){case 0:return a=o.filter(function(t){return t.score>=c}),_()?(y=e.tidy(function(){var o=E(t,n,a,i,u,f,[v,w],l,h,p,m),s=e.engine().makeTensorFromDataId(o.dataId,o.shape,o.dtype);return a.map(function(t,n){return function(t,n,r){return e.tidy(function(){return e.sub(e.mul(e.cast(e.equal(t,e.scalar(r)),"int32"),e.add(n,1)),1)})}(s,r,n)})}),[4,Promise.all(y.map(function(t){return t.data()}))]):[3,2];case 1:return d=s.sent(),y.forEach(function(t){return t.dispose()}),[3,6];case 2:return[4,t.data()];case 3:return b=s.sent(),[4,n.data()];case 4:return x=s.sent(),[4,r.data()];case 5:S=s.sent(),d=function(t,e,n,r,o,i,a,s,u,f,d){var l=s[0],c=s[1];void 0===d&&(d=5);for(var h=r.map(function(t){return new Int32Array(o*i).fill(-1)}),p=u.top,m=u.left,v=g([o,i],[l,c],u),w=v[0],y=v[1],b=M([l,c],a)[0],x=0;x<o;x+=1)for(var S=0;S<i;S+=1){var E=x*i+S;if(1===t[E]){var _=k({x:S,y:x},e,r,d,[p,m],[w,y],b,[o,i],a,f);_>=0&&(h[_][E]=n[E])}}return h}(b,x,S,a,i,u,f,[v,w],l,h),s.label=6;case 6:return[2,d.map(function(t,e){return{pose:a[e],data:t,height:i,width:u}})]}})})}function A(t){return Math.floor(t/2)}var I=function(){function t(t,e){this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=e}return t.prototype.enqueue=function(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)},t.prototype.dequeue=function(){var t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t},t.prototype.empty=function(){return-1===this.numberOfElements},t.prototype.size=function(){return this.numberOfElements+1},t.prototype.all=function(){return this.priorityQueue.slice(0,this.numberOfElements+1)},t.prototype.max=function(){return this.priorityQueue[0]},t.prototype.swim=function(t){for(;t>0&&this.less(A(t),t);)this.exchange(t,A(t)),t=A(t)},t.prototype.sink=function(t){for(;2*t<=this.numberOfElements;){var e=2*t;if(e<this.numberOfElements&&this.less(e,e+1)&&e++,!this.less(t,e))break;this.exchange(t,e),t=e}},t.prototype.getValueAt=function(t){return this.getElementValue(this.priorityQueue[t])},t.prototype.less=function(t,e){return this.getValueAt(t)<this.getValueAt(e)},t.prototype.exchange=function(t,e){var n=this.priorityQueue[t];this.priorityQueue[t]=this.priorityQueue[e],this.priorityQueue[e]=n},t}();function R(t,e,n,r,o,i){for(var a=i.shape,s=a[0],u=a[1],f=!0,d=Math.max(n-o,0),l=Math.min(n+o+1,s),c=d;c<l;++c){for(var h=Math.max(r-o,0),p=Math.min(r+o+1,u),m=h;m<p;++m)if(i.get(c,m,t)>e){f=!1;break}if(!f)break}return f}var H=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]].map(function(t){var e=t[0],n=t[1];return[m[e],m[n]]}),T=H.map(function(t){return t[1]}),B=H.map(function(t){return t[0]});function F(t,e,n,r){return{y:y(Math.round(t.y/e),0,n-1),x:y(Math.round(t.x/e),0,r-1)}}function D(t,e,n,r,o,i,a,s){void 0===s&&(s=2);for(var u=r.shape,f=u[0],d=u[1],l=function(t,e,n){var r=n.shape[2]/2;return{y:n.get(e.y,e.x,t),x:n.get(e.y,e.x,r+t)}}(t,F(e.position,i,f,d),a),c=b(e.position,l),p=0;p<s;p++){var m=F(c,i,f,d),g=v(m.y,m.x,n,o);c=b({x:m.x*i,y:m.y*i},{x:g.x,y:g.y})}var w=F(c,i,f,d),y=r.get(w.y,w.x,n);return{position:c,part:h[n],score:y}}function C(t,e,n,r,o,i){var a=e.shape[2],s=T.length,u=new Array(a),f=t.part,d=t.score,l=w(f,r,n);u[f.id]={score:d,part:h[f.id],position:l};for(var c=s-1;c>=0;--c){var p=T[c],m=B[c];u[p]&&!u[m]&&(u[m]=D(c,u[p],m,e,n,r,i))}for(c=0;c<s;++c){p=B[c],m=T[c];u[p]&&!u[m]&&(u[m]=D(c,u[p],m,e,n,r,o))}return u}function L(t,e,n,r){var o=n.x,i=n.y;return t.some(function(t){var n,a,s,u,f,d,l=t.keypoints[r].position;return n=i,a=o,s=l.y,u=l.x,(f=s-n)*f+(d=u-a)*d<=e})}function q(t,e,n){return n.reduce(function(n,r,o){var i=r.position,a=r.score;return L(t,e,i,o)||(n+=a),n},0)/n.length}var W=1;function z(t,e,n,r,o,i,a,s){void 0===a&&(a=.5),void 0===s&&(s=20);for(var u=[],f=function(t,e,n){for(var r=n.shape,o=r[0],i=r[1],a=r[2],s=new I(o*i*a,function(t){return t.score}),u=0;u<o;++u)for(var f=0;f<i;++f)for(var d=0;d<a;++d){var l=n.get(u,f,d);l<t||R(d,l,u,f,e,n)&&s.enqueue({score:l,part:{heatmapY:u,heatmapX:f,id:d}})}return s}(a,W,t),d=s*s;u.length<i&&!f.empty();){var l=f.dequeue();if(!L(u,d,w(l.part,o,e),l.part.id)){var c=C(l,t,e,o,n,r),h=q(u,d,c);u.push({keypoints:c,score:h})}}return u}var K,j=[-123.15,-115.9,-103.06],N=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return o(n,t),n.prototype.preprocessInput=function(t){return e.add(t,j)},n.prototype.nameOutputResults=function(t){var e=t[0],n=t[1],r=t[2],o=t[3],i=t[4],a=t[5];return{offsets:i,segmentation:t[6],partHeatmaps:a,longOffsets:o,heatmap:r,displacementFwd:n,displacementBwd:e,partOffsets:t[7]}},n}(l),V="https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/",Q="https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/";function U(t){if("undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas||"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement)return function(t){if("offsetHeight"in t&&0!==t.offsetHeight&&"offsetWidth"in t&&0!==t.offsetWidth)return[t.offsetHeight,t.offsetWidth];if(null!=t.height&&null!=t.width)return[t.height,t.width];throw new Error("HTMLImageElement must have height and width attributes set.")}(t);if("undefined"!=typeof ImageData&&t instanceof ImageData)return[t.height,t.width];if("undefined"!=typeof HTMLVideoElement&&t instanceof HTMLVideoElement)return function(t){return t.hasAttribute("height")&&t.hasAttribute("width")?[t.height,t.width]:[t.videoHeight,t.videoWidth]}(t);if(t instanceof e.Tensor)return[t.shape[0],t.shape[1]];throw new Error("error: Unknown input type: "+t+".")}function X(t,e){return function(t,e){return(t-1)%e==0}(t,e)?t:Math.floor(t/e)*e+1}var Y={low:"low",medium:"medium",high:"high",full:"full"},G=((K={})[Y.low]=.25,K[Y.medium]=.5,K[Y.high]=.75,K[Y.full]=1,K),J=.1,Z=2;function $(t,n,r){var o=r[0],i=r[1],a=function(t){if("string"==typeof t){var n=G[t];return e.util.assert("number"==typeof n,function(){return"string value of inputResolution must be one of "+Object.values(Y).join(",")+" but was "+t+"."}),n}return e.util.assert("number"==typeof t&&t<=Z&&t>=J,function(){return"inputResolution must be a string or number between "+J+" and "+Z+", but was "+t}),t}(t);return[X(o*a,n),X(i*a,n)]}function tt(t,n,r,o,i){var a=n[0],s=n[1],u=r[0],f=r[1],d=o[0],l=d[0],c=d[1],h=o[1],p=h[0],m=h[1];return void 0===i&&(i=!1),e.tidy(function(){var n=e.image.resizeBilinear(t,[u,f],!0);return i&&(n=e.sigmoid(n)),function(t,n,r){var o=n[0],i=n[1],a=r[0],s=a[0],u=a[1],f=r[1],d=f[0],l=f[1];return e.tidy(function(){var n=e.expandDims(t);return e.squeeze(e.image.cropAndResize(n,[[s/(o+s+u-1),d/(i+d+l-1),(s+o-1)/(o+s+u-1),(d+i-1)/(i+d+l-1)]],[0],[o,i]),[0])})}(n,[a,s],[[l,c],[p,m]])})}function et(t,n){var r=n[0],o=n[1],i=U(t),a=i[0],s=i[1],u=o/r,f=[0,0,0,0],d=f[0],l=f[1],c=f[2],h=f[3];return s/a<u?(d=0,l=0,c=Math.round(.5*(u*a-s)),h=Math.round(.5*(u*a-s))):(d=Math.round(.5*(1/u*s-a)),l=Math.round(.5*(1/u*s-a)),c=0,h=0),{resized:e.tidy(function(){var n=function(t){return t instanceof e.Tensor?t:e.browser.fromPixels(t)}(t);return n=e.pad3d(n,[[d,l],[c,h],[0,0]]),e.image.resizeBilinear(n,[r,o])}),padding:{top:d,left:c,right:h,bottom:l}}}function nt(t){return a(this,void 0,void 0,function(){return s(this,function(e){return[2,Promise.all(t.map(function(t){return t.buffer()}))]})})}function rt(t,e){return{score:t.score,keypoints:t.keypoints.map(function(t){var n=t.score,r=t.part,o=t.position;return{score:n,part:r,position:{x:e-1-o.x,y:o.y}}})}}function ot(t,e,n,r,o){var i=e[0],a=e[1],s=n[0],u=n[1],f=function(t,e,n,r,o){return void 0===r&&(r=0),void 0===o&&(o=0),1===n&&1===e&&0===r&&0===o?t:t.map(function(t){return function(t,e,n,r,o){return void 0===r&&(r=0),void 0===o&&(o=0),{score:t.score,keypoints:t.keypoints.map(function(t){var i=t.score,a=t.part,s=t.position;return{score:i,part:a,position:{x:s.x*n+o,y:s.y*e+r}}})}}(t,e,n,r,o)})}(t,(i+r.top+r.bottom)/s,(a+r.left+r.right)/u,-r.top,-r.left);return o?function(t,e){return e<=0?t:t.map(function(t){return rt(t,e)})}(f,a):f}var it={architecture:"MobileNetV1",outputStride:16,quantBytes:4,multiplier:.75},at=["MobileNetV1","ResNet50"],st={MobileNetV1:[8,16,32],ResNet50:[32,16]},ut={MobileNetV1:[.5,.75,1],ResNet50:[1]},ft=[1,2,4];var dt={flipHorizontal:!1,internalResolution:"medium",segmentationThreshold:.7,maxDetections:10,scoreThreshold:.4,nmsRadius:20},lt={flipHorizontal:!1,internalResolution:"medium",segmentationThreshold:.7,maxDetections:10,scoreThreshold:.4,nmsRadius:20,minKeypointScore:.3,refineSteps:10};function ct(t){var e=t.segmentationThreshold,n=t.maxDetections,r=t.scoreThreshold,o=t.nmsRadius;if(e<0||e>1)throw new Error("segmentationThreshold "+e+". Should be in range [0.0, 1.0]");if(n<=0)throw new Error("Invalid maxDetections "+n+". Should be > 0");if(r<0||r>1)throw new Error("Invalid scoreThreshold "+r+". Should be in range [0.0, 1.0]");if(o<=0)throw new Error("Invalid nmsRadius "+o+".")}function ht(t){var e=t.segmentationThreshold,n=t.maxDetections,r=t.scoreThreshold,o=t.nmsRadius,i=t.minKeypointScore,a=t.refineSteps;if(e<0||e>1)throw new Error("segmentationThreshold "+e+". Should be in range [0.0, 1.0]");if(n<=0)throw new Error("Invalid maxDetections "+n+". Should be > 0");if(r<0||r>1)throw new Error("Invalid scoreThreshold "+r+". Should be in range [0.0, 1.0]");if(o<=0)throw new Error("Invalid nmsRadius "+o+".");if(i<0||i>1)throw new Error("Invalid minKeypointScore "+i+".Should be in range [0.0, 1.0]");if(a<=0||a>20)throw new Error("Invalid refineSteps "+a+".Should be in range [1, 20]")}var pt=function(){function t(t){this.baseModel=t}return t.prototype.predictForPersonSegmentation=function(t){var e=this.baseModel.predict(t);return{segmentLogits:e.segmentation,heatmapScores:e.heatmapScores,offsets:e.offsets,displacementFwd:e.displacementFwd,displacementBwd:e.displacementBwd}},t.prototype.predictForPersonSegmentationAndPart=function(t){var e=this.baseModel.predict(t);return{segmentLogits:e.segmentation,partHeatmapLogits:e.partHeatmaps,heatmapScores:e.heatmapScores,offsets:e.offsets,displacementFwd:e.displacementFwd,displacementBwd:e.displacementBwd}},t.prototype.predictForMultiPersonInstanceSegmentationAndPart=function(t){var e=this.baseModel.predict(t);return{segmentLogits:e.segmentation,longOffsets:e.longOffsets,heatmapScores:e.heatmapScores,offsets:e.offsets,displacementFwd:e.displacementFwd,displacementBwd:e.displacementBwd,partHeatmaps:e.partHeatmaps}},t.prototype.segmentPersonActivation=function(t,n,r){var o=this;void 0===r&&(r=.5);var i=U(t),a=i[0],s=i[1],u=$(n,this.baseModel.outputStride,[a,s]),d=et(t,u),l=d.resized,c=d.padding,h=e.tidy(function(){var t=o.predictForPersonSegmentation(l),n=t.segmentLogits,i=t.heatmapScores,u=t.offsets,d=t.displacementFwd,h=t.displacementBwd,p=l.shape,m=p[0],g=p[1],v=tt(n,[a,s],[m,g],[[c.top,c.bottom],[c.left,c.right]],!0);return{segmentation:f(e.squeeze(v),r),heatmapScores:i,offsets:u,displacementFwd:d,displacementBwd:h}}),p=h.segmentation,m=h.heatmapScores,g=h.offsets,v=h.displacementFwd,w=h.displacementBwd;return l.dispose(),{segmentation:p,heatmapScores:m,offsets:g,displacementFwd:v,displacementBwd:w,padding:c,internalResolutionHeightAndWidth:u}},t.prototype.segmentPerson=function(t,e){return void 0===e&&(e=dt),a(this,void 0,void 0,function(){var n,r,o,a,u,f,d,l,c,h,p,m,g,v,w,y,b,x;return s(this,function(s){switch(s.label){case 0:return ct(e=i(i({},dt),e)),n=this.segmentPersonActivation(t,e.internalResolution,e.segmentationThreshold),r=n.segmentation,o=n.heatmapScores,a=n.offsets,u=n.displacementFwd,f=n.displacementBwd,d=n.padding,l=n.internalResolutionHeightAndWidth,c=r.shape,h=c[0],p=c[1],[4,r.data()];case 1:return m=s.sent(),r.dispose(),[4,nt([o,a,u,f])];case 2:return g=s.sent(),v=g[0],w=g[1],y=g[2],b=g[3],x=ot(x=z(v,w,y,b,this.baseModel.outputStride,e.maxDetections,e.scoreThreshold,e.nmsRadius),[h,p],l,d,!1),o.dispose(),a.dispose(),u.dispose(),f.dispose(),[2,{height:h,width:p,data:m,allPoses:x}]}})})},t.prototype.segmentMultiPerson=function(t,n){return void 0===n&&(n=lt),a(this,void 0,void 0,function(){var r,o,a,u,d,l,c,h,p,m,g,v,w,y,b,x,S,k,M,E,_,P=this;return s(this,function(s){switch(s.label){case 0:return ht(n=i(i({},lt),n)),r=U(t),o=r[0],a=r[1],u=$(n.internalResolution,this.baseModel.outputStride,[o,a]),d=et(t,u),l=d.resized,c=d.padding,h=e.tidy(function(){var t,r=P.predictForMultiPersonInstanceSegmentationAndPart(l),i=r.segmentLogits,s=r.longOffsets,d=r.heatmapScores,h=r.offsets,p=r.displacementFwd,m=r.displacementBwd,g=tt(i,[o,a],u,[[c.top,c.bottom],[c.left,c.right]],!0);return t=s,{segmentation:f(e.squeeze(g),n.segmentationThreshold),longOffsets:t,heatmapScoresRaw:d,offsetsRaw:h,displacementFwdRaw:p,displacementBwdRaw:m}}),p=h.segmentation,m=h.longOffsets,g=h.heatmapScoresRaw,v=h.offsetsRaw,w=h.displacementFwdRaw,y=h.displacementBwdRaw,[4,nt([g,v,w,y])];case 1:return b=s.sent(),x=b[0],S=b[1],k=b[2],M=b[3],E=ot(E=z(x,S,k,M,this.baseModel.outputStride,n.maxDetections,n.scoreThreshold,n.nmsRadius),[o,a],u,c,!1),[4,O(p,m,E,o,a,this.baseModel.outputStride,u,c,n.scoreThreshold,n.refineSteps,n.minKeypointScore,n.maxDetections)];case 2:return _=s.sent(),l.dispose(),p.dispose(),m.dispose(),g.dispose(),v.dispose(),w.dispose(),y.dispose(),[2,_]}})})},t.prototype.segmentPersonPartsActivation=function(t,n,r){var o=this;void 0===r&&(r=.5);var i=U(t),a=i[0],s=i[1],u=$(n,this.baseModel.outputStride,[a,s]),l=et(t,u),c=l.resized,h=l.padding,p=e.tidy(function(){var t=o.predictForPersonSegmentationAndPart(c),n=t.segmentLogits,i=t.partHeatmapLogits,u=t.heatmapScores,l=t.offsets,p=t.displacementFwd,m=t.displacementBwd,g=c.shape,v=g[0],w=g[1],y=tt(n,[a,s],[v,w],[[h.top,h.bottom],[h.left,h.right]],!0),b=tt(i,[a,s],[v,w],[[h.top,h.bottom],[h.left,h.right]],!0);return{partSegmentation:d(f(e.squeeze(y),r),b),heatmapScores:u,offsets:l,displacementFwd:p,displacementBwd:m}}),m=p.partSegmentation,g=p.heatmapScores,v=p.offsets,w=p.displacementFwd,y=p.displacementBwd;return c.dispose(),{partSegmentation:m,heatmapScores:g,offsets:v,displacementFwd:w,displacementBwd:y,padding:h,internalResolutionHeightAndWidth:u}},t.prototype.segmentPersonParts=function(t,e){return void 0===e&&(e=dt),a(this,void 0,void 0,function(){var n,r,o,a,u,f,d,l,c,h,p,m,g,v,w,y,b,x;return s(this,function(s){switch(s.label){case 0:return ct(e=i(i({},dt),e)),n=this.segmentPersonPartsActivation(t,e.internalResolution,e.segmentationThreshold),r=n.partSegmentation,o=n.heatmapScores,a=n.offsets,u=n.displacementFwd,f=n.displacementBwd,d=n.padding,l=n.internalResolutionHeightAndWidth,c=r.shape,h=c[0],p=c[1],[4,r.data()];case 1:return m=s.sent(),r.dispose(),[4,nt([o,a,u,f])];case 2:return g=s.sent(),v=g[0],w=g[1],y=g[2],b=g[3],x=ot(x=z(v,w,y,b,this.baseModel.outputStride,e.maxDetections,e.scoreThreshold,e.nmsRadius),[h,p],l,d,!1),o.dispose(),a.dispose(),u.dispose(),f.dispose(),[2,{height:h,width:p,data:m,allPoses:x}]}})})},t.prototype.segmentMultiPersonParts=function(t,n){return void 0===n&&(n=lt),a(this,void 0,void 0,function(){var r,o,a,d,l,c,h,p,m,g,v,w,y,b,x,S,k,M,E,_,O,A,I=this;return s(this,function(s){switch(s.label){case 0:return ht(n=i(i({},lt),n)),r=U(t),o=r[0],a=r[1],d=$(n.internalResolution,this.baseModel.outputStride,[o,a]),l=et(t,d),c=l.resized,h=l.padding,p=e.tidy(function(){var t=I.predictForMultiPersonInstanceSegmentationAndPart(c),r=t.segmentLogits,i=t.longOffsets,s=t.heatmapScores,l=t.offsets,p=t.displacementFwd,m=t.displacementBwd,g=t.partHeatmaps,v=tt(r,[o,a],d,[[h.top,h.bottom],[h.left,h.right]],!0),w=tt(g,[o,a],d,[[h.top,h.bottom],[h.left,h.right]],!0),y=i;return{segmentation:f(e.squeeze(v),n.segmentationThreshold),longOffsets:y,heatmapScoresRaw:s,offsetsRaw:l,displacementFwdRaw:p,displacementBwdRaw:m,partSegmentation:function(t){var n=t.shape,r=n[0],o=n[1],i=n[2];return e.tidy(function(){var n=u(t),a=e.expandDims(e.range(0,i,1,"int32"),1),s=e.cast(e.matMul(n,a),"int32");return e.reshape(s,[r,o])})}(w)}}),m=p.segmentation,g=p.longOffsets,v=p.heatmapScoresRaw,w=p.offsetsRaw,y=p.displacementFwdRaw,b=p.displacementBwdRaw,x=p.partSegmentation,[4,nt([v,w,y,b])];case 1:return S=s.sent(),k=S[0],M=S[1],E=S[2],_=S[3],O=ot(O=z(k,M,E,_,this.baseModel.outputStride,n.maxDetections,n.scoreThreshold,n.nmsRadius),[o,a],d,h,!1),[4,P(m,g,x,O,o,a,this.baseModel.outputStride,d,h,n.scoreThreshold,n.refineSteps,n.minKeypointScore,n.maxDetections)];case 2:return A=s.sent(),c.dispose(),m.dispose(),g.dispose(),v.dispose(),w.dispose(),y.dispose(),b.dispose(),x.dispose(),[2,A]}})})},t.prototype.dispose=function(){this.baseModel.dispose()},t}();function mt(t){return a(this,void 0,void 0,function(){var r,o,i,a,u,f;return s(this,function(s){switch(s.label){case 0:if(r=t.outputStride,o=t.quantBytes,i=t.multiplier,null==e)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return a=function(t,e,n){var r={1:"100",.75:"075",.5:"050"},o="model-stride"+t+".json";return 4===n?Q+"float/"+r[e]+"/"+o:Q+"quant"+n+"/"+r[e]+"/"+o}(r,i,o),[4,n.loadGraphModel(t.modelUrl||a)];case 1:return u=s.sent(),f=new c(u,r),[2,new pt(f)]}})})}function gt(t){return a(this,void 0,void 0,function(){var r,o,i,a,u;return s(this,function(s){switch(s.label){case 0:if(r=t.outputStride,o=t.quantBytes,null==e)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return i=function(t,e){var n="model-stride"+t+".json";return 4===e?V+"float/"+n:V+"quant"+e+"/"+n}(r,o),[4,n.loadGraphModel(t.modelUrl||i)];case 1:return a=s.sent(),u=new N(a,r),[2,new pt(u)]}})})}var vt={};function wt(t,e,n,r){var o=t.width,i=t.height,a=e.width,s=e.height;if(o!==a||i!==s)throw new Error("error: dimensions must match. "+n+" has dimensions "+o+"x"+i+", "+r+" has dimensions "+a+"x"+s)}function yt(t){var e=t.getContext("2d");e.scale(-1,1),e.translate(-t.width,0)}function bt(t,e,n){t.globalCompositeOperation=n,t.drawImage(e,0,0)}function xt(t){return vt[t]||(vt[t]=function(){if("undefined"!=typeof document)return document.createElement("canvas");if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(0,0);throw new Error("Cannot create a canvas in this context")}()),vt[t]}function St(t,e,n){var r=t.height,o=t.width,i=n.getContext("2d");n.width=o,n.height=r,i.clearRect(0,0,o,r),i.save(),/^((?!chrome|android).)*safari/i.test(navigator.userAgent)?function(t,e,n){for(var r=t.getContext("2d"),o=0,i=1/(2*Math.PI*5*5),a=n<3?1:2,s=-n;s<=n;s+=a)for(var u=-n;u<=n;u+=a)o+=i*Math.exp(-(u*u+s*s)/50);for(s=-n;s<=n;s+=a)for(u=-n;u<=n;u+=a)r.globalAlpha=i*Math.exp(-(u*u+s*s)/50)/o*n,r.drawImage(e,u,s);r.globalAlpha=1}(n,t,e):(i.filter="blur("+e+"px)",i.drawImage(t,0,0,o,r)),i.restore()}function kt(t,e,n){var r=xt(n);return 0===e?function(t,e){var n=t.width,r=t.height;e.width=n,e.height=r,e.getContext("2d").drawImage(t,0,0,n,r)}(t,r):St(t,e,r),r}function Mt(t,e){var n=xt(e);return function(t,e){e.width=t.width,e.height=t.height,e.getContext("2d").putImageData(t,0,0)}(t,n),n}function Et(t,e,n,r,o){if(void 0===e&&(e={r:0,g:0,b:0,a:0}),void 0===n&&(n={r:0,g:0,b:0,a:255}),void 0===r&&(r=!1),void 0===o&&(o=[1]),Array.isArray(t)&&0===t.length)return null;var i,a=(i=Array.isArray(t)?t:[t])[0],s=a.width,u=a.height,f=new Uint8ClampedArray(s*u*4);function d(t,e,n,r,o,i){void 0===i&&(i={r:0,g:255,b:255,a:255});for(var a=-o;a<=o;a++)for(var s=-o;s<=o;s++)if(0!==a&&0!==s){var u=(e+a)*r+(n+s);t[4*u+0]=i.r,t[4*u+1]=i.g,t[4*u+2]=i.b,t[4*u+3]=i.a}}function l(t,e,n,r,o,i){void 0===o&&(o=[1]),void 0===i&&(i=1);for(var a=0,s=-i;s<=i;s++)for(var u=function(i){if(0!==s&&0!==i){var u=(e+s)*r+(n+i);o.some(function(e){return e===t[u]})||(a+=1)}},f=-i;f<=i;f++)u(f);return a>0}for(var c=0;c<u;c+=1)for(var h=function(t){var a=c*s+t;f[4*a+0]=n.r,f[4*a+1]=n.g,f[4*a+2]=n.b,f[4*a+3]=n.a;for(var h=function(n){if(o.some(function(t){return t===i[n].data[a]})){f[4*a]=e.r,f[4*a+1]=e.g,f[4*a+2]=e.b,f[4*a+3]=e.a;var h=l(i[n].data,c,t,s,o);r&&c-1>=0&&c+1<u&&t-1>=0&&t+1<s&&h&&d(f,c,t,s,1)}},p=0;p<i.length;p++)h(p)},p=0;p<s;p+=1)h(p);return new ImageData(f,s,u)}var _t=[[110,64,170],[143,61,178],[178,60,178],[210,62,167],[238,67,149],[255,78,125],[255,94,99],[255,115,75],[255,140,56],[239,167,47],[217,194,49],[194,219,64],[175,240,91],[135,245,87],[96,247,96],[64,243,115],[40,234,141],[28,219,169],[26,199,194],[33,176,213],[47,150,224],[65,125,224],[84,101,214],[99,81,195]];var Ot={blurred:"blurred",blurredMask:"blurred-mask",mask:"mask",lowresPartMask:"lowres-part-mask"};t.BodyPix=pt,t.load=function(t){return void 0===t&&(t=it),a(this,void 0,void 0,function(){return s(this,function(e){return"ResNet50"===(t=function(t){if(null==(t=t||it).architecture&&(t.architecture="MobileNetV1"),at.indexOf(t.architecture)<0)throw new Error("Invalid architecture "+t.architecture+". Should be one of "+at);if(null==t.outputStride&&(t.outputStride=16),st[t.architecture].indexOf(t.outputStride)<0)throw new Error("Invalid outputStride "+t.outputStride+". Should be one of "+st[t.architecture]+" for architecture "+t.architecture+".");if(null==t.multiplier&&(t.multiplier=1),ut[t.architecture].indexOf(t.multiplier)<0)throw new Error("Invalid multiplier "+t.multiplier+". Should be one of "+ut[t.architecture]+" for architecture "+t.architecture+".");if(null==t.quantBytes&&(t.quantBytes=4),ft.indexOf(t.quantBytes)<0)throw new Error("Invalid quantBytes "+t.quantBytes+". Should be one of "+ft+" for architecture "+t.architecture+".");return t}(t)).architecture?[2,gt(t)]:"MobileNetV1"===t.architecture?[2,mt(t)]:[2,null]})})},t.blurBodyPart=function(t,e,n,r,o,i,a){void 0===r&&(r=[0,1]),void 0===o&&(o=3),void 0===i&&(i=3),void 0===a&&(a=!1);var s=kt(e,o,Ot.blurred);t.width=s.width,t.height=s.height;var u=t.getContext("2d");if(Array.isArray(n)&&0===n.length)u.drawImage(s,0,0);else{var f=function(t,e,n){var r=Mt(Et(t,{r:0,g:0,b:0,a:0},{r:0,g:0,b:0,a:255},!0,e),Ot.mask);return 0===n?r:kt(r,n,Ot.blurredMask)}(n,r,i);u.save(),a&&yt(t);var d=U(e),l=d[0],c=d[1];u.drawImage(e,0,0,c,l),bt(u,f,"destination-in"),bt(u,s,"destination-over"),u.restore()}},t.drawBokehEffect=function(t,e,n,r,o,i){void 0===r&&(r=3),void 0===o&&(o=3),void 0===i&&(i=!1);var a=kt(e,r,Ot.blurred);t.width=a.width,t.height=a.height;var s=t.getContext("2d");if(Array.isArray(n)&&0===n.length)s.drawImage(a,0,0);else{var u=function(t,e){var n=Mt(Et(t,{r:0,g:0,b:0,a:255},{r:0,g:0,b:0,a:0}),Ot.mask);return 0===e?n:kt(n,e,Ot.blurredMask)}(n,o);s.save(),i&&yt(t);var f=U(e),d=f[0],l=f[1];s.drawImage(e,0,0,l,d),bt(s,u,"destination-in"),bt(s,a,"destination-over"),s.restore()}},t.drawMask=function(t,e,n,r,o,i){void 0===r&&(r=.7),void 0===o&&(o=0),void 0===i&&(i=!1);var a=U(e),s=a[0],u=a[1];t.width=u,t.height=s;var f=t.getContext("2d");if(f.save(),i&&yt(t),f.drawImage(e,0,0),f.globalAlpha=r,n){wt({width:u,height:s},n,"image","mask");var d=kt(Mt(n,Ot.mask),o,Ot.blurredMask);f.drawImage(d,0,0,u,s)}f.restore()},t.drawPixelatedMask=function(t,e,n,r,o,i,a){void 0===r&&(r=.7),void 0===o&&(o=0),void 0===i&&(i=!1),void 0===a&&(a=10);var s=U(e),u=s[0];wt({width:s[1],height:u},n,"image","mask");var f=kt(Mt(n,Ot.mask),o,Ot.blurredMask);t.width=f.width,t.height=f.height;var d=t.getContext("2d");d.save(),i&&yt(t);var l=xt(Ot.lowresPartMask),c=l.getContext("2d");l.width=f.width*(1/a),l.height=f.height*(1/a),c.drawImage(f,0,0,f.width,f.height,0,0,l.width,l.height),d.imageSmoothingEnabled=!1,d.drawImage(l,0,0,l.width,l.height,0,0,t.width,t.height);for(var h=0;h<l.width;h++)d.beginPath(),d.strokeStyle="#ffffff",d.moveTo(a*h,0),d.lineTo(a*h,t.height),d.stroke();for(h=0;h<l.height;h++)d.beginPath(),d.strokeStyle="#ffffff",d.moveTo(0,a*h),d.lineTo(t.width,a*h),d.stroke();d.globalAlpha=1-r,d.drawImage(e,0,0,f.width,f.height),d.restore()},t.toColoredPartMask=function(t,e){if(void 0===e&&(e=_t),Array.isArray(t)&&0===t.length)return null;for(var n,r=(n=Array.isArray(t)?t:[t])[0],o=r.width,i=r.height,a=new Uint8ClampedArray(o*i*4),s=0;s<i*o;++s){var u=4*s;a[u+0]=255,a[u+1]=255,a[u+2]=255,a[u+3]=255;for(var f=0;f<n.length;f++){var d=n[f].data[s];if(-1!==d){var l=e[d];if(!l)throw new Error("No color could be found for part id "+d);a[u+0]=l[0],a[u+1]=l[1],a[u+2]=l[2],a[u+3]=255}}}return new ImageData(a,o,i)},t.toMask=Et,t.PART_CHANNELS=["left_face","right_face","left_upper_arm_front","left_upper_arm_back","right_upper_arm_front","right_upper_arm_back","left_lower_arm_front","left_lower_arm_back","right_lower_arm_front","right_lower_arm_back","left_hand","right_hand","torso_front","torso_back","left_upper_leg_front","left_upper_leg_back","right_upper_leg_front","right_upper_leg_back","left_lower_leg_front","left_lower_leg_back","right_lower_leg_front","right_lower_leg_back","left_feet","right_feet"],t.flipPoseHorizontal=rt,t.resizeAndPadTo=function(t,n,r){var o=n[0],i=n[1];void 0===r&&(r=!1);var a,s,u,f,d,l,c=t.shape,h=c[0],p=c[1]/h;if(p>i/o){a=i;var m=o-(s=Math.ceil(a/p));u=0,f=0,d=Math.floor(m/2),l=o-(s+d)}else{s=o;var g=i-(a=Math.ceil(o*p));u=Math.floor(g/2),f=i-(a+u),d=0,l=0}return{resizedAndPadded:e.tidy(function(){var n;return n=r?e.image.resizeBilinear(e.reverse(t,1),[s,a]):e.image.resizeBilinear(t,[s,a]),e.pad3d(n,[[d,l],[u,f],[0,0]])}),paddedBy:[[d,l],[u,f]]}},t.scaleAndCropToInputTensorShape=tt,t.version="2.2.0",Object.defineProperty(t,"__esModule",{value:!0})});
18
+ //# sourceMappingURL=body-pix.min.js.map
@@ -1,17 +1,18 @@
1
1
  /**
2
- * @license
3
- * Copyright 2019 Google LLC. All Rights Reserved.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- * =============================================================================
16
- */
17
- !function(e,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports,require("@tensorflow/tfjs-converter"),require("@tensorflow/tfjs-core")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-converter","@tensorflow/tfjs-core"],a):a(e.cocoSsd={},e.tf,e.tf)}(this,function(e,a,i){"use strict";function n(e,a,i,n){return new(i||(i=Promise))(function(t,m){function d(e){try{r(n.next(e))}catch(e){m(e)}}function s(e){try{r(n.throw(e))}catch(e){m(e)}}function r(e){e.done?t(e.value):new i(function(a){a(e.value)}).then(d,s)}r((n=n.apply(e,a||[])).next())})}function t(e,a){var i,n,t,m,d={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return m={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(m[Symbol.iterator]=function(){return this}),m;function s(m){return function(s){return function(m){if(i)throw new TypeError("Generator is already executing.");for(;d;)try{if(i=1,n&&(t=2&m[0]?n.return:m[0]?n.throw||((t=n.return)&&t.call(n),0):n.next)&&!(t=t.call(n,m[1])).done)return t;switch(n=0,t&&(m=[2&m[0],t.value]),m[0]){case 0:case 1:t=m;break;case 4:return d.label++,{value:m[1],done:!1};case 5:d.label++,n=m[1],m=[0];continue;case 7:m=d.ops.pop(),d.trys.pop();continue;default:if(!(t=(t=d.trys).length>0&&t[t.length-1])&&(6===m[0]||2===m[0])){d=0;continue}if(3===m[0]&&(!t||m[1]>t[0]&&m[1]<t[3])){d.label=m[1];break}if(6===m[0]&&d.label<t[1]){d.label=t[1],t=m;break}if(t&&d.label<t[2]){d.label=t[2],d.ops.push(m);break}t[2]&&d.ops.pop(),d.trys.pop();continue}m=a.call(e,d)}catch(e){m=[6,e],n=0}finally{i=t=0}if(5&m[0])throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}([m,s])}}}var m={1:{name:"/m/01g317",id:1,displayName:"person"},2:{name:"/m/0199g",id:2,displayName:"bicycle"},3:{name:"/m/0k4j",id:3,displayName:"car"},4:{name:"/m/04_sv",id:4,displayName:"motorcycle"},5:{name:"/m/05czz6l",id:5,displayName:"airplane"},6:{name:"/m/01bjv",id:6,displayName:"bus"},7:{name:"/m/07jdr",id:7,displayName:"train"},8:{name:"/m/07r04",id:8,displayName:"truck"},9:{name:"/m/019jd",id:9,displayName:"boat"},10:{name:"/m/015qff",id:10,displayName:"traffic light"},11:{name:"/m/01pns0",id:11,displayName:"fire hydrant"},13:{name:"/m/02pv19",id:13,displayName:"stop sign"},14:{name:"/m/015qbp",id:14,displayName:"parking meter"},15:{name:"/m/0cvnqh",id:15,displayName:"bench"},16:{name:"/m/015p6",id:16,displayName:"bird"},17:{name:"/m/01yrx",id:17,displayName:"cat"},18:{name:"/m/0bt9lr",id:18,displayName:"dog"},19:{name:"/m/03k3r",id:19,displayName:"horse"},20:{name:"/m/07bgp",id:20,displayName:"sheep"},21:{name:"/m/01xq0k1",id:21,displayName:"cow"},22:{name:"/m/0bwd_0j",id:22,displayName:"elephant"},23:{name:"/m/01dws",id:23,displayName:"bear"},24:{name:"/m/0898b",id:24,displayName:"zebra"},25:{name:"/m/03bk1",id:25,displayName:"giraffe"},27:{name:"/m/01940j",id:27,displayName:"backpack"},28:{name:"/m/0hnnb",id:28,displayName:"umbrella"},31:{name:"/m/080hkjn",id:31,displayName:"handbag"},32:{name:"/m/01rkbr",id:32,displayName:"tie"},33:{name:"/m/01s55n",id:33,displayName:"suitcase"},34:{name:"/m/02wmf",id:34,displayName:"frisbee"},35:{name:"/m/071p9",id:35,displayName:"skis"},36:{name:"/m/06__v",id:36,displayName:"snowboard"},37:{name:"/m/018xm",id:37,displayName:"sports ball"},38:{name:"/m/02zt3",id:38,displayName:"kite"},39:{name:"/m/03g8mr",id:39,displayName:"baseball bat"},40:{name:"/m/03grzl",id:40,displayName:"baseball glove"},41:{name:"/m/06_fw",id:41,displayName:"skateboard"},42:{name:"/m/019w40",id:42,displayName:"surfboard"},43:{name:"/m/0dv9c",id:43,displayName:"tennis racket"},44:{name:"/m/04dr76w",id:44,displayName:"bottle"},46:{name:"/m/09tvcd",id:46,displayName:"wine glass"},47:{name:"/m/08gqpm",id:47,displayName:"cup"},48:{name:"/m/0dt3t",id:48,displayName:"fork"},49:{name:"/m/04ctx",id:49,displayName:"knife"},50:{name:"/m/0cmx8",id:50,displayName:"spoon"},51:{name:"/m/04kkgm",id:51,displayName:"bowl"},52:{name:"/m/09qck",id:52,displayName:"banana"},53:{name:"/m/014j1m",id:53,displayName:"apple"},54:{name:"/m/0l515",id:54,displayName:"sandwich"},55:{name:"/m/0cyhj_",id:55,displayName:"orange"},56:{name:"/m/0hkxq",id:56,displayName:"broccoli"},57:{name:"/m/0fj52s",id:57,displayName:"carrot"},58:{name:"/m/01b9xk",id:58,displayName:"hot dog"},59:{name:"/m/0663v",id:59,displayName:"pizza"},60:{name:"/m/0jy4k",id:60,displayName:"donut"},61:{name:"/m/0fszt",id:61,displayName:"cake"},62:{name:"/m/01mzpv",id:62,displayName:"chair"},63:{name:"/m/02crq1",id:63,displayName:"couch"},64:{name:"/m/03fp41",id:64,displayName:"potted plant"},65:{name:"/m/03ssj5",id:65,displayName:"bed"},67:{name:"/m/04bcr3",id:67,displayName:"dining table"},70:{name:"/m/09g1w",id:70,displayName:"toilet"},72:{name:"/m/07c52",id:72,displayName:"tv"},73:{name:"/m/01c648",id:73,displayName:"laptop"},74:{name:"/m/020lf",id:74,displayName:"mouse"},75:{name:"/m/0qjjc",id:75,displayName:"remote"},76:{name:"/m/01m2v",id:76,displayName:"keyboard"},77:{name:"/m/050k8",id:77,displayName:"cell phone"},78:{name:"/m/0fx9l",id:78,displayName:"microwave"},79:{name:"/m/029bxz",id:79,displayName:"oven"},80:{name:"/m/01k6s3",id:80,displayName:"toaster"},81:{name:"/m/0130jx",id:81,displayName:"sink"},82:{name:"/m/040b_t",id:82,displayName:"refrigerator"},84:{name:"/m/0bt_c3",id:84,displayName:"book"},85:{name:"/m/01x3z",id:85,displayName:"clock"},86:{name:"/m/02s195",id:86,displayName:"vase"},87:{name:"/m/01lsmm",id:87,displayName:"scissors"},88:{name:"/m/0kmg4",id:88,displayName:"teddy bear"},89:{name:"/m/03wvsk",id:89,displayName:"hair drier"},90:{name:"/m/012xff",id:90,displayName:"toothbrush"}},d="https://storage.googleapis.com/tfjs-models/savedmodel/";var s=function(){function e(e,a){this.modelPath=a||""+d+this.getPrefix(e)+"/model.json"}return e.prototype.getPrefix=function(e){return"lite_mobilenet_v2"===e?"ssd"+e:"ssd_"+e},e.prototype.load=function(){return n(this,void 0,void 0,function(){var e,n;return t(this,function(t){switch(t.label){case 0:return e=this,[4,a.loadGraphModel(this.modelPath)];case 1:return e.model=t.sent(),[4,this.model.executeAsync(i.zeros([1,300,300,3]))];case 2:return n=t.sent(),[4,Promise.all(n.map(function(e){return e.data()}))];case 3:return t.sent(),n.map(function(e){return e.dispose()}),[2]}})})},e.prototype.infer=function(e,a){return n(this,void 0,void 0,function(){var n,m,d,s,r,o,l,p,c,y,u,f;return t(this,function(t){switch(t.label){case 0:return n=i.tidy(function(){return e instanceof i.Tensor||(e=i.browser.fromPixels(e)),e.expandDims(0)}),m=n.shape[1],d=n.shape[2],[4,this.model.executeAsync(n)];case 1:return s=t.sent(),r=s[0].dataSync(),o=s[1].dataSync(),n.dispose(),i.dispose(s),l=function(e,a){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var n,t,m=i.call(e),d=[];try{for(;(void 0===a||a-- >0)&&!(n=m.next()).done;)d.push(n.value)}catch(e){t={error:e}}finally{try{n&&!n.done&&(i=m.return)&&i.call(m)}finally{if(t)throw t.error}}return d}(this.calculateMaxScores(r,s[0].shape[1],s[0].shape[2]),2),p=l[0],c=l[1],y=i.getBackend(),i.setBackend("cpu"),u=i.tidy(function(){var e=i.tensor2d(o,[s[1].shape[1],s[1].shape[3]]);return i.image.nonMaxSuppression(e,p,a,.5,.5)}),f=u.dataSync(),u.dispose(),i.setBackend(y),[2,this.buildDetectedObjects(d,m,o,p,f,c)]}})})},e.prototype.buildDetectedObjects=function(e,a,i,n,t,d){for(var s=t.length,r=[],o=0;o<s;o++){for(var l=[],p=0;p<4;p++)l[p]=i[4*t[o]+p];var c=l[0]*a,y=l[1]*e,u=l[2]*a,f=l[3]*e;l[0]=y,l[1]=c,l[2]=f-y,l[3]=u-c,r.push({bbox:l,class:m[d[t[o]]+1].displayName,score:n[t[o]]})}return r},e.prototype.calculateMaxScores=function(e,a,i){for(var n=[],t=[],m=0;m<a;m++){for(var d=Number.MIN_VALUE,s=-1,r=0;r<i;r++)e[m*i+r]>d&&(d=e[m*i+r],s=r);n[m]=d,t[m]=s}return[n,t]},e.prototype.detect=function(e,a){return void 0===a&&(a=20),n(this,void 0,void 0,function(){return t(this,function(i){return[2,this.infer(e,a)]})})},e.prototype.dispose=function(){this.model&&this.model.dispose()},e}();e.load=function(e){return void 0===e&&(e={}),n(this,void 0,void 0,function(){var a,n,m;return t(this,function(t){switch(t.label){case 0:if(null==i)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");if(a=e.base||"lite_mobilenet_v2",n=e.modelUrl,-1===["mobilenet_v1","mobilenet_v2","lite_mobilenet_v2"].indexOf(a))throw new Error("ObjectDetection constructed with invalid base model "+a+". Valid names are 'mobilenet_v1', 'mobilenet_v2' and 'lite_mobilenet_v2'.");return[4,(m=new s(a,n)).load()];case 1:return t.sent(),[2,m]}})})},e.ObjectDetection=s,e.version="2.0.1",Object.defineProperty(e,"__esModule",{value:!0})});
2
+ * @license
3
+ * Copyright 2021 Google LLC. All Rights Reserved.
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ * =============================================================================
16
+ */
17
+ !function(e,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports,require("@tensorflow/tfjs-converter"),require("@tensorflow/tfjs-core")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-converter","@tensorflow/tfjs-core"],a):a((e=e||self).cocoSsd=e.cocoSsd||{},e.tf,e.tf)}(this,(function(e,a,i){"use strict";function n(e,a,i,n){return new(i||(i=Promise))((function(m,t){function d(e){try{o(n.next(e))}catch(e){t(e)}}function s(e){try{o(n.throw(e))}catch(e){t(e)}}function o(e){var a;e.done?m(e.value):(a=e.value,a instanceof i?a:new i((function(e){e(a)}))).then(d,s)}o((n=n.apply(e,a||[])).next())}))}function m(e,a){var i,n,m,t,d={label:0,sent:function(){if(1&m[0])throw m[1];return m[1]},trys:[],ops:[]};return t={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function s(t){return function(s){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;d;)try{if(i=1,n&&(m=2&t[0]?n.return:t[0]?n.throw||((m=n.return)&&m.call(n),0):n.next)&&!(m=m.call(n,t[1])).done)return m;switch(n=0,m&&(t=[2&t[0],m.value]),t[0]){case 0:case 1:m=t;break;case 4:return d.label++,{value:t[1],done:!1};case 5:d.label++,n=t[1],t=[0];continue;case 7:t=d.ops.pop(),d.trys.pop();continue;default:if(!(m=d.trys,(m=m.length>0&&m[m.length-1])||6!==t[0]&&2!==t[0])){d=0;continue}if(3===t[0]&&(!m||t[1]>m[0]&&t[1]<m[3])){d.label=t[1];break}if(6===t[0]&&d.label<m[1]){d.label=m[1],m=t;break}if(m&&d.label<m[2]){d.label=m[2],d.ops.push(t);break}m[2]&&d.ops.pop(),d.trys.pop();continue}t=a.call(e,d)}catch(e){t=[6,e],n=0}finally{i=m=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,s])}}}var t={1:{name:"/m/01g317",id:1,displayName:"person"},2:{name:"/m/0199g",id:2,displayName:"bicycle"},3:{name:"/m/0k4j",id:3,displayName:"car"},4:{name:"/m/04_sv",id:4,displayName:"motorcycle"},5:{name:"/m/05czz6l",id:5,displayName:"airplane"},6:{name:"/m/01bjv",id:6,displayName:"bus"},7:{name:"/m/07jdr",id:7,displayName:"train"},8:{name:"/m/07r04",id:8,displayName:"truck"},9:{name:"/m/019jd",id:9,displayName:"boat"},10:{name:"/m/015qff",id:10,displayName:"traffic light"},11:{name:"/m/01pns0",id:11,displayName:"fire hydrant"},13:{name:"/m/02pv19",id:13,displayName:"stop sign"},14:{name:"/m/015qbp",id:14,displayName:"parking meter"},15:{name:"/m/0cvnqh",id:15,displayName:"bench"},16:{name:"/m/015p6",id:16,displayName:"bird"},17:{name:"/m/01yrx",id:17,displayName:"cat"},18:{name:"/m/0bt9lr",id:18,displayName:"dog"},19:{name:"/m/03k3r",id:19,displayName:"horse"},20:{name:"/m/07bgp",id:20,displayName:"sheep"},21:{name:"/m/01xq0k1",id:21,displayName:"cow"},22:{name:"/m/0bwd_0j",id:22,displayName:"elephant"},23:{name:"/m/01dws",id:23,displayName:"bear"},24:{name:"/m/0898b",id:24,displayName:"zebra"},25:{name:"/m/03bk1",id:25,displayName:"giraffe"},27:{name:"/m/01940j",id:27,displayName:"backpack"},28:{name:"/m/0hnnb",id:28,displayName:"umbrella"},31:{name:"/m/080hkjn",id:31,displayName:"handbag"},32:{name:"/m/01rkbr",id:32,displayName:"tie"},33:{name:"/m/01s55n",id:33,displayName:"suitcase"},34:{name:"/m/02wmf",id:34,displayName:"frisbee"},35:{name:"/m/071p9",id:35,displayName:"skis"},36:{name:"/m/06__v",id:36,displayName:"snowboard"},37:{name:"/m/018xm",id:37,displayName:"sports ball"},38:{name:"/m/02zt3",id:38,displayName:"kite"},39:{name:"/m/03g8mr",id:39,displayName:"baseball bat"},40:{name:"/m/03grzl",id:40,displayName:"baseball glove"},41:{name:"/m/06_fw",id:41,displayName:"skateboard"},42:{name:"/m/019w40",id:42,displayName:"surfboard"},43:{name:"/m/0dv9c",id:43,displayName:"tennis racket"},44:{name:"/m/04dr76w",id:44,displayName:"bottle"},46:{name:"/m/09tvcd",id:46,displayName:"wine glass"},47:{name:"/m/08gqpm",id:47,displayName:"cup"},48:{name:"/m/0dt3t",id:48,displayName:"fork"},49:{name:"/m/04ctx",id:49,displayName:"knife"},50:{name:"/m/0cmx8",id:50,displayName:"spoon"},51:{name:"/m/04kkgm",id:51,displayName:"bowl"},52:{name:"/m/09qck",id:52,displayName:"banana"},53:{name:"/m/014j1m",id:53,displayName:"apple"},54:{name:"/m/0l515",id:54,displayName:"sandwich"},55:{name:"/m/0cyhj_",id:55,displayName:"orange"},56:{name:"/m/0hkxq",id:56,displayName:"broccoli"},57:{name:"/m/0fj52s",id:57,displayName:"carrot"},58:{name:"/m/01b9xk",id:58,displayName:"hot dog"},59:{name:"/m/0663v",id:59,displayName:"pizza"},60:{name:"/m/0jy4k",id:60,displayName:"donut"},61:{name:"/m/0fszt",id:61,displayName:"cake"},62:{name:"/m/01mzpv",id:62,displayName:"chair"},63:{name:"/m/02crq1",id:63,displayName:"couch"},64:{name:"/m/03fp41",id:64,displayName:"potted plant"},65:{name:"/m/03ssj5",id:65,displayName:"bed"},67:{name:"/m/04bcr3",id:67,displayName:"dining table"},70:{name:"/m/09g1w",id:70,displayName:"toilet"},72:{name:"/m/07c52",id:72,displayName:"tv"},73:{name:"/m/01c648",id:73,displayName:"laptop"},74:{name:"/m/020lf",id:74,displayName:"mouse"},75:{name:"/m/0qjjc",id:75,displayName:"remote"},76:{name:"/m/01m2v",id:76,displayName:"keyboard"},77:{name:"/m/050k8",id:77,displayName:"cell phone"},78:{name:"/m/0fx9l",id:78,displayName:"microwave"},79:{name:"/m/029bxz",id:79,displayName:"oven"},80:{name:"/m/01k6s3",id:80,displayName:"toaster"},81:{name:"/m/0130jx",id:81,displayName:"sink"},82:{name:"/m/040b_t",id:82,displayName:"refrigerator"},84:{name:"/m/0bt_c3",id:84,displayName:"book"},85:{name:"/m/01x3z",id:85,displayName:"clock"},86:{name:"/m/02s195",id:86,displayName:"vase"},87:{name:"/m/01lsmm",id:87,displayName:"scissors"},88:{name:"/m/0kmg4",id:88,displayName:"teddy bear"},89:{name:"/m/03wvsk",id:89,displayName:"hair drier"},90:{name:"/m/012xff",id:90,displayName:"toothbrush"}};var d=function(){function e(e,a){this.modelPath=a||"https://storage.googleapis.com/tfjs-models/savedmodel/"+this.getPrefix(e)+"/model.json"}return e.prototype.getPrefix=function(e){return"lite_mobilenet_v2"===e?"ssd"+e:"ssd_"+e},e.prototype.load=function(){return n(this,void 0,void 0,(function(){var e,n,t;return m(this,(function(m){switch(m.label){case 0:return e=this,[4,a.loadGraphModel(this.modelPath)];case 1:return e.model=m.sent(),n=i.zeros([1,300,300,3],"int32"),[4,this.model.executeAsync(n)];case 2:return t=m.sent(),[4,Promise.all(t.map((function(e){return e.data()})))];case 3:return m.sent(),t.map((function(e){return e.dispose()})),n.dispose(),[2]}}))}))},e.prototype.infer=function(e,a,t){return n(this,void 0,void 0,(function(){var n,d,s,o,r,l,p,c,y,u,f,b;return m(this,(function(m){switch(m.label){case 0:return n=i.tidy((function(){return e instanceof i.Tensor||(e=i.browser.fromPixels(e)),i.expandDims(e)})),d=n.shape[1],s=n.shape[2],[4,this.model.executeAsync(n)];case 1:return o=m.sent(),r=o[0].dataSync(),l=o[1].dataSync(),n.dispose(),i.dispose(o),p=this.calculateMaxScores(r,o[0].shape[1],o[0].shape[2]),c=p[0],y=p[1],u=i.getBackend(),"webgl"===i.getBackend()&&i.setBackend("cpu"),f=i.tidy((function(){var e=i.tensor2d(l,[o[1].shape[1],o[1].shape[3]]);return i.image.nonMaxSuppression(e,c,a,t,t)})),b=f.dataSync(),f.dispose(),u!==i.getBackend()&&i.setBackend(u),[2,this.buildDetectedObjects(s,d,l,c,b,y)]}}))}))},e.prototype.buildDetectedObjects=function(e,a,i,n,m,d){for(var s=m.length,o=[],r=0;r<s;r++){for(var l=[],p=0;p<4;p++)l[p]=i[4*m[r]+p];var c=l[0]*a,y=l[1]*e,u=l[2]*a,f=l[3]*e;l[0]=y,l[1]=c,l[2]=f-y,l[3]=u-c,o.push({bbox:l,class:t[d[m[r]]+1].displayName,score:n[m[r]]})}return o},e.prototype.calculateMaxScores=function(e,a,i){for(var n=[],m=[],t=0;t<a;t++){for(var d=Number.MIN_VALUE,s=-1,o=0;o<i;o++)e[t*i+o]>d&&(d=e[t*i+o],s=o);n[t]=d,m[t]=s}return[n,m]},e.prototype.detect=function(e,a,i){return void 0===a&&(a=20),void 0===i&&(i=.5),n(this,void 0,void 0,(function(){return m(this,(function(n){return[2,this.infer(e,a,i)]}))}))},e.prototype.dispose=function(){null!=this.model&&this.model.dispose()},e}();e.ObjectDetection=d,e.load=function(e){return void 0===e&&(e={}),n(this,void 0,void 0,(function(){var a,n,t;return m(this,(function(m){switch(m.label){case 0:if(null==i)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");if(a=e.base||"lite_mobilenet_v2",n=e.modelUrl,-1===["mobilenet_v1","mobilenet_v2","lite_mobilenet_v2"].indexOf(a))throw new Error("ObjectDetection constructed with invalid base model "+a+". Valid names are 'mobilenet_v1', 'mobilenet_v2' and 'lite_mobilenet_v2'.");return[4,(t=new d(a,n)).load()];case 1:return m.sent(),[2,t]}}))}))},e.version="2.2.2",Object.defineProperty(e,"__esModule",{value:!0})}));
18
+ //# sourceMappingURL=coco-ssd.min.js.map
package/html/libs/deeplab CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2019 Google LLC. All Rights Reserved.
3
+ * Copyright 2021 Google LLC. All Rights Reserved.
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
6
6
  * You may obtain a copy of the License at
@@ -16,7 +16,7 @@
16
16
  */
17
17
  /**
18
18
  * @license
19
- * Copyright 2019 Google LLC. All Rights Reserved.
19
+ * Copyright 2021 Google LLC. All Rights Reserved.
20
20
  * Licensed under the Apache License, Version 2.0 (the "License");
21
21
  * you may not use this file except in compliance with the License.
22
22
  * You may obtain a copy of the License at
@@ -44,4 +44,54 @@
44
44
 
45
45
  See the Apache Version 2.0 License for specific language governing permissions
46
46
  and limitations under the License.
47
- ***************************************************************************** */function n(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{l(r.next(e))}catch(e){a(e)}}function s(e){try{l(r.throw(e))}catch(e){a(e)}}function l(e){e.done?o(e.value):new n((function(t){t(e.value)})).then(i,s)}l((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var o={BASE_PATH:"https://tfhub.dev/tensorflow/tfjs-model/deeplab",CROP_SIZE:513,COLORMAPS:{ADE20K:[[0,0,0],[120,120,120],[180,120,120],[6,230,230],[80,50,50],[4,200,3],[120,120,80],[140,140,140],[204,5,255],[230,230,230],[4,250,7],[224,5,255],[235,255,7],[150,5,61],[120,120,70],[8,255,51],[255,6,82],[143,255,140],[204,255,4],[255,51,7],[204,70,3],[0,102,200],[61,230,250],[255,6,51],[11,102,255],[255,7,71],[255,9,224],[9,7,230],[220,220,220],[255,9,92],[112,9,255],[8,255,214],[7,255,224],[255,184,6],[10,255,71],[255,41,10],[7,255,255],[224,255,8],[102,8,255],[255,61,6],[255,194,7],[255,122,8],[0,255,20],[255,8,41],[255,5,153],[6,51,255],[235,12,255],[160,150,20],[0,163,255],[140,140,140],[250,10,15],[20,255,0],[31,255,0],[255,31,0],[255,224,0],[153,255,0],[0,0,255],[255,71,0],[0,235,255],[0,173,255],[31,0,255],[11,200,200],[255,82,0],[0,255,245],[0,61,255],[0,255,112],[0,255,133],[255,0,0],[255,163,0],[255,102,0],[194,255,0],[0,143,255],[51,255,0],[0,82,255],[0,255,41],[0,255,173],[10,0,255],[173,255,0],[0,255,153],[255,92,0],[255,0,255],[255,0,245],[255,0,102],[255,173,0],[255,0,20],[255,184,184],[0,31,255],[0,255,61],[0,71,255],[255,0,204],[0,255,194],[0,255,82],[0,10,255],[0,112,255],[51,0,255],[0,194,255],[0,122,255],[0,255,163],[255,153,0],[0,255,10],[255,112,0],[143,255,0],[82,0,255],[163,255,0],[255,235,0],[8,184,170],[133,0,255],[0,255,92],[184,0,255],[255,0,31],[0,184,255],[0,214,255],[255,0,112],[92,255,0],[0,224,255],[112,224,255],[70,184,160],[163,0,255],[153,0,255],[71,255,0],[255,0,163],[255,204,0],[255,0,143],[0,255,235],[133,255,0],[255,0,235],[245,0,255],[255,0,122],[255,245,0],[10,190,212],[214,255,0],[0,204,255],[20,0,255],[255,255,0],[0,153,255],[0,41,255],[0,255,204],[41,0,255],[41,255,0],[173,0,255],[0,245,255],[71,0,255],[122,0,255],[0,255,184],[0,92,255],[184,255,0],[0,133,255],[255,214,0],[25,194,194],[102,255,0],[92,0,255]],CITYSCAPES:[[128,64,128],[244,35,232],[70,70,70],[102,102,156],[190,153,153],[153,153,153],[250,170,30],[220,220,0],[107,142,35],[152,251,152],[70,130,180],[220,20,60],[255,0,0],[0,0,142],[0,0,70],[0,60,100],[0,80,100],[0,0,230],[119,11,32]],PASCAL:[[0,0,0],[128,0,0],[0,128,0],[128,128,0],[0,0,128],[128,0,128],[0,128,128],[128,128,128],[64,0,0],[192,0,0],[64,128,0],[192,128,0],[64,0,128],[192,0,128],[64,128,128],[192,128,128],[0,64,0],[128,64,0],[0,192,0],[128,192,0],[0,64,128],[128,64,128],[0,192,128],[128,192,128],[64,64,0],[192,64,0],[64,192,0],[192,192,0],[64,64,128],[192,64,128],[64,192,128],[192,192,128],[0,0,64],[128,0,64],[0,128,64],[128,128,64],[0,0,192],[128,0,192],[0,128,192],[128,128,192],[64,0,64],[192,0,64],[64,128,64],[192,128,64],[64,0,192],[192,0,192],[64,128,192],[192,128,192],[0,64,64],[128,64,64],[0,192,64],[128,192,64],[0,64,192],[128,64,192],[0,192,192],[128,192,192],[64,64,64],[192,64,64],[64,192,64],[192,192,64],[64,64,192],[192,64,192],[64,192,192],[192,192,192],[32,0,0],[160,0,0],[32,128,0],[160,128,0],[32,0,128],[160,0,128],[32,128,128],[160,128,128],[96,0,0],[224,0,0],[96,128,0],[224,128,0],[96,0,128],[224,0,128],[96,128,128],[224,128,128],[32,64,0],[160,64,0],[32,192,0],[160,192,0],[32,64,128],[160,64,128],[32,192,128],[160,192,128],[96,64,0],[224,64,0],[96,192,0],[224,192,0],[96,64,128],[224,64,128],[96,192,128],[224,192,128],[32,0,64],[160,0,64],[32,128,64],[160,128,64],[32,0,192],[160,0,192],[32,128,192],[160,128,192],[96,0,64],[224,0,64],[96,128,64],[224,128,64],[96,0,192],[224,0,192],[96,128,192],[224,128,192],[32,64,64],[160,64,64],[32,192,64],[160,192,64],[32,64,192],[160,64,192],[32,192,192],[160,192,192],[96,64,64],[224,64,64],[96,192,64],[224,192,64],[96,64,192],[224,64,192],[96,192,192],[224,192,192],[0,32,0],[128,32,0],[0,160,0],[128,160,0],[0,32,128],[128,32,128],[0,160,128],[128,160,128],[64,32,0],[192,32,0],[64,160,0],[192,160,0],[64,32,128],[192,32,128],[64,160,128],[192,160,128],[0,96,0],[128,96,0],[0,224,0],[128,224,0],[0,96,128],[128,96,128],[0,224,128],[128,224,128],[64,96,0],[192,96,0],[64,224,0],[192,224,0],[64,96,128],[192,96,128],[64,224,128],[192,224,128],[0,32,64],[128,32,64],[0,160,64],[128,160,64],[0,32,192],[128,32,192],[0,160,192],[128,160,192],[64,32,64],[192,32,64],[64,160,64],[192,160,64],[64,32,192],[192,32,192],[64,160,192],[192,160,192],[0,96,64],[128,96,64],[0,224,64],[128,224,64],[0,96,192],[128,96,192],[0,224,192],[128,224,192],[64,96,64],[192,96,64],[64,224,64],[192,224,64],[64,96,192],[192,96,192],[64,224,192],[192,224,192],[32,32,0],[160,32,0],[32,160,0],[160,160,0],[32,32,128],[160,32,128],[32,160,128],[160,160,128],[96,32,0],[224,32,0],[96,160,0],[224,160,0],[96,32,128],[224,32,128],[96,160,128],[224,160,128],[32,96,0],[160,96,0],[32,224,0],[160,224,0],[32,96,128],[160,96,128],[32,224,128],[160,224,128],[96,96,0],[224,96,0],[96,224,0],[224,224,0],[96,96,128],[224,96,128],[96,224,128],[224,224,128],[32,32,64],[160,32,64],[32,160,64],[160,160,64],[32,32,192],[160,32,192],[32,160,192],[160,160,192],[96,32,64],[224,32,64],[96,160,64],[224,160,64],[96,32,192],[224,32,192],[96,160,192],[224,160,192],[32,96,64],[160,96,64],[32,224,64],[160,224,64],[32,96,192],[160,96,192],[32,224,192],[160,224,192],[96,96,64],[224,96,64],[96,224,64],[224,224,64],[96,96,192],[224,96,192],[96,224,192],[224,224,192]]},DATASET_MAX_ENTRIES:{PASCAL:256,CITYSCAPES:256,ADE20K:151},LABELS:{PASCAL:["background","aeroplane","bicycle","bird","boat","bottle","bus","car","cat","chair","cow","dining table","dog","horse","motorbike","person","potted plant","sheep","sofa","train","TV"],CITYSCAPES:["road","sidewalk","building","wall","fence","pole","traffic light","traffic sign","vegetation","terrain","sky","person","rider","car","truck","bus","train","motorcycle","bicycle"],ADE20K:["background","wall","building","sky","floor","tree","ceiling","road","bed","windowpane","grass","cabinet","sidewalk","person","earth","door","table","mountain","plant","curtain","chair","car","water","painting","sofa","shelf","house","sea","mirror","rug","field","armchair","seat","fence","desk","rock","wardrobe","lamp","bathtub","railing","cushion","base","box","column","signboard","chest","counter","sand","sink","skyscraper","fireplace","refrigerator","grandstand","path","stairs","runway","case","pool","pillow","screen","stairway","river","bridge","bookcase","blind","coffee","toilet","flower","book","hill","bench","countertop","stove","palm","kitchen","computer","swivel","boat","bar","arcade","hovel","bus","towel","light","truck","tower","chandelier","awning","streetlight","booth","television","airplane","dirt","apparel","pole","land","bannister","escalator","ottoman","bottle","buffet","poster","stage","van","ship","fountain","conveyer","canopy","washer","plaything","swimming","stool","barrel","basket","waterfall","tent","bag","minibike","cradle","oven","ball","food","step","tank","trade","microwave","pot","animal","bicycle","lake","dishwasher","screen","blanket","sculpture","hood","sconce","vase","traffic","tray","ashcan","fan","pier","screen","plate","monitor","bulletin","shower","radiator","glass","clock","flag"]}};function a(e,t){return""+o.BASE_PATH+"/"+(4===t?e+"/1/default/1/model.json":e+"/1/quantized/"+t+"/1/model.json")+"?tfjs-format=file"}function i(e){if("pascal"===e)return o.COLORMAPS.PASCAL;if("ade20k"===e)return o.COLORMAPS.ADE20K;if("cityscapes"===e)return o.COLORMAPS.CITYSCAPES;throw new Error("SemanticSegmentation cannot be constructed with an invalid base model "+e+". Try one of 'pascal', 'cityscapes' and 'ade20k'.")}function s(e){if("pascal"===e)return o.LABELS.PASCAL;if("ade20k"===e)return o.LABELS.ADE20K;if("cityscapes"===e)return o.LABELS.CITYSCAPES;throw new Error("SemanticSegmentation cannot be constructed with an invalid base model "+e+". Try one of 'pascal', 'cityscapes' and 'ade20k'.")}function l(e,t,o,a){return n(this,void 0,void 0,(function(){var n,i,s,l,c,u,d,f,h,p,b,g,m,w;return r(this,(function(r){switch(r.label){case 0:if(e.length<t.length)throw new Error("The colormap must be expansive enough to encode each label. Aborting, since the given colormap has length "+e.length+", but there are "+t.length+" labels.");return n=o.shape,i=n[0],s=n[1],l=tf.buffer([i,s,3],"int32"),[4,o.array()];case 1:for(c=r.sent(),u=new Set,d=0;d<i;++d)for(f=0;f<s;++f)w=c[d][f],u.add(w),l.set(e[w][0],d,f,0),l.set(e[w][1],d,f,1),l.set(e[w][2],d,f,2);return h=l.toTensor(),[4,tf.browser.toPixels(h,a)];case 2:for(p=r.sent(),tf.dispose(h),b={},g=0,m=Array.from(u);g<m.length;g++)w=m[g],b[t[w]]=e[w];return[2,{legend:b,segmentationMap:p}]}}))}))}var c=function(){function e(e,t){this.model=e,this.base=t}return e.prototype.predict=function(e){var t=this;return tf.tidy((function(){var n=function(e){return tf.tidy((function(){var t=e instanceof tf.Tensor?e:tf.browser.fromPixels(e),n=t.shape,r=n[0],a=n[1],i=o.CROP_SIZE/Math.max(a,r),s=Math.round(r*i),l=Math.round(a*i);return tf.image.resizeBilinear(t,[s,l]).expandDims(0)}))}(e);return tf.squeeze(t.model.execute(n))}))},e.prototype.segment=function(e,t){return void 0===t&&(t={}),n(this,void 0,void 0,(function(){var n,o,a,c,u,d,f,h,p,b,g=this;return r(this,(function(r){switch(r.label){case 0:if(!(t.colormap&&t.labels||this.base))throw new Error("Calling the 'segment' method requires either the 'base' attribute to be defined (e.g. 'pascal', 'cityscapes' or'ade20k'), or 'colormap' and 'labels' options to be set. Aborting, since neither has been provided.");return t.colormap&&t.labels||(t.colormap=i(this.base),t.labels=s(this.base)),n=t.colormap,o=t.labels,a=t.canvas,c=tf.tidy((function(){return g.predict(e)})),u=c.shape,d=u[0],f=u[1],[4,l(n,o,c,a)];case 1:return h=r.sent(),p=h.legend,b=h.segmentationMap,tf.dispose(c),[2,{legend:p,height:d,width:f,segmentationMap:b}]}}))}))},e.prototype.dispose=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){return this.model&&this.model.dispose(),[2]}))}))},e}();e.SemanticSegmentation=c,e.getColormap=i,e.getLabels=s,e.getURL=a,e.load=function(e){return void 0===e&&(e={base:"pascal",quantizationBytes:2}),n(this,void 0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:if(null==tf)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");if(e.base){if(-1===["pascal","cityscapes","ade20k"].indexOf(e.base))throw new Error("SemanticSegmentation cannot be constructed with an invalid base model "+e.base+". Try one of 'pascal', 'cityscapes' and 'ade20k'.");if(-1===[1,2,4].indexOf(e.quantizationBytes))throw new Error("Only quantization to 1, 2 or 4 bytes is supported.")}else if(!e.modelUrl)throw new Error("SemanticSegmentation can be constructed either by passing the weights URL or one of the supported base model names from 'pascal', 'cityscapes' and 'ade20k',together with the degree of quantization (either 1, 2 or 4).Aborting, since neither has been provided.");return[4,t.loadGraphModel(e.modelUrl||a(e.base,e.quantizationBytes))];case 1:return n=r.sent(),[2,new c(n,e.base)]}}))}))},e.toSegmentationImage=l,e.version="0.1.1",Object.defineProperty(e,"__esModule",{value:!0})}));
47
+ ***************************************************************************** */function n(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{l(r.next(e))}catch(e){a(e)}}function s(e){try{l(r.throw(e))}catch(e){a(e)}}function l(e){e.done?o(e.value):new n((function(t){t(e.value)})).then(i,s)}l((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}
48
+ /**
49
+ * @license
50
+ * Copyright 2019 Google LLC. All Rights Reserved.
51
+ * Licensed under the Apache License, Version 2.0 (the "License");
52
+ * you may not use this file except in compliance with the License.
53
+ * You may obtain a copy of the License at
54
+ *
55
+ * http://www.apache.org/licenses/LICENSE-2.0
56
+ *
57
+ * Unless required by applicable law or agreed to in writing, software
58
+ * distributed under the License is distributed on an "AS IS" BASIS,
59
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
60
+ * See the License for the specific language governing permissions and
61
+ * limitations under the License.
62
+ * =============================================================================
63
+ */var o={BASE_PATH:"https://tfhub.dev/tensorflow/tfjs-model/deeplab",CROP_SIZE:513,COLORMAPS:{ADE20K:[[0,0,0],[120,120,120],[180,120,120],[6,230,230],[80,50,50],[4,200,3],[120,120,80],[140,140,140],[204,5,255],[230,230,230],[4,250,7],[224,5,255],[235,255,7],[150,5,61],[120,120,70],[8,255,51],[255,6,82],[143,255,140],[204,255,4],[255,51,7],[204,70,3],[0,102,200],[61,230,250],[255,6,51],[11,102,255],[255,7,71],[255,9,224],[9,7,230],[220,220,220],[255,9,92],[112,9,255],[8,255,214],[7,255,224],[255,184,6],[10,255,71],[255,41,10],[7,255,255],[224,255,8],[102,8,255],[255,61,6],[255,194,7],[255,122,8],[0,255,20],[255,8,41],[255,5,153],[6,51,255],[235,12,255],[160,150,20],[0,163,255],[140,140,140],[250,10,15],[20,255,0],[31,255,0],[255,31,0],[255,224,0],[153,255,0],[0,0,255],[255,71,0],[0,235,255],[0,173,255],[31,0,255],[11,200,200],[255,82,0],[0,255,245],[0,61,255],[0,255,112],[0,255,133],[255,0,0],[255,163,0],[255,102,0],[194,255,0],[0,143,255],[51,255,0],[0,82,255],[0,255,41],[0,255,173],[10,0,255],[173,255,0],[0,255,153],[255,92,0],[255,0,255],[255,0,245],[255,0,102],[255,173,0],[255,0,20],[255,184,184],[0,31,255],[0,255,61],[0,71,255],[255,0,204],[0,255,194],[0,255,82],[0,10,255],[0,112,255],[51,0,255],[0,194,255],[0,122,255],[0,255,163],[255,153,0],[0,255,10],[255,112,0],[143,255,0],[82,0,255],[163,255,0],[255,235,0],[8,184,170],[133,0,255],[0,255,92],[184,0,255],[255,0,31],[0,184,255],[0,214,255],[255,0,112],[92,255,0],[0,224,255],[112,224,255],[70,184,160],[163,0,255],[153,0,255],[71,255,0],[255,0,163],[255,204,0],[255,0,143],[0,255,235],[133,255,0],[255,0,235],[245,0,255],[255,0,122],[255,245,0],[10,190,212],[214,255,0],[0,204,255],[20,0,255],[255,255,0],[0,153,255],[0,41,255],[0,255,204],[41,0,255],[41,255,0],[173,0,255],[0,245,255],[71,0,255],[122,0,255],[0,255,184],[0,92,255],[184,255,0],[0,133,255],[255,214,0],[25,194,194],[102,255,0],[92,0,255]],CITYSCAPES:[[128,64,128],[244,35,232],[70,70,70],[102,102,156],[190,153,153],[153,153,153],[250,170,30],[220,220,0],[107,142,35],[152,251,152],[70,130,180],[220,20,60],[255,0,0],[0,0,142],[0,0,70],[0,60,100],[0,80,100],[0,0,230],[119,11,32]],PASCAL:[[0,0,0],[128,0,0],[0,128,0],[128,128,0],[0,0,128],[128,0,128],[0,128,128],[128,128,128],[64,0,0],[192,0,0],[64,128,0],[192,128,0],[64,0,128],[192,0,128],[64,128,128],[192,128,128],[0,64,0],[128,64,0],[0,192,0],[128,192,0],[0,64,128],[128,64,128],[0,192,128],[128,192,128],[64,64,0],[192,64,0],[64,192,0],[192,192,0],[64,64,128],[192,64,128],[64,192,128],[192,192,128],[0,0,64],[128,0,64],[0,128,64],[128,128,64],[0,0,192],[128,0,192],[0,128,192],[128,128,192],[64,0,64],[192,0,64],[64,128,64],[192,128,64],[64,0,192],[192,0,192],[64,128,192],[192,128,192],[0,64,64],[128,64,64],[0,192,64],[128,192,64],[0,64,192],[128,64,192],[0,192,192],[128,192,192],[64,64,64],[192,64,64],[64,192,64],[192,192,64],[64,64,192],[192,64,192],[64,192,192],[192,192,192],[32,0,0],[160,0,0],[32,128,0],[160,128,0],[32,0,128],[160,0,128],[32,128,128],[160,128,128],[96,0,0],[224,0,0],[96,128,0],[224,128,0],[96,0,128],[224,0,128],[96,128,128],[224,128,128],[32,64,0],[160,64,0],[32,192,0],[160,192,0],[32,64,128],[160,64,128],[32,192,128],[160,192,128],[96,64,0],[224,64,0],[96,192,0],[224,192,0],[96,64,128],[224,64,128],[96,192,128],[224,192,128],[32,0,64],[160,0,64],[32,128,64],[160,128,64],[32,0,192],[160,0,192],[32,128,192],[160,128,192],[96,0,64],[224,0,64],[96,128,64],[224,128,64],[96,0,192],[224,0,192],[96,128,192],[224,128,192],[32,64,64],[160,64,64],[32,192,64],[160,192,64],[32,64,192],[160,64,192],[32,192,192],[160,192,192],[96,64,64],[224,64,64],[96,192,64],[224,192,64],[96,64,192],[224,64,192],[96,192,192],[224,192,192],[0,32,0],[128,32,0],[0,160,0],[128,160,0],[0,32,128],[128,32,128],[0,160,128],[128,160,128],[64,32,0],[192,32,0],[64,160,0],[192,160,0],[64,32,128],[192,32,128],[64,160,128],[192,160,128],[0,96,0],[128,96,0],[0,224,0],[128,224,0],[0,96,128],[128,96,128],[0,224,128],[128,224,128],[64,96,0],[192,96,0],[64,224,0],[192,224,0],[64,96,128],[192,96,128],[64,224,128],[192,224,128],[0,32,64],[128,32,64],[0,160,64],[128,160,64],[0,32,192],[128,32,192],[0,160,192],[128,160,192],[64,32,64],[192,32,64],[64,160,64],[192,160,64],[64,32,192],[192,32,192],[64,160,192],[192,160,192],[0,96,64],[128,96,64],[0,224,64],[128,224,64],[0,96,192],[128,96,192],[0,224,192],[128,224,192],[64,96,64],[192,96,64],[64,224,64],[192,224,64],[64,96,192],[192,96,192],[64,224,192],[192,224,192],[32,32,0],[160,32,0],[32,160,0],[160,160,0],[32,32,128],[160,32,128],[32,160,128],[160,160,128],[96,32,0],[224,32,0],[96,160,0],[224,160,0],[96,32,128],[224,32,128],[96,160,128],[224,160,128],[32,96,0],[160,96,0],[32,224,0],[160,224,0],[32,96,128],[160,96,128],[32,224,128],[160,224,128],[96,96,0],[224,96,0],[96,224,0],[224,224,0],[96,96,128],[224,96,128],[96,224,128],[224,224,128],[32,32,64],[160,32,64],[32,160,64],[160,160,64],[32,32,192],[160,32,192],[32,160,192],[160,160,192],[96,32,64],[224,32,64],[96,160,64],[224,160,64],[96,32,192],[224,32,192],[96,160,192],[224,160,192],[32,96,64],[160,96,64],[32,224,64],[160,224,64],[32,96,192],[160,96,192],[32,224,192],[160,224,192],[96,96,64],[224,96,64],[96,224,64],[224,224,64],[96,96,192],[224,96,192],[96,224,192],[224,224,192]]},DATASET_MAX_ENTRIES:{PASCAL:256,CITYSCAPES:256,ADE20K:151},LABELS:{PASCAL:["background","aeroplane","bicycle","bird","boat","bottle","bus","car","cat","chair","cow","dining table","dog","horse","motorbike","person","potted plant","sheep","sofa","train","TV"],CITYSCAPES:["road","sidewalk","building","wall","fence","pole","traffic light","traffic sign","vegetation","terrain","sky","person","rider","car","truck","bus","train","motorcycle","bicycle"],ADE20K:["background","wall","building","sky","floor","tree","ceiling","road","bed","windowpane","grass","cabinet","sidewalk","person","earth","door","table","mountain","plant","curtain","chair","car","water","painting","sofa","shelf","house","sea","mirror","rug","field","armchair","seat","fence","desk","rock","wardrobe","lamp","bathtub","railing","cushion","base","box","column","signboard","chest","counter","sand","sink","skyscraper","fireplace","refrigerator","grandstand","path","stairs","runway","case","pool","pillow","screen","stairway","river","bridge","bookcase","blind","coffee","toilet","flower","book","hill","bench","countertop","stove","palm","kitchen","computer","swivel","boat","bar","arcade","hovel","bus","towel","light","truck","tower","chandelier","awning","streetlight","booth","television","airplane","dirt","apparel","pole","land","bannister","escalator","ottoman","bottle","buffet","poster","stage","van","ship","fountain","conveyer","canopy","washer","plaything","swimming","stool","barrel","basket","waterfall","tent","bag","minibike","cradle","oven","ball","food","step","tank","trade","microwave","pot","animal","bicycle","lake","dishwasher","screen","blanket","sculpture","hood","sconce","vase","traffic","tray","ashcan","fan","pier","screen","plate","monitor","bulletin","shower","radiator","glass","clock","flag"]}};
64
+ /**
65
+ * @license
66
+ * Copyright 2019 Google LLC. All Rights Reserved.
67
+ * Licensed under the Apache License, Version 2.0 (the "License");
68
+ * you may not use this file except in compliance with the License.
69
+ * You may obtain a copy of the License at
70
+ *
71
+ * http://www.apache.org/licenses/LICENSE-2.0
72
+ *
73
+ * Unless required by applicable law or agreed to in writing, software
74
+ * distributed under the License is distributed on an "AS IS" BASIS,
75
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76
+ * See the License for the specific language governing permissions and
77
+ * limitations under the License.
78
+ * =============================================================================
79
+ */function a(e,t){return""+o.BASE_PATH+"/"+(4===t?e+"/1/default/1/model.json":e+"/1/quantized/"+t+"/1/model.json")+"?tfjs-format=file"}function i(e){if("pascal"===e)return o.COLORMAPS.PASCAL;if("ade20k"===e)return o.COLORMAPS.ADE20K;if("cityscapes"===e)return o.COLORMAPS.CITYSCAPES;throw new Error("SemanticSegmentation cannot be constructed with an invalid base model "+e+". Try one of 'pascal', 'cityscapes' and 'ade20k'.")}function s(e){if("pascal"===e)return o.LABELS.PASCAL;if("ade20k"===e)return o.LABELS.ADE20K;if("cityscapes"===e)return o.LABELS.CITYSCAPES;throw new Error("SemanticSegmentation cannot be constructed with an invalid base model "+e+". Try one of 'pascal', 'cityscapes' and 'ade20k'.")}function l(e,t,o,a){return n(this,void 0,void 0,(function(){var n,i,s,l,c,u,d,f,h,p,b,g,m,w;return r(this,(function(r){switch(r.label){case 0:if(e.length<t.length)throw new Error("The colormap must be expansive enough to encode each label. Aborting, since the given colormap has length "+e.length+", but there are "+t.length+" labels.");return n=o.shape,i=n[0],s=n[1],l=tf.buffer([i,s,3],"int32"),[4,o.array()];case 1:for(c=r.sent(),u=new Set,d=0;d<i;++d)for(f=0;f<s;++f)w=c[d][f],u.add(w),l.set(e[w][0],d,f,0),l.set(e[w][1],d,f,1),l.set(e[w][2],d,f,2);return h=l.toTensor(),[4,tf.browser.toPixels(h,a)];case 2:for(p=r.sent(),tf.dispose(h),b={},g=0,m=Array.from(u);g<m.length;g++)w=m[g],b[t[w]]=e[w];return[2,{legend:b,segmentationMap:p}]}}))}))}
80
+ /** @license See the LICENSE file. */var c=function(){function e(e,t){this.model=e,this.base=t}return e.prototype.predict=function(e){var t=this;return tf.tidy((function(){var n=tf.cast(function(e){return tf.tidy((function(){var t=e instanceof tf.Tensor?e:tf.browser.fromPixels(e),n=t.shape,r=n[0],a=n[1],i=o.CROP_SIZE/Math.max(a,r),s=Math.round(r*i),l=Math.round(a*i);return tf.expandDims(tf.image.resizeBilinear(t,[s,l]))}))}(e),"int32");return tf.squeeze(t.model.execute(n))}))},e.prototype.segment=function(e,t){return void 0===t&&(t={}),n(this,void 0,void 0,(function(){var n,o,a,c,u,d,f,h,p,b,g=this;return r(this,(function(r){switch(r.label){case 0:if(!(t.colormap&&t.labels||this.base))throw new Error("Calling the 'segment' method requires either the 'base' attribute to be defined (e.g. 'pascal', 'cityscapes' or'ade20k'), or 'colormap' and 'labels' options to be set. Aborting, since neither has been provided.");return t.colormap&&t.labels||(t.colormap=i(this.base),t.labels=s(this.base)),n=t.colormap,o=t.labels,a=t.canvas,c=tf.tidy((function(){return g.predict(e)})),u=c.shape,d=u[0],f=u[1],[4,l(n,o,c,a)];case 1:return h=r.sent(),p=h.legend,b=h.segmentationMap,tf.dispose(c),[2,{legend:p,height:d,width:f,segmentationMap:b}]}}))}))},e.prototype.dispose=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){return this.model&&this.model.dispose(),[2]}))}))},e}();e.SemanticSegmentation=c,e.getColormap=i,e.getLabels=s,e.getURL=a,e.load=
81
+ /**
82
+ * @license
83
+ * Copyright 2019 Google LLC. All Rights Reserved.
84
+ * Licensed under the Apache License, Version 2.0 (the "License");
85
+ * you may not use this file except in compliance with the License.
86
+ * You may obtain a copy of the License at
87
+ *
88
+ * http://www.apache.org/licenses/LICENSE-2.0
89
+ *
90
+ * Unless required by applicable law or agreed to in writing, software
91
+ * distributed under the License is distributed on an "AS IS" BASIS,
92
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93
+ * See the License for the specific language governing permissions and
94
+ * limitations under the License.
95
+ * =============================================================================
96
+ */
97
+ function(e){return void 0===e&&(e={base:"pascal",quantizationBytes:2}),n(this,void 0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:if(null==tf)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");if(e.base){if(-1===["pascal","cityscapes","ade20k"].indexOf(e.base))throw new Error("SemanticSegmentation cannot be constructed with an invalid base model "+e.base+". Try one of 'pascal', 'cityscapes' and 'ade20k'.");if(-1===[1,2,4].indexOf(e.quantizationBytes))throw new Error("Only quantization to 1, 2 or 4 bytes is supported.")}else if(!e.modelUrl)throw new Error("SemanticSegmentation can be constructed either by passing the weights URL or one of the supported base model names from 'pascal', 'cityscapes' and 'ade20k',together with the degree of quantization (either 1, 2 or 4).Aborting, since neither has been provided.");return[4,t.loadGraphModel(e.modelUrl||a(e.base,e.quantizationBytes))];case 1:return n=r.sent(),[2,new c(n,e.base)]}}))}))},e.toSegmentationImage=l,e.version="0.2.1",Object.defineProperty(e,"__esModule",{value:!0})}));
package/html/libs/posenet CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2019 Google LLC. All Rights Reserved.
3
+ * Copyright 2021 Google LLC. All Rights Reserved.
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
6
6
  * You may obtain a copy of the License at
@@ -14,4 +14,5 @@
14
14
  * limitations under the License.
15
15
  * =============================================================================
16
16
  */
17
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@tensorflow/tfjs-core"),require("@tensorflow/tfjs-converter")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-core","@tensorflow/tfjs-converter"],e):e(t.posenet={},t.tf,t.tf)}(this,function(t,e,r){"use strict";var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function i(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var o=function(){return(o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function u(t,e,r,n){return new(r||(r=Promise))(function(i,o){function u(t){try{a(n.next(t))}catch(t){o(t)}}function s(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){t.done?i(t.value):new r(function(e){e(t.value)}).then(u,s)}a((n=n.apply(t,e||[])).next())})}function s(t,e){var r,n,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,n=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(i=(i=u.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(6===o[0]&&u.label<i[1]){u.label=i[1],i=o;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(o);break}i[2]&&u.ops.pop(),u.trys.pop();continue}o=e.call(t,u)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var a=function(){function t(t,r){this.model=t,this.outputStride=r;var n=this.model.inputs[0].shape;e.util.assert(-1===n[1]&&-1===n[2],function(){return"Input shape ["+n[1]+", "+n[2]+"] must both be equal to or -1"})}return t.prototype.predict=function(t){var r=this;return e.tidy(function(){var e=r.preprocessInput(t.toFloat()).expandDims(0),n=r.model.predict(e).map(function(t){return t.squeeze([0])}),i=r.nameOutputResults(n);return{heatmapScores:i.heatmap.sigmoid(),offsets:i.offsets,displacementFwd:i.displacementFwd,displacementBwd:i.displacementBwd}})},t.prototype.dispose=function(){this.model.dispose()},t}(),l=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return i(r,t),r.prototype.preprocessInput=function(t){return e.tidy(function(){return e.div(t,127.5).sub(1)})},r.prototype.nameOutputResults=function(t){return{offsets:t[0],heatmap:t[1],displacementFwd:t[2],displacementBwd:t[3]}},r}(a);function f(t){return Math.floor(t/2)}var c=function(){function t(t,e){this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=e}return t.prototype.enqueue=function(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)},t.prototype.dequeue=function(){var t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t},t.prototype.empty=function(){return-1===this.numberOfElements},t.prototype.size=function(){return this.numberOfElements+1},t.prototype.all=function(){return this.priorityQueue.slice(0,this.numberOfElements+1)},t.prototype.max=function(){return this.priorityQueue[0]},t.prototype.swim=function(t){for(;t>0&&this.less(f(t),t);)this.exchange(t,f(t)),t=f(t)},t.prototype.sink=function(t){for(;2*t<=this.numberOfElements;){var e=2*t;if(e<this.numberOfElements&&this.less(e,e+1)&&e++,!this.less(t,e))break;this.exchange(t,e),t=e}},t.prototype.getValueAt=function(t){return this.getElementValue(this.priorityQueue[t])},t.prototype.less=function(t,e){return this.getValueAt(t)<this.getValueAt(e)},t.prototype.exchange=function(t,e){var r=this.priorityQueue[t];this.priorityQueue[t]=this.priorityQueue[e],this.priorityQueue[e]=r},t}();function p(t,e,r,n,i,o){for(var u=o.shape,s=u[0],a=u[1],l=!0,f=Math.max(r-i,0),c=Math.min(r+i+1,s),p=f;p<c;++p){for(var h=Math.max(n-i,0),d=Math.min(n+i+1,a),m=h;m<d;++m)if(o.get(p,m,t)>e){l=!1;break}if(!l)break}return l}var h=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],d=h.length,m=h.reduce(function(t,e,r){return t[e]=r,t},{}),y=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]],v=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]].map(function(t){var e=t[0],r=t[1];return[m[e],m[r]]});function g(t,e,r,n){return{y:n.get(t,e,r),x:n.get(t,e,r+d)}}function b(t,e,r){var n=g(t.heatmapY,t.heatmapX,t.id,r),i=n.y,o=n.x;return{x:t.heatmapX*e+o,y:t.heatmapY*e+i}}function w(t,e,r){return t<e?e:t>r?r:t}function x(t,e){return{x:t.x+e.x,y:t.y+e.y}}var _=y.map(function(t){var e=t[0],r=t[1];return[m[e],m[r]]}),S=_.map(function(t){return t[1]}),E=_.map(function(t){return t[0]});function M(t,e,r,n){return{y:w(Math.round(t.y/e),0,r-1),x:w(Math.round(t.x/e),0,n-1)}}function k(t,e,r,n,i,o,u,s){void 0===s&&(s=2);for(var a=n.shape,l=a[0],f=a[1],c=function(t,e,r){var n=r.shape[2]/2;return{y:r.get(e.y,e.x,t),x:r.get(e.y,e.x,n+t)}}(t,M(e.position,o,l,f),u),p=x(e.position,c),d=0;d<s;d++){var m=M(p,o,l,f),y=g(m.y,m.x,r,i);p=x({x:m.x*o,y:m.y*o},{x:y.x,y:y.y})}var v=M(p,o,l,f),b=n.get(v.y,v.x,r);return{position:p,part:h[r],score:b}}function O(t,e,r,n,i,o){var u=e.shape[2],s=S.length,a=new Array(u),l=t.part,f=t.score,c=b(l,n,r);a[l.id]={score:f,part:h[l.id],position:c};for(var p=s-1;p>=0;--p){var d=S[p],m=E[p];a[d]&&!a[m]&&(a[m]=k(p,a[d],m,e,r,n,o))}for(p=0;p<s;++p){d=E[p],m=S[p];a[d]&&!a[m]&&(a[m]=k(p,a[d],m,e,r,n,i))}return a}function I(t,e,r,n){var i=r.x,o=r.y;return t.some(function(t){var r,u,s,a,l,f,c=t.keypoints[n].position;return r=o,u=i,s=c.y,a=c.x,(l=s-r)*l+(f=a-u)*f<=e})}function j(t,e,r){return r.reduce(function(r,n,i){var o=n.position,u=n.score;return I(t,e,o,i)||(r+=u),r},0)/r.length}var R=1;function P(t,e,r,n,i,o,u,s){void 0===u&&(u=.5),void 0===s&&(s=20);for(var a=[],l=function(t,e,r){for(var n=r.shape,i=n[0],o=n[1],u=n[2],s=new c(i*o*u,function(t){return t.score}),a=0;a<i;++a)for(var l=0;l<o;++l)for(var f=0;f<u;++f){var h=r.get(a,l,f);h<t||p(f,h,a,l,e,r)&&s.enqueue({score:h,part:{heatmapY:a,heatmapX:l,id:f}})}return s}(u,R,t),f=s*s;a.length<o&&!l.empty();){var h=l.dequeue();if(!I(a,f,b(h.part,i,e),h.part.id)){var d=O(h,t,e,i,r,n),m=j(a,f,d);a.push({keypoints:d,score:m})}}return a}function N(t){var r=t.shape,n=r[0],i=r[1],o=r[2];return e.tidy(function(){var r,u,s=t.reshape([n*i,o]).argMax(0),a=s.div(e.scalar(i,"int32")).expandDims(1),l=(r=s,u=i,e.tidy(function(){var t=r.div(e.scalar(u,"int32"));return r.sub(t.mul(e.scalar(u,"int32")))})).expandDims(1);return e.concat([a,l],1)})}function B(t,e,r,n){return{y:n.get(t,e,r),x:n.get(t,e,r+d)}}function q(t,r,n){return e.tidy(function(){var i=function(t,r){for(var n=[],i=0;i<d;i++){var o=B(t.get(i,0).valueOf(),t.get(i,1).valueOf(),i,r),u=o.x,s=o.y;n.push(s),n.push(u)}return e.tensor2d(n,[d,2])}(t,n);return t.toTensor().mul(e.scalar(r,"int32")).toFloat().add(i)})}function A(t,e,r){return u(this,void 0,void 0,function(){var n,i,o,u,a,l,f,c,p,d;return s(this,function(s){switch(s.label){case 0:return n=0,i=N(t),[4,Promise.all([t.buffer(),e.buffer(),i.buffer()])];case 1:return o=s.sent(),u=o[0],a=o[1],l=o[2],[4,(f=q(l,r,a)).buffer()];case 2:return c=s.sent(),p=Array.from(function(t,e){for(var r=e.shape[0],n=new Float32Array(r),i=0;i<r;i++){var o=e.get(i,0),u=e.get(i,1);n[i]=t.get(o,u,i)}return n}(u,l)),d=p.map(function(t,e){return n+=t,{position:{y:c.get(e,0),x:c.get(e,1)},part:h[e],score:t}}),i.dispose(),f.dispose(),[2,{keypoints:d,score:n/d.length}]}})})}var H="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",F="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";var T=[-123.15,-115.9,-103.06],V=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.preprocessInput=function(t){return t.add(T)},e.prototype.nameOutputResults=function(t){var e=t[0],r=t[1];return{offsets:t[2],heatmap:t[3],displacementFwd:e,displacementBwd:r}},e}(a);var Y=Number.NEGATIVE_INFINITY,K=Number.POSITIVE_INFINITY;function Q(t){return t.reduce(function(t,e){var r=t.maxX,n=t.maxY,i=t.minX,o=t.minY,u=e.position,s=u.x,a=u.y;return{maxX:Math.max(r,s),maxY:Math.max(n,a),minX:Math.min(i,s),minY:Math.min(o,a)}},{maxX:Y,maxY:Y,minX:K,minY:K})}function X(t,e,r,n,i){return void 0===n&&(n=0),void 0===i&&(i=0),{score:t.score,keypoints:t.keypoints.map(function(t){var o=t.score,u=t.part,s=t.position;return{score:o,part:u,position:{x:s.x*r+i,y:s.y*e+n}}})}}function z(t,e){return G(t,e)?t:Math.floor(t/e)*e+1}function D(t){e.util.assert("number"==typeof t||"object"==typeof t,function(){return"Invalid inputResolution "+t+". Should be a number or an object with width and height"}),"object"==typeof t&&(e.util.assert("number"==typeof t.width,function(){return"inputResolution.width has a value of "+t.width+" which is invalid; it must be a number"}),e.util.assert("number"==typeof t.height,function(){return"inputResolution.height has a value of "+t.height+" which is invalid; it must be a number"}))}function W(t,e){return D(t),"object"==typeof t?[z(t.height,e),z(t.width,e)]:[z(t,e),z(t,e)]}var C=[8,16,32];function G(t,e){return(t-1)%e==0}function U(t){return t instanceof e.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}function J(t,r){var n=r[0],i=r[1],o=U(t),u=o[0],s=o[1],a=i/n,l=[0,0,0,0],f=l[0],c=l[1],p=l[2],h=l[3];return s/u<a?(f=0,c=0,p=Math.round(.5*(a*u-s)),h=Math.round(.5*(a*u-s))):(f=Math.round(.5*(1/a*s-u)),c=Math.round(.5*(1/a*s-u)),p=0,h=0),{resized:e.tidy(function(){var r=function(t){return t instanceof e.Tensor?t:e.browser.fromPixels(t)}(t);return(r=e.pad3d(r,[[f,c],[p,h],[0,0]])).resizeBilinear([n,i])}),padding:{top:f,left:p,right:h,bottom:c}}}function L(t,e,r,n,i){var o=e[0],u=e[1],s=r[0],a=r[1],l=function(t,e,r,n,i){return void 0===n&&(n=0),void 0===i&&(i=0),1===r&&1===e&&0===n&&0===i?t:t.map(function(t){return X(t,e,r,n,i)})}(t,(o+n.top+n.bottom)/s,(u+n.left+n.right)/a,-n.top,-n.left);return i?function(t,e){return e<=0?t:t.map(function(t){return function(t,e){return{score:t.score,keypoints:t.keypoints.map(function(t){var r=t.score,n=t.part,i=t.position;return{score:r,part:n,position:{x:e-1-i.x,y:i.y}}})}}(t,e)})}(l,u):l}var Z={architecture:"MobileNetV1",outputStride:16,multiplier:.75,inputResolution:257},$=["MobileNetV1","ResNet50"],tt={MobileNetV1:[8,16,32],ResNet50:[32,16]},et={MobileNetV1:[.5,.75,1],ResNet50:[1]},rt=[1,2,4];var nt={flipHorizontal:!1},it={flipHorizontal:!1,maxDetections:5,scoreThreshold:.5,nmsRadius:20};var ot=function(){function t(t,r){var n;n=t.outputStride,e.util.assert("number"==typeof n,function(){return"outputStride is not a number"}),e.util.assert(C.indexOf(n)>=0,function(){return"outputStride of "+n+" is invalid. It must be either 8, 16, or 32"}),function(t,r){e.util.assert("number"==typeof t[0]&&"number"==typeof t[1],function(){return"both resolution values must be a number but had values "+t}),e.util.assert(G(t[0],r),function(){return"height of "+t[0]+" is invalid for output stride "+r+"."}),e.util.assert(G(t[1],r),function(){return"width of "+t[1]+" is invalid for output stride "+r+"."})}(r,t.outputStride),this.baseModel=t,this.inputResolution=r}return t.prototype.estimateMultiplePoses=function(t,e){return void 0===e&&(e=it),u(this,void 0,void 0,function(){var r,n,i,a,l,f,c,p,h,d,m,y,v,g,b,w,x,_,S,E,M;return s(this,function(k){switch(k.label){case 0:return r=o({},it,e),function(t){var e=t.maxDetections,r=t.scoreThreshold,n=t.nmsRadius;if(e<=0)throw new Error("Invalid maxDetections "+e+". Should be > 0");if(r<0||r>1)throw new Error("Invalid scoreThreshold "+r+". Should be in range [0.0, 1.0]");if(n<=0)throw new Error("Invalid nmsRadius "+n+".")}(e),n=this.baseModel.outputStride,i=this.inputResolution,a=U(t),l=a[0],f=a[1],c=J(t,i),p=c.resized,h=c.padding,d=this.baseModel.predict(p),m=d.heatmapScores,y=d.offsets,v=d.displacementFwd,g=d.displacementBwd,[4,function(t){return u(this,void 0,void 0,function(){return s(this,function(e){return[2,Promise.all(t.map(function(t){return t.buffer()}))]})})}([m,y,v,g])];case 1:return b=k.sent(),w=b[0],x=b[1],_=b[2],S=b[3],[4,P(w,x,_,S,n,r.maxDetections,r.scoreThreshold,r.nmsRadius)];case 2:return E=k.sent(),M=L(E,[l,f],i,h,r.flipHorizontal),m.dispose(),y.dispose(),v.dispose(),g.dispose(),p.dispose(),[2,M]}})})},t.prototype.estimateSinglePose=function(t,e){return void 0===e&&(e=nt),u(this,void 0,void 0,function(){var r,n,i,u,a,l,f,c,p,h,d,m,y,v,g,b;return s(this,function(s){switch(s.label){case 0:return r=o({},nt,e),n=this.baseModel.outputStride,i=this.inputResolution,u=U(t),a=u[0],l=u[1],f=J(t,i),c=f.resized,p=f.padding,h=this.baseModel.predict(c),d=h.heatmapScores,m=h.offsets,y=h.displacementFwd,v=h.displacementBwd,[4,A(d,m,n)];case 1:return g=s.sent(),b=L([g],[a,l],i,p,r.flipHorizontal),d.dispose(),m.dispose(),y.dispose(),v.dispose(),c.dispose(),[2,b[0]]}})})},t.prototype.estimatePoses=function(t,e){return u(this,void 0,void 0,function(){return s(this,function(r){switch(r.label){case 0:return"single-person"!==e.decodingMethod?[3,2]:[4,this.estimateSinglePose(t,e)];case 1:return[2,[r.sent()]];case 2:return[2,this.estimateMultiplePoses(t,e)]}})})},t.prototype.dispose=function(){this.baseModel.dispose()},t}();function ut(t){return u(this,void 0,void 0,function(){var n,i,o,u,a,f,c;return s(this,function(s){switch(s.label){case 0:if(n=t.outputStride,i=t.quantBytes,o=t.multiplier,null==e)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return u=function(t,e,r){var n={1:"100",.75:"075",.5:"050"},i="model-stride"+t+".json";return 4===r?H+"float/"+n[e]+"/"+i:H+"quant"+r+"/"+n[e]+"/"+i}(n,o,i),[4,r.loadGraphModel(t.modelUrl||u)];case 1:return a=s.sent(),f=new l(a,n),c=W(t.inputResolution,f.outputStride),[2,new ot(f,c)]}})})}function st(t){return u(this,void 0,void 0,function(){var n,i,o,u,a,l;return s(this,function(s){switch(s.label){case 0:if(n=t.outputStride,i=t.quantBytes,null==e)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return o=function(t,e){var r="model-stride"+t+".json";return 4===e?F+"float/"+r:F+"quant"+e+"/"+r}(n,i),[4,r.loadGraphModel(t.modelUrl||o)];case 1:return u=s.sent(),a=new V(u,n),l=W(t.inputResolution,a.outputStride),[2,new ot(a,l)]}})})}t.decodeMultiplePoses=P,t.decodeSinglePose=A,t.MobileNet=l,t.partChannels=["left_face","right_face","right_upper_leg_front","right_lower_leg_back","right_upper_leg_back","left_lower_leg_front","left_upper_leg_front","left_upper_leg_back","left_lower_leg_back","right_feet","right_lower_leg_front","left_feet","torso_front","torso_back","right_upper_arm_front","right_upper_arm_back","right_lower_arm_back","left_lower_arm_front","left_upper_arm_front","left_upper_arm_back","left_lower_arm_back","right_hand","right_lower_arm_front","left_hand"],t.partIds=m,t.partNames=h,t.poseChain=y,t.load=function(t){return void 0===t&&(t=Z),u(this,void 0,void 0,function(){return s(this,function(e){return"ResNet50"===(t=function(t){if(null==(t=t||Z).architecture&&(t.architecture="MobileNetV1"),$.indexOf(t.architecture)<0)throw new Error("Invalid architecture "+t.architecture+". Should be one of "+$);if(null==t.inputResolution&&(t.inputResolution=257),D(t.inputResolution),null==t.outputStride&&(t.outputStride=16),tt[t.architecture].indexOf(t.outputStride)<0)throw new Error("Invalid outputStride "+t.outputStride+". Should be one of "+tt[t.architecture]+" for architecutre "+t.architecture+".");if(null==t.multiplier&&(t.multiplier=1),et[t.architecture].indexOf(t.multiplier)<0)throw new Error("Invalid multiplier "+t.multiplier+". Should be one of "+et[t.architecture]+" for architecutre "+t.architecture+".");if(null==t.quantBytes&&(t.quantBytes=4),rt.indexOf(t.quantBytes)<0)throw new Error("Invalid quantBytes "+t.quantBytes+". Should be one of "+rt+" for architecutre "+t.architecture+".");return t}(t)).architecture?[2,st(t)]:"MobileNetV1"===t.architecture?[2,ut(t)]:[2,null]})})},t.PoseNet=ot,t.getAdjacentKeyPoints=function(t,e){return v.reduce(function(r,n){var i=n[0],o=n[1];return function(t,e,r){return t<r||e<r}(t[i].score,t[o].score,e)?r:(r.push([t[i],t[o]]),r)},[])},t.getBoundingBox=Q,t.getBoundingBoxPoints=function(t){var e=Q(t),r=e.minX,n=e.minY,i=e.maxX,o=e.maxY;return[{x:r,y:n},{x:i,y:n},{x:i,y:o},{x:r,y:o}]},t.scaleAndFlipPoses=L,t.scalePose=X,t.version="2.2.1",Object.defineProperty(t,"__esModule",{value:!0})});
17
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@tensorflow/tfjs-core"),require("@tensorflow/tfjs-converter")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-core","@tensorflow/tfjs-converter"],e):e(t.posenet={},t.tf,t.tf)}(this,function(t,e,r){"use strict";var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function i(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var o=function(){return(o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function u(t,e,r,n){return new(r||(r=Promise))(function(i,o){function u(t){try{a(n.next(t))}catch(t){o(t)}}function s(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){t.done?i(t.value):new r(function(e){e(t.value)}).then(u,s)}a((n=n.apply(t,e||[])).next())})}function s(t,e){var r,n,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,n=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(i=(i=u.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(6===o[0]&&u.label<i[1]){u.label=i[1],i=o;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(o);break}i[2]&&u.ops.pop(),u.trys.pop();continue}o=e.call(t,u)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var a=function(){function t(t,r){this.model=t,this.outputStride=r;var n=this.model.inputs[0].shape;e.util.assert(-1===n[1]&&-1===n[2],function(){return"Input shape ["+n[1]+", "+n[2]+"] must both be equal to or -1"})}return t.prototype.predict=function(t){var r=this;return e.tidy(function(){var n=r.preprocessInput(e.cast(t,"float32")),i=e.expandDims(n,0),o=r.model.predict(i).map(function(t){return e.squeeze(t,[0])}),u=r.nameOutputResults(o);return{heatmapScores:e.sigmoid(u.heatmap),offsets:u.offsets,displacementFwd:u.displacementFwd,displacementBwd:u.displacementBwd}})},t.prototype.dispose=function(){this.model.dispose()},t}(),l=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return i(r,t),r.prototype.preprocessInput=function(t){return e.tidy(function(){return e.sub(e.div(t,127.5),1)})},r.prototype.nameOutputResults=function(t){return{offsets:t[0],heatmap:t[1],displacementFwd:t[2],displacementBwd:t[3]}},r}(a);function f(t){return Math.floor(t/2)}var c=function(){function t(t,e){this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=e}return t.prototype.enqueue=function(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)},t.prototype.dequeue=function(){var t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t},t.prototype.empty=function(){return-1===this.numberOfElements},t.prototype.size=function(){return this.numberOfElements+1},t.prototype.all=function(){return this.priorityQueue.slice(0,this.numberOfElements+1)},t.prototype.max=function(){return this.priorityQueue[0]},t.prototype.swim=function(t){for(;t>0&&this.less(f(t),t);)this.exchange(t,f(t)),t=f(t)},t.prototype.sink=function(t){for(;2*t<=this.numberOfElements;){var e=2*t;if(e<this.numberOfElements&&this.less(e,e+1)&&e++,!this.less(t,e))break;this.exchange(t,e),t=e}},t.prototype.getValueAt=function(t){return this.getElementValue(this.priorityQueue[t])},t.prototype.less=function(t,e){return this.getValueAt(t)<this.getValueAt(e)},t.prototype.exchange=function(t,e){var r=this.priorityQueue[t];this.priorityQueue[t]=this.priorityQueue[e],this.priorityQueue[e]=r},t}();function p(t,e,r,n,i,o){for(var u=o.shape,s=u[0],a=u[1],l=!0,f=Math.max(r-i,0),c=Math.min(r+i+1,s),p=f;p<c;++p){for(var h=Math.max(n-i,0),d=Math.min(n+i+1,a),m=h;m<d;++m)if(o.get(p,m,t)>e){l=!1;break}if(!l)break}return l}var h=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],d=h.length,m=h.reduce(function(t,e,r){return t[e]=r,t},{}),y=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]],v=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]].map(function(t){var e=t[0],r=t[1];return[m[e],m[r]]});function g(t,e,r,n){return{y:n.get(t,e,r),x:n.get(t,e,r+d)}}function b(t,e,r){var n=g(t.heatmapY,t.heatmapX,t.id,r),i=n.y,o=n.x;return{x:t.heatmapX*e+o,y:t.heatmapY*e+i}}function w(t,e,r){return t<e?e:t>r?r:t}function x(t,e){return{x:t.x+e.x,y:t.y+e.y}}var _=y.map(function(t){var e=t[0],r=t[1];return[m[e],m[r]]}),S=_.map(function(t){return t[1]}),E=_.map(function(t){return t[0]});function M(t,e,r,n){return{y:w(Math.round(t.y/e),0,r-1),x:w(Math.round(t.x/e),0,n-1)}}function k(t,e,r,n,i,o,u,s){void 0===s&&(s=2);for(var a=n.shape,l=a[0],f=a[1],c=function(t,e,r){var n=r.shape[2]/2;return{y:r.get(e.y,e.x,t),x:r.get(e.y,e.x,n+t)}}(t,M(e.position,o,l,f),u),p=x(e.position,c),d=0;d<s;d++){var m=M(p,o,l,f),y=g(m.y,m.x,r,i);p=x({x:m.x*o,y:m.y*o},{x:y.x,y:y.y})}var v=M(p,o,l,f),b=n.get(v.y,v.x,r);return{position:p,part:h[r],score:b}}function O(t,e,r,n,i,o){var u=e.shape[2],s=S.length,a=new Array(u),l=t.part,f=t.score,c=b(l,n,r);a[l.id]={score:f,part:h[l.id],position:c};for(var p=s-1;p>=0;--p){var d=S[p],m=E[p];a[d]&&!a[m]&&(a[m]=k(p,a[d],m,e,r,n,o))}for(p=0;p<s;++p){d=E[p],m=S[p];a[d]&&!a[m]&&(a[m]=k(p,a[d],m,e,r,n,i))}return a}function I(t,e,r,n){var i=r.x,o=r.y;return t.some(function(t){var r,u,s,a,l,f,c=t.keypoints[n].position;return r=o,u=i,s=c.y,a=c.x,(l=s-r)*l+(f=a-u)*f<=e})}function j(t,e,r){return r.reduce(function(r,n,i){var o=n.position,u=n.score;return I(t,e,o,i)||(r+=u),r},0)/r.length}var R=1;function N(t,e,r,n,i,o,u,s){void 0===u&&(u=.5),void 0===s&&(s=20);for(var a=[],l=function(t,e,r){for(var n=r.shape,i=n[0],o=n[1],u=n[2],s=new c(i*o*u,function(t){return t.score}),a=0;a<i;++a)for(var l=0;l<o;++l)for(var f=0;f<u;++f){var h=r.get(a,l,f);h<t||p(f,h,a,l,e,r)&&s.enqueue({score:h,part:{heatmapY:a,heatmapX:l,id:f}})}return s}(u,R,t),f=s*s;a.length<o&&!l.empty();){var h=l.dequeue();if(!I(a,f,b(h.part,i,e),h.part.id)){var d=O(h,t,e,i,r,n),m=j(a,f,d);a.push({keypoints:d,score:m})}}return a}function P(t){var r=t.shape,n=r[0],i=r[1],o=r[2];return e.tidy(function(){var r,u,s=e.reshape(t,[n*i,o]),a=e.argMax(s,0),l=e.expandDims(e.div(a,e.scalar(i,"int32")),1),f=e.expandDims((r=a,u=i,e.tidy(function(){var t=e.div(r,e.scalar(u,"int32"));return e.sub(r,e.mul(t,e.scalar(u,"int32")))})),1);return e.concat([l,f],1)})}function B(t,e,r,n){return{y:n.get(t,e,r),x:n.get(t,e,r+d)}}function q(t,r,n){return e.tidy(function(){var i=function(t,r){for(var n=[],i=0;i<d;i++){var o=B(t.get(i,0).valueOf(),t.get(i,1).valueOf(),i,r),u=o.x,s=o.y;n.push(s),n.push(u)}return e.tensor2d(n,[d,2])}(t,n);return e.add(e.cast(e.mul(t.toTensor(),e.scalar(r,"int32")),"float32"),i)})}function A(t,e,r){return u(this,void 0,void 0,function(){var n,i,o,u,a,l,f,c,p,d;return s(this,function(s){switch(s.label){case 0:return n=0,i=P(t),[4,Promise.all([t.buffer(),e.buffer(),i.buffer()])];case 1:return o=s.sent(),u=o[0],a=o[1],l=o[2],[4,(f=q(l,r,a)).buffer()];case 2:return c=s.sent(),p=Array.from(function(t,e){for(var r=e.shape[0],n=new Float32Array(r),i=0;i<r;i++){var o=e.get(i,0),u=e.get(i,1);n[i]=t.get(o,u,i)}return n}(u,l)),d=p.map(function(t,e){return n+=t,{position:{y:c.get(e,0),x:c.get(e,1)},part:h[e],score:t}}),i.dispose(),f.dispose(),[2,{keypoints:d,score:n/d.length}]}})})}var H="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",T="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";var V=[-123.15,-115.9,-103.06],Y=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return i(r,t),r.prototype.preprocessInput=function(t){return e.add(t,V)},r.prototype.nameOutputResults=function(t){var e=t[0],r=t[1];return{offsets:t[2],heatmap:t[3],displacementFwd:e,displacementBwd:r}},r}(a);var F=Number.NEGATIVE_INFINITY,K=Number.POSITIVE_INFINITY;function Q(t){return t.reduce(function(t,e){var r=t.maxX,n=t.maxY,i=t.minX,o=t.minY,u=e.position,s=u.x,a=u.y;return{maxX:Math.max(r,s),maxY:Math.max(n,a),minX:Math.min(i,s),minY:Math.min(o,a)}},{maxX:F,maxY:F,minX:K,minY:K})}function X(t,e,r,n,i){return void 0===n&&(n=0),void 0===i&&(i=0),{score:t.score,keypoints:t.keypoints.map(function(t){var o=t.score,u=t.part,s=t.position;return{score:o,part:u,position:{x:s.x*r+i,y:s.y*e+n}}})}}function z(t,e){return G(t,e)?t:Math.floor(t/e)*e+1}function D(t){e.util.assert("number"==typeof t||"object"==typeof t,function(){return"Invalid inputResolution "+t+". Should be a number or an object with width and height"}),"object"==typeof t&&(e.util.assert("number"==typeof t.width,function(){return"inputResolution.width has a value of "+t.width+" which is invalid; it must be a number"}),e.util.assert("number"==typeof t.height,function(){return"inputResolution.height has a value of "+t.height+" which is invalid; it must be a number"}))}function W(t,e){return D(t),"object"==typeof t?[z(t.height,e),z(t.width,e)]:[z(t,e),z(t,e)]}var C=[8,16,32];function G(t,e){return(t-1)%e==0}function U(t){return t instanceof e.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}function J(t,r){var n=r[0],i=r[1],o=U(t),u=o[0],s=o[1],a=i/n,l=[0,0,0,0],f=l[0],c=l[1],p=l[2],h=l[3];return s/u<a?(f=0,c=0,p=Math.round(.5*(a*u-s)),h=Math.round(.5*(a*u-s))):(f=Math.round(.5*(1/a*s-u)),c=Math.round(.5*(1/a*s-u)),p=0,h=0),{resized:e.tidy(function(){var r=function(t){return t instanceof e.Tensor?t:e.browser.fromPixels(t)}(t);return r=e.pad3d(r,[[f,c],[p,h],[0,0]]),e.image.resizeBilinear(r,[n,i])}),padding:{top:f,left:p,right:h,bottom:c}}}function L(t,e,r,n,i){var o=e[0],u=e[1],s=r[0],a=r[1],l=function(t,e,r,n,i){return void 0===n&&(n=0),void 0===i&&(i=0),1===r&&1===e&&0===n&&0===i?t:t.map(function(t){return X(t,e,r,n,i)})}(t,(o+n.top+n.bottom)/s,(u+n.left+n.right)/a,-n.top,-n.left);return i?function(t,e){return e<=0?t:t.map(function(t){return function(t,e){return{score:t.score,keypoints:t.keypoints.map(function(t){var r=t.score,n=t.part,i=t.position;return{score:r,part:n,position:{x:e-1-i.x,y:i.y}}})}}(t,e)})}(l,u):l}var Z={architecture:"MobileNetV1",outputStride:16,multiplier:.75,inputResolution:257},$=["MobileNetV1","ResNet50"],tt={MobileNetV1:[8,16,32],ResNet50:[32,16]},et={MobileNetV1:[.5,.75,1],ResNet50:[1]},rt=[1,2,4];var nt={flipHorizontal:!1},it={flipHorizontal:!1,maxDetections:5,scoreThreshold:.5,nmsRadius:20};var ot=function(){function t(t,r){var n;n=t.outputStride,e.util.assert("number"==typeof n,function(){return"outputStride is not a number"}),e.util.assert(C.indexOf(n)>=0,function(){return"outputStride of "+n+" is invalid. It must be either 8, 16, or 32"}),function(t,r){e.util.assert("number"==typeof t[0]&&"number"==typeof t[1],function(){return"both resolution values must be a number but had values "+t}),e.util.assert(G(t[0],r),function(){return"height of "+t[0]+" is invalid for output stride "+r+"."}),e.util.assert(G(t[1],r),function(){return"width of "+t[1]+" is invalid for output stride "+r+"."})}(r,t.outputStride),this.baseModel=t,this.inputResolution=r}return t.prototype.estimateMultiplePoses=function(t,e){return void 0===e&&(e=it),u(this,void 0,void 0,function(){var r,n,i,a,l,f,c,p,h,d,m,y,v,g,b,w,x,_,S,E,M;return s(this,function(k){switch(k.label){case 0:return r=o({},it,e),function(t){var e=t.maxDetections,r=t.scoreThreshold,n=t.nmsRadius;if(e<=0)throw new Error("Invalid maxDetections "+e+". Should be > 0");if(r<0||r>1)throw new Error("Invalid scoreThreshold "+r+". Should be in range [0.0, 1.0]");if(n<=0)throw new Error("Invalid nmsRadius "+n+".")}(e),n=this.baseModel.outputStride,i=this.inputResolution,a=U(t),l=a[0],f=a[1],c=J(t,i),p=c.resized,h=c.padding,d=this.baseModel.predict(p),m=d.heatmapScores,y=d.offsets,v=d.displacementFwd,g=d.displacementBwd,[4,function(t){return u(this,void 0,void 0,function(){return s(this,function(e){return[2,Promise.all(t.map(function(t){return t.buffer()}))]})})}([m,y,v,g])];case 1:return b=k.sent(),w=b[0],x=b[1],_=b[2],S=b[3],[4,N(w,x,_,S,n,r.maxDetections,r.scoreThreshold,r.nmsRadius)];case 2:return E=k.sent(),M=L(E,[l,f],i,h,r.flipHorizontal),m.dispose(),y.dispose(),v.dispose(),g.dispose(),p.dispose(),[2,M]}})})},t.prototype.estimateSinglePose=function(t,e){return void 0===e&&(e=nt),u(this,void 0,void 0,function(){var r,n,i,u,a,l,f,c,p,h,d,m,y,v,g,b;return s(this,function(s){switch(s.label){case 0:return r=o({},nt,e),n=this.baseModel.outputStride,i=this.inputResolution,u=U(t),a=u[0],l=u[1],f=J(t,i),c=f.resized,p=f.padding,h=this.baseModel.predict(c),d=h.heatmapScores,m=h.offsets,y=h.displacementFwd,v=h.displacementBwd,[4,A(d,m,n)];case 1:return g=s.sent(),b=L([g],[a,l],i,p,r.flipHorizontal),d.dispose(),m.dispose(),y.dispose(),v.dispose(),c.dispose(),[2,b[0]]}})})},t.prototype.estimatePoses=function(t,e){return u(this,void 0,void 0,function(){return s(this,function(r){switch(r.label){case 0:return"single-person"!==e.decodingMethod?[3,2]:[4,this.estimateSinglePose(t,e)];case 1:return[2,[r.sent()]];case 2:return[2,this.estimateMultiplePoses(t,e)]}})})},t.prototype.dispose=function(){this.baseModel.dispose()},t}();function ut(t){return u(this,void 0,void 0,function(){var n,i,o,u,a,f,c;return s(this,function(s){switch(s.label){case 0:if(n=t.outputStride,i=t.quantBytes,o=t.multiplier,null==e)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return u=function(t,e,r){var n={1:"100",.75:"075",.5:"050"},i="model-stride"+t+".json";return 4===r?H+"float/"+n[e]+"/"+i:H+"quant"+r+"/"+n[e]+"/"+i}(n,o,i),[4,r.loadGraphModel(t.modelUrl||u)];case 1:return a=s.sent(),f=new l(a,n),c=W(t.inputResolution,f.outputStride),[2,new ot(f,c)]}})})}function st(t){return u(this,void 0,void 0,function(){var n,i,o,u,a,l;return s(this,function(s){switch(s.label){case 0:if(n=t.outputStride,i=t.quantBytes,null==e)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return o=function(t,e){var r="model-stride"+t+".json";return 4===e?T+"float/"+r:T+"quant"+e+"/"+r}(n,i),[4,r.loadGraphModel(t.modelUrl||o)];case 1:return u=s.sent(),a=new Y(u,n),l=W(t.inputResolution,a.outputStride),[2,new ot(a,l)]}})})}t.decodeMultiplePoses=N,t.decodeSinglePose=A,t.MobileNet=l,t.partChannels=["left_face","right_face","right_upper_leg_front","right_lower_leg_back","right_upper_leg_back","left_lower_leg_front","left_upper_leg_front","left_upper_leg_back","left_lower_leg_back","right_feet","right_lower_leg_front","left_feet","torso_front","torso_back","right_upper_arm_front","right_upper_arm_back","right_lower_arm_back","left_lower_arm_front","left_upper_arm_front","left_upper_arm_back","left_lower_arm_back","right_hand","right_lower_arm_front","left_hand"],t.partIds=m,t.partNames=h,t.poseChain=y,t.load=function(t){return void 0===t&&(t=Z),u(this,void 0,void 0,function(){return s(this,function(e){return"ResNet50"===(t=function(t){if(null==(t=t||Z).architecture&&(t.architecture="MobileNetV1"),$.indexOf(t.architecture)<0)throw new Error("Invalid architecture "+t.architecture+". Should be one of "+$);if(null==t.inputResolution&&(t.inputResolution=257),D(t.inputResolution),null==t.outputStride&&(t.outputStride=16),tt[t.architecture].indexOf(t.outputStride)<0)throw new Error("Invalid outputStride "+t.outputStride+". Should be one of "+tt[t.architecture]+" for architecture "+t.architecture+".");if(null==t.multiplier&&(t.multiplier=1),et[t.architecture].indexOf(t.multiplier)<0)throw new Error("Invalid multiplier "+t.multiplier+". Should be one of "+et[t.architecture]+" for architecture "+t.architecture+".");if(null==t.quantBytes&&(t.quantBytes=4),rt.indexOf(t.quantBytes)<0)throw new Error("Invalid quantBytes "+t.quantBytes+". Should be one of "+rt+" for architecture "+t.architecture+".");if("MobileNetV1"===t.architecture&&32===t.outputStride&&1!==t.multiplier)throw new Error("When using an output stride of 32, you must select 1 as the multiplier.");return t}(t)).architecture?[2,st(t)]:"MobileNetV1"===t.architecture?[2,ut(t)]:[2,null]})})},t.PoseNet=ot,t.getAdjacentKeyPoints=function(t,e){return v.reduce(function(r,n){var i=n[0],o=n[1];return function(t,e,r){return t<r||e<r}(t[i].score,t[o].score,e)?r:(r.push([t[i],t[o]]),r)},[])},t.getBoundingBox=Q,t.getBoundingBoxPoints=function(t){var e=Q(t),r=e.minX,n=e.minY,i=e.maxX,o=e.maxY;return[{x:r,y:n},{x:i,y:n},{x:i,y:o},{x:r,y:o}]},t.scaleAndFlipPoses=L,t.scalePose=X,t.version="2.2.2",Object.defineProperty(t,"__esModule",{value:!0})});
18
+ //# sourceMappingURL=posenet.min.js.map