Post image unsplash-logo Franck V.

Machine learning is really fun to play with. Instead of a more traditional approach of working out a solution for a problem, and getting an answer from it, we input answers to a problem, and get a solution from it. Weird? Yeah, a bit. But it’s a refreshing think-outside-the-box experience, especially if you’ve been stuck with traditional programming for a long time.

Programming machine learning can be approached in a variety of ways. The most common, at the time of writing this post, is to use Python and usually some kind of Notebook software/service to code, arrange and visualize problems easily. This approach is fine and offers a hard to beat overview, allows for easy sharing and collaboration and uses a known and easy programming language. I strongly advise to try this approach first, especially if you’re completely new to machine learning. Then again, maybe you are focusing on a new language to learn, and really want to stick to that language. Perhaps you hate Python for some reason or you just want a different approach. Resources for machine learning without Python is harder to find but it’s definitely doable.

What to expect from this series

The goal for this guide is to be a a cover-it-all for getting started with machine learning with TensorFlow in Rust. As such it will be quite broad and not necessarily go into deep details about everything. (Deep details for machine learning seems easy to find anyway - simple overviews and tutorials are not)

This guide will assume a Windows 10 PC with Rust 2018 edition on a machine with a CUDA supported Nvidia graphics card (GPU) for TensorFlow. If your setup differs you should still be able to get something out of this series but I will not describe other setups. If you’re running Linux, Docker, etc, all of these are typically more documented compared to a Windows/GPU setup. For example, running Tensorflow on Windows 10 without GPU support is really easy, simply spin up a Docker image that includes everything you need. On Linux you can get Tensorflow Docker images with included GPU support as well. You can read more about Tensorflow’s Docker support and instructions here.

Traditional machine learning in Rust

I will not spend a lot of time selling in the Rust programming language, the official Rust website does a much better job. My opinion is that Rust is a really nice language to use for machine learning for a couple of reasons; It is very fast, you can easily compile your app for multiple devices/architectures and it is powered by Cargo and for easily using existing code and packages. I also find it a very hygienic and fun language to use.

A few crates exist for machine learning in Rust, many without the need to download additional dependencies. Rusty machine is a good example. Unfortunately not very actively maintained but it still covers a lot of machine learning algorithms and is easy to use. In fact, I find this crate sufficient for most of my hobby projects and it would probably work fine for small/medium “real” projects as well. I highly recommend you start prototyping with a crate like this since the time from setup to writing code is minimal compared to setting up a GPU supported Tensorflow environment.

TensorFlow machine learning in Rust

If you’re exploring or planning to train very large datasets, maybe for a really deep neural network, you will eventually grow tired of watching progress bars slowly ticking along as your CPUs cough and sweat to get your model ready. This is where you want GPU support. Again, this (usually) occurs a bit further down the machine learning road and it’s probably not where you want to start your journey.

Setting up TensorFlow with GPU support on a Windows 10 PC is, sadly, not the easiest thing to do. TensorFlow agree and recommend to use their Docker images instead of a manual setup. Unfortunately, at this time, Windows users cannot get the GPU to pass through to Docker. So if we want to have GPU support, we have to set it up ourselves.

The next part of the series will go through setting up TensorFlow and all the Nvidia and CUDA dependencies on Windows 10.