Channel order & Keras Conversion

I had been working with a network that used 3D convolutions in Keras, but because CoreML only supports 2D convolutional layers, I reshaped my data to achieve the same effect in 2D space. In order to do this, between convolutional layers, I have several reshape and permute layers. Using a test data set, my model was able to train, and the export scripts for CoreML ran just fine.


However, when I tried to compile in Xcode, using my exported model, it threw an error, complaining that my concatenate layer did not have the same height & width values for each of the layers feeding to it. This was odd, since I had worked pretty hard to make sure to have the dimension that was of varying length in the channel dimension going into the concatenate layer specifically because the export script had complained about exactly the same thing.


Looking at the full error message, it seems that CoreML operates as channel first, while my Keras code operates as channel last. This means that while my reshape and permute layers imported exactly as they had been in my Keras model, they would not work as intended, since the data are ordered differently.


I assumed that the solution to this was to change my Keras settings to channel first, and rewrite the reshape and permute layers to work for channel first. This was an annoying, but ultimately trivial way to handle the problem.


Except now the coremltools export will not run, because it throws an error saying that it does not support channel first.


Is there some way to get Keras, CoreML, and coremltools to use the same ordering? I would not expect the export script to be able to modify my reshape and permute layers to achieve exactly the same thing they did with the different ordering. I suppose the least optimal solution would be to have permute layers that switch the ordering that get included in the CoreML version, that are not in the Keras version, but surely there is a better way to solve this problem, right?