Mask R-CNN Project (Road Damage Detection)

Table of Contents

  1. General Info
  2. Installation
    2.1. HPC
    2.2. Local Machine
    2.3. Google CoLab
  3. Notes

General Info

General Information about the project (In Progress...)

Installation

Intro to Installation (In Progress...)

High Performance Computing (HPC)

Step 0: Logging into HPC (Cal Poly Pomona)

  • Fill in the form at this link to request the access to HPC

  • Follow the instruction in this link to setup VPN

  • Read the slides in this link to go over the basics of HPC

  • When connected to CPP's VPN, run the command below and type in the password to access HPC through command line (where username is CPP's username+password credentials)

ssh -l [username] hpc.cpp.edu

Note: There are 2 folders that a user can access in HPC

  • /home/username/ : main directory, where all the packages are installed (very limited storage-wised)

  • /data03/home/username/ : main working directory, where to clone the code (no limit in storage)


Step 1: Clone the GitHub Repository in /data03/home/username:

Change current directory to /data03/home/username

cd /data03/home/username/

Download Mask R-CNN Code to HPC using Git Clone

git clone https://github.com/KossBoii/RoadDamageDetection.git

Change durrent directory to RoadDamageDetection

cd RoadDamageDetection

Step 2: Create & Setup Anaconda Environment:

Create the Anaconda Virtual Environment

conda create --name py3 python=3.7.0
conda activate py3
pip install opencv-python
pip install scikit-image
  • Having Nvidia card (Using GPU to train ~ faster):

    Note: Make sure to go to this link to download and setup CUDA Toolkit 11.3

    conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
    
  • Not Having Nvidia card (Using CPU to train ~ slower):

    conda install pytorch torchvision torchaudio cpuonly -c pytorch
    

After downloading and setting up PyTorch + TorchVision + TorchAudio, install Detectron2:

python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

Notes: Error when installing Detectron2 on HPC

gcc: error: unrecognized command line option '-std=c++14'
error: command 'usr/bin/gcc' failed with exit code 1
  • To resolve this, run the commands below to tell the system the path to the gcc version that supports c++14:

    export PATH=/apps/local/gcc11.2.0/bin:$PATH
    
    export LD_LIBRARY_PATH=/apps/local/gcc11.2.0/lib64:$LD_LIBRARY_PATH
    
  • After running the 2 commands above, the environment issue should be resolved. Then, re-run the following command to install Detectron2:

    python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
    

Step 3: Train the Models:

sbatch running_script/train.sh [dataset_name] [backbone_model]

Step 4: Evaluating/Inferencing the Trained Models:

Evaluation:

sbatch running_script/evaluate.sh [list of models' name]

Inferencing:

sbatch running_script/inference.sh [train_model_name] [testing_image_path] [confidence_threshold]

Note:

  • tmn (trained model name): the model name wanted to run inference script, which can be found under [output] folder

  • tip (testing image path): the path to user's testing images

  • ct (confidence threshold): value between 0 and 1. Used to determine whether one is an instance or not



Local Machine

Step 1: Clone the GitHub Repository in the directory you want:

git clone https://github.com/KossBoii/RoadDamageDetection.git

Step 2: Create & Setup Anaconda Environment:

Create the Anaconda Virtual Environment

conda create --name py3 python=3.7.0
conda activate py3
pip install opencv-python
pip install scikit-image
  • Having Nvidia card (Using GPU to train ~ faster):

    Note: Make sure to go to this link to download and setup CUDA Toolkit 11.3

    conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
    
  • Not Having Nvidia card (Using CPU to train ~ slower):

    conda install pytorch torchvision torchaudio cpuonly -c pytorch
    

After downloading and setting up PyTorch + TorchVision + TorchAudio, install Detectron2:

python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

Step 3: Train the Models:

python train.py --training-dataset=[dataset_name] --backbone=[backbone_model]

Step 4: Evaluating/Inferencing the Trained Models:

Evaluation:

python evaluate.py --model-name=[tmn]

Inferencing:

python inference.py --model-name=[tmn] --img-path=[tip] --confidence-threshold=[ct]

Note:

  • tmn (trained model name): the model name wanted to run inference script, which can be found under [output] folder

  • tip (testing image path): the path to user's testing images

  • ct (confidence threshold): value between 0 and 1. Used to determine whether one is an instance or not



Google CoLab

... In Progress ...



Notes:

Notes for both inference/evaluation script:

  • HPC:

    • First go into the output file and get models' folder name (Ex:/output/model_3/). By specifiying list of models' name, the script will run through just these files

    • Without specifying the list of models' name, the script will run through all the folder existing in the output folder

  • Local Machine:

    • Inference/evaluation script can only be run each trained model separately

Notes for training script:

  • Replace [dataset_name] with the user's actual training dataset name in dataset folder (i.e., roadstress_new or roadstress_old)

  • Replace [backbone_model] with one of the options from table below:

Backbone Model Name [backbone_model]
R50_C4_1x "COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x.yaml"
R50_DC5_1x "COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_1x.yaml"
R50_FPN_1x "COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml"
R50_C4_3x "COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x.yaml"
R50_DC5_3x "COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_3x.yaml"
R50_FPN_3x "COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"
R101_C4_3x "COCO-InstanceSegmentation/mask_rcnn_R_101_C4_3x.yaml"
R101_DC5_3x "COCO-InstanceSegmentation/mask_rcnn_R_101_DC5_3x.yaml"
R101_FPN_3x "COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml"
X101_32x8d_FPN_3x "COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x.yaml"