The name of the closure, or the function to execute. If a name is provided, the 2nd argument should be the function. If debug mode is on, the timing and the memory usage of the function will be tracked and displayed on the console using the provided name.
Optional
fn: ScopeFn<T>The function to execute.
Executes the provided function
fn
and after it is executed, cleans up all intermediate tensors allocated byfn
except those returned byfn
.fn
must not return a Promise (async functions not allowed). The returned result can be a complex object.Using this method helps avoid memory leaks. In general, wrap calls to operations in
tf.tidy
for automatic memory cleanup.NOTE: Variables do not get cleaned up when inside a tidy(). If you want to dispose variables, please use
tf.disposeVariables
or call dispose() directly on variables.