MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / createBatchDetTensor

Function createBatchDetTensor

paddleocr-js/packages/core/src/models/det.ts:348–373  ·  view source on GitHub ↗
(
  ort: OrtModule,
  preps: DetPreprocessResult[],
  maxH: number,
  maxW: number
)

Source from the content-addressed store, hash-verified

346}
347
348function createBatchDetTensor(
349 ort: OrtModule,
350 preps: DetPreprocessResult[],
351 maxH: number,
352 maxW: number
353): Tensor {
354 const batch = preps.length;
355 const plane = 3 * maxH * maxW;
356 const out = new Float32Array(batch * plane);
357 for (let i = 0; i < batch; i += 1) {
358 const prep = preps[i];
359 const chw = prep.tensor.data as Float32Array;
360 const { dstH, dstW } = prep;
361 const base = i * plane;
362 for (let c = 0; c < 3; c += 1) {
363 const srcChannelBase = c * dstH * dstW;
364 const dstChannelBase = base + c * maxH * maxW;
365 for (let y = 0; y < dstH; y += 1) {
366 const srcRow = srcChannelBase + y * dstW;
367 const dstRow = dstChannelBase + y * maxW;
368 out.set(chw.subarray(srcRow, srcRow + dstW), dstRow);
369 }
370 }
371 }
372 return new ort.Tensor("float32", out, [batch, 3, maxH, maxW]);
373}
374
375function packDetBatchTensor(ort: OrtModule, preps: DetPreprocessResult[]): Tensor {
376 const maxH = Math.max(...preps.map((p) => p.dstH));

Callers 1

packDetBatchTensorFunction · 0.85

Calls 1

setMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…