I run a Keypoints detection model using tfjs and then post process it (still using tfjs). Then I use dataSync() on the final tensor in order to process it using JS. The dataSync() takes about 4 times more than the inference + post-processing time. I guess that it happens because dataSync() pulls the data from the GPU. Is there a way to make this process faster? Here's the code that I am using:
let output = model.execute(input_image_tensor);
let kpts = postProcess(output);
renderKpts(kpts.dataSync());
Thank you.
dataSync() pulls data from specific tensor, so it depends on tensor size - what is the value of kpts.shape?
there is no chance if its just a few keypoints that it takes more than a milisecond.
** update **
just tried using webgl backend, it's around ~5 microseconds
const tensor = tf.randomNormal([1, 4, 3]);
const time0 = performance.now();
const data = tensor.dataSync();
const time1 = performance.now();
console.log({ size: tensor.size, time: time1 - time0 });
{ "size": 12, "time": 0.004999995231628418 }