Beer Inspector AI: How to Define a “Good” Beer?

Unique Datasentics’s Project: Assessing Beer Quality by Computer Vision

Lukas Tryner
Jul 21, 2020 · 6 min read
Photo by Timothy Dykes on Unsplash.

Filled with mingled cream and amber,

I will drain that glass again.

Such hilarious visions clamber

Through the chamber of my brain.

Quaintest thoughts, queerest fancies

Come to life and fade away.

What care I how time advances;

I am drinking ale today.

This was a poem about the main topic of this article, beer, called “Lines on Ale” by an American writer and poet Edgar Allen Poe. Czech beer is a phenomenon that has made our small republic famous all over the world. It is also a subject of many arguments and quarrels, whether it is not too cheap or expensive, which brand tastes the best or whether drinking “one” before driving should be prohibited or not.

Photo by radovan on Unsplash.

Let’s not discuss these subjective topics and just forward to the main objective one: how to define and measure beer’s quality. Since that is the reason to pay a bit more for a beer in the pub, isn’t it? It doesn’t matter what brand, size, or color of the beer you prefer, a bit more expensive beer in the premium restaurant should be “better” than the one in some local pub.

But what is the definition of a “good” beer that we, consumers, can register on a glass of the brought lager? According to beer brewers, there are three visual indicators that the beer was drafted correctly, which are assessed by hired controllers and must be fulfilled to get the “good” beer.

The first one is quite obvious: beer ratio. Every beer brand usually possesses its glass that their beer should be drafted in. On this glass, there should be accurate and clear marks of the bottom and top border-lines for the correctly drafted beer (or at least one). That means, that if the beer border-line is strictly on the 0.5l mark on the glass, you should always get this much beer, no more, no less. In this scenario, both incorrect possibilities are equally wrong (subjectively you would probably not mind getting more beer).

Pilsner Urquell glass, photo by Hana Mara on Pexels.

Since the marking system with one border-line would depend a lot on the skill of the bartender, most brands use two border-lines. For example for the Pilsner Urquell brand, the correct beer ratio is defined as a range between the lowest and highest point of the company logo on the glass. In other words, the correct beer ratio of the drafted beer is a range between 55 and 78 percent of the glass’s height! Now imagine the difference in the volumes in the limit cases!

Equally important is the beer head structure. Beer head (also head or collar) should be dense, thick, airtight, optimally there should not be any noticeable air bubbles, because their bursting leads to thinner airy beer head and faster lager warming. Correct beer head structure should prevent losing beer head a few seconds after your beer was brought to your table and that the beer head will still “sit” on top of the beer until you “finish” it.

Photo by Frank Luca on Unsplash.

Beer head lacing (also lacing or lace) on the glass is the last visual indicator and directly corresponds to the beer head structure. If the beer head structure is correct, then you should see a beer head lacing (nearly) every time you sip the lager. Beer head lacing has several forms. It can be in the shape of a circle or semicircle around the circumference of the glass or simply a blob.

Cropped photo by Peter Kraayvanger on Pixabay.

These three attributes are very important for breweries because they can easily get feedback about their created products. Also, how these products are handled by bartenders since bad pub ratings with their drafted beer can affect their salaries. Therefore they hire controllers, whose work is to take a stroll in their city and check the brand’s drafted beers in the pubs and restaurants.

And here is the dilemma. Every received feedback is subjective because all the controllers judge the drafted beer by their own opinion, which can be affected by their current mood or simply liking that pub/bartender. Also, there isn’t any proof, that would support the controller’s statements about that specific drafted beer.

Beer Inspector logo.

That’s why Beer Inspector comes to play! It is a tool that objectively assesses drafted beer by a photo and stores the results in a database for reporting and further optimization. Beer Inspector utilizes deep learning methods to train a model on a given large image dataset, which then assesses a taken photo. The only thing that a hired controller has to do is to take a photo of the drafted beer three times (one photo per visual indicator) — one from a distance to correctly measure the beer ratio, one close up photo of the beer head for its structure and then after taking a few sips the last one for beer head lacing on the glass.

For beer ratio, this tool has to solve many additional subtasks first, such as rotation of the image, different shooting heights, or the beer caps (when the beer head is higher than the edge of the glass). Then it detects the front of the glass, beer, and then correctly calculates the beer ratio.

Original image and image with detected beer ratio.

Classifying beer head structure has some issues too. How do bubbles in the beer head have to be big and how many of them have to be there for the beer head to be considered bad? The solution is to detect the beer head in the glass, select only this area from the image and divide it into many small parts. Then each of these parts is classified whether it is good or bad beer head structure. Finally, these results are summed up and we receive the beer head ratio, which represents how many parts of the beer head were classified as good. Now we only need to select some threshold value.

Original image and image with classified beer head grids.

It is nearly an identical story with the beer head lacing on the glass. Photos and calculated results are then stored in the database for reporting and further study for method and/or model improvements.

And that’s it! In summary, Beer Inspector’s advantage is that it objectively classifies drafted beer from the photo and brings full documentation and reports to the customer.

The next part will be focused on the technical solution!

Thank you for reading! If you have any further questions or suggestions, feel free to leave a response. Also, if you have a topic in mind that you would like us to cover in future posts, let us know.

DataSentics

An agile machine learning and cloud data engineering boutique

DataSentics

Make data science and machine learning have a real impact on organizations across the world — demystify the hype and black magic surrounding AI/ML and bring to life transparent production-level data science solutions and products delivering tangible impact and innovation.

Lukas Tryner

Written by

Data Scientist of the DataSentics located in Prague. Specialized in computer vision and deep learning.

DataSentics

Make data science and machine learning have a real impact on organizations across the world — demystify the hype and black magic surrounding AI/ML and bring to life transparent production-level data science solutions and products delivering tangible impact and innovation.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store