使用 Apple PoseNet 模型的方法时内存泄漏
Memory leaks when using methods of Apple PoseNet model
我正在使用示例 «Detecting Human Body Poses in an Image» 中的代码(源代码可通过 link 下载获得)。
当我在我的 iPhone 7+ 上启动此代码时,在我的设备变热并且应用程序崩溃后,使用内存显着增加。
在我的代码中,我使用了 Posenet
class 的 predict
方法。调试后发现调用模型时出现问题,但不知道如何解决。
func predict(_ image: CGImage) {
DispatchQueue.global(qos: .userInitiated).async {
let input = PoseNetInput(image: image, size: self.modelInputSize)
//Problem is below
guard let prediction = try? self.poseNetMLModel.prediction(from: input) else {
return
}
//Problem is above
let poseNetOutput = PoseNetOutput(prediction: prediction,
modelInputSize: self.modelInputSize,
modelOutputStride: self.outputStride)
DispatchQueue.main.async {
self.delegate?.poseNet(self, didPredict: poseNetOutput)
}
}
}
方法是从 captureOutput
调用的。
问题是什么?如何解决?
P.S。
这是启动应用程序 1.5 分钟后的内存使用情况。当内存使用量达到 600 MGB 应用程序崩溃。
大量内存泄漏和 CVObject 内存使用。但我不知道如何解决它。
这是 iOS 版本的问题。它曾经是 iOS 13.0.1,当我将它更新到 13.5.1 时,问题就解决了。
我正在使用示例 «Detecting Human Body Poses in an Image» 中的代码(源代码可通过 link 下载获得)。
当我在我的 iPhone 7+ 上启动此代码时,在我的设备变热并且应用程序崩溃后,使用内存显着增加。
在我的代码中,我使用了 Posenet
class 的 predict
方法。调试后发现调用模型时出现问题,但不知道如何解决。
func predict(_ image: CGImage) {
DispatchQueue.global(qos: .userInitiated).async {
let input = PoseNetInput(image: image, size: self.modelInputSize)
//Problem is below
guard let prediction = try? self.poseNetMLModel.prediction(from: input) else {
return
}
//Problem is above
let poseNetOutput = PoseNetOutput(prediction: prediction,
modelInputSize: self.modelInputSize,
modelOutputStride: self.outputStride)
DispatchQueue.main.async {
self.delegate?.poseNet(self, didPredict: poseNetOutput)
}
}
}
方法是从 captureOutput
调用的。
问题是什么?如何解决?
P.S。
这是启动应用程序 1.5 分钟后的内存使用情况。当内存使用量达到 600 MGB 应用程序崩溃。
大量内存泄漏和 CVObject 内存使用。但我不知道如何解决它。
这是 iOS 版本的问题。它曾经是 iOS 13.0.1,当我将它更新到 13.5.1 时,问题就解决了。