Tensorflow AutoML内存问题(GPU中的内存使用率很高)

时间:2020-06-24 07:31:48

标签: javascript tensorflow memory-leaks automl

大家好。

我正在使用Tensorflow和AutomML识别给定图像上的特定标签的项目。我已经有一个训练有素的模型可以胜任这项工作。但是,我的内存有问题。根据图像大小,每隔一段时间(随着图像大小的增加,我会更频繁地)出现以下错误:

backend_webgl.ts:2767 High memory usage in GPU: 2232.56 MB, most likely due to a memory leak

此后,应用程序将无法在任何新(或旧)图像上检测到更多标签。为了使应用程序能够正常工作,我需要清除浏览器数据。

我的主要问题是该代码是继承的,以前的程序员不确定如何帮助我。我已尽力找到所有可能的东西,但似乎无济于事。主要问题是我无法找到一种在处理和映像后释放该内存的方法。我一直在尝试dispose() method,但是它什么也没做。我找不到使用AutoML时处理张量的任何示例。

这是代码。

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.4/dist/tf.min.js"></script>
<script src="https://unpkg.com/@tensorflow/tfjs-automl"></script>

let model;

// this method is used to load model
// callback is used to run detection once model is loaded
function loadModel(callback) {
  const MODEL_URL = 'model/model.json'

  tf.automl.loadObjectDetection(MODEL_URL).then(m => {
    model = m
    console.log("Loaded model");
    callback();

  });
}

// here the detection is made
async function detect(img) {
    const { width: imgWidth, height: imgHeight } = img
    const detections = await model.detect(img);
    return detections.map(({box, label, score}) => {
        const {left, top, width, height} = box
        const boxPercent = {
            left: left / imgWidth,
            top: top / imgHeight,
            width: width / imgWidth,
            height: height / imgHeight
        }
        return new Detection(boxPercent, label, score)
    });
}

现在,因为它是继承的,而且我是Tensorflow的新手,所以我被困在这里。我希望有人可以帮助我。

0 个答案:

没有答案