Model Module

This module contain all methods to create and use a CSRNet model for crowd counting

class Crowd_counting.model.CSRNet(*args: Any, **kwargs: Any)[source]

Bases: Module

This class represents a CSRNet model

forward(x)[source]
Crowd_counting.model.evaluate(model, img_paths, MAE=True, MSE=True)[source]

Compute the MSE-MAE of the model on a designated set of images

Parameters
  • model – a CSRNet already trained model

  • image_paths (list) – paths to the images used for evaluation

  • MAE (bool) – If set to False the MAE is not computed

  • MSE (bool) – If set to False the MSE is not computed

Returns

the MAE of the model (0 if the MAE parameter is set to False)

Returns

the MSE of the model (0 if the MSE parameter is set to False)

Crowd_counting.model.load_model(model_path, use_gpu=True)[source]

Load a stored already trained CSRNet model.

Parameters
  • model_path – the path to the stored model

  • use_gpu – if the model is loaded on gpu or cpu

Returns

the loaded model

Return type

CSRNet

Crowd_counting.model.load_pretrained(model_name='shanghaiA')[source]

Load one of the already pretrained models of the librairy

Parameters

model_name – name of the pretrained model to be charged. Can be shanghaiA, shanghaiB, A10

Returns

the loaded model

Return type

CSRNet

Crowd_counting.model.predict(model, image_path, use_gpu=True)[source]

Predict the stimated number of people and density map from an image

Parameters
  • model – a CSRNet already trained model

  • image_path – path to the image to be predicted

  • use_gpu – if the model is loaded on gpu or cpu

Returns

the estimated number of people

Returns

the estimated density map

Crowd_counting.model.visualize(image, ground_truth=None, model=None, figsize=(100, 100))[source]

Visualize an image and eventually its ground_truth and one model prediction using matplotlib

Parameters
  • image – the path to base image

  • ground_truth – a .h5 file corresponding to the ground_truth of the image

  • model – a model used to make a prediction on the base image