(
heatmapScores: tf.Tensor3D, offsets: tf.Tensor3D,
outputStride: PoseNetOutputStride)
| 55 | * and position. |
| 56 | */ |
| 57 | export async function decodeSinglePose( |
| 58 | heatmapScores: tf.Tensor3D, offsets: tf.Tensor3D, |
| 59 | outputStride: PoseNetOutputStride): Promise<Pose> { |
| 60 | let totalScore = 0.0; |
| 61 | |
| 62 | const heatmapValues = argmax2d(heatmapScores); |
| 63 | |
| 64 | const allTensorBuffers = await Promise.all( |
| 65 | [heatmapScores.buffer(), offsets.buffer(), heatmapValues.buffer()]); |
| 66 | |
| 67 | const scoresBuffer = allTensorBuffers[0]; |
| 68 | const offsetsBuffer = allTensorBuffers[1]; |
| 69 | const heatmapValuesBuffer = allTensorBuffers[2]; |
| 70 | |
| 71 | const offsetPoints = |
| 72 | getOffsetPoints(heatmapValuesBuffer, outputStride, offsetsBuffer); |
| 73 | const offsetPointsBuffer = await offsetPoints.buffer(); |
| 74 | |
| 75 | const keypointConfidence = |
| 76 | Array.from(getPointsConfidence(scoresBuffer, heatmapValuesBuffer)); |
| 77 | |
| 78 | const keypoints = keypointConfidence.map((score, keypointId): Keypoint => { |
| 79 | totalScore += score; |
| 80 | return { |
| 81 | position: { |
| 82 | y: offsetPointsBuffer.get(keypointId, 0), |
| 83 | x: offsetPointsBuffer.get(keypointId, 1) |
| 84 | }, |
| 85 | part: partNames[keypointId], |
| 86 | score |
| 87 | }; |
| 88 | }); |
| 89 | |
| 90 | heatmapValues.dispose(); |
| 91 | offsetPoints.dispose(); |
| 92 | |
| 93 | return {keypoints, score: totalScore / keypoints.length}; |
| 94 | } |
no test coverage detected