-
Run Docker in your Mac
-
Open the terminal
-
Downlaod the project workspace. Run:
git clone https://github.com/sunyu912/tensorflow-mobile-example.git
If you see errors on not recognizing git, you need to install Git first. Please see https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- Get into the folder:
cd tensorflow-mobile-example/
- Copy your trained tf_files:
cp -r ~/tf_files .
- Run Docker environment:
docker run -it --publish 6006:6006 --volume ${HOME}/tensorflow-mobile-example:/tensorflow-mobile-example --workdir /tensorflow-mobile-example tensorflow/tensorflow:1.1.0 bash
- Verify the tool and model prediction works:
python scripts/label_image.py tf_files/flower_photos/daisy/21652746_cc379e0eea_m.jpg tf_files/retrained_graph.pb
If you can see the prediction output, that means the tool has been installed correctly.
- Optimze the model for mobile:
python -m tensorflow.python.tools.optimize_for_inference --input=tf_files/retrained_graph.pb --output=tf_files/optimized_graph.pb --input_names="Cast" --output_names="final_result"
- Copy the optimized models to mobile Android projecT:
cp tf_files/optimized_graph.pb android/assets/retrained_graph.pb
cp tf_files/retrained_labels.txt android/assets/
-
Open Android Studio (Please install it first at https://developer.android.com/studio/index.html
-
Import an existing Android project. Please choose the
androidfolder in thetensorflow-mobile-examplefolder. -
Run the project.