(
input: PosenetInput, [targetH, targetW]: [number, number])
| 218 | } |
| 219 | |
| 220 | export 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 | |
| 251 | export function scaleAndFlipPoses( |
| 252 | poses: Pose[], [height, width]: [number, number], |
no test coverage detected