How to use the @tensorflow-models/posenet/dist/util.getInputTensorDimensions function in @tensorflow-models/posenet

To help you get started, we’ve selected a few @tensorflow-models/posenet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googlecreativelab / teachablemachine-community / libraries / pose / src / custom-posenet.ts View on Github external
public async poseOutputsToKeypoints(
		input: PosenetInput,
		heatmapScores: tf.Tensor3D,
		offsets: tf.Tensor3D,
		displacementFwd: tf.Tensor3D,
		displacementBwd: tf.Tensor3D,
		padding: Padding,
		flipHorizontal = false
	) {
		const config = {
			maxDetections: MAX_PREDICTIONS,
			scoreThreshold: 0.5,
			nmsRadius: 20
		};

		const [height, width] = getInputTensorDimensions(input);

		const outputStride = this.posenetModel.baseModel.outputStride;
		const inputResolution = this.posenetModel.inputResolution;

		const [scoresBuffer, offsetsBuffer, displacementsFwdBuffer, displacementsBwdBuffer] 
			= await toTensorBuffers3D([heatmapScores, offsets, displacementFwd, displacementBwd]);

		const poses = await decodeMultiplePoses(scoresBuffer, offsetsBuffer, displacementsFwdBuffer,
			displacementsBwdBuffer, outputStride, config.maxDetections, config.scoreThreshold, config.nmsRadius);

		const resultPoses = scaleAndFlipPoses(poses, [height, width], inputResolution,
			padding, flipHorizontal);

		heatmapScores.dispose();
		offsets.dispose();
		displacementFwd.dispose();