Retraining one of Google's CNN image classification models to new categories using Transfer Learning. This can be an much faster (in a few minutes) than training from scratch (Inception V3 took Google, 2 weeks).
- Based on Transfer Learning Colab
sudo pip install --ignore-installed --upgrade https://github.com/lakshayg/tensorflow-build/releases/download/tf1.9.0-ubuntu16.04-py27-py35/tensorflow-1.9.0-cp35-cp35m-linux_x86_64.whl
sudo pip install tensorflow-hub
mkdir retrain
cd retrain
curl -LO http://download.tensorflow.org/example_images/flower_photos.tgz
tar xzf flower_photos.tgz
curl -LO https://github.com/tensorflow/hub/raw/master/examples/image_retraining/retrain.py
reduce the number of images by ~70% : 3681 -> 1668
ls flower_photos/* | wc -l
rm flower_photos/*/[3-9]*
rm flower_photos/daisy/ flower_photos/dandelion/ flower_photos/tulips/ -r
ls flower_photos/* | wc -l
also only use 2 flowers e.g. roses and sunflowers : 1668 -> 591
python3 retrain.py --image_dir ./flower_photos --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/2 --how_many_training_steps 500
2m29s : Codenvy - Python 3 - 591 images - 500 Steps - mobilenet_v2_100_224 - Test 98.0%
curl -LO https://github.com/tensorflow/tensorflow/raw/master/tensorflow/examples/label_image/label_image.py
wget https://5.imimg.com/data5/AA/KK/MY-6677193/red-rose-500x500.jpg
python label_image.py --graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt --input_layer=Placeholder --output_layer=final_result --input_height=224 --input_width=224 --image=red-rose-500x500.jpg | grep 'roses\|sunflowers'
cp /tmp/output* ./
download images, rename folder, zip, upload, unzip, mkdir, mv
Batch Image downloader
Loads images on screen, in Google Images Scroll for more images.
Zip: in windows right click - Send to - Compressed (zipped) folder
Upload: in codenvy - Projects - Upload File
unzip foldername.zip
mkdir images
mv foldername images
moves foldername
into images
folder
bottlenecks, graph & model in /tmp
curl -LO https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz
tar -xvzf inception_v3_2016_08_28_frozen.pb.tar.gz
curl -LO https://raw.githubusercontent.com/EN10/SimpleInception/master/5918348-image.jpg
python label_image.py \
--graph=inception_v3_2016_08_28_frozen.pb --labels=imagenet_slim_labels.txt \
--image=5918348-image.jpg