B.3. Memory management in TensorFlow.js: tf.dispose() and tf.tidy()
In TensorFlow.js, if you deal directly with tensor objects, you need to perform memory management on them. In particular, a tensor needs to be disposed after creation and use, or it will continue to occupy the memory allocated for it. If undisposed tensors become too many in number or too large in their total size, they will eventually cause the browser tab to run out of WebGL memory or cause the Node.js process to run out of system or GPU memory (depending on whether the CPU or GPU version of tfjs-node is being used). TensorFlow.js does not perform automatic garbage collection of user-created tensors.[5] This is because JavaScript does not support object finalization. TensorFlow.js ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access