Skip to content

YOLO-CROWD is a lightweight crowd counting and face detection model that is based on Yolov5s and can run on edge devices, as well as fixing the problems of face occlusion, varying face scales, and other challenges of crowd counting

License

Notifications You must be signed in to change notification settings

zaki1003/YOLO-CROWD

Repository files navigation

YOLO-CROWD

YOLO-CROWD is a lightweight crowd counting and face detection model that is based on Yolov5s and can run on edge devices, as well as fixing the problems of face occlusion, varying face scales, and other challenges of crowd counting

Description

Deep learning-based algorithms for face and crowd identification have advanced significantly. These algorithms can be broadly categorized into two groups: one-stage detectors like YOLO and two-stage detectors like Faster R-CNN. One-stage detectors have been widely employed in many applications due to the better balance between accuracy and speed, but as we are all aware, YOLO algorithms are significantly impacted by occlusion in crowd scenarios. In our project, we propose a real-time crowd counter and face detector called YOLO-CROWD, which has an inference speed of 9 ms and contains 461 layers and 18388982 parameters. It is based on the one-stage detector YOLOv5. In order to improve the receptive field of small faces, we use a Receptive Field Enhancement module termed RFE. We then use NWD Loss to compensate for the sensitivity of IoU to the position deviation of small objects. We also employ Repulsion Loss to address face occlusion and utilize an attention module called SEAM.

Demo

test-yolo-crowd

Screenshot from 2023-04-07 15-49-11

Screenshot from 2023-04-07 15-48-52

Comparison Between Yolov5s And YOLO-CROWD

[email protected] [email protected] Precision Recall Box loss Object loss Inference Time (ms)
Yolov5s 39.4 0.15 0.754 0.382 0.120 0.266 7
YOLO-CROWD 43.6 0.158 0.756 0.424 0.091 0.158 9

Environment Requirments

Create a Python Virtual Environment.

conda create -n {name} python=x.x

Enter Python Virtual Environment.

conda activate {name}

Install pytorch in this.

pip install torch==1.10.0+cu111 torchvision==0.11.0+cu111 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

Install other python package.

pip install -r requirements.txt

Step-Through Example

Installation

Get the code.

git clone https://github.com/Krasjet-Yu/YOLO-FaceV2.git

Dataset

Download our Dataset crowd-counting-dataset-w3o7w, While exporting the datset try to choose YOLO v5 PyTorch Format.

our-dataset

Preweight

The link is yolov5s.pt

Training

Train your model on crowd-counting-dataset-w3o7w dataset.

python train.py --weights preweight.pt    
                --data data/WIDER_FACE.yaml    
                --cfg models/yolov5s_v2_RFEM_MultiSEAM.yaml     
                --batch-size 32   
                --epochs 250

Postweight

The link is yolo-crowd.pt If you want to have more inference speed try to install TensorRt and use this vesion yolo-crowd.engine

Test

python detect.py --weights ./preweight/best.pt --source ./data/images/test.jpg --plot-label --view-img

Evaluate

Evaluate the trained model via next code on WIDER FACE

If you don't want to train, you can also directly use our trained model to evaluate.

The link is yolo-facev2_last.pt

python widerface_pred.py --weights runs/train/x/weights/best.pt     
                         --save_folder ./widerface_evaluate/widerface_txt_x    
cd widerface_evaluate/    
python evaluation.py --pred ./widerface_txt_x

Download the eval_tool to show the performance.

The result is shown below:

Results

results-yolo-crowd

Finetune

see in ultralytics/yolov5#607

# Single-GPU
python train.py --epochs 10 --data coco128.yaml --weights yolov5s.pt --cache --evolve

# Multi-GPU
for i in 0 1 2 3 4 5 6 7; do
  sleep $(expr 30 \* $i) &&  # 30-second delay (optional)
  echo 'Starting GPU '$i'...' &&
  nohup python train.py --epochs 10 --data coco128.yaml --weights yolov5s.pt --cache --device $i --evolve > evolve_gpu_$i.log &
done

# Multi-GPU bash-while (not recommended)
for i in 0 1 2 3 4 5 6 7; do
  sleep $(expr 30 \* $i) &&  # 30-second delay (optional)
  echo 'Starting GPU '$i'...' &&
  "$(while true; do nohup python train.py... --device $i --evolve 1 > evolve_gpu_$i.log; done)" &
done

Reference

https://github.com/ultralytics/yolov5

*https://github.com/deepcam-cn/yolov5-face

https://github.com/open-mmlab/mmdetection

https://github.com/dongdonghy/repulsion_loss_pytorch

Contact

We use code's license is MIT License. The code can be used for business inquiries or professional support requests.

About

YOLO-CROWD is a lightweight crowd counting and face detection model that is based on Yolov5s and can run on edge devices, as well as fixing the problems of face occlusion, varying face scales, and other challenges of crowd counting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published