Git Product home page Git Product logo

context-aware-crowd-counting's Introduction

Context-Aware Crowd Counting

This repository is a PyTorch implementation for the paper Context-Aware Crowd Counting. Weizhe Liu, Mathieu Salzmann, Pascal Fua. CVPR. 2019. If you use this code in your research, please cite the paper.

State-of-the-art methods for counting people in crowded scenes rely on deep networks to estimate crowd density. They typically use the same filters over the whole image or over large image patches. Only then do they estimate local scale to compensate for perspective distortion. This is typically achieved by training an auxiliary classifier to select, for predefined image patches, the best kernel size among a limited set of choices. As such, these methods are not endto-end trainable and restricted in the scope of context they can leverage.

In this paper, we introduce an end-to-end trainable deep architecture that combines features obtained using multiple receptive field sizes and learns the importance of each such feature at each image location. In other words, our approach adaptively encodes the scale of the contextual information required to accurately predict crowd density. This yields an algorithm that outperforms state-of-the-art crowd counting methods, especially when perspective effects are strong.

Figure 1: Context-Aware Network. (Top) RGB images are fed to a font-end network that comprises the first 10 layers of the VGG-16 network. The resulting local features are grouped in blocks of different sizes by average pooling followed by a 1×1 convolutional layer. They are then up-sampled back to the original feature size to form the contrast features. Contrast features are further used to learn the weights for the scale-aware features that are then fed to a back-end network to produce the final density map. (Bottom) As shown in this expanded version of the first part of the network, the contrast features are the difference between local features and context features.

Figure 2: Crowd density estimation on ShanghaiTech. First row: Image from Part A. Second row: Image from Part B. Our model adjusts to rapid scale changes and delivers density maps that are close to the ground truth.

Installation

PyTorch 0.4.1

Python 2.7

Dataset

 1. Download ShanghaiTech Part B Dataset from Dropbox: link or Baidu Disk: link.

 2. Create the hdf5 files with make_dataset.py, you need to set the path according to dataset location.

 3. Use create_json.py to generate the json file which contains the path to the images.

Training

In command line:

python train.py train.json val.json

The json files here are generated from previous step (Dataset. 3.)

Tesing

 1. Modify the "test.py", make sure the path is correct.

 2. In command line:

python test.py

Venice Dataset

The dataset is in GoogleDrive.

Notes

 1. This is the implementation for ShanghaiTech part B, the pretrained model is in GoogleDrive with MAE=7.5

 2. For ShanghaiTech Part A, refer to this, thanks CommissarMa for this implementation.

 3. For some dataset which training images have different size, we set batch size to 1, like ShanghaiTech part A. For others, you could set your batch size according to you GPU memory, but the batch size may affect your model accuracy during training.

 4. For the selection of train/val dataset, we follow the same setting as previous work, you could find it here

Citing


@InProceedings{Liu_2019_CVPR,

author = {Liu, Weizhe and Salzmann, Mathieu and Fua, Pascal},

title = {Context-Aware Crowd Counting},

booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},

month = {June},

year = {2019}

}

@InProceedings{Liu_2019_IROS,

author = {Liu, Weizhe and Lis, Krzysztof Maciej and Salzmann, Mathieu and Fua, Pascal},

title = {Geometric and Physical Constraints for Drone-Based Head Plane Crowd Density Estimation},

booktitle = {IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS)},

month = {November},

year = {2019}

}

Contact

For any questions regard this paper/code, please directly contact Weizhe Liu.

context-aware-crowd-counting's People

Contributors

weizheliu avatar zhaoyi-yan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

context-aware-crowd-counting's Issues

Computation Time for Each Image

Hi Weizhe and Zhaoyi,

First of all I'd like to show my gratitude for your great contribution in image crowd counting. Your work may have benefited numerous other researchers (including me).

I am very interested in extending your work CAN to real-time video crowd counting, in which computation time really matters. Could you upload your trained models to this repo or do you have any idea about how much time it took to process one image from those benchmark datasets?

Many thanks,
Yiming

Expanded Context-Aware Network

Geometry-Guided Context Learning is a smart idea but it is difficult to find in the codes. Would you please localize it?

Thank you for providing us with technical assistance. We tried to plot the density using `https://github.com/weizheliu/People-Flows/blob/main/plot.py` file on this directory " context aware crowd counting" but it gives an error of importing CANNet2s. Since we trained the CANNet model defined in model.py file. We are interested in plot density maps only using the CANNet not using the CANNet2s. Then, is it still possible to generate density maps using CANNet model ?

Thank you for providing us with technical assistance. We tried to plot the density using https://github.com/weizheliu/People-Flows/blob/main/plot.py file on this directory " context aware crowd counting" but it gives an error of importing CANNet2s. Since we trained the CANNet model defined in model.py file. We are interested in plot density maps only using the CANNet not using the CANNet2s. Then, is it still possible to generate density maps using CANNet model ?

Originally posted by @aliraza0769 in #2 (comment)

some improved issues

Hi, thank you very much for this code,
I'm a university researcher and want to improve this code of yours to get a better result,
What fine-tuning would you suggest?
Hope you have a nice day~

how to visualize the predicted densities of model

How to transform the multidimensional NumPy array into a 3-dimensional RGB image to visualize predicted densities of the model. The model outputs densities NumPy arrays with size: (1, 1, 45, 80), type: float32. Looking forward to your response. Thank you

Shrunk Output Size

Hi Weizhe,

In your code, there is max pooling with stride and kernel size of 2 in the encoder, but there is no corresponding treatment to enlarge the layer output in the decoder. As a result, the final output size will be smaller, which means the density map does not have the same height and width of the input image.

Best wishes,
Yiming

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.