microsoft / customvision-tfjs

NPM package for TensorFlow.js models exported from Custom Vision Service
https://customvision.ai
MIT License
28 stars 22 forks source link

Memory leak in creation of tensor #7

Closed drmanhatin closed 3 years ago

drmanhatin commented 3 years ago

Hi,

There's a memory leak in this library. Happens after a few dozens of tensors have been created. I can show you on teams if you like, just send me a message.

My (working) implementation of tensorflowjs is accessible at https://github.com/drmanhatin/CustomVisionRealTime/blob/main/nodejsdemo/public/main.js.

Most important part:

   let t4d = tf.tidy(() => {
          const image = tf.browser.fromPixels(canvas).resizeBilinear([320, 320])
          return tf.tensor4d(image.dataSync(), [1, 320, 320, 3])
  })

Wrapping with tidy ensures automatic cleanup.

shonohs commented 3 years ago

Hello,

Thanks for reporting the issue. I will look into it and make a fix this week.

shonohs commented 3 years ago

Fixed the memory leak in f9c6003488ad86c8a5759a66d51e30fa6951cde9