This repository presents a concise and efficient PyTorch implementation of the CSRNet architecture for crowd counting, optimized for compatibility with Mac M1/M2/M3 GPUs and Nvidia GPUs. It includes comprehensive code for dataset preparation, model training, and visualization, suitable for both research and practical applications.
Next goal is to test and implement the integration of CSRNet and IIM, aiming for enhanced crowd counting accuracy through improved image preprocessing. IIM Repository: taohan10200/IIM
Key Features:
CSRNet Architecture: Leverages dilated convolutions for precise density estimation.
GPU Acceleration: Employs PyTorch with MPS for efficient training on Mac M1/M2/M3 GPUs, and cuda for Nvidia GPUs.
Streamlined Implementation: Focused on core model and training pipeline for clarity.
Dataset Handling: Prepares the ShanghaiTech dataset, including density map generation.
Memory Optimization: Addresses GPU memory limitations during density map creation.
- Python 3.6 or later
- PyTorch 1.4 or later
- torchvision
- h5py
- scipy
- matplotlib
- Pillow (PIL Fork)
- Pytorch should be downloaded with cuda to work properly if on windows
-
Acquire Dataset:
Download the ShanghaiTech dataset from here and extract it into
ShanghaiTech
within this repository. -
Generate Density Maps:
Execute
makedataset.py
to efficiently create density maps, optimizing memory usage. -
Explore Data Visually:
Run
densityChecker.py
to visualize an image-density map pair for understanding. -
Train the CSRNet Model:
Initiate model training with
train.py
, maximizing performance on Mac M1/M2/M3 GPUs.
- Employs initial 23 layers of pre-trained VGG16 for feature extraction.
- Backend: Incorporates 6 convolutional layers with ReLU activations for density map generation.
dataset.py
defines a custom dataset class for seamless data loading and preprocessing.model.py
encapsulates the SimplifiedCSRNet model architecture.
- Original CSRNet Paper: CSRNet: Dilated Convolutional Neural Networks for Understanding the Highly Congested Scenes
- Reference PyTorch Implementation: CSRNet-pytorch