First impressions about Uber’s Ludwig. A simple machine learning tool. Or not?

German Gensetskiy
Go Wombat
Published in
4 min readMay 3, 2019
Ludwig logo

Not so long ago Uber presented a promising tool intended to simplify work with deep machine learning algorithms.

Ludwig is a toolbox that allows to train and test deep learning models without the need to write code.

And so, we were very interested to check that out. Is it a machine that will take our jobs or a useful tool that we can work with.

The interesting part — is that Ludwig provides a Python API, so it must be simple to integrate the model with your applications.

Task

As a simple task for our experiment, we decided to do an image classification — is it a person on the image or not. For a better understanding of simplicity (or complexity) of the tool, we asked some of our teammates, that never used to work with deep machine learning before, to do the same.

Data

Well, despite the fact that Ludwig must make your work with deep learning algorithms simple — you still need to find and prepare some data to work with.

So, I started to look for some open datasets with people on it. I found two that seemed suitable to me. A “Stanford 40 Actions” and “INRIA Person Dataset”. After looking through them I decided to use Stanford’s dataset as positive (where the person present) images and for negative one — INRIA part with negative (where are no persons) images.

Ludwig works with CSV annotations. For images, you just need to put a path in your CSV file and specify type: image in the model config file. To annotate my dataset I used a simple python script.

Setting up “Ludwig”

Well, that part is mostly pretty simple. I just started to go through “Getting started” part of the official Ludwig’s documentation. Actually, if you just want to have a simple CPU enabled the version of Ludwig in your environment, it’s all about pip install ludwig.

But, if you want to have a GPU enabled one you will need to clone Ludwig from GitHub repository and change tensorflow to tensorflow-gpu in requirements.txt and in setup.py.

It actually would be pretty useful if there was a package ludwig-gpu. And I decided — why not to make a simple one for myself. Since pip allows us to install packages just from git repository very easy, I simply forked the repo and changed the requirements. After that, all I need is to do pip install git+https://github.com/Ignisor/ludwig-gpu.git.

And of course, if you’re planning to use GPU you need to install all of the Tensorflow requirements. It’s all described here.

Model parameters

Ludwig works with model parameters in YAML format. There is a plenty amount of examples for most of the use cases. I decided to keep it simple and just use an example provided for image classification.

input_features:
-
name: image_path
type: image
encoder: stacked_cnn

output_features:
-
name: class
type: category

But when I started to train I got this error:

ValueError: could not broadcast input array from shape (424,300,3) into shape (300,354,3)

Not really descriptive one as for a user that not familiar with tensors. That one happens because images have different resolution. Fortunately, Ludwig, has some preprocessing built in:

input_features:
-
name: image_path
type: image
encoder: stacked_cnn
preprocessing:
resize_method: interpolate
height: 400
width: 300

output_features:
-
name: class
type: category

But even now, one more problem happened to me. When I start training — My PC just freezes. The problem for me was that default batch size is 128 and my machine quickly ran out of memory. And the fix is simple:

input_features:
-
name: image_path
type: image
encoder: stacked_cnn
preprocessing:
resize_method: interpolate
height: 400
width: 300

output_features:
-
name: class
type: category

training:
batch_size: 16

Training

To start training your model — all you need is just one command:

ludwig experiment -mdf model_definition.yaml -g 0 --data_csv humans_data.csv

About parameters:

  • -mdf — Model definition file. YAML file describing the model.
  • -g — List of GPUs to use.
  • --data_csv — path to file with CSV that describes the data.

Why it’s experiment instead of train? This command combines training and prediction into a single handy command. It will train the model and then check the accuracy.

Example and visual check using Python API

To present results you can use Jupyter Notebook or a simple python script. Using a Ludwig’s Python API.

API is quite simple to use:

model = LudwigModel.load('model/')
result = model.predict(data_csv='predict.csv')

But there was one trouble. Preprocessing was not working because of some minor bug. So, it’s open-source, why not to fix it ;)

Here is what I’ve got, not perfect, but good enough to understand how to work with Ludwig.

Jupyter with an example of the model predictions

Thanks for reading! Hope you liked it.

German Gensetskiy under the support of Go Wombat Team.

P.S. In case of any troubles I will be happy to hear your feedback. You can reach me out by the email: Ignis2497@gmail.com

--

--