Skip to content

Instantly share code, notes, and snippets.

@haoxi911
Last active March 15, 2018 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haoxi911/1b43af29cd6b9ae07fabd3bafd39dd15 to your computer and use it in GitHub Desktop.
Save haoxi911/1b43af29cd6b9ae07fabd3bafd39dd15 to your computer and use it in GitHub Desktop.
Retrain Mobilenet_v1 with Oxford IIIT Pet dataset
# Train
cd ~/tensorflow/
source ./bin/activate
python tensorflow/tensorflow/examples/image_retraining/retrain.py \
--image_dir $(pwd)/datasets/oxford-iiit-pet/images/ \
--learning_rate=0.001 \
--testing_percentage=20 \
--validation_percentage=20 \
--train_batch_size=32 \
--validation_batch_size=-1 \
--flip_left_right True \
--random_scale=30 \
--random_brightness=30 \
--eval_step_interval=100 \
--how_many_training_steps=1000 \
--architecture mobilenet_1.0_224 \
--print_misclassified_test_images \
--output_graph=$(pwd)/datasets/oxford-iiit-pet/output_graph.pb \
--output_labels=$(pwd)/datasets/oxford-iiit-pet/output_labels.txt
# TF-Lite
cd ~/tensorflow/tensorflow/
bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=$(pwd)/../datasets/oxford-iiit-pet/output_graph.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--output_file=$(pwd)/../datasets//oxford-iiit-pet/output_graph.tflite \
--inference_type=FLOAT \
--input_type=FLOAT \
--input_arrays=input \
--output_arrays=final_result \
--input_shapes=1,224,224,3
# Test
cd ~/tensorflow/tensorflow/
bazel-bin/tensorflow/examples/label_image/label_image \
--input_layer=input \
--output_layer=final_result \
--graph=$(pwd)/../datasets/oxford-iiit-pet/output_graph.pb \
--input_mean=128 \
--input_std=128 \
--image=$(pwd)/../datasets/oxford-iiit-pet/images/chihuahua/chihuahua_9.jpg \
--input_width=224 \
--input_height=224 \
--labels=$(pwd)/../datasets/oxford-iiit-pet/output_labels.txt
@haoxi911
Copy link
Author

INFO:tensorflow:2018-03-15 11:08:19.220329: Step 0: Train accuracy = 68.8%
INFO:tensorflow:2018-03-15 11:08:19.221644: Step 0: Cross entropy = 3.289592
INFO:tensorflow:2018-03-15 11:08:19.898481: Step 0: Validation accuracy = 16.0% (N=1519)
INFO:tensorflow:2018-03-15 11:16:11.568249: Step 100: Train accuracy = 100.0%
INFO:tensorflow:2018-03-15 11:16:11.569362: Step 100: Cross entropy = 0.879976
INFO:tensorflow:2018-03-15 11:16:12.188951: Step 100: Validation accuracy = 85.2% (N=1519)
INFO:tensorflow:2018-03-15 11:24:07.870928: Step 200: Train accuracy = 81.2%
INFO:tensorflow:2018-03-15 11:24:07.872125: Step 200: Cross entropy = 0.726239
INFO:tensorflow:2018-03-15 11:24:08.479805: Step 200: Validation accuracy = 86.9% (N=1519)
INFO:tensorflow:2018-03-15 11:32:01.983302: Step 300: Train accuracy = 96.9%
INFO:tensorflow:2018-03-15 11:32:01.984279: Step 300: Cross entropy = 0.460043
INFO:tensorflow:2018-03-15 11:32:02.567386: Step 300: Validation accuracy = 88.2% (N=1519)
INFO:tensorflow:2018-03-15 11:40:00.793730: Step 400: Train accuracy = 87.5%
INFO:tensorflow:2018-03-15 11:40:00.794807: Step 400: Cross entropy = 0.366273
INFO:tensorflow:2018-03-15 11:40:01.386012: Step 400: Validation accuracy = 89.1% (N=1519)
INFO:tensorflow:2018-03-15 11:47:57.474488: Step 500: Train accuracy = 93.8%
INFO:tensorflow:2018-03-15 11:47:57.475564: Step 500: Cross entropy = 0.395242
INFO:tensorflow:2018-03-15 11:47:58.088154: Step 500: Validation accuracy = 89.1% (N=1519)
INFO:tensorflow:2018-03-15 11:55:52.344787: Step 600: Train accuracy = 84.4%
INFO:tensorflow:2018-03-15 11:55:52.345826: Step 600: Cross entropy = 0.583648
INFO:tensorflow:2018-03-15 11:55:52.936640: Step 600: Validation accuracy = 88.3% (N=1519)
INFO:tensorflow:2018-03-15 12:03:48.777964: Step 700: Train accuracy = 90.6%
INFO:tensorflow:2018-03-15 12:03:48.779046: Step 700: Cross entropy = 0.257073
INFO:tensorflow:2018-03-15 12:03:49.380604: Step 700: Validation accuracy = 89.3% (N=1519)
INFO:tensorflow:2018-03-15 12:11:47.202229: Step 800: Train accuracy = 96.9%
INFO:tensorflow:2018-03-15 12:11:47.203278: Step 800: Cross entropy = 0.216174
INFO:tensorflow:2018-03-15 12:11:47.809565: Step 800: Validation accuracy = 89.1% (N=1519)
INFO:tensorflow:2018-03-15 12:19:44.088443: Step 900: Train accuracy = 93.8%
INFO:tensorflow:2018-03-15 12:19:44.089479: Step 900: Cross entropy = 0.283246
INFO:tensorflow:2018-03-15 12:19:44.691898: Step 900: Validation accuracy = 89.3% (N=1519)
INFO:tensorflow:2018-03-15 12:27:33.155976: Step 999: Train accuracy = 96.9%
INFO:tensorflow:2018-03-15 12:27:33.157082: Step 999: Cross entropy = 0.233713
INFO:tensorflow:2018-03-15 12:27:33.762864: Step 999: Validation accuracy = 89.3% (N=1519)
INFO:tensorflow:Final test accuracy = 89.8% (N=1458)

@haoxi911
Copy link
Author

2018-03-15 12:42:17.455515: I tensorflow/examples/label_image/main.cc:250] chihuahua (9): 0.985502
2018-03-15 12:42:17.455732: I tensorflow/examples/label_image/main.cc:250] sphynx (14): 0.0134067
2018-03-15 12:42:17.455790: I tensorflow/examples/label_image/main.cc:250] siamese (29): 0.000288703
2018-03-15 12:42:17.455934: I tensorflow/examples/label_image/main.cc:250] miniature pinscher (26): 0.000269378
2018-03-15 12:42:17.455998: I tensorflow/examples/label_image/main.cc:250] abyssinian (6): 7.23909e-05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment