MetalImageRecognition: creating batch normalized binaries dat files

Hi,

I am testing the sample code linked below about using Metal to perform inference on tensorflow trained network Inception v3.

https://developer.apple.com/library/content/samplecode/MetalImageRecognition/Introduction/Intro.html

It's very interesting because on my tests inference using Metal outperforms 5x inference on the same network using tensorflow library on the same device.
In the brief documentation that you provide you say "we are using trained parameters (weights and bias) we have fetched from, pre-trained and saved network on TensorFlow"

However I can't understand how you create the batch normalized binary dat files.

Could you please explain how to create these binary files, so that we can adapt the example to our network?


Thank you for your time,

Giovanni

Replies

If you're using Tensorflow on iOS, I'm pretty sure it's not using the GPU.


If you're interested, I've put together a repo that converts Inception v3 batch-normalized weights into de-normalized weights for MPSCNNConvolution:

https://github.com/kakugawa/MetalCNNWeights

Hi @kakugawa, thanks for sharing that script. I want to modified it to work with a retrained inception network (where only the final layer is tweaked) https://www.tensorflow.org/tutorials/image_retraining


I cannot figure out how to get weights and biases for the final output layer to work with your script. Any help is greatly appreciated!

TensorFlow comes with a tool that lets you "fold" the batch normalization layers into the weights of the preceding convolutional layer. So you can just ask TensorFlow to compute the weights and biases that are adjusted for batch norm.


https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/graph_transforms/README.md

Tensorflow out of the box doesn't support OpenCL compilation although there are some efforts to port it around on the net with varying success as there are not good mappings to all CUDA functions in OpenCL. So it's very unlikely to be using the GPU effectively if t all on iOS.