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

Function padAndResizeTo

posenet/src/util.ts:220–249  ·  view source on GitHub ↗
(
    input: PosenetInput, [targetH, targetW]: [number, number])

Source from the content-addressed store, hash-verified

218}
219
220export function padAndResizeTo(
221 input: PosenetInput, [targetH, targetW]: [number, number]):
222 {resized: tf.Tensor3D, padding: Padding} {
223 const [height, width] = getInputTensorDimensions(input);
224 const targetAspect = targetW / targetH;
225 const aspect = width / height;
226 let [padT, padB, padL, padR] = [0, 0, 0, 0];
227 if (aspect < targetAspect) {
228 // pads the width
229 padT = 0;
230 padB = 0;
231 padL = Math.round(0.5 * (targetAspect * height - width));
232 padR = Math.round(0.5 * (targetAspect * height - width));
233 } else {
234 // pads the height
235 padT = Math.round(0.5 * ((1.0 / targetAspect) * width - height));
236 padB = Math.round(0.5 * ((1.0 / targetAspect) * width - height));
237 padL = 0;
238 padR = 0;
239 }
240
241 const resized: tf.Tensor3D = tf.tidy(() => {
242 let imageTensor = toInputTensor(input);
243 imageTensor = tf.pad3d(imageTensor, [[padT, padB], [padL, padR], [0, 0]]);
244
245 return tf.image.resizeBilinear(imageTensor, [targetH, targetW]);
246 });
247
248 return {resized, padding: {top: padT, left: padL, right: padR, bottom: padB}};
249}
250
251export function scaleAndFlipPoses(
252 poses: Pose[], [height, width]: [number, number],

Callers 2

estimateMultiplePosesMethod · 0.90
estimateSinglePoseMethod · 0.90

Calls 2

getInputTensorDimensionsFunction · 0.70
toInputTensorFunction · 0.70

Tested by

no test coverage detected