You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currently handdetector.js module downloads all results and processes per-class scores in js before going back to tfjs
which causes large dataset transfers from tfjs backend
(either gpu (when used with webgl tfjs backend) or from within webassembly context (when used with wasm tfjs backend))
and then recreate required tensor and upload it back to tfjs backend
that is a double unnecessary round-trip for data plus cpu intensive processing loop in js
a much more efficient approach is to handle as much processing as possible using tfjs and only download final results
(not to mention much shorter code)
asyncfunctiondetectHands(input: Tensor,outputSize=[1,1]){consthands=tf.tidy(()=>{const[rawScores,rawBoxes]=awaitmodels.executeAsync(tensor,modelOutputNodes);constboxes=tf.squeeze(rawBoxes,[0,2]);// remove zero-dims constscores=tf.squeeze(rawScores,[0]);// remove zero-dims constclassScores=tf.unstack(scores,1);// split all-scores into individual per-class scoresconsthands=[];// now lets process data once per each class// could also be used to process only some classes, e.g. skip face if desiredfor(leti=0;i<classScores.length;i++){// get best results for each classnmsT=awaittf.image.nonMaxSuppressionAsync(boxes,classScores[i],maxDetected,iouThreshold,minConfidence);constnms=awaitnmsT.data();for(constresofnms){// now process only those best resultsconstboxSlice=tf.slice(t.boxes,res,1);// download just the box we needconstyxBox=awaitboxSlice.data();// convert [y1,x1,y1,x2] to [x,y,width,height]constboxRaw=[yxBox[1],yxBox[0],yxBox[3]-yxBox[1],yxBox[2]-yxBox[0]];// scale back to original resolutionconstbox=[Math.trunc(boxRaw[0]*outputSize[0]),Math.trunc(boxRaw[1]*outputSize[1]),Math.trunc(boxRaw[2]*outputSize[0]),Math.trunc(boxRaw[3]*outputSize[1])];constscoreSlice=tf.slice(classScores[i],res,1);// download just the score we needconstscore=awaitscoreSlice.data();consthand={score: score[0], box, boxRaw,class: classes[i]};hands.push(hand);}}returnhands;})}
i'd post this as PR, but it's total change of the library, so posting here instead...
.hth.
The text was updated successfully, but these errors were encountered:
vladmandic
changed the title
post-processing optimization suggestion
post-processing optimization suggestion (with code)
Sep 21, 2021
currently
handdetector.js
module downloads all results and processes per-class scores in js before going back to tfjswhich causes large dataset transfers from tfjs backend
(either gpu (when used with
webgl
tfjs backend) or from within webassembly context (when used withwasm
tfjs backend))and then recreate required tensor and upload it back to tfjs backend
that is a double unnecessary round-trip for data plus cpu intensive processing loop in js
a much more efficient approach is to handle as much processing as possible using tfjs and only download final results
(not to mention much shorter code)
i'd post this as PR, but it's total change of the library, so posting here instead...
.hth.
The text was updated successfully, but these errors were encountered: