Skip to content

xcjames/imse4175_all

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IMSE4175 Code Implementation

This is the repository for IMSE4175 Object Detection and Tracking System on Bicycle Lanes.
Run git clone https://github.com/xcjames/imse4175_all

1. Building Environment

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”

2. Data Preparing (/imse4175)

2.1 CCTV datasets

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"

2.2 FLIR RGB and FLIR Thermal datasets

  1. 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.

  2. 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, run python json2yolo.py, then modify the path in yolov5/flir.yaml, yolov5/flir_thermal.yaml.

  3. 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’]

3. yolov5 model training (/yolov5)

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

4. yolov8 model training (/yolov8)

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”

5 Generate Object Detection and Tracking videos

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}

About

All code for IMSE4175

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published