This APP is inspired by Not Hotdog of Jian Yang's idea in Silicon Valley, and it is just another version of it: Not Minion
- TensorFlow
- Python 2 & 3 (Only for Step 2)
It first retrains TensorFlow Inception v3
's last layer to learn how a Minion image looks like, makes a model, then applies this model into TensorFlow
's example iOS App to recognize a Minion.
If you want to build your own Not something from scratch, you should read from Step 1. Otherwise, you can jump to Step 5.
First you have to install all tools listed in Requirements. Please refer to their websites and GitHub.
Prepare for image sets.
TensorFlow Inception v3
is used to classify objects, so you have to divide images into 2 categories: Minions and Not Minions. And the root image directory should be organized as below:
└── Minion Images <---- DIRECTORY_TO_YOUR_IMAGES
├── Minions
└── Not Minions <---- DIRECTORY_TO_IMAGE_DOWNLOAD
-
You can download or scrape many Minion images from Internet, and put them into Minions.
-
In
Image Crawler
there is a random image downloader for Not Minions. Usage:
python3 /Image Crawler/random_imgur.py -i 200 -o DIRECTORY_TO_IMAGE_DOWNLOAD
python2 /Image Crawler/delete_not_jpg.py -o DIRECTORY_TO_IMAGE_DOWNLOAD
random_imgur.py
uses Python3, anddelete_not_jpg.py
uses Python2.- The
DIRECTORY_TO_IMAGE_DOWNLOAD
in two commands should be the same.
Once you have installed TensorFlow
, you can begin to retrain it to learn your something. In this App, it is Minion.
It means the image directory should contains 2 sub directories, each of them contains the corresponding images. (You have done this in Step 2)
Then execute the following commands in terminal:
cd ROOT_DIRECTORY_OF_TENSORFLOW
bazel build tensorflow/examples/image_retraining:retrain
bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir DIRECTORY_TO_YOUR_IMAGES
This shall take a while, based on the performance of your computer.
Now you have generated the output_graph.pb
file in /tmp
by default. Now in terminal, please enter
cd ROOT_DIRECTORY_OF_TENSORFLOW
bazel build tensorflow/examples/label_image:label_image && \
bazel-bin/tensorflow/examples/label_image/label_image \
--graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt \
--output_layer=final_result \
--input_layer=Mul \
--image=PATH_TO_YOUR_TEST_IMAGE
and witness Miracle!
2017-06-12 14:32:09.507037: I tensorflow/examples/label_image/main.cc:251] minions (1): 0.999147
2017-06-12 14:32:09.507057: I tensorflow/examples/label_image/main.cc:251] not minions (0): 0.000853157
2017-06-12 14:31:43.194735: I tensorflow/examples/label_image/main.cc:251] not minions (0): 0.890092
2017-06-12 14:31:43.194766: I tensorflow/examples/label_image/main.cc:251] minions (1): 0.109908
The float number at the end of each line represents the likelihood that this image is (not) a minion.
If you just want to run this app on your iPhone, you can start from this step. You need to have TensorFlow
prepared on your Mac.
-
Clone this repo.
-
Copy the
/Not Minion TensorFlow Example
directory (which is an example iOS App provided byTensorFlow
with our own model applied) intoROOT_DIRECTORY_OF_TENSORFLOW/tensorflow/tensorflow/contrib/ios_examples/
. -
Download the trained Minion model from BaiduDisk and copy it to
../Not Minion TensorFlow Example/data
or
Copy your own
output_labels.txt
andoutput_graph.pb
to../Not Minion TensorFlow Example/data
and rename them asimagenet_comp_graph_label_strings.txt
andtensorflow_inception_graph.pb
. -
Open
Not Minion TF.xcodeproj
and run!Maybe you need to change Developer Certificates.
Transform Inception v3
model to Core ML
format and apply it with CoreML Framework
in iOS 11.
Created on 2017-07-05