Skip to content

LuongTuanAnh163002/Yolov2s

Repository files navigation

YOLOV2: Build from scratch, Train YOLOV2 with Custom dataset

Generic badge PyTorch - Version Python - Version

Table of Contents
  1. About The Project
  2. Project Structure
  3. Data Preparation
  4. How to run repository with custom dataset
  5. Try with example in google colab
  6. Conclusion
  7. License
  8. Acknowledgements

In this project we will build YOLOV2 from scratch and training with all CUSTOM dataset

Yolov2s
  │   train.py                      # Train script
  │   detect.py                     # Detect script inference

├───model │ yolo.py #Define yolov2 model structure │ ├───data │ custom_dataset.yaml #Config data custom_dataset.yaml │ └───utils │ datasets.py #Processing datasets │ metrics.py # Compute metrics │ loss.py # Define loss function │ general.py # Various helper functions │ plots.py # Some plot function

Yolov2s
└───datasets
    ├───images
    │   ├───train
          ├───file_name.jpg
          ├───..............
    │   └───valid
          ├───file_name.jpg
          ├───..............
        
    ├───labels
    │   ├───train
          ├───file_name.txt
          ├───.............
    │   └───valid
          ├───file_name.txt
          ├───.............

1.For training

+Step1: Install virtual environment, package

  conda create --name yolo python=3.10.12
  git clone https://github.com/LuongTuanAnh163002/Yolov2s.git
  cd Yolov2s
  conda activate yolo
  pip install -r requirements.txt
  

+Step2: Dowload dataset

  #for ubuntu/linux
  bash ./script/get_fruit.sh
  \
  #for window
  pip install gdown
  gdown 1btZfd9hFpY7J_UGDMHkUtia-2VggcLRP
  tar -xf fruit_dataset.zip
  del fruit_dataset.zip
  

+Step3: Go to "data" folder then create another file .yaml like custom_dataset.yaml

+Step4: Run the command below to training for pretrain

python train.py --data data/file_name.yaml --epochs 20 --device [0, 1, 2..] --data_format yolo

After you run and done training, all results save in runs/train/exp/..., folder runs automatic create after training done:

2.For detect

  #for file
  python detect.py --source file_name.jpg --weight ../runs/train/../weights/__.pth --conf_thres 0.15 --device [0, 1, 2,..]
  #for folder
  python detect.py --source path_folder --weight ../runs/train/../weights/__.pth --conf_thres 0.15 --device [0, 1, 2,..]
  #for video
  python detect.py --source video.mp4 --weight ../runs/train/../weights/__.pth --conf_thres 0.15 --device [0, 1, 2,..]
  

3.Launch tensorboard

tensorboard --logdir ../runs/train/name_project --bind_all --port=2002

1.For training with fruit dataset

Open In Colab

2.For inferrence with my model

Open In Colab

You can dowload weight here:

last_tank.pth last_fruit.pth

We build complete yolov2 from scratch but we have some advantage and disadvantage:

Advantage

  • Simple
  • Speed
  • Train with many other dataset

Disadvantage

  • Can only train with small dataset, if the amount of data is large, the data processing speed will be slow and model training will also take more time
  • Only jpg files images are supported during training, in the future we will improve to support more file types images.
  • Haven't exported model to onnx or tensorRT yet. In the near future we will update the conversion code for onnx and tensorRT.

See LICENSE for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published