Tensorflow.js不会释放内存

时间:2019-07-28 19:19:21

标签: javascript tensorflow tensorflow.js

运行机器学习代码后,我注意到tf.memory()返回的是大值。我尝试遍历代码并修复潜在的内存泄漏,但是tf.memory()仍然显示较大的值。然后,我尝试使用tf.disposeVariables()来为我清理所有泄漏,例如:

  console.log(tf.memory())
  tf.disposeVariables()                                                                                                                                                                                                                                                                
  await sleep(1000)                                                                                                                                                                    
  console.log(tf.memory())                                                                                                                                                             
  await sleep(3000)                                                                                                                                                                    
  console.log(tf.memory())                                                                                                                                                             
  await sleep(6000)                                                                                                                                                                    
  console.log(tf.memory())                                                                                                                                                             
  await sleep(9000)                                                                                                                                                                    
  console.log(tf.memory())

并输出:

{ unreliable: true,
  numTensors: 7731,
  numDataBuffers: 7731,
  numBytes: 283828 }
{ unreliable: true,
  numTensors: 7717,
  numDataBuffers: 7717,
  numBytes: 283244 }
{ unreliable: true,
  numTensors: 7717,
  numDataBuffers: 7717,
  numBytes: 283244 }
{ unreliable: true,
  numTensors: 7717,
  numDataBuffers: 7717,
  numBytes: 283244 }
{ unreliable: true,
  numTensors: 7717,
  numDataBuffers: 7717,
  numBytes: 283244 }

看来张量分配没有被删除。可能是什么原因造成的?

0 个答案:

没有答案