Building My Own (And Better) Google Lens
Tags: ai, imageclassification, machinelearning
Published: 2020-08-12 09:21:28

---
title: Building My Own (And Better) Google Lens
published: true
date: 2019-02-04 12:00:00 UTC
tags: ai, imageclassification, machinelearning
canonical_url: https://flyingnobita.com/posts/2019/02/04/building_google_lens
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/wy31n9fjf3ff241dcy9a.jpg
---

What finally motivated me to build an image classification mobile app?

## Table of Contents 

1. [So what is fastai? Or fast.ai?](#so-what-is-fastai-or-fastai)
2. [Why Google Lens](#why-google-lens)

I recently took the [Deep Learning Part 1 online course](https://course.fast.ai) offered by Jeremy Howard. Having taken other machine learning MOOCs before, including courses from [Andrew Ng](https://www.coursera.org/learn/machine-learning), [Sebastien Thrun](https://www.udacity.com/course/intro-to-machine-learning--ud120), [Geoffrey Hinton](https://www.youtube.com/playlist?list=PLoRl3Ht4JOcdU872GhiYWf6jwrk_SNhz9), I can say that Jeremy’s course is indeed a bit different from the others. I don’t know if this is because of the top-down approach he used to present the topic (he quoted [research](https://www.gse.harvard.edu/news/uk/09/01/education-bat-seven-principles-educators) that shows it helps students learn and I agree), or his strong emphasis on the practical approach to AI, or it’s his self-deprecating humour that he enjoys using to poke fun at his management consulting job in his previous life. The correct answer is probably all of the above.

Now that I am eagerly waiting for Part 2 of his course, I have decided to heed his advice and build a (supposedly) small project to practice the techniques he taught in class using the fastai library. This is an effect that the previous courses I took didn’t have on me.

In this and future posts, I will talk about how I progress on the project and discuss topics that come up which I find interesting.

## So what is fastai? Or fast.ai?

Jeremy started a company [fast.ai](https://www.fast.ai/) to educate AI to the masses, with an interesting endgame:

> Our goal at fast.ai is for there to be nothing to teach.

fast.ai offers free online courses, which are recordings from his [SFU classes](https://www.usfca.edu/data-institute/certificates/deep-learning-part-one).

In [2017](https://www.fast.ai/2017/09/08/introducing-pytorch-for-fastai/), he decided to switch the deep learning framework he was using in his course from Keras and TensorFlow to [PyTorch](https://pytorch.org/). But he didn’t just stop there. Instead, he took the idea of Keras and built an opinionated library, [fastai](https://github.com/fastai/fastai), on top of PyTorch. He added helpful tools and incorporated the latest best practices that made applying AI to solving common problems a breeze.

PyTorch, a rewrite of [Torch](http://torch.ch/) (a defunct ML library based on Lua), got its roots from the ML research community and has been getting a lot of [attention](https://www.oreilly.com/ideas/why-ai-and-machine-learning-researchers-are-beginning-to-embrace-pytorch) in the general ML community recently. I think doing the fasta.ai course would be the perfect way for me to start using it.

Having said that, a key point that Jeremy made which resonates well with me is that we should not be focusing on learning the actual framework (though this is necessary), as there will always be newer and better frameworks being developed. Instead, we should be focusing our attention on learning the underlying AI concepts and techniques, which will allow us to switch framework if needed.

![arXiv.org Monthly Submission Rates](https://res.cloudinary.com/flyingnobita/image/fetch/c_limit,f_auto,q_auto,w_768/https://flyingnobita.com/assets/images/posts/building_google_lens__arxiv_monthly_submission_rates.webp)<figcaption><p>Keeping up with AI research is hard enough (<a href="https://arxiv.org/stats/monthly_submissions">source</a>)</p>
</figcaption>

## Why Google Lens

Computer vision has always been a popular branch of AI for anyone new to the field as the basic concepts can be understood easily when presented with vivid visuals. [MNIST](https://en.wikipedia.org/wiki/MNIST_database) is basically the Hello World for ML. While the recent advances in AI have made writing a simple image classifier easy (e.g. classifying digits, dogs vs cats) and requiring only a few lines of code, it gets much harder if we want to classify an object from a much larger number of possible labels.

![Not A Hotdog!](https://res.cloudinary.com/flyingnobita/image/fetch/c_limit,f_auto,q_auto,w_768/https://flyingnobita.com/assets/images/posts/building_google_lens__not-hotdog.webp)<figcaption><p>Building this should be much quicker</p>
</figcaption>

Using [Google Lens](https://lens.google.com/) as an example, it is very good at recognizing objects from a few pre-defined categories, such as landmarks, plants, and dog breeds. But if I want to identify an object that is not in these categories, say the [species of a butterfly](https://butterfly-conservation.org/butterflies/adonis-blue), or the name of a [Van Gogh painting](https://www.kaggle.com/gfolego/vangogh), then it wouldn’t work. Google Lens will suggest images which contain objects that look similar to my photo, but I would still need to click on that image and search the page for the information that I’m looking for.

Now if I had a trained model for identifying butterfly species and another model for identifying Van Gogh paints, and I could tell Google Lens beforehand which model to use, then the aforementioned problem might be solved.

This sounds to me like a simple and fun project to work on, and it might even be useful at times (at least until Google Lens, or [Bing Visual Search](https://www.digitaltrends.com/mobile/bing-visual-search-launches/), can start doing this).

Let’s try it.