LWCC: A LightWeight Crowd Counting library for Python that includes several pretrained state-of-the-art models.

Overview

LWCC: A LightWeight Crowd Counting library for Python

LWCC is a lightweight crowd counting framework for Python. It wraps four state-of-the-art models all based on convolutional neural networks: CSRNet, Bayesian crowd counting, DM-Count, and SFANet. The library is based on PyTorch.

Installation

The easiest way to install library LWCC and its prerequisites is to use the package manager pip.

pip install lwcc

Usage

You can import the library and use its functionalities by:

from lwcc import LWCC

Count estimation

Most straightforward way to use the library:

img = "path/to/image"
count = LWCC.get_count(img)

This uses CSRNet pretrained on SHA (default). You can choose a different model pretrained on different data set using:

count = LWCC.get_count(img, model_name = "DM-Count", model_weights = "SHB")

The result is a float with predicted count.

Large images

Note: By default all images are resized such that the longest side is less than 1000px, preserving the aspect ratio. Otherwise models might perform worse for large images with sparse crowds (counting patterns on shirts, dresses). If you are estimating dense crowds, we recommend you to set the resize_img to False. The call should look like this:

count = LWCC.get_count(img, model_name = "DM-Count", model_weights = "SHB", resize_img = True)

Multiple images

Library allows prediction of count for multiple images with a single call of get_count. You can simply pass a list of image paths:

img1 = "path/to/image1"
img2 = "path/to/image2"
count = LWCC.get_count([img1, img2])

Result is then a dictionary of pairs image_name : image_count: result

Density map

You can also request a density map by setting flag return_density = True. The result is then a tuple (count, density_map), where density_map is a 2d array with predicted densities. The array is smaller than the input image and its size depends on the model.

import matplotlib.pyplot as plt

count, density = LWCC.get_count(img, return_density = True)

plt.imshow(density)
plt.show()

result_density

This also works for multiple images (list of image paths as input). Result is then a tuple of two dictionaries, where the first dictionary is the same as above (pairs of image_name : image_count) and the second dictionary contains pairs of image_name : density_map.

Loading the model

You can also directly access the PyTorch models by loading them first with the load_model method.

model = LWCC.load_model(model_name = "DM-Count", model_weights = "SHA")

The loaded model is a PyTorch model and you can access its weights as with any other PyTorch model.

You can use it for inference as:

 count = LWCC.get_count(img, model = model)

Models

LWCC currently offers 4 models (CSRNet, Bayesian crowd counting, DM-Count, SFANet) pretrained on Shanghai A, Shanghai B, and UCF-QNRF datasets. The following table shows the model name and MAE / MSE result of the available pretrained models on the test sets.

Model name SHA SHB QNRF
CSRNet 75.44 / 113.55 11.27 / 19.32 Not available
Bay 66.92 / 112.07 8.27 / 13.56 90.43 / 161.41
DM-Count 61.39 / 98.56 7.68 / 12.66 88.97 / 154.11
SFANet Not available 7.05 / 12.18 Not available

Valid options for model_name are written in the first column and thus include: CSRNet, Bay, DM-Count, and SFANet. Valid options for model_weights are written in the first row and thus include: SHA, SHB, and QNRF.

Note: Not all model_weights are supported with all model_names. See the above table for possible combinations.

How does it work?

The goal of crowd counting methods is to determine the number of people present in a particular area. There exist many approaches (detection, regression, density-based approaches), however, since 2015 many convolutional neural network (CNN) based approaches have been proposed. The basic idea behind CNN based approaches is that they normally try to predict the density map from the input image and infer the count from it. These models differ in the use of different backbones, loss functions, additional maps, etc. If you are interested in a particular algorithm, you are welcome to read the paper belonging to the specific model.

FAQ - Frequently asked questions

Can I see some more examples of LWCC in action?

Yes, you can find some examples in Examples.ipynb!

How accurate are the models?

You can see the mean absolute error (MAE) and mean squared error (MSE) of the pretrained models on test sets in section models. We recommend models pretrained on SHA or QNRF for dense crowds, and SHB for sparse crowds.

Is GPU support available?

No, GPU support is currently not supported yet, but is planned for the future version.

Can I load custom weights?

Full support of loading custom pretrained weights is not supported, but is planned in the future version.

Can I train the models myself?

The library does not support training, only inference.

Why are my results bad?

This might depend on the model you use, image size, density or type of the crowd, or the weights that you use. For example, models might often make mistakes for images with a group portrait, as they are trained on images containing crowds on streets, concerts, etc. Using SHAweights on relatively sparse crowds might also give very wrong results. On the other hand, SHB might perform better as the weights were trained on Shanghai B data set, which containts images with relatively sparse crowds. Using high quality images with sparse crowds might also yield bad results, as the algorithms might mistake some textures of clothings for a crowd.

As a rule of thumb, you should use SHB if you are planning on estimating the number of people in images with sparse crowds, and SHA or QNRF for images with dense crowds. Keep in mind that current algorithms predict the density, and there still might be some mistakes. You are welcome to try out different combinations of models and weights and see which one works the best for your problem.

Support

If you like the library please show us your support by ⭐️ starring the project!

If you wish to include your own crowd counting model, please contact us ([email protected] or [email protected]).

Stargazers

Stargazers repo roster for @tersekmatija/lwcc

Citation

This library is a result of a research of CNN Crowd Counting models by Matija Teršek and Maša Kljun. Although the paper has not been published yet, please provide the link to this GitHub repository if you use LWCC in your research.

License

This library is licensed under MIT license (see LICENSE). Licenses of the models wrapped in the library will be inherited, depending on the model you use ( CSRNet, Bayesian crowd counting, DM-Count, and SFANet).

