Attendance Estimation with Azure ML
Tags: machinelearning, azure, python, crowdcounting
Published: 2020-04-08 06:27:47

---
title: Attendance Estimation with Azure ML
published: true
date: 2020-04-06 07:08:17 UTC
tags: machinelearning, azure, python, crowdcounting
canonical_url: https://towardsdatascience.com/attendance-estimation-with-azure-ml-e6678f8a44ed
---

![](https://cdn-images-1.medium.com/max/1024/1*I8-1bMsuaVMeqUpsIPK3dQ.jpeg)

![](https://cdn-images-1.medium.com/max/328/1*rHj2T7WBvQdWleR9M-3GZg.png)<figcaption>Image from Pexels https://www.pexels.com/photo/people-on-stadium-event-1916816/</figcaption>

TLDR; This post provides an E2E Jupyter notebook for training crowd counting models with [C-3-Framework](https://github.com/gjy3035/C-3-Framework) and [AzureML SDK for Python](https://docs.microsoft.com/en-us/python/api/overview/azure/ml/?WT.mc.id=aiapril-medium-abornst&view=azure-ml-py)

### What is Audience Estimation

Often as AI Cloud Developer Advocate I find myself talking in front of various audiences. Now that I have some time to work on some new demos while working from home I’ve been thinking of how to better understand the reach of the audience I talk too for when life resumes to normal.

Often I estimate the reach of my of talks based on registrations or by eyeballing but what if there was a better way. As an AI engineer I was inspired by the work done by the [Microsoft CAT team on crowd counting](https://github.com/microsoft/computervision-recipes/tree/master/contrib/crowd_counting). I couldn’t find any tutorials on how to train these kinds of models at scale on the cloud and decided to write my own and document the process for my readers.

Code for the post can be found below

[aribornstein/AudienceEstimationAuzreML](https://github.com/aribornstein/AudienceEstimationAuzreML)

If you are new to Azure you can get started a free subscription using the link below.

[Create your Azure free account today | Microsoft Azure](https://azure.microsoft.com/en-us/free/?WT.mc.id=aiapril-medium-abornst)

### Detection vs Dense Approaches

Before we get started we should try to understand the differences between the top two audience estimation approaches.

![](https://cdn-images-1.medium.com/max/802/0*7UkupL9RP-vj1En4.PNG)<figcaption>Pictured Dense Model on Left, Pose Detection Model on Right. Image from <a href="https://github.com/microsoft/computervision-recipes/tree/master/contrib/crowd_counting">https://github.com/microsoft/computervision-recipes/tree/master/contrib/crowd_counting</a></figcaption>

**Detection Based Approaches** , such as person detection, semantic segmentation, and pose estimation, work best on small crowds but have trouble scaling to estimating the size of larger audiences of the dozens or more people.

![](https://cdn-images-1.medium.com/max/910/0*bHdjeIs16Ts6e7Uz)<figcaption>Results of detection post and segmention from the pynino library <a href="https://github.com/hampen2929/pyvino">https://github.com/hampen2929/pyvino</a></figcaption>

**Dense Approaches** try to learn a feature mapping between the original image and a density map of generated from placing a keypoint on all the people in the image. These models work best for estimating the size of larger audiences.

![](https://cdn-images-1.medium.com/max/983/1*-_9pXUaxSiqvSrs03qVpiA.png)<figcaption>An example of Dense Map and the estimated output returned from Density Approximation Model</figcaption>

One of the most popular Dense models for is the [Multi Column CNN (**MCNN)** Model](https://zpascal.net/cvpr2016/Zhang_Single-Image_Crowd_Counting_CVPR_2016_paper.pdf) due to it’s relatively quick evaluation time.

### Running a Pretrained Dense Approximator Model

There is [extensive documentation on how to train your own and use pre-trained detection](https://medium.com/@ylashin/detectron2-the-basic-end-to-end-tutorial-5ac90e2f90e3) based models in the cloud as well as some [great out of the box cloud services.](https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/concept-object-detection?WT.mc.id=aiapril-medium-abornst)

In this post we will demonstrate how to run and train your own MCNN Dense Approximate Model with the [AzureML SDK](https://docs.microsoft.com/en-us/python/api/overview/azure/ml/?WT.mc.id=aiapril-medium-abornst&view=azure-ml-py) and the [C-3-Framework](https://github.com/gjy3035/C-3-Framework).

The C-3 framework developed by Junyu Gao provides provide pre-processing code for six common mainstream crowd counting data sets and multiple model configurations of MCNN implemented in PyTorch.

[gjy3035/C-3-Framework](https://github.com/gjy3035/C-3-Framework)

In his G[itHub Repo](https://github.com/gjy3035/C-3-Framework), Gao provides links to the processed datasets and pre-trained models he doesn’t provide an end to end example on one document, however so I took the liberty to write one in Jupyter notebooks myself that shows how to install the C3-Framework and run a pre-trained model.

[aribornstein/AudienceEstimationAzureML](https://github.com/aribornstein/AudienceEstimationAzureML/blob/master/LocalCrowdCounting.ipynb)

### Training your own Dense Approximation Model at Scale with Azure ML

![](https://cdn-images-1.medium.com/max/1024/0*9LW6B6_sr02_7zud.gif)

The [Azure Machine Learning Service](https://docs.microsoft.com/en-us/azure/machine-learning/?WT.mc.id=aiapril-medium-abornst) provides several ways to train machine learning models, from code first solutions using the [SDK](https://docs.microsoft.com/en-us/azure/machine-learning/?WT.mc.id=aiapril-medium-abornst)to low code solutions such as [AutoML](https://azure.microsoft.com/en-us/blog/visual-interface-for-azure-machine-learning-service/?WT.mc_id=aiapril-medium-abornst) and the [Visual Designer](https://azure.microsoft.com/en-us/blog/visual-interface-for-azure-machine-learning-service/?WT.mc_id=aiapril-medium-abornst).

There are 8 simple steps for training a model with the [AzureML SDK](https://docs.microsoft.com/en-us/azure/machine-learning/?WT.mc.id=aiapril-medium-abornst)

![](https://cdn-images-1.medium.com/max/1024/0*9VTE1LS1pHULFUrS)<figcaption>The first 3 steps pertain to setting up your training infrastructure from choosing your compute to loading your data.</figcaption>

![](https://cdn-images-1.medium.com/max/1024/0*9SQaLv2SAxJ_mzRN)<figcaption>The remaining five steps relate to setting up the environment to run and experiment with different training scripts and manage the resulting model.</figcaption>

In the notebook below you will see an example of each of these 8 steps end to end with to train your own Audience Estimation models at scale.

[aribornstein/AudienceEstimationAzureML](https://github.com/aribornstein/AudienceEstimationAuzreML/blob/master/AML%20Crowd%20Counting%20Notebook.ipynb)

Once you run the notebook be sure to check out my 9tips for production machine learning and try playing around with code. I’ve left a couple of challenges for you to try at the bottom of the notebook.

[9 Advanced Tips for Production Machine Learning](https://dev.to/azure/9-advanced-tips-for-production-machine-learning-4ccg)

Additionally, I’ve included some other great resources on Crowd Counting below.

### Additional Resources

- [gjy3035/Awesome-Crowd-Counting](https://github.com/gjy3035/Awesome-Crowd-Counting)
- [It's a Record-Breaking Crowd! A Must-Read Tutorial to Build your First Crowd Counting Model using Deep Learning](https://www.analyticsvidhya.com/blog/2019/02/building-crowd-counting-model-python/)
- [microsoft/computervision-recipes](https://github.com/microsoft/computervision-recipes/tree/master/contrib/crowd_counting)
- [C^3 Framework系列之一：一个基于PyTorch的开源人群计数框架](https://zhuanlan.zhihu.com/p/65650998)
- [Crowd Counting Made Easy](https://medium.com/secure-and-private-ai-writing-challenge/crowd-counting-made-easy-1bf84f18ff61)

### Next Steps

Here are some additional resources to help with your computer vision journey on Azure.

- [Custom Vision | Microsoft Azure](https://azure.microsoft.com/en-us/services/cognitive-services/custom-vision-service/?WT.mc_id=aiapril-medium-abornst)
- [Computer Vision | Microsoft Azure](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/?WT.mc_id=aiapril-medium-abornst)
- [Video Indexer - AI Video Insights | Microsoft Azure](https://azure.microsoft.com/en-us/services/media-services/video-indexer/?WT.mc_id=aiapril-medium-abornst)
- [Computer Vision Explorer](https://vision-explorer.allenai.org/)
- [facebookresearch/detectron2](https://github.com/facebookresearch/detectron2)

### About the Author

[**Aaron (Ari) Bornstein**](https://www.linkedin.com/in/aaron-ari-bornstein-22aa7a77/) is an AI researcher with a passion for history, engaging with new technologies and computational medicine. As an Open Source Engineer at Microsoft’s Cloud Developer Advocacy team, he collaborates with Israeli Hi-Tech Community, to solve real world problems with game changing technologies that are then documented, open sourced, and shared with the rest of the world.

* * *