* Infer through PoseNet, and estimates multiple poses using the outputs. * This does standard ImageNet pre-processing before inferring through the * model. The image should pixels should have values [0-255]. It detects * multiple poses and finds their parts from part scores and displacement
(
input: PosenetInput,
config: MultiPersonInferenceConfig = MULTI_PERSON_INFERENCE_CONFIG)
| 277 | * in the same scale as the original image |
| 278 | */ |
| 279 | async estimateMultiplePoses( |
| 280 | input: PosenetInput, |
| 281 | config: MultiPersonInferenceConfig = MULTI_PERSON_INFERENCE_CONFIG): |
| 282 | Promise<Pose[]> { |
| 283 | const configWithDefaults: MultiPersonInferenceConfig = { |
| 284 | ...MULTI_PERSON_INFERENCE_CONFIG, |
| 285 | ...config |
| 286 | }; |
| 287 | |
| 288 | validateMultiPersonInputConfig(config); |
| 289 | |
| 290 | const outputStride = this.baseModel.outputStride; |
| 291 | const inputResolution = this.inputResolution; |
| 292 | |
| 293 | const [height, width] = getInputTensorDimensions(input); |
| 294 | |
| 295 | const {resized, padding} = padAndResizeTo(input, inputResolution); |
| 296 | |
| 297 | const {heatmapScores, offsets, displacementFwd, displacementBwd} = |
| 298 | this.baseModel.predict(resized); |
| 299 | |
| 300 | const allTensorBuffers = await toTensorBuffers3D( |
| 301 | [heatmapScores, offsets, displacementFwd, displacementBwd]); |
| 302 | |
| 303 | const scoresBuffer = allTensorBuffers[0]; |
| 304 | const offsetsBuffer = allTensorBuffers[1]; |
| 305 | const displacementsFwdBuffer = allTensorBuffers[2]; |
| 306 | const displacementsBwdBuffer = allTensorBuffers[3]; |
| 307 | |
| 308 | const poses = await decodeMultiplePoses( |
| 309 | scoresBuffer, offsetsBuffer, displacementsFwdBuffer, |
| 310 | displacementsBwdBuffer, outputStride, configWithDefaults.maxDetections, |
| 311 | configWithDefaults.scoreThreshold, configWithDefaults.nmsRadius); |
| 312 | |
| 313 | const resultPoses = scaleAndFlipPoses( |
| 314 | poses, [height, width], inputResolution, padding, |
| 315 | configWithDefaults.flipHorizontal); |
| 316 | |
| 317 | heatmapScores.dispose(); |
| 318 | offsets.dispose(); |
| 319 | displacementFwd.dispose(); |
| 320 | displacementBwd.dispose(); |
| 321 | resized.dispose(); |
| 322 | |
| 323 | return resultPoses; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Infer through PoseNet, and estimates a single pose using the outputs. |
no test coverage detected