【发布时间】:2021-07-05 12:26:50
【问题描述】:
问题
我在 Tensorflow JS 上运行一个多阶段对象检测网络。第一部分是一个单独的网络检测对象,然后将它们从主输入图像中删除。这些剪切图像的大小可能会有所不同,并直接馈送到执行另一次检测的第二个网络。
我的应用程序运行良好,但一段时间后内存不足。我发现内存增长的原因是剪切张量即使在处理它们之后仍然分配内存。
系统
- @tensorflow/tfjs v.3.7.0
- Microsoft Edge v.91.0.864.59
代码
while(running) {
tf.engine().startScope()
...
for(cutout count...)
...
const cropped_image = input_tensor.slice([ymin, xmin], crop_size)
const cropped_image_expanded = tf.expandDims(cropped_image, 0);
const pred = await this.props.models.ssd_2nd_stage.executeAsync(cropped_image_expanded);
tf.dispose(cropped_image);
tf.dispose(cropped_image_expanded);
...
}
...
console.log(tf.memory())
tf.engine().endScope()
tf.engine().disposeVariables()
}
日志
开头tf.memory() 显示:
{unreliable: false, numBytesInGPU: 136710800, numBytesInGPUAllocated: 563751816, numBytesInGPUFree: 427041016, numTensors: 1517, …}
过了一会儿……
{unreliable: false, numBytesInGPU: 136710800, numBytesInGPUAllocated: 615142084, numBytesInGPUFree: 478431284, numTensors: 1517, …}
您可以清楚地看到 TFJS 不会释放之前的 GPU 分配,这会在一段时间后导致 OOM 错误。
我有什么遗漏的吗?
【问题讨论】:
标签: javascript memory tensorflow.js