Open the Makefile from tensorflow/contrib/makefile/Makefile then, if you use TensorFlow 1.4, search for IOS_ARCH. For each of the architectures (5 in total: ARMV7, ARMV7S, ARM64, I386, X86_64), change -D__ANDROID_TYPES_SLIM__ to
-D__ANDROID_TYPES_FULL__. The Makefile in TensorFlow 1.5 (or 1.6/1.7) is a little different, although it's still in the same folder; for 1.5/1.6/1.7, search for ANDROID_TYPES_SLIM and change it to ANDROID_TYPES_FULL. Now rebuild the TensorFlow library by running tensorflow/contrib/makefile/build_all_ios.sh. After this, the RefSwitch error will be gone when loading the model file. The app size built with the TensorFlow library with full data type support will be about 70 MB versus 37 MB, the app size when built with the default slim data types.
As if enough were not enough, yet another model loading error occurs:
Could not create TensorFlow Graph: Invalid argument: No OpKernel was registered to support Op 'RandomUniform' with these attrs. Registered devices: [CPU], Registered kernels: <no registered kernels>.
Luckily, you should be pretty familiar with how to fix this kind of error if you have gone through the previous chapters. Here's a quick recap: first find out which op and kernel files define and implement the operation, then check to see if the op or kernel file is included in the tf_op_files.txt file, and there should be at least one missing, causing the error; now just add the op or kernel file to tf_op_files.txt and rebuild the library. In our case, run the following commands:
grep RandomUniform tensorflow/core/ops/*.cc
grep RandomUniform tensorflow/core/kernels/*.cc
And you'll see these files as output:
tensorflow/core/ops/random_grad.cc
tensorflow/core/ops/random_ops.cc:
tensorflow/core/kernels/random_op.cc
The tensorflow/contrib/makefile/tf_op_files.txt file only has the first two files, so just add the last one, tensorflow/core/kernels/random_op.cc, to the end of tf_op_files.txt, and run tensorflow/contrib/makefile/build_all_ios.sh again.
Finally, all errors are gone when loading the model, and we can start having some real fun by implementing the app logic to handle user drawing, converting the points to a format expected by the model, and getting the classification results back.