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
[NeurIPS-2021] Mosaicking to Distill: Knowledge Distillation from Out-of-Domain Data

MosaicKD Code for NeurIPS-21 paper "Mosaicking to Distill: Knowledge Distillation from Out-of-Domain Data" 1. Motivation Natural images share common l

ZJU-VIPA 37 Nov 10, 2022
Self-Supervised Learning of Event-based Optical Flow with Spiking Neural Networks

Self-Supervised Learning of Event-based Optical Flow with Spiking Neural Networks Work accepted at NeurIPS'21 [paper, video]. If you use this code in

TU Delft 43 Dec 07, 2022
Custom Implementation of Non-Deep Networks

ParNet Custom Implementation of Non-deep Networks arXiv:2110.07641 Ankit Goyal, Alexey Bochkovskiy, Jia Deng, Vladlen Koltun Official Repository https

Pritama Kumar Nayak 20 May 27, 2022
The repository contains source code and models to use PixelNet architecture used for various pixel-level tasks. More details can be accessed at .

PixelNet: Representation of the pixels, by the pixels, and for the pixels. We explore design principles for general pixel-level prediction problems, f

Aayush Bansal 196 Aug 10, 2022
NeuroFind - A solution to the to the Task given by the Oberseminar of Messtechnik Institute of TU Dresden in 2021

NeuroFind A solution to the to the Task given by the Oberseminar of Messtechnik

1 Jan 20, 2022
[ICLR 2021] "CPT: Efficient Deep Neural Network Training via Cyclic Precision" by Yonggan Fu, Han Guo, Meng Li, Xin Yang, Yining Ding, Vikas Chandra, Yingyan Lin

CPT: Efficient Deep Neural Network Training via Cyclic Precision Yonggan Fu, Han Guo, Meng Li, Xin Yang, Yining Ding, Vikas Chandra, Yingyan Lin Accep

26 Oct 25, 2022
In this project we predict the forest cover type using the cartographic variables in the training/test datasets.

Kaggle Competition: Forest Cover Type Prediction In this project we predict the forest cover type (the predominant kind of tree cover) using the carto

Marianne Joy Leano 1 Mar 15, 2022
git《Tangent Space Backpropogation for 3D Transformation Groups》(CVPR 2021) GitHub:1]

LieTorch: Tangent Space Backpropagation Introduction The LieTorch library generalizes PyTorch to 3D transformation groups. Just as torch.Tensor is a m

Princeton Vision & Learning Lab 482 Jan 06, 2023
Using pretrained language models for biomedical knowledge graph completion.

LMs for biomedical KG completion This repository contains code to run the experiments described in: Scientific Language Models for Biomedical Knowledg

Rahul Nadkarni 41 Nov 30, 2022
Official implementation of ACMMM'20 paper 'Self-supervised Video Representation Learning Using Inter-intra Contrastive Framework'

Self-supervised Video Representation Learning Using Inter-intra Contrastive Framework Official code for paper, Self-supervised Video Representation Le

Li Tao 103 Dec 21, 2022
Efficient Two-Step Networks for Temporal Action Segmentation (Neurocomputing 2021)

Efficient Two-Step Networks for Temporal Action Segmentation This repository provides a PyTorch implementation of the paper Efficient Two-Step Network

8 Apr 16, 2022
Code for pre-training CharacterBERT models (as well as BERT models).

Pre-training CharacterBERT (and BERT) This is a repository for pre-training BERT and CharacterBERT. DISCLAIMER: The code was largely adapted from an o

Hicham EL BOUKKOURI 31 Dec 05, 2022
Classifying audio using Wavelet transform and deep learning

Audio Classification using Wavelet Transform and Deep Learning A step-by-step tutorial to classify audio signals using continuous wavelet transform (C

Aditya Dutt 17 Nov 29, 2022
A repo that contains all the mesh keys needed for mesh backend, along with a code example of how to use them in python

Mesh-Keys A repo that contains all the mesh keys needed for mesh backend, along with a code example of how to use them in python Have been seeing alot

Joseph 53 Dec 13, 2022
PyTorch implementation of the TTC algorithm

Trust-the-Critics This repository is a PyTorch implementation of the TTC algorithm and the WGAN misalignment experiments presented in Trust the Critic

0 Nov 29, 2021
robomimic: A Modular Framework for Robot Learning from Demonstration

robomimic [Homepage]   [Documentation]   [Study Paper]   [Study Website]   [ARISE Initiative] Latest Updates [08/09/2021] v0.1.0: Initial code and pap

ARISE Initiative 178 Jan 05, 2023
[ICCV 2021] Self-supervised Monocular Depth Estimation for All Day Images using Domain Separation

ADDS-DepthNet This is the official implementation of the paper Self-supervised Monocular Depth Estimation for All Day Images using Domain Separation I

LIU_LINA 52 Nov 24, 2022
[ACM MM2021] MGH: Metadata Guided Hypergraph Modeling for Unsupervised Person Re-identification

Introduction This project is developed based on FastReID, which is an ongoing ReID project. Projects BUC In projects/BUC, we implement AAAI 2019 paper

WuYiming 7 Apr 13, 2022
Learning to Reach Goals via Iterated Supervised Learning

Vanilla GCSL This repository contains a vanilla implementation of "Learning to Reach Goals via Iterated Supervised Learning" proposed by Dibya Gosh et

Christoph Heindl 4 Aug 10, 2022
Official Codes for Graph Modularity:Towards Understanding the Cross-Layer Transition of Feature Representations in Deep Neural Networks.

Dynamic-Graphs-Construction Official Codes for Graph Modularity:Towards Understanding the Cross-Layer Transition of Feature Representations in Deep Ne

11 Dec 14, 2022