All Projects → Neerajj9 → CSRNet-keras

Neerajj9 / CSRNet-keras

Licence: MIT license
Implementation of the CSRNet paper (CVPR 18) in keras-tensorflow

Programming Languages

Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to CSRNet-keras

S-DCNet
Unofficial Pytorch implementation of S-DCNet and SS-DCNet
Stars: ✭ 17 (-84.11%)
Mutual labels:  crowd-counting
NWPU-Crowd-Sample-Code
The sample code for a large-scale crowd counting dataset, NWPU-Crowd.
Stars: ✭ 140 (+30.84%)
Mutual labels:  crowd-counting
IIM
PyTorch implementations of the paper: "Learning Independent Instance Maps for Crowd Localization"
Stars: ✭ 94 (-12.15%)
Mutual labels:  crowd-counting
CrowdFlow
Optical Flow Dataset and Benchmark for Visual Crowd Analysis
Stars: ✭ 87 (-18.69%)
Mutual labels:  crowd-counting
MARUNet
Multi-level Attention Refined UNet for crowd counting
Stars: ✭ 30 (-71.96%)
Mutual labels:  crowd-counting
Smart-City-Sample
The smart city reference pipeline shows how to integrate various media building blocks, with analytics powered by the OpenVINO™ Toolkit, for traffic or stadium sensing, analytics and management tasks.
Stars: ✭ 141 (+31.78%)
Mutual labels:  crowd-counting
Awesome Crowd Counting
Awesome Crowd Counting
Stars: ✭ 1,720 (+1507.48%)
Mutual labels:  crowd-counting
Dense-Scale-Network-for-Crowd-Counting
An unofficial implement of paper "Dense Scale Network for Crowd Counting", link: https://arxiv.org/abs/1906.09707
Stars: ✭ 25 (-76.64%)
Mutual labels:  crowd-counting
pytorch-ACSCP
Unofficial implementation of "Crowd Counting via Adversarial Cross-Scale Consistency Pursuit" with pytorch - CVPR 2018
Stars: ✭ 18 (-83.18%)
Mutual labels:  crowd-counting
PCC-Net
PCC Net: Perspective Crowd Counting via Spatial Convolutional Network
Stars: ✭ 63 (-41.12%)
Mutual labels:  crowd-counting
keras-mcnn
keras实现的人群密度检测网络"Single Image Crowd Counting via Multi Column Convolutional Neural Network",欢迎试用、关注并反馈问题...
Stars: ✭ 23 (-78.5%)
Mutual labels:  crowd-counting
ACSCP cGAN
Code implementation for paper that "ACSCS: Crowd Counting via Adversarial Cross-Scale Consistency Pursuit"; This is method of Crowd counting by conditional generation adversarial networks
Stars: ✭ 36 (-66.36%)
Mutual labels:  crowd-counting
Variations-of-SFANet-for-Crowd-Counting
The official implementation of "Encoder-Decoder Based Convolutional Neural Networks with Multi-Scale-Aware Modules for Crowd Counting"
Stars: ✭ 78 (-27.1%)
Mutual labels:  crowd-counting
PyramidScaleNetwork
To the best of our knowledge, this is the first work to explicitly address feature similarity issue in multi-column design. Extensive experiments on four challenging benchmarks (ShanghaiTech, UCF_CC_50, UCF-QNRF, and Mall) demonstrate the effectiveness of the proposed innovations as well as the superior performance over the state-of-the-art. Mor…
Stars: ✭ 17 (-84.11%)
Mutual labels:  crowd-counting
ailia-models
The collection of pre-trained, state-of-the-art AI models for ailia SDK
Stars: ✭ 1,102 (+929.91%)
Mutual labels:  crowd-counting
crowd-counting
Image Crowd Counting Using Convolutional Neural Network and Markov Random Field
Stars: ✭ 32 (-70.09%)
Mutual labels:  crowd-counting
W-Net-Keras
An unofficial implementation of W-Net for crowd counting.
Stars: ✭ 20 (-81.31%)
Mutual labels:  crowd-counting
Crowd-Counting-with-MCNNs
Crowd counting on the ShanghaiTech dataset, using multi-column convolutional neural networks.
Stars: ✭ 23 (-78.5%)
Mutual labels:  crowd-counting

CSRNet-keras

Implementation of the CSRNet paper (CVPR 18) in keras-tensorflow. First ever to be done in keras-tf as of 21/9/18.

Mindspark Hackathon Winning Project(Kumbh-Mela Disaster Management):

