Deep Learning in Scala Part 3: Object Detection

In this post, we're going to create an off the shelve object detector using OpenCV and TensorFlow for Scala. The detector will be able to detect common objects like people in still images and videos. It will also be able to run on a live video stream captured from your webcam.

Object detection

In the previous post we talked about image recognition (or image classification). Image recognition is about recognizing what the content of an image is. In object detection, we want to predict where one or multiple objects are located in an image. Usually when we say object detection we mean recognition and localization together. I.e. we want a neural net to tell us that the image contains a beagle, and to also tell us the location of the beagle within the image.

Dogs example Dogs object detection example
In image recognition, the neural network predicts the content of the image as "beagle". In object detection, it additionally predicts the position of the beagles.

In most cases, a neural network is trained to predict the coordinates of the rectangle surrounding an object, called bounding box, and to classify the object within that bounding box. The classification part is almost always done using a convolutional …

more ...

Deep Learning in Scala Part 2: Hello, Neural Net!

In the first part of this series, we saw a high-level overview of deep learning, and why Scala is a good fit for building neural networks. We also discussed what a deep learning library should provide, and we looked at a few existing libraries. Now it's time to build the canonical "Hello, World!" example for deep learning: Classifying handwritten digits.

Creating a neural network

Building a neural network usually consists of the following steps:

  1. Determine your goal.
  2. Prepare the training data (collect, preprocess, vectorize etc.).
    1. Divide the data into training set/cross-validation set/test set for evaluation.
  3. Create the neural network architecture.
    1. Define the types, number and size of layers.
    2. Define other hyperparameters such as loss function, optimizer, or learning rate.
  4. Train your model on the training data.
  5. Evaluate your model on the cross-validation set.
  6. Depending on the results, repeat steps 3-5 with different hyperparameters, or collect more data until you're satisfied with the results.
  7. Do a final evaluation on the test set.

In our case, the task is already set: We want to recognize handwritten digits. The second step, data preparation, usually takes most of the effort, but we don't have to worry about it here because it has …

more ...

Deep Learning in Scala Part 1: Basics and Libraries


Deep learning is a subset of machine learning, which has seen a tremendous growth in popularity recently. One of the reasons for that growth is that deep learning has brought huge advances to fields such as computer vision, speech recognition or machine translation. Those are fields that are mostly dealing with unstructured data that have traditionally been difficult for computers. Another reason for the success of deep learning, compared to traditional machine learning approaches, is its ability to automatically learn features from raw data, such as images, reducing the need for expensive manual feature engineering and making it applicable to a broader range of domains.

Deep learning is actually just a newer term for modern artificial neural networks. It's called "Deep", because these networks tend to be stacked in a sequence of several successive layers of computation. In a nutshell, common types of deep neural networks can learn to approximate very complex functions by being trained on (usually a lot of) known examples. After being trained, a deep learning model can be applied to previously unseen data and, with high probability, make correct predictions about that data.

Neural networks are not a new idea, they have been around for …

more ...