Skip to content

Instantly share code, notes, and snippets.

@kunal732
Last active April 19, 2018 16:37
Show Gist options
  • Save kunal732/3b11b4dc654e36b8391d566ba9f84c88 to your computer and use it in GitHub Desktop.
Save kunal732/3b11b4dc654e36b8391d566ba9f84c88 to your computer and use it in GitHub Desktop.
Building an Image Classifier Ingredients
#First item is to make sure you have Docker installed. We'll be using docker to setup a tensorflow image.
To make sure docker is installed properly you can run the
'docker hello-world'
image and should get the appropriate response.
#To install and an image with tensorflow
docker run -it tensorflow/tensorflow bash
#Download and unzip the Tensorflow for poets scripts
curl -O http://104.131.75.92:8000/tensorflow-for-poets-2-master.zip
#next we are going to download images of the Avengers, particularly Thor, Hulk and Captain America and store in tf_files/
curl -O http://104.131.75.92:8000/avengers.zip
#next we are going to set some Shell variables so tensorflow knows what architecture and image resolution we are going to use.
export IMAGE_SIZE=224
export ARCHITECTURE="mobilenet_0.50_${IMAGE_SIZE}"
#next we're going to run tensorboard in the background to help monitor progress
tensorboard --logdir tf_files/training_summaries &
#train the model
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/avengers_photos
#download a sample image to test model against
curl -O https://www.cinematographe.it/wp-content/uploads/2017/10/thor-ragnarok-hulk-mark-ruffalo.jpg
#run the trained model
python -m scripts.label_image \
--graph=tf_files/retrained_graph.pb \
--image=tf_files/thor-ragnarok-hulk-mark-ruffalo.jpg
#Copy our model onto our host with the following:
docker cp 7fa495b291fb:/notebooks/tf_files/tensorflow-for-poets-2-master/tf_files .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment