Algorithmia Blog - Deploying AI at scale

Algorithm Spotlight: Crowd Counter

Source: Wikipedia

Despite only making it into the political mainstream recently, crowd size estimation has always been an important task for corporate development, retail planning, and resource allocation. It helps property owners and event organizers predict demand, understand utilization of physical locations, and test different product launches and arrangements. And Machine Learning is making it more accessible than ever.

What is crowd counter?

Crowd Counter is an algorithm in our marketplace that implements a deep-learning based crowd counting method. This method considers the estimation problem as a regression problem, and tries to create a heatmap of the possible locations of people’s heads using a convolutional neural network (CNN). Below is an image of the neural network structure, taken from the paper.

What are some good use cases?

Similar to any other deep learning based method, crowd counter is highly biased by the training data it is trained on. Here are a few things to consider before feeding inputs to our model:

  • The more visible faces your training data has, the better your model will work.
  • It’s important that your training images and the people in these images are the right size in terms of numbers of pixels: images that are too small or too large will result in estimation errors.
  • For very large images, consider dividing images into several small images, and add up the results of the individual images to come up with an overall estimate.

Below are three images from ShanghaiTech dataset to demonstrate good and bad use cases.

There are several issues with the third image that do not exist in the first two images, such as occlusions, bad lightning, a higher number of people not facing the camera, and a higher number of smaller people (in terms of number of pixels). All of these factors contribute to the degraded performance in terms of the estimation error.

Using crowd counter on Algorithmia

Using the crowd counter algorithm is as simple as a few lines of code on Algorithmia. Here’s what it would look like in Python:

import Algorithmia

input = {
"image": "data://deeplearning/example_data/Batsheva_theater_crowd.jpg"
}
client = Algorithmia.client('simssb+PbkWBK1DKmA4Rfm0rVV61')
algo = client.algo('deeplearning/CrowdCounter/0.3.0')
print(algo.pipe(input).result)

Sample Output:

{
"count": 65
}

And just in case you don’t love Python, we’ve got clients in most major programming languages.

Conclusion

Crowd Counter is an algorithm that can be used to estimate the number of people in an image, and it’s especially useful for cases where manual counting can be time consuming. We utilized a recent deep learning based model to approach this problem. The model is good at giving a rough estimate of the number of people in an image, especially when people are not too small or too large (in terms of number of pixels), when they’re not occluded by other objects, and as long as the lightning is reasonable.

This algorithm is still at its infancy, and we are open to suggestions and improvements. Let us know what you think! You can say hi at hello@algorithmia.com, or make your case on Twitter to @algorithmia.

References

– Zhang, Yingying, et al. “Single-image crowd counting via multi-column convolutional neural network.” Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.

– https://github.com/desenzhou/ShanghaiTechDataset. Copyright (c) 2017, Desen Zhou All rights reserved. Link to license: https://github.com/desenzhou/ShanghaiTechDataset/blob/master/LICENSE

– Demo image was retrieved from Wikipedia, and it is licensed under CC BY-SA 3.0 : https://en.wikipedia.org/wiki/Audience#/media/File:Batsheva_theater_crowd_in_Tel_Aviv_by_David_Shankbone.jpg