• Keeps a tf.Tensor generated inside a tf.tidy from being disposed automatically.

    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();

    Type Parameters

    Parameters

    • result: T

      The tensor to keep from being disposed.

    Returns T

    Doc

Generated using TypeDoc