简体   繁体   中英

How can I delete a model in Tensorflow.js?

When reading the official documentation, I am aware that when handling Tensors directly one must explicitly destroy them after use to avoid memory leaks:

let mytensor = tf.tensor([1, 2, 3, 4]);
tf.dispose(mytensor);

However, what can one do to dispose of a model ? Is simply calling mymodel.dispose() enough, or is there something else I should do?

A model contains layers. Each layer contains weights that can be disposed. To dispose these weights, layer.dispose can be used.

model.layers.forEach(l => l.dispose())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM