( context: DetRunContext, fullOutput: Tensor, preps: DetPreprocessResult[], params: InternalDetParams )
| 417 | } |
| 418 | |
| 419 | function postprocess( |
| 420 | context: DetRunContext, |
| 421 | fullOutput: Tensor, |
| 422 | preps: DetPreprocessResult[], |
| 423 | params: InternalDetParams |
| 424 | ): InternalDetBatchItem[] { |
| 425 | const { cv, ort, config } = context; |
| 426 | const od = fullOutput.dims; |
| 427 | if (od.length !== 3 && od.length !== 4) { |
| 428 | throw new Error(`Unexpected det output dims: [${od.join(", ")}]`); |
| 429 | } |
| 430 | const ohFull = od.length === 4 ? od[2] : od[1]; |
| 431 | const owFull = od.length === 4 ? od[3] : od[2]; |
| 432 | const nOut = od.length === 4 ? od[0] : preps.length === 1 ? 1 : od[0]; |
| 433 | if (nOut !== preps.length) { |
| 434 | throw new Error( |
| 435 | `Detection batch output N=${String(nOut)} does not match input batch ${String(preps.length)}` |
| 436 | ); |
| 437 | } |
| 438 | |
| 439 | const maxH = Math.max(...preps.map((p) => p.dstH)); |
| 440 | const maxW = Math.max(...preps.map((p) => p.dstW)); |
| 441 | |
| 442 | const items: InternalDetBatchItem[] = []; |
| 443 | for (let i = 0; i < preps.length; i += 1) { |
| 444 | const prep = preps[i]; |
| 445 | const { cropOh, cropOw } = detFeatureCropDims(prep.dstH, prep.dstW, maxH, maxW, ohFull, owFull); |
| 446 | const planeTensor = sliceBatchedDetOutputPlane( |
| 447 | ort, |
| 448 | fullOutput, |
| 449 | i, |
| 450 | cropOh, |
| 451 | cropOw, |
| 452 | ohFull, |
| 453 | owFull |
| 454 | ); |
| 455 | const boxes = decodeDetOutput( |
| 456 | { cv, config }, |
| 457 | planeTensor, |
| 458 | prep, |
| 459 | params.thresh, |
| 460 | params.boxThresh, |
| 461 | params.unclipRatio |
| 462 | ); |
| 463 | items.push({ prep, boxes }); |
| 464 | } |
| 465 | return items; |
| 466 | } |
| 467 | |
| 468 | function decodeDetOutput( |
| 469 | context: { cv: OpenCv; config: DetModelConfig }, |
no test coverage detected
searching dependent graphs…