如何解决CoreML Catalyst MPSNNReduceFeatureChannelsArgumentMax返回全零
我正在使用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 举报,一经查实,本站将立刻删除。