Machine Learning in the Real World 🧠 πŸ€–

ML for real-world applications is much more than designing fancy networks and fine-tuning parameters.

In fact, you will spend most of your time curating a good dataset.

Let's go through the process together πŸ‘‡

#RepostFriday

Collect Data πŸ’½

We need to represent the real world as accurately as possible. If some situations are underrepresented we are introducing Sampling Bias.

Sampling Bias is nasty because we'll have high test accuracy, but our model will perform badly when deployed.

πŸ‘‡
Traffic Lights 🚦

Let's build a model to recognize traffic lights for a self-driving car. We need to collect data for different:

β–ͺ️ Lighting conditions
β–ͺ️ Weather conditions
β–ͺ️ Distances and viewpoints
β–ͺ️ Strange variants

And if we sample only 🚦 we won't detect πŸš₯ πŸ€·β€β™‚οΈ

πŸ‘‡
Data Cleaning 🧹

Now we need to clean all corrupted and irrelevant samples. We need to remove:

β–ͺ️ Overexposed or underexposed images
β–ͺ️ Images in irrelevant situations
β–ͺ️ Faulty images

Leaving them in the dataset will hurt our model's performance!

πŸ‘‡
Preprocess Data βš™οΈ

Most ML models like their data nicely normalized and properly scaled. Bad normalization can also lead to worse performance (I have a nice story for another time...)

β–ͺ️ Crop and resize all images
β–ͺ️ Normalize all values (usually 0 mean and 1 std. dev.)

πŸ‘‡
Label Data 🏷️

Manual labeling is expensive. Try to be clever and automate as much as possible:

β–ͺ️ Generate labels from the input data
β–ͺ️ Use slow, but accurate algorithms offline
β–ͺ️ Pre-label data during collection
β–ͺ️ Develop good labeling tools
β–ͺ️ Use synthetic data?

πŸ‘‡
Label Correction ❌

You will always have errors in the labels - humans make mistakes. Review and iterate!

β–ͺ️ Spot checks to find systematic problems
β–ͺ️ Improve labeling guidelines and tools
β–ͺ️ Review test results and fix labels
β–ͺ️ Label samples multiple times

πŸ‘‡
The danger of label errors πŸ§‘β€πŸ«

A recent study by MIT found that 10 of the most popular public datasets had 3.4% label errors on average (ImageNet had 5.8%).

This even lead authors to choose the wrong (and more complex) model as their best one!

https://t.co/dfZPz6xnU0

πŸ‘‡
Balance Dataset βš–οΈ

Dealing with imbalanced data can be tricky...

Let's classify the color of the 🚦 - we can get 97% just by learning to recognize 🟒 and πŸ”΄, just because 🟑 is severely underrepresented.

I have a separate thread on this topic:
https://t.co/R8z3AeDD2b

πŸ‘‡
Train and Evaluate Model πŸ’ͺπŸ“

This is the part that is usually covered by ML courses. Now is the time to try out different features, network architectures, fine-tune parameters etc.

But we are not done yet... πŸ‘‡
Iterative Process πŸ”„

In most real-world applications the bottleneck is not the model itself, but the data. After having a first model, we need to review where it has problems and go back to:

β–ͺ️ Collecting and labeling more data
β–ͺ️ Correcting labels
β–ͺ️ Balancing the data

πŸ‘‡
Deploy Model 🚒

Deploying the model in production poses some additional constraints:

β–ͺ️ Speed
β–ͺ️ Cost
β–ͺ️ Stability
β–ͺ️ Privacy
β–ͺ️ Hardware availability and integration

We have to find a good trade-off between these factors and accuracy.

Now we are done, right? No...πŸ‘‡
Monitoring πŸ–₯️

The performance of the model will start degrading over time because the world keeps changing:

β–ͺ️ Concept drift - the real-world distribution changes
β–ͺ️ Data drift - the properties of the data change

We need to detect this, retrain, and deploy again.

Example πŸ‘‡
Drift ➑️

We now have a trained model to recognize 🚦, but people keep inventing new variants - see what some creative people in Munich came up with πŸ˜„

We need a way to detect that we have a problem, collect data, label, and retrain our model.

πŸ‘‡
Summary 🏁

This is how a typical ML pipeline for real-world applications looks like. Please remember this:

β–ͺ️ Curating a good dataset is the most important thing
β–ͺ️ Dataset curation is an iterative process
β–ͺ️ Monitoring is critical to ensure good performance over time
Every Friday I repost one of my old threads so more people get the chance to see them. During the rest of the week, I post new content on machine learning and web3.

If you are interested in seeing more, follow me @haltakov
.

More from haltakov.eth 🌍 πŸ‡ΊπŸ‡¦

Machine Learning Paper Reviews πŸ”ŽπŸ“œ

Check out this thread for short reviews of some interesting Machine Learning and Computer Vision papers. I explain the basic ideas and main takeaways of each paper in a Twitter thread.

πŸ‘‡ I'm adding new reviews all the time! πŸ‘‡

AlexNet - the paper that started the deep learning revolution in Computer Vision!


DenseNet - reducing the size and complexity of CNNs by adding dense connections between layers.


Playing for data - generating synthetic GT from a video game (GTA V) and using it to improving semantic segmentation models.


Transformers for image recognition - a new paper with the potential to replace convolutions with a transformer.
Let's talk about a common problem in ML - imbalanced data βš–οΈ

Imagine we want to detect all pixels belonging to a traffic light from a self-driving car's camera. We train a model with 99.88% performance. Pretty cool, right?

Actually, this model is useless ❌

Let me explain πŸ‘‡


The problem is the data is severely imbalanced - the ratio between traffic light pixels and background pixels is 800:1.

If we don't take any measures, our model will learn to classify each pixel as background giving us 99.88% accuracy. But it's useless!

What can we do? πŸ‘‡

Let me tell you about 3 ways of dealing with imbalanced data:

β–ͺ️ Choose the right evaluation metric
β–ͺ️ Undersampling your dataset
β–ͺ️ Oversampling your dataset
β–ͺ️ Adapting the loss

Let's dive in πŸ‘‡

1️⃣ Evaluation metrics

Looking at the overall accuracy is a very bad idea when dealing with imbalanced data. There are other measures that are much better suited:
β–ͺ️ Precision
β–ͺ️ Recall
β–ͺ️ F1 score

I wrote a whole thread on


2️⃣ Undersampling

The idea is to throw away samples of the overrepresented classes.

One way to do this is to randomly throw away samples. However, ideally, we want to make sure we are only throwing away samples that look similar.

Here is a strategy to achieve that πŸ‘‡

More from All

You May Also Like