Team : Pratik Ratadiya(Web/Django), Aditya Malte(ML/DL), Kshitij Patil(Android), Neeraj Panse(ML/DL)

In order to aid the ML/DL community, we have open sourced the deep learning part of the project.

CVPR 2018 Paper : https://arxiv.org/abs/1802.10062

Official Pytorch Implementation : https://github.com/leeyeehoo/CSRNet-pytorch

As we were searching over the internet, we could not find any keras implementation of the state of the art paper CSRNet. A large part of the deep learning community uses keras-tensorflow to implement their neural network models. Thus, we implemented the CSRNet model in keras-tensorflow. Tensorflow has a massive advantage when it comes to deployability(eg. Android,etc).

Dataset :

The dataset used is ShanghaiTech dataset available here : Drive Link

The dataset is divided into two parts, A and B. Part A consists of images with a high density of crowd. Part B consists of images with sparse crowd scenes.

Data Preprocessing :

In data preprocessing, the main objective was to convert the ground truth provided by the ShanghaiTech dataset into density maps. For a given image the dataset provided a sparse matrix consisting of the head annotations in that image. This sparse matrix was converted into a 2D density map by passing through a Gaussian Filter. The sum of all the cells in the density map results in the actual count of people in that particular image. Refer the Preprocess.ipynb notebook for the same.

Data preprocessing math explained:

Given a set of head annotations our task is to convert it to a density map.

  1. Build a kdtree(a kdtree is a data structure that allows fast computation of K Nearest neighbours) of the head annotations.
  2. Find the average distances for each head with K(in this case 4) nearest heads in the head annotations. Multpiply this value by a factor, 0.3 as suggested by the author of the paper.
  3. Put this value as sigma and convolve using the 2D Gaussian filter.

Model :

The CSRNet model uses Convolutional Neural Networks to map the input image to it's respective density map. The model does not make use of any fully connected layers and thus the size of the input image is variable. As a result, the model learns from a large amount of varied data and there is no information loss considering the image resolution. There is no need of reshaping/resizing the image while inferencing. The model architecture is such that considering the input image to be (x,y,3), the output is a density map of size (x/8,y/8,1).

The model architecture is divided into two parts, front-end and back-end. The front-end consists of 13 pretrained layers of the VGG16 model ( 10 Convolution layers and 3 MaxPooling layers ). The fully connected layers of the VGG16 are not taken. The back-end comprises of Dilated Convolution layers. The dilation rate at which maximum accuracy was obtained was experimentally found out be 2 as suggested in the CSRNet paper.

Batch Normalisation functionality is also provided in the code. As VGG16 does not have any BN layers, we built a custom VGG16 model and ported pretrained weights of VGG16 to this model.

Vairable Size Input

In keras it is difficult to train a model where the size of the input image is variable. Keras does not allow variable size inputs to be trained in the same batch. One way to tackle this is to combine all images having the same image dimension and train them as a batch. The ShanghaiTech dataset does not contain many images having the same image size and thus such batches could not be made. Another approach is to train each image independantly and run a loop over all images. This approach is not efficient in terms of memory usage and computation time. Thus, we built a custom data generator in keras to efficiently train variable sized images. With a data generator, efficient memory usage takes place and the time taken for training reduces drastically.

The paper also specifies cropping of images as a part of data augmentation. However, the Pytorch implementation does not use cropping of images while training. Hence we have provided a function preprocess_input() which can be used inside image_generator() to add the cropping functionality. We have trained the model without cropping the images.

The two parts of the dataset, A and B, were trained on two seperate models with the same architecture for 200 epochs. The other hyperparameters were kept identical to those specified in the CSRNet paper and pytorch implementation.

Refer the Model.ipynb notebook for the same.

Inference :

The model A performs very well on dense crowd whereas the model B performs vey well on sparse crowd. The density map generated by both models are accurate enough to depict the varied density of the crowd. Refer to the Inference.ipynb for generating inference.

Given below is the result on actual images taken from the test set provided in the ShanghaiTech dataset.

Actual Image :

Generated Density Map :

Actual Count : 258

Predicted Count : 232

Result :

Given below is comparison between the MAE error produced by our model.

Dataset MAE
ShanghaiTech part A 65.92
ShanghaiTech part B 11.01

Requirements :

  1. Keras : 2.2.2
  2. Tensorflow : 1.9.0
  3. Scipy : 1.1.0
  4. Numpy : 1.14.3
  5. Pillow(PIL) : 5.1.0
  6. OpenCV : 3.4.1
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].