About bottlenecks

Here, we will try to understand how the retraining process works. The ImageNet models we are using are made up of many layers stacked on top of each other. These layers are pre-trained and already have sufficient information that will help in image classification. All we are trying to do is train the very last layer, final_training_ops , when all the previous layers retrain their already trained state.

The following screenshot is taken from TensorBoard. You can open TensorBoard in your browser to get a better look at it. You will find it in the Graphs tab:

In the preceding diagram, the softmax node on the left-hand side is the output layer of the original model. All the nodes to the right of softmax were added by the retraining script.

Note that this will only work after the retrain script finishes generating the bottleneck files.

Bottleneck is the term used to refer to the layer just before the final output layer that does the classification. Bottleneck does not imply its conventional meaning of something that slows down the whole process. We use the term bottleneck because, near the output, the representation is much more compact than in the main body of the network.

Every image is reused multiple times during training. Calculating the layers behind the bottleneck for each image takes a significant amount of time. Since these lower layers of the network are not being modified, their output can be cached and reused. Now, you have the TensorFlow retrained model in your hand. Let's test the model that we just trained using the following command:

python -m scripts.label_image 
--graph=tf_files/retrained_graph.pb
--image=tf_filesfood_photospizza1.jpg

Executing the previous code block will give you the class that the food image belongs to. Now, let's go to the next task: converting the tensorflow model into the Core ML format.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset