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 ...

Get Deep Learning with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.