Table of Contents
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 ├───.............
+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:
#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,..]
tensorboard --logdir ../runs/train/name_project --bind_all --port=2002
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.