Skip to content

A repository created as part of Intel Unnati program, 2023

Notifications You must be signed in to change notification settings

noel-robert/intelunnati_TeamTRON

Repository files navigation

intelunnati_TeamTRON

Intel Unnati Project - Team TRON

This repository is created as part of Intel UNNATI Industrial Training Project, 2023. The topic of our project was "Road Object Detection with Deep Learning".

Our aim is to develop a model that could identify objects in roads, specifically Indian roads. The reason that other commonly available models could not work properly in this environment is due to the variety of objects found in Indian roads.

Setting-up environment and Data pre-processing:

  1. Clone | fork this project - intelunnati_TeamTRON.

  2. Download the dataset (Indian Driving Dataset) from http://idd.insaan.iiit.ac.in [you will be asked to create an account]. IDD Detection (22.8 GB) is the dataset being used in this case.
    - Note that dataset directory here does not have Annotations and JPEGImages folders due to the large size of the dataset.
    - Also, instead of downloading the dataset, you can directly download the preprocessed dataset I have uploaded to Google Drive - modified_dataset.7z.

  3. Extract downloaded dataset and place into TeamTRON_MarBaseliosCollegeOfEngineeringAndTechnology_RoadObjectDetectionWithDeepLearning/data. This will replace the IDD_Detection folder already present.

  4. While in the intelunnati_TeamTRON folder, create a virtual environment named yolov5-env using the following command - python -m venv yolov5-env. [This step is recommended so that modules needed for this project will not affect any other projects.]
    - To activate the environment, type yolov5-env\Scripts\activate in your terminal.

  5. Navigate to TeamTRON_MarBaseliosCollegeOfEngineeringAndTechnology_RoadObjectDetectionWithDeepLearning/models and clone the YOLOv5 Github repository into this using the terminal command git clone https://github.com/ultralytics/yolov5. [You will notice that there is already a file named yolov5 when you clone the main repository itself, but it won't actually contain any files as it just links to an external repository]
    Navigate further into the cloned directory using cd yolov5 and use pip install -r requirements.txt to install required modules.

  6. Navigate to TeamTRON_MarBaseliosCollegeOfEngineeringAndTechnology_RoadObjectDetectionWithDeepLearning/code and run pip install lxml to install lxml module, which is needed for data preprocessing.

  7. Run datasetPreprocessing.py using the command python datasetPreprocessing.py. This will create a new folder modified_dataset in data folder, which is where dataset is stored in the proper format.

  8. As of 13/07/2023, it has been noticed that a package Pillow v10.0.0 is causing issues. So, it is recommended to downgrade to version 9.5 using the code pip install --upgrade Pillow==9.5.

(Optional) Installing CUDA for training on GPU:
  1. Check if your NVIDIA GPU supports CUDA.

  2. To download CUDA, check CUDA Toolkit 12.2 Downloads | NVIDIA Developer, and for older versions check CUDA Toolkit Archive | NVIDIA Developer.

  3. Download PyTorch. Make sure that Compute Platform versions of PyTorch and CUDA match.

  4. Optionally, try installing cuDNN, but a NVIDIA Developer Program Membership is required for this.

Model training:

  1. YOLOv5 has 5 different pretrained models to choose from - YOLOv5n, YOLOv5s, YOLOv5m, YOLOv5l, and YOLOv5xl. The .yaml files for these models along with configuration file idd.yaml are present within the models folder. These files have been modified to suit requirements of this project.

  2. Move to models/yolov5 directory and use the below command for training the model python train.py --img --batch --epochs --data <data/data.yaml> --cfg [change values within <>].

    Add --device cuda:0 at the end if you want to use a dedicated GPU.

    Use --weights <path_to_weights> if you have pretrained weights from any previous runs.

    Optional: you can set the number of workers with --workers <no_of_workers> but do take note that workers should not exceed the number of cores your CPU has.

    For example during the first training, the command was:

    python train.py --img 640 --batch 8 --epochs 50 --data ../idd.yaml --cfg ../yolov5n.yaml --device cuda:0 --workers 8
  3. Results of model training can be found in models/yolov5/runs/trains/exp_no.
    A weights folder is also present containing best.pt and last.pt. The best.pt file contains the weights to be used for next iteration.

