问题描述
我正在使用CoreML进行图像分割。我有一个VNCoreMLRequest来运行返回MLMultiArray的模型。为了加快处理模型输出的速度,我使用MPSNNReduceFeatureChannelsArgumentMax将多数组输出缩减为2D数组,然后将其转换为灰度图像。
这在iOS上效果很好,但是当在Mac上作为催化剂构建运行时,输出2D数组全为零。
我正在iMac Pro上运行版本12.2 beta 2(12B5025f)。我没有看到任何运行时错误。 MPSNNReduceFeatureChannelsArgumentMax似乎在Mac Catalyst上不起作用。 我可以通过遍历所有数组维来直接减少cpu上的通道,但这非常慢。这证明了模型输出有效,只是金属缩小功能失败了。 还有其他人使用CoreML和Catalyst吗?
以下是无效的代码:
let buffer = self.queue.makeCommandBuffer()
let filter = MPSNNReduceFeatureChannelsArgumentMax(device: self.device)
filter.encode(commandBuffer: buffer!,sourceImage: probs,destinationImage: classes)
// add a callback to handle the buffer's completion and commit the buffer
buffer?.addCompletedHandler({ (_buffer) in
let argmax = try! MLMultiArray(shape: [1,softmax.shape[1],softmax.shape[2]],dataType: .float32)
classes.readBytes(argmax.dataPointer,dataLayout: .featureChannelsxHeightxWidth,imageIndex: 0)
// unmap the discrete segmentation to RGB pixels
guard var mask = codesToMask(argmax) else {
return
}
// display image in view
dispatchQueue.main.async {
self.imageView.image = mask
}
})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)