

Want to Train Computer Vision Models 100x Faster? Meet MissingLink.ai
ModelingComputer VisionKerasSponsored Postposted by Tareq Aljaber April 3, 2019 Tareq Aljaber

To stay competitive, large and small organizations are turning to deep learning and AI for faster innovation. They strive to create value, improve customer experience and ship faster to differentiate themselves from the competition, so they place tremendous pressure and demands on their data science teams to deliver fast.
This tutorial is a step-by-step guide to training deep learning models faster with MissingLink. The goal is to enable teams to experiment ten times faster with the same resources, and cut their cloud costs by as much as 30%.
Let’s dive in – How to train a computer vision model with Keras
I will take an existing implementation of a deep learning algorithm, integrate, manage and visualize it in MissingLink. We start with a code sample that trains a model based on the MNIST dataset using a convolutional neural network, add the MissingLink SDK. We will then run the experiment in a MissingLink-controlled emulated server.
A few things we need to do before we dive into this tutorial:
- Sign up for a free missinglink.ai account.
- Have Python and Docker installed on your workstation.
NOTE: This tutorial assumes you’re using virtualenv to scope your working environment. If you don’t have it installed, you can follow this guide to set it up.
Fork the MissingLink Keras Github repository
After the forked repository is created, clone it locally in your workstation. Click Clone or download in Github:
Now copy the URL for cloning the repository
Next, let’s open a terminal and git clone using the pasted URL of your forked repository:
1
2
3
|
$ git clone
git@github.com:<YOUR_GITHUB_USERNAME>/missinglink–keras–tutorial1.git
$ cd missinglink–keras–tutorial1
|
Now that the code is on your machine, let’s prepare the environment. Run the following commands:
1
2
3
|
$ python3 –m virtualenv env
$ source env/bin/activate
$ pip install –r requirements.txt
|
Let’s run it
You can try to run the example:
1
2
3
|
$ python mnist_cnn.py
|
Install and initialize the MissingLink CLI
MissingLink provides a command line interface (CLI) that allows you to control everything from the terminal.
Let’s go ahead and install it:
1
2
3
|
$ pip install missinglink
|
Next, authenticate with the MissingLink backend.
1
2
3
|
$ ml auth init
|
Creating a project
MissingLink allows you to manage several projects. Let’s create a new project for this tutorial:
1
2
3
|
$ ml projects create —display–name tutorials
|
Create the experiment in MissingLink
Open the mnist_cnn.py script file and import the MissingLink SDK:
1
2
3
4
5
6
7
8
9
10
11
|
// …
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
+import missinglink
batch_size = 128
num_classes = 10
epochs = 12
// …
|
Now we need to initialize a callback object that Keras will call during the different stages of the experiment:
[Related article: Getting to Know Keras for New Data Scientists]
1
2
3
4
5
6
7
8
9
|
// …
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
import missinglink
+
+missinglink_callback = missinglink.KerasCallback()batch_size = 128
num_classes = 10
epochs = 12
// …
|
Finally, let Keras use our callback object. We want to add calls during the training and test stages. Scroll all the way to the bottom of the file and add the MissingLink callback to the fit() function call:
1
2
3
4
5
6
7
8
9
10
11
12
|
// ...
model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test),
+ callbacks=[missinglink_callback])
score = model.evaluate(x_test, y_test, verbose=0)
print(‘Test loss:’, score[0])
print(‘Test accuracy:’, score[1])
// ...
|
Lastly, let the MissingLink SDK know we’re starting the testing stage:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// …
model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test),
callbacks=[missinglink_callback])
–score = model.evaluate(x_test, y_test, verbose=0)
+with missinglink_callback.test(model):
+ score = model.evaluate(x_test, y_test, verbose=0)
+
print(‘Test loss:’, score[0])
print(‘Test accuracy:’, score[1])
// …
|
Run the integrated experiment
We’re all set up to run the experiment again, but this time to see it in the Missing Link dashboard.
Go back to the terminal and run the script again:
1
2
3
|
$ python mnist_cnn.py
|
You should see the initialization and the beginning of training. Now, switch back to the MissingLink dashboard.
Open the MissingLink dashboard and click the projects toolbar button on the left. In this page, you should see the list of experiments that belong to your project.
Choose the tutorials project. Your experiment appears.
Now you can click anywhere on the experiment line to show more information about the experiment’s progress.
Commit the code changes
Let’s commit our code to the repo. Go to your terminal and run the following commands:
1
2
3
4
5
|
$ git add .
$ git commit –m “integrate with missinglink”
$ git push
|
That’s it. In the next post, we will go over how to run multiple experiments in parallel on a managed server. MissingLink can help you manage your cloud and on-premise servers as a single grid, so you don’t have to worry about that and only focus on training your model.
We encourage you to give MissingLink a try today and let us know what you need in the future. We eagerly await your feedback and ideas as to how we can take your deep learning experiments to the next level. Reach out via the orange chat icon in the MissingLink.ai dashboard or tweet us at @missinglinkai.