1. Install TensorFlow
https://sunggukim.blogspot.kr/2018/05/tensorflow-install-tensorflow-with.html
2. download source for TFMobile for Poets2
git clone https://github.com/googlecodelabs/tensorflow-for-poets-2
cd tensorflow-for-poets-2
git checkout end_of_first_codelab
dir tf_files/
3. test model
python -m scripts.label_image \
--graph=tf_files/retrained_graph.pb \
--image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg
4. Optimize model
python -m tensorflow.python.tools.optimize_for_inference \
--input=tf_files/retrained_graph.pb \
--output=tf_files/optimized_graph.pb \
--input_names="input" \
--output_names="final_result"
5. Quantize weights
python -m scripts.quantize_graph \
--input=tf_files/optimized_graph.pb \
--output=tf_files/rounded_graph.pb \
--output_node_names=final_result \
--mode=weights_rounded
6. Check compress rate
gzip -c tf_files/rounded_graph.pb > tf_files/rounded_graph.pb.gz
gzip -l tf_files/rounded_graph.pb.gz
compressed uncompressed ratio uncompressed_name
1633131 5460032 70.1% tf_files/rounded_graph.pb
7. Compare two models : less then one tenth of a percent
python -m scripts.label_image \
--image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg \
--graph=tf_files/optimized_graph.pb
python -m scripts.label_image \
--image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg \
--graph=tf_files/rounded_graph.pb
8. Download additional data for a full set of photos. [ 200MB ]
curl http://download.tensorflow.org/example_images/flower_photos.tgz \
| tar xz -C tf_files
9. Evaluate performance
python -m scripts.evaluate tf_files/optimized_graph.pb
python -m scripts.evaluate tf_files/rounded_graph.pb
10. Customize app
Source : tensorflow-for-poets-2\android\tfmobile
10-1. Open source with Android Studio.
10-2. Update graph.pb and labels.txt to android/tfmobile/assets
copy ./tf_files/rounded_graph.pb ./android/tfmobile/assets/graph.pb
copy ./tf_files/retrained_labels.txt ./android/tfmobile/assets/labels.txt
11. Change the output_name in ClassifierActivity.java
private static final String INPUT_NAME = "input";
private static final String OUTPUT_NAME = "final_result";
<Reference>
https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2/#
https://www.tensorflow.org/install/
https://towardsdatascience.com/north-indian-food-or-south-indian-food-deep-learning-knows-it-all-part-2-14a59d0ffc15
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android
https://towardsdatascience.com/tensorflow-on-mobile-tutorial-1-744703297267
Thanks for the useful information.
답글삭제Machine Learning training in Pallikranai Chennai
Data science training in Pallikaranai
Python Training in Pallikaranai chennai
Bigdata training in Pallikaranai chennai
Spark with ML training in Pallikaranai chennai