且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

张量已处置

更新时间:2023-12-04 20:44:58

处理张量是因为您在使用张量之前先调用 tf.tidy .要使用张量 img 并清除所有中间张量,必须从 tf.tidy

The tensors are disposed because you call tf.tidy before using them. To use the tensor img and clean all intermediates tensors, it has to be explicitly returned from the callback of tf.tidy

const img = tf.tidy(() => {
        const im = getImage();
        return im;
        // since im is returned, it will not be disposed;
        // but all unused intermediate tensors will be cleaned up
     })

images.push(img)
labels.push(label) // labels are 0,1,2