tensorFlow on iOS

Inspired from Pete Warden's blog:

https://petewarden.com/2016/09/27/tensorflow-for-mobile-poets/

Bazel guide:

https://bazel.build/versions/master/docs/bazel-user-manual.html#flag--host_jvm_args

Step 1:

Assuming that we have already ran the retrain.py on train_images like this:

root@15a68539db77:/tf_files# python retrain_ORIG.py --bottleneck_dir=/tf_files/bottlenecks --how_many_training_steps=500 --model_dir
=/tf_files/inception --output_graph=/tf_files/retrained_graph.pb --output_labels=/tf_files/retrained_labels.txt --image_dir=/tf_file
s/train_images/ --summaries_dir=/tmp/retrain_logs


Using docker container, where tensorflow is installed (AWS)
Build the label image tool:
---------------------------

cd /tensorflow
bazel build --jobs=1 tensorflow/examples/label_image:label_image

* The --jobs=1 helps reduce the VM memory footprint, otherwise the default mode 
  spawns 200 jobs and the VM crashes with memory error
This generates a binary file 'label_image' as:
bazel-bin/tensorflow/examples/label_image/label_image

With the help of this tool we can run the model and get labels for images

Test it out, before proceeding forward. This is a sanity check:
----------------------------------------------------------------

bazel-bin/tensorflow/examples/label_image/label_image \
--output_layer=final_result \
--labels=/tf_files/retrained_labels.txt \
--graph=/tf_files/retrained_graph.pb
--input_layer=Mul \
--image=/tf_files/flower_photos/daisy/5547758_eea9edfd54_n.jpg

In my case:
-----------
bazel-bin/tensorflow/examples/label_image/label_image --output_layer=final_result --labels=/tf_files/
retrained_labels_11.txt --graph=/tf_files/retrained_graph_11.pb --input_layer=Mul --image=/tf_files/test_images_1/moldyusdareject/20
170420_134921.jpg

bazel-bin/tensorflow/examples/label_image/label_image --output_layer=final_result --labels=/tf_files/retrained_labels.txt --graph=/tf_files/retrained_graph.pb --input_layer=Mul --image=/tf_files/test_images_1/moldyusdareject/20170420_134921.jpg

using test image from the internet:
bazel-bin/tensorflow/examples/label_image/label_image --output_layer=final_result --labels=/tf_files/retrained_labels.txt --graph=/tf_files/retrained_graph.pb --input_layer=Mul --image=/tf_files/test_images_internet/strawberry_m3.jpg


Tip: The --input_layer=Mul is needed to avoid "FeedInputs: unable to find feed output input" error

This also gives some 'W' (warning messages). From the community information the advice to avoid these Warning
messages is to use: export TF_CPP_MIN_LOG_LEVEL=2. But, this did not work, since it also suppressed the
prediction information from appearing on screen

Step 2:

Step 3:

Step 4:

Step 5:

Step 5:

Step 6:

Own App Building:

Ref: https://www.youtube.com/watch?v=0r9w3V923rk

The iOS part in the video runs between 11:28 to 15:40

Time: 13:50

Size of App:

Last updated

Was this helpful?