Skip to content

Commit 4968e0f

Browse files
committed
change more arraySync
1 parent 7fbc49c commit 4968e0f

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/ssdMobilenetv1/SsdMobilenetv1.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,16 @@ export class SsdMobilenetv1 extends NeuralNetwork<NetParams> {
8585
const padX = inputSize / reshapedDims.width
8686
const padY = inputSize / reshapedDims.height
8787

88+
const boxesData = boxes.arraySync()
8889
const results = indices
8990
.map(idx => {
9091
const [top, bottom] = [
91-
Math.max(0, boxes.arraySync()[idx][0]),
92-
Math.min(1.0, boxes.arraySync()[idx][2])
92+
Math.max(0, boxesData[idx][0]),
93+
Math.min(1.0, boxesData[idx][2])
9394
].map(val => val * padY)
9495
const [left, right] = [
95-
Math.max(0, boxes.arraySync()[idx][1]),
96-
Math.min(1.0, boxes.arraySync()[idx][3])
96+
Math.max(0, boxesData[idx][1]),
97+
Math.min(1.0, boxesData[idx][3])
9798
].map(val => val * padX)
9899
return new FaceDetection(
99100
scoresData[idx],

src/ssdMobilenetv1/nonMaxSuppression.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ export function nonMaxSuppression(
4949
}
5050

5151
function IOU(boxes: tf.Tensor2D, i: number, j: number) {
52-
const yminI = Math.min(boxes.arraySync()[i][0], boxes.arraySync()[i][2])
53-
const xminI = Math.min(boxes.arraySync()[i][1], boxes.arraySync()[i][3])
54-
const ymaxI = Math.max(boxes.arraySync()[i][0], boxes.arraySync()[i][2])
55-
const xmaxI = Math.max(boxes.arraySync()[i][1], boxes.arraySync()[i][3])
56-
const yminJ = Math.min(boxes.arraySync()[j][0], boxes.arraySync()[j][2])
57-
const xminJ = Math.min(boxes.arraySync()[j][1], boxes.arraySync()[j][3])
58-
const ymaxJ = Math.max(boxes.arraySync()[j][0], boxes.arraySync()[j][2])
59-
const xmaxJ = Math.max(boxes.arraySync()[j][1], boxes.arraySync()[j][3])
52+
const boxesData = boxes.arraySync()
53+
const yminI = Math.min(boxesData[i][0], boxesData[i][2])
54+
const xminI = Math.min(boxesData[i][1], boxesData[i][3])
55+
const ymaxI = Math.max(boxesData[i][0], boxesData[i][2])
56+
const xmaxI = Math.max(boxesData[i][1], boxesData[i][3])
57+
const yminJ = Math.min(boxesData[j][0], boxesData[j][2])
58+
const xminJ = Math.min(boxesData[j][1], boxesData[j][3])
59+
const ymaxJ = Math.max(boxesData[j][0], boxesData[j][2])
60+
const xmaxJ = Math.max(boxesData[j][1], boxesData[j][3])
6061
const areaI = (ymaxI - yminI) * (xmaxI - xminI)
6162
const areaJ = (ymaxJ - yminJ) * (xmaxJ - xminJ)
6263
if (areaI <= 0 || areaJ <= 0) {

0 commit comments

Comments
 (0)