TensorFlow setup for image classification example in Windows

This post aims to setup environment for  ‘TensorFlow for Poets’ case but with slight adaptations for Windows (7) environment. You can find the linux version here.

Tensorflow for Windows

https://www.tensorflow.org/install/install_windows

Anaconda distribution includes data science modules but a minimum of the modules is installed with the miniconda version, which is is used below: https://conda.io/miniconda.html  .

Environment creation within conda

conda create -n tensor2 python=3.6

activate tensor2

pip install tensorflow

Grab the test images

wget http://download.tensorflow.org/example_images/flower_photos.tgz   

tar xfz flower_photos.tgz -C tf_files\

 

Setup the environment for training

set IMAGE_SIZE=224

set ARCHITECTURE="mobilenet_0.50_%IMAGE_SIZE%"

python -m scripts.retrain -h

python -m scripts.retrain   --bottleneck_dir=tf_files/bottlenecks \
  --how_many_training_steps=500   --model_dir=tf_files/models/   \
--summaries_dir=tf_files/training_summaries/"%ARCHITECTURE%" \
  --output_graph=tf_files/retrained_graph.pb  \
 --output_labels=tf_files/retrained_labels.txt  \
 --architecture="%ARCHITECTURE%"   --image_dir=tf_files/flower_photos

Label the test image or image of your own.

python -m  scripts.label_image -h

python -m scripts.label_image     --graph=tf_files/retrained_graph.pb \
      --image=915045_p30.png 


and the results are

Evaluation time (1-image): 0.464s

tulips 0.9960024
dandelion 0.002221214
sunflowers 0.0017093202
roses 5.8004178e-05
daisy 9.087755e-06

So it can be seen that at least with this model water-lilys are not in the suggested options, the style of the image makes TensorFlow to mix them to tulips…

 

Remember to register to the DHN18  , and pick “Miniature histories – Digitized newspapers and cultural heritage assets as source for the local history” as your workshop!