Owner
Matija Teršek
Data Science Master's student
Matija Teršek
Multi-Scale Aligned Distillation for Low-Resolution Detection (CVPR2021)

MSAD Multi-Scale Aligned Distillation for Low-Resolution Detection Lu Qi*, Jason Kuen*, Jiuxiang Gu, Zhe Lin, Yi Wang, Yukang Chen, Yanwei Li, Jiaya J

Jia Research Lab 115 Dec 23, 2022
Official Pytorch implementation of the paper "MotionCLIP: Exposing Human Motion Generation to CLIP Space"

MotionCLIP Official Pytorch implementation of the paper "MotionCLIP: Exposing Human Motion Generation to CLIP Space". Please visit our webpage for mor

Guy Tevet 173 Dec 26, 2022
A small tool to joint picture including gif

README 做设计的时候遇到拼接长图的情况,但是发现没有什么好用的能拼接gif的工具。 于是自己写了个gif拼接小工具。 可以自动拼接gif、png和jpg等常见格式。 效果 从上至下 从下至上 从左至右 从右至左 使用 克隆仓库 git clone https://github.com/Dels

3 Dec 15, 2021
Measure WWjj polarization fraction

WlWl Polarization Measure WWjj polarization fraction Paper: arXiv:2109.09924 Notice: This code can only be used for the inference process, if you want

4 Apr 10, 2022
NNR conformation conditional and global probabilities estimation and analysis in peptides or proteins fragments

NNR and global probabilities estimation and analysis in peptides or protein fragments This module calculates global and NNR conformation dependent pro

0 Jul 15, 2021
Emblaze - Interactive Embedding Comparison

Emblaze - Interactive Embedding Comparison Emblaze is a Jupyter notebook widget for visually comparing embeddings using animated scatter plots. It bun

CMU Data Interaction Group 77 Nov 24, 2022
The software associated with a paper accepted at EMNLP 2021 titled "Open Knowledge Graphs Canonicalization using Variational Autoencoders".

Open-KG-canonicalization The software associated with a paper accepted at EMNLP 2021 titled "Open Knowledge Graphs Canonicalization using Variational

International Business Machines 13 Nov 11, 2022
Official code of the paper "Expanding Low-Density Latent Regions for Open-Set Object Detection" (CVPR 2022)

OpenDet Expanding Low-Density Latent Regions for Open-Set Object Detection (CVPR2022) Jiaming Han, Yuqiang Ren, Jian Ding, Xingjia Pan, Ke Yan, Gui-So

csuhan 64 Jan 07, 2023
Code for CPM-2 Pre-Train

CPM-2 Pre-Train Pre-train CPM-2 此分支为110亿非 MoE 模型的预训练代码,MoE 模型的预训练代码请切换到 moe 分支 CPM-2技术报告请参考link。 0 模型下载 请在智源资源下载页面进行申请,文件介绍如下: 文件名 描述 参数大小 100000.tar

Tsinghua AI 136 Dec 28, 2022
Python implementation of Project Fluent

Project Fluent This is a collection of Python packages to use the Fluent localization system. python-fluent consists of these packages: fluent.syntax

Project Fluent 155 Dec 28, 2022
This dlib-based facial login system

Facial-Login-System This dlib-based facial login system is a technology capable of matching a human face from a digital webcam frame capture against a

Mushahid Ali 3 Apr 23, 2022
Devkit for 3D -- Some utils for 3D object detection based on Numpy and Pytorch

D3D Devkit for 3D: Some utils for 3D object detection and tracking based on Numpy and Pytorch Please consider siting my work if you find this library

Jacob Zhong 27 Jul 07, 2022
Repository for the AugmentedPCA Python package.

Overview This Python package provides implementations of Augmented Principal Component Analysis (AugmentedPCA) - a family of linear factor models that

Billy Carson 6 Dec 07, 2022
Lightweight Face Image Quality Assessment

LightQNet This is a demo code of training and testing [LightQNet] using Tensorflow. Uncertainty Losses: IDQ loss PCNet loss Uncertainty Networks: Mobi

Kaen 5 Nov 18, 2022
Raindrop strategy for Irregular time series

Graph-Guided Network For Irregularly Sampled Multivariate Time Series Overview This repository contains processed datasets and implementation code for

Zitnik Lab @ Harvard 74 Jan 03, 2023
Springer Link Download Module for Python

♞ pupalink A simple Python module to search and download books from SpringerLink. 🧪 This project is still in an early stage of development. Expect br

Pupa Corp. 18 Nov 21, 2022
Supplementary materials to "Spin-optomechanical quantum interface enabled by an ultrasmall mechanical and optical mode volume cavity" by H. Raniwala, S. Krastanov, M. Eichenfield, and D. R. Englund, 2022

Supplementary materials to "Spin-optomechanical quantum interface enabled by an ultrasmall mechanical and optical mode volume cavity" by H. Raniwala,

Stefan Krastanov 1 Jan 17, 2022
Implementations of polygamma, lgamma, and beta functions for PyTorch

lgamma Implementations of polygamma, lgamma, and beta functions for PyTorch. It's very hacky, but that's usually ok for research use. To build, run: .

Rachit Singh 24 Nov 09, 2021
This repository is for our paper Exploiting Scene Graphs for Human-Object Interaction Detection accepted by ICCV 2021.

SG2HOI This repository is for our paper Exploiting Scene Graphs for Human-Object Interaction Detection accepted by ICCV 2021. Installation Pytorch 1.7

HT 10 Dec 20, 2022
Official code for paper Exemplar Based 3D Portrait Stylization.

3D-Portrait-Stylization This is the official code for the paper "Exemplar Based 3D Portrait Stylization". You can check the paper on our project websi

60 Dec 07, 2022