This is the repository for IMSE4175 Object Detection and Tracking System on Bicycle Lanes.
Run git clone https://github.com/xcjames/imse4175_all
Use nvidia-smi
to see the NVIDIA GPU you are using. Use nvcc --version
to see the CUDA version you have, should be >=V11.1.105
i. Open command line, change to the project directory, and execute “git clone https://github.com/ultralytics/yolov5.git”.
ii. Make sure that Python >= 3.8.0 and PyTorch>=1.8.is installed. Use “nvidia-smi” command to see the NVIDIA GPU you are using. Use “nvcc --version” to see the CUDA version you have, which should be >=V11.1.105
iii. Install all Python packages required by running “cd yolov5” then “pip install -r requirements.txt”
Put some bike lanes videos in /imse4175/videos, and make new directories /imse4175/img_data/images, change the pwd in video2img.py to the current /imse4175/ path, and run python video2img.py
.
Then, quickly go over all images and select the images that contains some objects, which is suitable for image labelling. Then, go to https://www.makesense.ai/, do image labelling locally using https://github.com/HumanSignal/labelImg. This is the tutorial for Labelimg:https://www.youtube.com/watch?v=p0nR2YsCY_U.
After getting all yolo labels, make new directories: img_data/images and img_data/labels. Put all images and labels inside these two directories directly, respectively.
Then, create 3 directories: /img_data/train, /img_data/test, /img_data/val, and create empty directories /images, /labels inside each 3 of them. Move images in img_data/images, labels in img_data/labels into img_data/train/images, img_data/train/labels.
Runpython split_train_val_test.py {path of the /img_data}
, then modify the path in yolov5/cctv.yaml.
Important: The name of directories must be "images" and "labels"
-
Download FLIR dataset: https://www.flir.com/oem/adas/adas-dataset-form/ and download the FLIR README.txt if more information is needed. Make a new directory /FLIR, get into it and unzip the compressed file.
-
There are 6 directories under “/FLIR”: • /images_rgb_train
• /images_rgb_val
• /images_thermal_train
• /images_thermal_val
• /video_rgb_test
• /video_thermal_test.
inside each directory, create 2 sub-directories:/images, /labels. Put all images in /images, and modify the variable paths and output_path in json2yolo.py. Then, runpython json2yolo.py
, then modify the path in yolov5/flir.yaml, yolov5/flir_thermal.yaml. -
Modify “yolov5/models/yolov5s.yaml”, change “nc” to 8, representing 8 categories, then create “yolov5/data/flir.yaml”, and write the information in the following format: path: /root/autodl-tmp/FLIR/ # dataset root dir train: images_rgb_train
val: images_rgb_val test: video_rgb_test nc: 8 names: ['person', 'car', 'dog','bicycle', 'e-bike', 'other vehicles', ‘scooter’, ‘stroller’]
You don't need to Install requirements here, since I have put all the dependencies you need at the beginning "Building Environment".
Run git clone https://github.com/ultralytics/yolov5.git
outside /imse4175_all. In /imse4175_all/yolov5, copy flir.yaml, flir_thermal.yaml, cctv.yaml to ./yolov5/data.
Run the following command for model training:
python train.py --data flir.yaml --weights yolov5s.pt --img 640 --epochs 150 --cfg yolov5s.yaml;
python train.py --data flir_thermal.yaml --weights yolov5s.pt --img 640 --epochs 150 --cfg yolov5s.yaml;
python train.py --data cctv.yaml --weights yolov5s.pt --img 640 --epochs 300 --cfg yolov5s.yaml
i. Change directory to “/yolov5”, run the command “python train.py --data flir.yaml --weights yolov5s.pt --img 640 –epochs 150”
Run the following command for model training:
python train.py {cloned yolov5 path}/data/flir.yaml 150;
python train.py {cloned yolov5 path}/data/flir_thermal.yaml 150;
python train.py {cloned yolov5 path}/data/cctv.yaml 300
ii. The trained models and results will be stored under “/yolov5/runs/train”
Find YOLOv5 and YOLOv8 trained models "best.pt" files,
copy their path to main_yolov5.py or main_yolov8.py.
Run the following command for object tracking & counting for some ".mp4" videos:
python main_yolov5.py {video path} {.pt yolo model path};
python main_yolov8.py {video path} {.pt yolo model path}