Image recognition training with TensorFlow Inception and transfer learning
Read this in other languages: 한국어.
Transfer learning is the process of taking a pre-trained model (the weights and parameters of a network that has been trained on a large dataset by somebody else) and “fine-tuning” the model with your own dataset. The idea is that this pre-trained model will act as a feature extractor. You will remove the last layer of the network and replace it with your own classifier (depending on what your problem space is). You then freeze the weights of all the other layers and train the network normally (Freezing the layers means not changing the weights during gradient descent/optimization). For this experiment we used Google's Inception-V3 pretrained model for Image Classification. This model consists of two parts:
- Feature extraction part with a convolutional neural network.
- Classification part with fully-connected and softmax layers.
The pre-trained Inception-v3 model achieves state-of-the-art accuracy for recognizing general objects with 1000 classes. The model extracts general features from input images in the first part and classifies them based on those features in the second part. We will use this pre-trained model and re-train it it to classify houses with or without swimming pools.
Included components
- IBM Power AI: A software platform that includes the most popular machine learning frameworks with IBM Power Systems.
- IBM Power Systems: IBM Power Systems is IBM's Power Architecture-based server line, built with open technologies and designed for mission-critical applications.
- Nimbix Cloud Computing Platform: An HPC & Cloud Supercomputing platform enabling engineers, scientists & developers, to build, compute, analyze, and scale simulations in the cloud
Featured technologies
- Jupyter Notebooks: An open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text.
- Tensorflow: An open source software library for numerical computation using data flow graphs.
Watch the Video
Steps
Follow these steps to setup and run this developer journey. The steps are described in detail below.
- Register for a Trial Nimbix Cloud Platform account
- Navigating the Nimbix UI
- Deploy and run the PowerAI Notebooks application
- Access and start the Jupyter notebook
- Run the notebook
- Analyze the results
- Save and share
- Shut down the PowerAI Notebooks job
1. Register for a Trial Nimbix Cloud Platform account
IBM has partnered with Nimbix to provide journey developers a trial account that provides 10 hours of free processing time on the PowerAI platform.
The registration process is as follows:
- Go to the IBM Cognitive Journey Demo Registration Page and submit the form to initiate the registration process.
- Wait for a confirmation email. Note that this process is not automated so it may take up to 24 hours to be reviewed and approved.
- Once you receive the email, you will have 24 hours to complete the process by clicking on the provided link:
- The above link will take you to this page where you need to create and confirm your account password:
NOTE: A "Promotional Code" is not required.
- Wait for a confirmation email that will will provide instructions for logging into Nimbix:
- Click the link to take you to the Nimbix login page:
2. Navigating the Nimbix UI
The Nimbix UI has two main controls located at the top of the panel.
-
Click on
NIBMIX
to display a drop-down list of available modes. Click again to hide the list. In the example view above, we have selected theDashboard
mode. -
On the left-side, click on the
collapsible
icon to display a drop-down list of views that are associated with the selected mode. Click on the icon again to hide the list. In the example above, we have selected theCurrent Jobs
dashboard view.
3. Deploy and run the PowerAI Notebooks application
Once signed into Nimbix, deploy the PowerAI Notebooks application.
- Search for and select the
PowerAI Notebooks
application in the list of available apps in theCompute:All Applications
view.
- From the
PowerAI Notebooks
application panel, click theTensorFlow
button:
- From the
TensorFlow
configuration panel, accept all default values and click theSubmit
button:
NOTE: Ignore the $/hr charge listed. With your trial account you receive 10 hours of free processing time.
-
Once started, the following
Dashboard
panel will be displayed. When the serverStatus
turns toProcessing
, the server is ready to be accessed.Click on
(click to show)
to get the password. -
Click
Click here to connect
to launch web access to the notebooks.
- Log-in using the user name
nimbix
and the previously supplied password.
4. Access and start the Jupyter notebook
Use git clone to download the example notebook, dataset, and retraining library with a single command.
- Get a new terminal window by clicking on the
New
pull-down and selectingTerminal
.
- Run the following command to clone the git repo:
git clone https://github.com/IBM/powerai-transfer-learning
- Once done, you can exit the terminal and return to the notebook browser. Use the
Files
tab and click onpowerai-transfer-learning
thennotebooks
and thenClassifying-House-And-Pool-Images.ipynb
to open the notebook.
5. Run the notebook
When a notebook is executed, what is actually happening is that each code cell in the notebook is executed, in order, from top to bottom.
Each code cell is selectable and is preceded by a tag in the left margin. The tag
format is In [x]:
. Depending on the state of the notebook, the x
can be:
- A blank, this indicates that the cell has never been executed.
- A number, this number represents the relative order this code step was executed.
- A
*
, this indicates that the cell is currently executing.
There are several ways to execute the code cells in your notebook:
- One cell at a time.
- Select the cell, and then press the
Play
button in the toolbar.
- Select the cell, and then press the
- Batch mode, in sequential order.
- From the
Cell
menu bar, there are several options available. For example, you canRun All
cells in your notebook, or you canRun All Below
, that will start executing from the first cell under the currently selected cell, and then continue executing all cells that follow.
- From the
6. Analyze the results
When you run the "Main" code cell you can watch the training as the accuracy quickly improves. At the end, the final test accuracy is shown. We usually see somewhere around 85% accuracy with these images.
We captured the model before and after the training. Look at our example images at the bottom of the notebook and see our before and after results.
The results should go from no recognition ability at all to a pretty good success rate. You might find it interesting to try different images and see if you can identify why it has more difficulty classifying some images.
7. Save and share
How to save your work:
Because this notebook is running temporarily on a Nimbix Cloud server, use the following options to save your work:
Under the File
menu, there are options to:
Download as...
will download the notebook to your local system.Print Preview
will allow you to print the current state of the notebook.
8. Shut down the PowerAI Notebooks job
Remember to shutdown the server to free up resources on the Nimbix Cloud Platform. Also, remember that the free trial registration only provides 10 hours of compute time.
- From the Nimbix
Dashboard:Current Jobs
view, click on theShutdown
button and confirm.