- Setup the docker container for Tensorflow 1.6
sudo docker run -it -d -v `pwd`:/notebooks tensorflow/tensorflow:1.6.0 /bin/bash
- List the dockers
sudo docker ps
- Get into the docker container
sudo docker exec -it (container-id) /bin/bash
- Test the already existing model
python -m scripts.label_image \
--graph=tf_files/retrained_graph.pb \
--image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg
- Optimize your model using toco(TensorFlow Lite Optimizing Converter)
IMAGE_SIZE=224
toco \
--input_file=tf_files/retrained_graph.pb \
--output_file=tf_files/optimized_graph.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TENSORFLOW_GRAPHDEF \
--input_shape=1,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_array=input \
--output_array=final_result
- Retest the existing model
python -m scripts.label_image \
--graph=tf_files/retrained_graph.pb\
--image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg
- Test the optimized model
python -m scripts.label_image \
--graph=tf_files/optimized_graph.pb \
--image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg
- Convert the model to TensorflowLite format
IMAGE_SIZE=224
toco \
--input_file=tf_files/retrained_graph.pb \
--output_file=tf_files/optimized_graph.lite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_shape=1,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_array=input \
--output_array=final_result \
--inference_type=FLOAT \
--input_type=FLOAT
- Create a directory for your reference
mkdir android_tf
- Copy the .lite file to the reference folder
cp tf_files/optimized_graph.lite android_tf/
- Copy the labels file to the reference folder
cp tf_files/retrained_labels.txt android_tf/
- Declare in case required
declare USER=yourname
- Copy to your storage drive
gsutil cp -R android_tf/* gs://flower_${USER}/android_tf/
In case of some issue with gsutil, reinstall google cloud sdk:
cd TensorflowStarter
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
apt-get update
apt-get install google-cloud-sdk
gcloud init
https://docs.google.com/forms/d/1FSYrE9H7J6gTBzdzUyfAGGPAerKZcqqzu7hOADsmXjM