Skip to content

aleksander-vedvik/Bachelor

Repository files navigation

Bachelor

I will provide a quick guide below on how to get started with this repository. README files are also provided in all relevant folders, which give a short description and explanation of each file in the respective folders.

ROOT or . is defined as the same folder where this readme file is located.

Installation

Prerequisites

Install dependencies:

pip install requirements.txt

TensorFlowAPI:

  1. Download protoc and add to PATH:

    • Download Protoc.

    • Add protoc to Windows PATH: "PATH TO DIRECTORY\protoc\protoc-3.15.6-win64\bin"

  2. Clone this repository into the "./training/tensorflowapi/" folder.

  3. Install dependencies:

     cd ./training/tensorflowapi/research/slim && pip install -e .
    
  4. Download pre-trained models here and put them in the "./training/pre-trained-models" folder. The models used in this thesis are: ssd_mobnet, efficientdet and faster_rcnn.

YOLOv5:

Follow the installation steps provided here by Ultralytics. Clone the repository into the "./training/yolov5/" folder. (Keep the dataset.yaml file. It is used when training the yolov5 model)

Prepare the data

Datasets

  1. Download the datasets from here.
  2. Move the datasets into the folder "./data/" (Folder structure is given in the README file located in the folder "./data")

TensorFlowAPI:

Create .tfrecords by running this command from ROOT:

cd ./training/scripts
python generate_records.py

YOLOv5:

Prepare the training and validation dataset for YOLOv5 by running this command from ROOT:

cd ./training/scripts
python generate_yolo.py

Train

TensforFlowAPI:

Run this command from ROOT to train a model from TensorFlowAPI:

cd training
python tensorflowapi/research/object_detection/model_main_tf2.py --model_dir=models/*MODEL_NAME* --pipeline_config_path=models/*MODEL_NAME*/pipeline.config --num_train_steps=*NUMBER_OF_STEPS*

The different models used are:

  • Model name: ssd_mobnet, number of steps: 10 000
  • Model name: efficientdet, number of steps: 15 000
  • Model name: faster_rcnn, number of steps: 20 000

YOLOv5:

python ./yolov5/train.py --img 640 --batch 4 --epoch 30 --data ./dataset.yaml --cfg ./yolov5/models/yolov5x.yaml --weights ./yolov5x.pt --name ./yolov5x_trained

Trained models:

Checkpoints from the trained model used in the thesis can be downloaded from here. The checkpoints are stored in the "Checkpoints" folder on the Google Drive folder. These checkpoints should have a similar folder structure to this Github. I.e. the checkpoints must be placed in the respective folders located under "./training/".

Eval

TensforFlowAPI:

Run this command from ROOT to train a model from TensorFlowAPI:

cd training
python tensorflowapi/research/object_detection/model_main_tf2.py --model_dir=models/*MODEL_NAME* --pipeline_config_path=models/*MODEL_NAME*/pipeline.config --checkpoint_dir=models/*MODEL_NAME*

The different models used are:

  • Model name: ssd_mobnet
  • Model name: efficientdet
  • Model name: faster_rcnn

Tensorboard

You can use Tensorboard to get info regarding the fine-tuned models. Navigate to the model folders and run:

tensorboard --logdir=.

Test the models on the test dataset:

Run this command from ROOT to test the models:

python run.py -m *model* -c *checkpoint* -r *number* -t *tracking_model* -i *image_enhancement_method* -f *filename* -s *number* -p *bool*

Description of flags:

  • -m: Specify which object detection model to use.
    • Options: yolov5, yolov5_trained, ssd_mobnet, efficientdet, faster_rcnn
    • Default: yolov5
  • -c: Specify the checkpoint to use. Only relevant for the models from TensorFlowAPI.
  • -r: Resize the input frame. Specify a number that should be used as the scale factor.
  • -t: Specify which tracking model to use.
    • Options: DeepSort, simple
    • Default: DeepSort
  • -i: Specify which image enhancement method to use:
    • Options: none, gray_linear, gray_nonlinear, he, retinex_ssr, retinex_msr, mask
    • Default: none
  • -f: Specify a filename to save the results to a file.
  • -s: Specify how many frames should be skipped.
  • -p: If given, a pre-trained model will be used. The model name must correspond to the folder name in the "pre-trained-models" directory.
  • It is possible to simply run python run.py without any flags. Then pre-trained YOLOv5x, deep SORT, and no image enhancement will be applied. No files will be saved.

References:

References are also cited in the files where code has been used.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages