TensorflowLite iOS 示例问题

TensorflowLite iOS example issue

我已经从GitHub官方账号下载了iOS的tensorflowlite Posenet示例

https://github.com/tensorflow/examples/tree/master/lite/examples/posenet/ios

我可以 运行 设备上的示例,但出现以下错误

2021-05-18 00:57:50.385071+0530 PoseNet[8112:3939417] 调整大小错误:源图像比例和目标图像比例不同 2021-05-18 00:57:50.385531+0530 PoseNet[8112:3939417] 预处理失败 2021-05-18 00:57:50.385797+0530 PoseNet[8112:3939417] 无法获得推理结果。

有没有人遇到过这个问题,我们如何解决?

我的解决方案在这里。

  1. 转到 CVPixelBufferExtension.swift 文件。

  2. 第 32 行:func resize(从来源:CGRect,到大小:CGSize)-> CVPixelBuffer? 请禁用以下代码。

    //    guard abs(rect.size.width / rect.size.height - source.size.width / source.size.height) < 1e-5
    //    else {
    //      os_log(
    //        "Resizing Error: source image ratio and destination image ratio is different",
    //        type: .error)
    //      return nil
    //    }
    

Explanation: The resize function first checks if the current buffer rect contains the source rect with this code guard rect.contains(source) else. and the resize function actually crops the area of the frames from camera. so it doesn't need to validate the aspect ratio. That's why We can safely disable the code.