Keeps a tf.Tensor generated inside a tf.tidy from being disposed automatically.
tf.Tensor
tf.tidy
let b;const y = tf.tidy(() => { const one = tf.scalar(1); const a = tf.scalar(2); // b will not be cleaned up by the tidy. a and one will be cleaned up // when the tidy ends. b = tf.keep(a.square()); console.log('numTensors (in tidy): ' + tf.memory().numTensors); // The value returned inside the tidy function will return // through the tidy, in this case to the variable y. return b.add(one);});console.log('numTensors (outside tidy): ' + tf.memory().numTensors);console.log('y:');y.print();console.log('b:');b.print(); Copy
let b;const y = tf.tidy(() => { const one = tf.scalar(1); const a = tf.scalar(2); // b will not be cleaned up by the tidy. a and one will be cleaned up // when the tidy ends. b = tf.keep(a.square()); console.log('numTensors (in tidy): ' + tf.memory().numTensors); // The value returned inside the tidy function will return // through the tidy, in this case to the variable y. return b.add(one);});console.log('numTensors (outside tidy): ' + tf.memory().numTensors);console.log('y:');y.print();console.log('b:');b.print();
The tensor to keep from being disposed.
Generated using TypeDoc
Keeps a
tf.Tensor
generated inside atf.tidy
from being disposed automatically.