File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { tf } from '..' ;
1
2
import { BoundingBox } from './BoundingBox' ;
2
3
import { extractImagePatches } from './extractImagePatches' ;
3
4
import { nms } from './nms' ;
@@ -26,8 +27,12 @@ export async function stage2(
26
27
)
27
28
stats . stage2_rnet = Date . now ( ) - ts
28
29
29
- const scoreDatas = await Promise . all ( rnetOuts . map ( out => out . scores . data ( ) ) )
30
- const scores = scoreDatas . map ( arr => Array . from ( arr ) ) . reduce ( ( all , arr ) => all . concat ( arr ) )
30
+ const scoresTensor = rnetOuts . length > 1
31
+ ? tf . concat ( rnetOuts . map ( out => out . scores ) )
32
+ : rnetOuts [ 0 ] . scores
33
+ const scores = Array . from ( await scoresTensor . data ( ) )
34
+ scoresTensor . dispose ( )
35
+
31
36
const indices = scores
32
37
. map ( ( score , idx ) => ( { score, idx } ) )
33
38
. filter ( c => c . score > scoreThreshold )
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { extractImagePatches } from './extractImagePatches';
4
4
import { nms } from './nms' ;
5
5
import { ONet } from './ONet' ;
6
6
import { ONetParams } from './types' ;
7
+ import { tf } from '..' ;
7
8
8
9
export async function stage3 (
9
10
img : HTMLCanvasElement ,
@@ -27,8 +28,12 @@ export async function stage3(
27
28
)
28
29
stats . stage3_onet = Date . now ( ) - ts
29
30
30
- const scoreDatas = await Promise . all ( onetOuts . map ( out => out . scores . data ( ) ) )
31
- const scores = scoreDatas . map ( arr => Array . from ( arr ) ) . reduce ( ( all , arr ) => all . concat ( arr ) )
31
+ const scoresTensor = onetOuts . length > 1
32
+ ? tf . concat ( onetOuts . map ( out => out . scores ) )
33
+ : onetOuts [ 0 ] . scores
34
+ const scores = Array . from ( await scoresTensor . data ( ) )
35
+ scoresTensor . dispose ( )
36
+
32
37
const indices = scores
33
38
. map ( ( score , idx ) => ( { score, idx } ) )
34
39
. filter ( c => c . score > scoreThreshold )
You can’t perform that action at this time.
0 commit comments