MCPcopy
hub / github.com/tensorflow/tfjs-models / decodeSinglePose

Function decodeSinglePose

posenet/src/single_pose/decode_single_pose.ts:57–94  ·  view source on GitHub ↗
(
    heatmapScores: tf.Tensor3D, offsets: tf.Tensor3D,
    outputStride: PoseNetOutputStride)

Source from the content-addressed store, hash-verified

55 * and position.
56 */
57export 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}

Callers 1

estimateSinglePoseMethod · 0.90

Calls 5

argmax2dFunction · 0.90
getOffsetPointsFunction · 0.90
getPointsConfidenceFunction · 0.90
disposeMethod · 0.65
allMethod · 0.45

Tested by

no test coverage detected