Validating the trained model:

  1. Validation images are present inside modified_dataset/images/val. To run the program for using trained weights to validate, use the following code while in models/yolov5 directory:

    python val.py --data ../idd.yaml --weights runs/train/exp5/weights/best.pt --device cuda:0

    you might need to change the path for weights to point to latest set of weights obtained.

  2. yolov5/runs/val/exp_no contains output after running the command.

Detecting object in images:

  1. We have successfully trained a model on our dataset and validated. Now, our model is ready.

  2. You need to place your custom image inside data/custom_test_images and run the following command python detect.py --source <path/to/images> --weights <path/to/weights.pt> --conf 0.4. Here, only those with a confidence threshold of 0.4 is chosen. Example code to directly run detect.py is:

    python detect.py --source ../../data/custom_test_images/test1.jpg --weights runs/train/exp5/weights/best.pt --conf 0.4
  3. Results can be found inside yolov5/runs/detect/exp_no.

Note: Due to the large size of results folder, you man not be able to see contents of yolov5/models as it is a GitHub repository inside this main one. So, we have included all results we got as a folder named runs in Google Drive.

If you have skipped training and directly want to use the weights from us, navigate to the yolov5 directory you have cloned from official repository and place contents of this folder (which contains results of the training runs), into runs folder (ie, models/yolov5/runs).

Demo video has also been uploaded through Google Drive link intelunnati_TeamTRON - Visual Studio Code 2023-07-15 01-00-11.mp4 due to the large size of ~ 250MB.

Collaborators:

@Josh Danny Alex
@Noel John Robert
@Nubi Fathima N

Folder Structure

italicized file | folder name means it will not be present on cloning this directory and has to be obtained from some other source, as mentioned

intelunnati_TeamTRON/
  ├── TeamTRON_MarBaseliosCollegeOfEngineeringAndTechnology_RoadObjectDetectionWithDeepLearning/
  │   ├── code/
  │   │   └── dataPreprocessing.py
  │   ├── data/
  │   │   ├── custom_test_images/
  │   │   │   ├── test1.jpg
  │   │   │   ├── test2.jpg
  │   │   │   ├── .
  │   │   │   └── .
  │   │   ├── IDD_Detection/
  │   │   │   ├── Annotations/
  │   │   │   │   ├── .
  │   │   │   │   └── .
  │   │   │   ├── JPEGImages/
  │   │   │   │   ├── .
  │   │   │   │   └── .
  │   │   │   ├── test.txt
  │   │   │   ├── train.txt
  │   │   │   └── val.txt
  │   │   └── modified_dataset/
  │   │      ├── images/
  │   │      │   ├── test/
  │   │      │   │   └── .
  │   │      │   ├── train/
  │   │      │   │   └── .
  │   │      │   └── val/
  │   │      │      └── .
  │   │      ├── labels/
  │   │      │   ├── test/
  │   │      │   ├── train/
  │   │      │   │   └── .
  │   │      │   └── val/
  │   │      │      └── .
  │   │      └── class_mapping.json
  │   ├── demo_videos/
  │   │   ├── intelunnati_TeamTRON - Visual Studio Code 2023-07-15 01-00-11.mp4
  │   │   └── read.txt
  │   ├── docs/
  │   │   ├── read_this.txt
  │   │   └── TeamTRON_ProjectReport.pdf
  │   └── models/
  │      ├── yolov5/
  │      │   ├── .
  │      │   └── runs/
  │      │   │   ├── detect/
  │      │   │   ├── train/
  │      │   │   └── val/
  │      │   └── .
  │      ├── idd.yaml
  │      ├── yolov5l.yaml
  │      ├── yolov5m.yaml
  │      ├── yolov5n.yaml
  │      ├── yolov5s.yaml
  │      └── yolov5x.yaml
  ├── yolov5-env/
  │   ├── .
  │   └── .
  ├── .gitignore
  └── README.md



GDrive link for all related files that couldn't be placed into GitHub directly.

About

A repository created as part of Intel Unnati program, 2023

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages