/yolov7-carla-object-detection_1

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors

Primary LanguageJupyter NotebookGNU General Public License v3.0GPL-3.0

YOLOv7 Repository for Object Detection in CARLA Simulator

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors

Can be used to train an object detector on a CARLA simulator object detection dataset. You can find the dataset in my other repository here: https://github.com/DanielHfnr/Carla-Object-Detection-Dataset

Installation

Create a virtual environment and install required packages. You can also use a docker environment, please check the original repo for that.

python3 -m pip install --user virtualenv   # Install if needed
python3 -m venv venv
pip install -r requirements.txt

Afterwards you can activate the virtual environment.

source venv/bin/activate

Training

Data preparation. Download CARLA object detection dataset.

bash scripts/get_carla.sh

Single GPU training

# train p5 models
python train.py --workers 8 --device 0 --batch-size 32 --data data/carla.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml

# train p6 models
python train_aux.py --workers 8 --device 0 --batch-size 16 --data data/carla.yaml --img 640 640 --cfg cfg/training/yolov7-w6.yaml --weights '' --name yolov7-w6 --hyp data/hyp.scratch.p6.yaml

Multiple GPU training

# train p5 models
python -m torch.distributed.launch --nproc_per_node 4 --master_port 9527 train.py --workers 8 --device 0,1,2,3 --sync-bn --batch-size 128 --data data/carla.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml

# train p6 models
python -m torch.distributed.launch --nproc_per_node 8 --master_port 9527 train_aux.py --workers 8 --device 0,1,2,3,4,5,6,7 --sync-bn --batch-size 128 --data data/carla.yaml --img 640 640 --cfg cfg/training/yolov7-w6.yaml --weights '' --name yolov7-w6 --hyp data/hyp.scratch.p6.yaml

Inference

On video:

python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source yourvideo.mp4

On image:

python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source yourimage.jpg

Export

Pytorch to ONNX with NMS

python export.py --weights yolov7-tiny.pt --grid --end2end --simplify \
        --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640

Pytorch to TensorRT another way

python export.py --weights yolov7-tiny.pt --grid --include-nms

Tested with: Python 3.7.13, Pytorch 1.12.0+cu113

Citation

@article{wang2022yolov7,
  title={{YOLOv7}: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors},
  author={Wang, Chien-Yao and Bochkovskiy, Alexey and Liao, Hong-Yuan Mark},
  journal={arXiv preprint arXiv:2207.02696},
  year={2022}
}

Changelog

2023-01-06

Changed

  • Added utilities to work with carla dataset
  • Modified original README