( ort: OrtModule, preps: DetPreprocessResult[], maxH: number, maxW: number )
| 346 | } |
| 347 | |
| 348 | function 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 | |
| 375 | function packDetBatchTensor(ort: OrtModule, preps: DetPreprocessResult[]): Tensor { |
| 376 | const maxH = Math.max(...preps.map((p) => p.dstH)); |
no test coverage detected
searching dependent graphs…