如何使用 MPS (MetalPerformanceShaders) 制作 Flatten 滤镜?

How to make a Flatten filter by using MPS (MetalPerformanceShaders)?

我正在 运行 iOS 上为 MNIST 进行 CNN 推理。 Apple 提供了一个很好的代码示例作为开始。 https://developer.apple.com/library/content/samplecode/MPSCNNHelloWorld/Introduction/Intro.html#//apple_ref/doc/uid/TP40017482-Intro-DontLinkElementID_2

然而,当我试图通过使用 MPS 实现更复杂的 CNN 模型(例如 https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py)时,我发现 "Flatten" 过滤器没有 class。

我查看了 MPS 框架以找到重塑或更改维度的功能,但找不到合适的功能。 (例如 MPSImageConversion 似乎只用于转换颜色,而不是用于尺寸。

如果有人知道 Flatten 的过滤器或如何将多维图像转换为一维图像,请告诉我。

不需要展平层,因为 MPS 可以处理多维数据作为输入。