Search code examples
iosimage-processingflattenmetalmnist

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


I'm working on running CNN inference for MNIST on iOS. There is a good code sample from Apple to start. https://developer.apple.com/library/content/samplecode/MPSCNNHelloWorld/Introduction/Intro.html#//apple_ref/doc/uid/TP40017482-Intro-DontLinkElementID_2

However, When I tried to implement much complex CNN model (e.g. https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py) by using MPS, I found that there was no class for "Flatten" filter.

I looked through MPS framework to find the function to reshape or change a dimension, but I couldn't find the right one. (e.g. MPSImageConversion seems only for converting a color, but not for a dimension.

If someone knows the filter for Flatten or how to convert multi-dimension image to 1D image, please let me know.


Solution

  • Flatten layer is not required because MPS can handle multi-dimensional data as an input.