Technical Manual(TM) Image Processing Platform Team04 Name First Role Second Role Third Role Hao Wu Requirements Engineer Software Architect Implementer Junran Liu Operational Concept Engineer Software Architect Implementer, Trainer Meiyi Yang Project Manager Life Cycle Plan Implementer Vinny DeGenova IIV & V Quality Focal Point Implementer Xiangchen Zhao Life Cycle Plan Prototyper Implementer Xinhui Liu Feasibility Analyst Operational Concept Engineer Implementer, Tester Yifan Liu Prototyper Requirements Engineer Implementer 12/04/2016
Version History Date Author Version Changes made Rationale 12/04/16 Xiangchen 1.0 First Version Initial Draft for TRR ARB
Table of Contents VERSION HISTORY... II TABLE OF TABLES... IV TABLE OF FIGURES... V 1. Introduction...1 1.1 System Overview...1 1.2 System Requirements...1 2. Installation Procedures...2 2.1 TensorFlow installation...2 2.2 Django&Celery installation...3 2.3 MySQL installation...3 3. Algorithm Manual...4 3.1 Background...4 3.2 Retrain Model...4 3.3 Image recognition...5
Technical Manual (TM) Version 1.0 Table of Tables No table of figures entries found. TM_TRR_F16a_T16_V1.0.doc Version Date: 12/04/16
Technical Manual (TM) Version 1.0 Table of Figures No table of figures entries found. TM_TRR_F16a_T16_V1.0.doc Version Date: 12/04/16
1. Introduction 1.1 System Overview The purpose of our system is to detect some specific classes of images that users want in thousands of original images. We implement it with a back-end classification algorithm and a front-end website, which we called Image Processing Platform. Here, this manual is a system administrator s manual. In this manual, you can find how to deploy our Image Processing Platform on your own server and how to use and even optimize the image recognition algorithm. 1.2 System Requirements Ubuntu 14.04 / 14.10 / 15.04/ 16.04 Python 3.5 1.2.1 Hardware Requirements TensorFlow has two version: CPU version and GPU version(only NVIDIA Graphic card). The GPU version will have a shorter time for retraining the model. Our system is running in the GPU version TensorFlow environment. However, the CPU version is also compatible here. 1.2.2 Software Requirements Tensorflow r0.11 Mysql 5.7 Django 1.9.2 Celery 1.3 Cuda Toolkit 8.0 CuDNN v5
2. Installation Procedures To deploy the whole platform on your own server, you need first install three software: TensorFlow Framework, Django and Celery, MySQL. The following part will give you a complete manual on how to install these software, Or you can follow the introduction on their website. 2.1 TensorFlow installation ## 1. Install tensorflow export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow- 0.11.0-cp35-cp35m-linux_x86_64.whl sudo pip3 install --upgrade $TF_BINARY_URL ## 2. Install Bazel dependencies #### Install JDK 8 sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer #### echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" sudo tee /etc/apt/sources.list.d/bazel.list sudo apt install curl curl https://bazel.build/bazel-release.pub.gpg sudo apt-key add - #### sudo apt-get install pkg-config zip g++ zlib1g-dev unzip ## 3. Install Bazel Download file from: https://github.com/bazelbuild/bazel/releases chmod +x bazel-0.4.0-installer-linux-x86_64.sh./bazel-0.4.0-installer-linux-x86_64.sh --user ## 4.Test #### get the path python3 -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))' #### test image recognition cd /usr/local/lib/python3.5/dist-packages/tensorflow cd models/image/imagenet python3 classify_image.py You can find detailed installation manual on the TensorFlow website: https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#requirements
2.2 Django&Celery installation ## 1. Install Django sudo pip3 install django==1.9.2 sudo pip3 install django-celery==3.1.17 pip3 install celery==3.1.24 ## pip install celery==3.1.24 sudo apt-get install rabbitmq-server sudo pip3 install pymysql==0.7.9 ## 2. Test django-admin --version celery --version ## 3. Configurate mysql database to use our project mysql -u root -p mysql>> CREATE DATABASE IPP; (configure "setting.py" -> database) ## 4. Run Django project python3 manage.py migrate ## run it first time if you don't have a database tables python3 manage.py runserver python3 manage.py celery worker --loglevel=info 2.3 MySQL installation sudo apt-get install mysql-server sudo apt install mysql-client sudo apt install libmysqlclient-dev sudo apt-get install python3-mysqldb sudo netstat -tap grep mysql vi /etc/mysql/mysql.conf.d/mysqld.cnf mysql -u root -p mysql> use mysql; mysql> select 'host' from user where user='root'; mysql> update user set host = '%' where user = 'root'; mysql> flush privileges; mysql> select 'host' from user where = 'root'; service mysql start
3. Algorithm Manual 3.1 Background There are two ways to use our algorithm to do the image recognition task. The first way is to run the algorithm script in the terminal and the second way is to use our front-end platform. For the second way, you can find details in the User Manual. Here, we introduce how to use the first way, directly run the algorithm script. For basic image recognition knowledge with TensorFlow, you can find it here: https://www.tensorflow.org/versions/r0.9/tutorials/image_recognition/index.html We take the pre-trained inception v3 image recognition model, retrain it on our own data. Till now, we have three functions: retrain the model (retrain.py), test the accuracy of the retrained model (retrain_test.py), classify the test image(classify_image.py) 3.2 Retrain Model TensorFlow has a pre-trained model called inception for image recognition. After you setup TensorFlow, you can retrain this model to work on your own dataset. Once you have the images, you can build the retrainer like this, from the root of your TensorFlow source directory: bazel build tensorflow/examples/image_retraining:retrain The retrainer can then be run like this (python3.5): python3 {YOU_PATH}/retrain.py --image_dir {DATASET_PATH} You can add distortion, modify some parameters like this (details in retrain.py): python3 {YOU_PATH}/retrain.py --image_dir {DATASET_PATH} --random_crop 5 -- how_many_training_steps=50000 3.2.1 Bottlenecks The script can take thirty minutes or more to complete, depending on the speed of your machine. The first phase analyzes all the images on disk and calculates the bottleneck values for each of them. 'Bottleneck' is an informal term we often use for the layer just before the final output layer that actually does the classification. This penultimate layer has been trained to output a set of values that's good enough for the classifier to use to distinguish between all the classes it's been asked to recognize. That means it has to be a meaningful and compact summary of the images, since it has to contain enough information for the classifier to make a good choice in a very small set of values. The reason our final layer retraining can work on new classes is that it turns out the kind of information needed to distinguish between all the 1,000 classes in ImageNet is often also useful to distinguish between new kinds of objects. Because every image is reused multiple times during training and calculating each bottleneck takes a significant amount of time, it speeds things up to cache these bottleneck values on disk so they don't have to be repeatedly
recalculated. By default they're stored in the /tmp/bottleneck directory, and if you rerun the script they'll be reused so you don't have to wait for this part again. 3.2.2 Training Once the bottlenecks are complete, the actual training of the top layer of the network begins. You'll see a series of step outputs, each one showing training accuracy, validation accuracy, and the cross entropy. The training accuracy shows what percent of the images used in the current training batch were labeled with the correct class. The validation accuracy is the precision on a randomly-selected group of images from a different set. The key difference is that the training accuracy is based on images that the network has been able to learn from so the network can overfit to the noise in the training data. A true measure of the performance of the network is to measure its performance on a data set not contained in the training data -- this is measured by the validation accuracy. If the train accuracy is high but the validation accuracy remains low, that means the network is overfitting and memorizing particular features in the training images that aren't helpful more generally. Cross entropy is a loss function which gives a glimpse into how well the learning process is progressing. The training's objective is to make the loss as small as possible, so you can tell if the learning is working by keeping an eye on whether the loss keeps trending downwards, ignoring the short-term noise. By default this script will run 4,000 training steps. Each step chooses ten images at random from the training set, finds their bottlenecks from the cache, and feeds them into the final layer to get predictions. Those predictions are then compared against the actual labels to update the final layer's weights through the back-propagation process. As the process continues you should see the reported accuracy improve, and after all the steps are done, a final test accuracy evaluation is run on a set of images kept separate from the training and validation pictures. This test evaluation is the best estimate of how the trained model will perform on the classification task. 3.2.3 Visualizing the Retraining with TensorBoard The script includes TensorBoard summaries that make it easier to understand, debug, and optimize the retraining. For example, you can visualize the graph and statistics, such as how the weights or accuracy varied during training. To launch TensorBoard, run this command during or after retraining: tensorboard --logdir /tmp/retrain_logs 3.3 Image recognition The retrain.py script will write out a version of the Inception v3 network with a final layer retrained to your categories to /tmp/output_graph.pb, and a text file containing the labels to /tmp/output_labels.txt. Since you've replaced the top layer, you will need to specify the new name in the script, for example with the flag -- output_layer=final_result After you retrain the model, you could use classify_image.py to classify the test image. Change the file name to fit your retrained model in classify_image.py: uid_lookup_path = os.path.join(flags.model_dir, 'output_labels.txt') with tf.gfile.fastgfile(os.path.join(flags.model_dir, 'output_graph.pb'), 'rb') as f: