September 23, 2018 | Joe Salomon

What You Need to Know About TensorFlow

Tensorflow logo

There are some detection problems in the world that only experts can solve, and by doing so are saving lives every day. Radiologists looking for intracerebral hemorrhage (ICH) save lives, but their time is scarce and expensive.

But what if we could build an AI to perform this sort of detection?

It is no simple task to train a CNN model, such as U-Net, to achieve this. But with the progress of deep learning libraries such as TensorFlow, the revolution of cloud providers such as AWS, Azure, and GCP, and deep learning platforms such as MissingLink, it’s becoming increasingly feasible for startups to build an app at almost any scale—including to mimic the work of radiologists and other experts. As evidence, one of our customers, Aidoc, just received FDA approval for exactly such a solution.

Let’s take a closer look at what TensorFlow brings to the table.

What Is TensorFlow?

TensorFlow is an open source software library for high-performance numerical computation. It’s free and easy to use. And as a software library, it can be downloaded and used in your preferred language (such as Python and others).

What Was TensorFlow Built For?

TensorFlow was built by the Google Brain team for high-performance numerical computations—in a readable, simple library for Python and other languages—for complex deep learning data models. But TensorFlow is so much more than just a library for deep learning models and is critical for data science teams.

Distributed Training

If your team is exploring different types of CNN models, from AlexNet to VGG-19, you have probably discovered it can take days or even weeks to train a model on a single GPU. On CPUs, this problem was addressed years ago with technologies such as Hadoop for distributed data and MapReduce for distributed computing. But scaling out across GPUs introduces new complexities that require a new approach. Enter TensorFlow.

Distributed TensorFlow allows for the use of multiple GPUs with just a few lines of code. You can decide how fast you want to run your model and have a choice of different computing units as well as how many to run simultaneously. In addition to reducing training time through parallelization, TensorFlow solves another problem. Unlike traditional distributed computing, with TensorFlow you don’t need to set up servers for managing the distribution. Here’s a simple tutorial to implement your model on distributed servers.

Data Pipelines

Two very big problems when building a deep learning algorithm is data cleansing and data augmentation. And these are two of the functionalities handled by data pipelines.

Data Cleansing

On a large-scale data stream, data cleansing can come at a high computational cost, as dirty data requires correcting, deleting, replacing and more.

Data Augmentation

In the world of big data deep learning, the more labeled data you have, the stronger your model can be. To address the problem of small data sets, rotating, mirroring, and other augmentation techniques for your data is a great solution.

TensorFlow helps address both issues. Let’s see how.

The TensorFlow Solution to Data Pipelines: Dataset API

Let’s look at a few uses of a TensorFlow API.

Pre-fetching

Pre-fetching is a technique for speeding up fetch operations. In deep learning, pre-fetching is a great tool to speed up training. While your model is training on a GPU, it can simultaneously utilize the CPU to fetch the next batch and do the pre-processing of the data. With TensorFlow, This feature runs automatically It is a great time-saver when running a deep neural network model. See here for a more detailed explanation of dataset pipeline performance.

Streaming

When dealing with very large datasets, specifically in computer vision scenarios, the local disk and memory on the machine are not big enough to contain the entire dataset locally. One powerful solution is streaming subsets of the data as needed. TensorFlow supports streaming as part of the data fetching mechanism built into tf.data. Streaming allows for researchers to define their data sources and TensorFlow will automatically fetch the data on demand, removing barriers for dealing with huge datasets.

Supporting Multiple Sources of Data

In some experiments, you may want to aggregate several image databases into one image model. Or in text modeling, you might have different sequences and different symbols that need to be converted to readable features. TensorFlow was built to address this challenge.

TensorBoard

Monitoring can be a big issue for data scientists. How can you tell what the best hyperparameters are for your hypothesis? How can you spot a mistake that can impact the model’s runtime?

TensorBoard is a plugin for TensorFlow that allows you to visualize progress while running your hypothesis. When building a model, data manipulation and changing hyperparameters are very common. TensorBoard is a great debugger tool for exploring your hypothesis.

TensorBoard enables you to optimize, debug, and understand complex models being run. So you can compare models for accuracy on train, dev, and test as well as in regards to the runtime and resources each model requires. Let’s review some of its key capabilities.

Fully configured TensorBoard from the TensorFlow site

TensorFlow Debugger

At the 2018 TensorFlow Dev Summit, Justine Tunney and Shanqing Cai introduced a new feature: the TensorFlow Debugger: “TensorFlow Debugger is an interactive web GUI for controlling the execution of TensorFlow models, setting breakpoints, stepping through graph nodes, watching tensors flow in real-time, and pinpointing problems down to the tiniest NaN. This tool now comes included with TensorBoard via its open plugin API.”

For more details on this, check out a video covering this new debugging tool from the summit.

TensorBoard Graph Visualization

One of the most popular and useful tools in TensorBoard is the ability to visualize the graph. When building a complex deep network, with different CNN and RNN architectures that maybe go together to a Vanilla neural network and additional hidden layers, it is extremely useful to be able to visualize all of this in an interactive and easy way. TensorBoard allows you to do this.

tf.summary

The TensorFlow.summary library is somewhat similar to the classic R summary function, but for deep learning uses. It takes a regular tensor and outputs summarized values that go into TensorBoard.

  • summary.scalar: is for a scalar tensor such as accuracy value or loss
  • summary.histogram: plots a histogram of non-scalar tensors such as bias matrices
  • summary.image: plots images such as your generated output or train

TensorBoard can be a powerful tool that solves many engineering pains in deep learning. What TensorBoard is not good at, however, is comparing several different hypotheses. Think of three data scientists working on the same model from different angles. With TensorBoard, you can visualize their progress but not compare their approaches. As a data science team leader, how can you choose the one that best fits your needs and establish the optimal strategy for your data science team?

This is where MissingLink comes in and we will elaborate on that in a future post.

Summary

As the data science community continues to grow, so do the problems it faces. Meanwhile,  different tools to address this are developing as well. TensorFlow is such a tool, built as a deep learning library to help reduce complex modeling code to a few simple lines. As the amount and variety of data increase, so does the demand to run faster models, prefetch data from different sources, run that data on better pipelines, and monitor progress made.

TensorFlow was built not only to simplify code but also to run it for any type and quantity of data. Having said that, most data scientists are not developers. So efforts are being made to make TensorFlow fast, flexible, and easy to use for cloud and scalability applications so that any data science team out there can easily implement it.

All the capabilities we presented here are available today for data science teams to explore the world of data without any server boundaries or backend complexity. So even small companies, such as the deep learning startup Aidoc, can build a machine that accelerates the work of the most talented expert radiologists in hospitals around the world.

Joe Salomon
Joe Salomon
VP Product