model.csrnet

Description

πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦ Congested Scene Recognition network: Dilated convolutional neural networks for understanding the highly congested scenes.

class Node(config=None, **kwargs)[source]

Initializes and uses CSRNet model to predict the density map and crowd count.

The csrnet node is capable of predicting the number of people in dense and sparse crowds. The dense and sparse crowd models were trained using data from ShanghaiTech Part A and ShanghaiTech Part B respectively. As the models were trained to recognize congested scenes, the estimates are less accurate if the number of people are low (e.g. less than 10).

Inputs

img (numpy.ndarray): A NumPy array of shape \((height, width, channels)\) containing the image data in BGR format.

Outputs

density_map (numpy.ndarray): A NumPy array of shape \((H, W)\) representing the number of persons per pixel. \(H\) and \(W\) are the height and width of the input image, respectively. The sum of the array is the estimated total number of people.

count (int): An integer representing the number of counted objects.

Configs
  • model_type (str) – {β€œdense”, β€œsparse”}, default=”sparse”.
    Defines the type of CSRNet model to be used. The node uses the sparse crowd model by default and can be changed to using the dense crowd model. As a rule of thumb, the dense crowd model should be used if the people in a given image or video frame are packed shoulder to shoulder, e.g., stadiums.

  • weights_parent_dir (Optional[str]) – default = null.
    Change the parent directory where weights will be stored by replacing null with an absolute path to the desired directory.

  • width (int) – default = 640.
    By default, the width of an image will be resized to 640 for inference. The height of the image will be resized proportionally to preserve its aspect ratio. In general, decreasing the width of an image will improve inference speed. However, this might impact the accuracy of the model.

References

CSRNet: Dilated Convolutional Neural Networks for Understanding the Highly Congested Scenes: https://arxiv.org/pdf/1802.10062.pdf

Model weights trained by https://github.com/Neerajj9/CSRNet-keras

Inference code adapted from https://github.com/Neerajj9/CSRNet-keras