How to draw tensor3D type image data (RGB) to screen by WebGL?
I want to draw image data in a tensor3D (It's shape is [height, width, 3]) to screen by WebGL instead downloading the data from GPU. Because outPixels.dataSync() is too slow.
How big is your image? I've been doing some timing tests and it looks like downloading pixels isn't that slow, it's usually the entire graph that is slow. One way you can test this is:
var start = performance.now();
var y = model(x);
for (var i = 0; i < 9; i++) y = y.add(model(x));
y.dataSync();
var duration = performance.now() - start;
This only requires one texture download, but you can divide duration by 10 to get (approximately) the run time of your model.
@kylemcdonald Thank you for your reply. The width and height of my image are 1800 and 1656. It takes about 4s to download the data from GPU. I want to display this image on a canvas quickly in a image supper resolution application.
Is it possible to provide a renderTensorPixels2Canvas(pixels, canvas) method to render the corresponding texture data to specified canvas directly?
+1 dataSync() blocks until all GPU operations are done, the timing of that function is not just the download. We've seen that rendering with WebGL isn't fast enough to warrant the complexity. If you don't want to block the UI thread in the meantime, you can call await result.data() and then tf.toPixels(result).
Folks
Need help here. The model execution time is very good but dataSync is taking enormous amount of time. This is making lot of models 'not' real-time. Any thoughts or suggestions. Apparently downloading smaller tensors is much faster e.g. downloading tensor with 2 numbers takes about 5-10ms while 50 numbers tensor takes good 50ms.
Thanks for all the suggestions in advance.
Hi @rajeev-tbrew, the profiling time of the dataSync is not indicative of the download time. dataSync blocks the UI thread until all of the work is done and the download is complete. The actual time of a download is pretty cheap, overall. A slow dataSync of a predictions means your model is too large, try reducing the size of the model!
Nikhil
It's possible that I am misunderstanding your suggestions. I have measured how much time model.predict takes and how much time datasync takes. The model predict time is about 12ms while datasync is almost 50ms. I did same analysis with faceapi.js models. BTW, on a machine with nvidia 1060, datasync for the same model is about 10ms. Pls note model.predict time remains same on both machines. Please do let me know if you need any further information. Thanks a lot for all your help.
On Wed, 31 Oct 2018, 8:02 pm Nikhil Thorat <[email protected] wrote:
Hi @rajeev-tbrew https://github.com/rajeev-tbrew, the profiling time of the dataSync is not indicative of the download time. dataSync blocks the UI thread until all of the work is done and the download is complete. The actual time of a download is pretty cheap, overall. A slow dataSync of a predictions means your model is too large, try reducing the size of the model!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tensorflow/tfjs/issues/351#issuecomment-434709493, or mute the thread https://github.com/notifications/unsubscribe-auth/Ak0dzTON1d1kErT0Rs3QdLx124rSgDloks5uqbRvgaJpZM4UPwfC .
If you time a model.predict() the only thing you are actually measuring is the time it takes to schedule the operations on the GPU, not the actual time it takes to run them (calling ops are sync, if we synced at each op call then you would block the UI thread). The synchronization between CPU and GPU happens with a dataSync or a data call -- to time a predict properly (meaning, time all of the operations from start to finish on the GPU) you must introduce a sync between the CPU and GPU.
Hope this helps.
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!