human/dist/human.node-nobundle.js

19 lines
245 KiB
JavaScript
Raw Normal View History

2020-11-16 21:51:46 +01:00
var __create=Object.create;var __defProp=Object.defineProperty;var __getProtoOf=Object.getPrototypeOf;var __hasOwnProp=Object.prototype.hasOwnProperty;var __getOwnPropNames=Object.getOwnPropertyNames;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __markAsModule=target=>__defProp(target,"__esModule",{value:true});var __commonJS=(callback,module2)=>()=>{if(!module2){module2={exports:{}};callback(module2.exports,module2)}return module2.exports};var __export=(target,all)=>{__markAsModule(target);for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __exportStar=(target,module2,desc)=>{__markAsModule(target);if(typeof module2==="object"||typeof module2==="function"){for(let key of __getOwnPropNames(module2))if(!__hasOwnProp.call(target,key)&&key!=="default")__defProp(target,key,{get:()=>module2[key],enumerable:!(desc=__getOwnPropDesc(module2,key))||desc.enumerable})}return target};var __toModule=module2=>{if(module2&&module2.__esModule)return module2;return __exportStar(__defProp(__create(__getProtoOf(module2)),"default",{value:module2,enumerable:true}),module2)};var require_blazeface=__commonJS(exports2=>{const NUM_LANDMARKS=6;function generateAnchors(inputSize){const spec={strides:[inputSize/16,inputSize/8],anchors:[2,6]};const anchors=[];for(let i=0;i<spec.strides.length;i++){const stride=spec.strides[i];const gridRows=Math.floor((inputSize+stride-1)/stride);const gridCols=Math.floor((inputSize+stride-1)/stride);const anchorsNum=spec.anchors[i];for(let gridY=0;gridY<gridRows;gridY++){const anchorY=stride*(gridY+.5);for(let gridX=0;gridX<gridCols;gridX++){const anchorX=stride*(gridX+.5);for(let n=0;n<anchorsNum;n++){anchors.push([anchorX,anchorY])}}}}return anchors}const disposeBox=box=>{box.startEndTensor.dispose();box.startPoint.dispose();box.endPoint.dispose()};const createBox=startEndTensor=>({startEndTensor,startPoint:tf.slice(startEndTensor,[0,0],[-1,2]),endPoint:tf.slice(startEndTensor,[0,2],[-1,2])});const scaleBox=(box,factors)=>{const starts=tf.mul(box.startPoint,factors);const ends=tf.mul(box.endPoint,factors);const newCoordinates=tf.concat2d([starts,ends],1);return createBox(newCoordinates)};function decodeBounds(boxOutputs,anchors,inputSize){const boxStarts=tf.slice(boxOutputs,[0,1],[-1,2]);const centers=tf.add(boxStarts,anchors);const boxSizes=tf.slice(boxOutputs,[0,3],[-1,2]);const boxSizesNormalized=tf.div(boxSizes,inputSize);const centersNormalized=tf.div(centers,inputSize);const halfBoxSize=tf.div(boxSizesNormalized,2);const starts=tf.sub(centersNormalized,halfBoxSize);const ends=tf.add(centersNormalized,halfBoxSize);const startNormalized=tf.mul(starts,inputSize);const endNormalized=tf.mul(ends,inputSize);const concatAxis=1;return tf.concat2d([startNormalized,endNormalized],concatAxis)}function scaleBoxFromPrediction(face2,scaleFactor){return tf.tidy(()=>{const box=face2["box"]?face2["box"]:face2;return scaleBox(box,scaleFactor).startEndTensor.squeeze()})}class BlazeFaceModel{constructor(model,config2){this.blazeFaceModel=model;this.width=config2.detector.inputSize;this.height=config2.detector.inputSize;this.anchorsData=generateAnchors(config2.detector.inputSize);this.anchors=tf.tensor2d(this.anchorsData);this.inputSize=tf.tensor1d([this.width,this.height]);this.config=config2;this.scaleFaces=.8}async getBoundingBoxes(inputImage){if(!inputImage||inputImage.isDisposedInternal||inputImage.shape.length!==4||inputImage.shape[1]<1||inputImage.shape[2]<1)return null;const[detectedOutputs,boxes,scores]=tf.tidy(()=>{const resizedImage=inputImage.resizeBilinear([this.width,this.height]);const normalizedImage=tf.sub(resizedImage.div(127.5),1);const batchedPrediction=this.blazeFaceModel.predict(normalizedImage);let prediction;if(Array.isArray(batchedPrediction)){const sorted=batchedPrediction.sort((a,b)=>a.size-b.size);const concat384=tf.concat([sorted[0],sorted[2]],2);const concat512=tf.concat([sorted[1],sorted[3]],2);const concat=tf.concat([concat512,concat384],1);prediction=concat.squeeze(0)}else{prediction=batchedPrediction.squeeze()}const decodedBounds=decodeBounds(prediction
2020-11-04 07:11:24 +01:00
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
//# sourceMappingURL=human.node-nobundle.js.map