/YOLOR

They talk about the implement of YOLOR and they're Pytorch architecture.

🔱Download YoloR Github Resources from WongKinYiu

🔗 https://github.com/WongKinYiu/yolor

Image from Gyazo

🔱Do the following Pre-Work

1.Create a new environment

conda create -n yolor python=3.9
conda activate yolor
cd yolor

2.Install Pytorch corresponded to your CUDA version

Enter the cmd to check version.

nvidia-smi

image

Go through Pytorch to copy installmental command.

🔗https://pytorch.org/get-started/locally/

image

After that, you must make sure that your Torch can work.

Enter the cmd to make sure.

python
import torch
torch.cuda.is_available() 

If it work successfully, it'll show * True *.

image

3.Install the requirements.txt

pip install -r requirements.txt

4.Downloads the pre-trained weight.

Scroll it until you see the title named "Testing", you'll see a link named yolor_p6.pt. Just download it!!

Image from Gyazo

🔱Prepare data for testing as the following step

Because my service is Windows, not Ubuntu, we need to execute it like below.

If you master yolor, you can skip this step. The main purpose in the step is to make sure the sucess of necessiry installment.

Open scripts/get_coco.sh with Git for Windows

image

If you don't have Git, you can download from the link.

🔗 https://git-scm.com/downloads

After you opened it, it'll like this.

image

Then, your yolor/scripts will full of zips, including test2017, train2017, val2017, and cco2017label.

image

Unzip and move them.

You can move them to anywhere, but onething must make sure that their paths are same with yolor/data/coco.yaml.

image

🔱Testing

Enter the command as following to test whether verything is alright.

    python test.py --data data/coco.yaml --img 1280 --batch 32 --conf 0.001 --iou 0.65 --device 0 --cfg cfg/yolor_p6.cfg --weights weights/yolor_p6.pt --name yolor_p6_val

Let me show you how it's like

🔱Prepare your own train data

1.Installment-Labelimg

First, open your anaconda prompt, then enter in:

pip install labelimg

image

after finished, you can open it by the command:

labelimg

and it looks like that image

2.Operatation-Labelimg

After the application is opend, then open the folder full of pictures.

Image from Gyazo

Finally, circle the object you wanna train for detection.

5ea2cfa6f6463a4af9846d6c4a2d9900

🔱Amend the variables to fit in your own model

Put your own data to yolor/data/data

image

Create a .cfg file in yolor/cfg

You can copy if from any .cfg file and amend some variables.

Like me, i chose yolor_p6.cfg.

And considering my Ram, so justify batch, subdivision, width, height, learning_rate, max_batches, steps.

steps = (0.8 * max_batches ,0.9 * max_batches)

image

filters = (classes + 5) * 3 Search "[yolo]", and change the filters before "yolo", like bellowing picture shows.

image

It approximately in line 1569,1573,11577,1581,1605,1649,1693,1737.

image image image image image

Create a .yaml file in yolor/data

It record the paths of your data handled in the last step, the number of classes, and classes' names.

image

⚠ Type is .yaml

Create a .names file in yolor/data

Store your own classes in lines like yolov4.

image

⚠ Type is .names

image

🔱Trian the model

Train a new model

    python train.py --batch-size 4 --img 640 640 --data data/your.yaml --cfg cfg/your.cfg --epochs 300

If it break accidently, you don't need to train it from the start. Let me show you

Train from the middle

    python train.py --batch-size 4 --img 640 640 --data data/your.yaml --cfg cfg/your.cfg --weights runs/train/yolor_p6/weights/best.pt --epochs 300

Check and run your model

After training ,your weight will store in yolor/runs/train/yolor_???

Run it and TAKE A BREAK !!

Test in Videos

    python detect.py --source path/your_video--cfg cfg/your.cfg --weights runs/train/your_best.pt 

Test in Images

    python detect.py --source path/image/pic.jpg --cfg cfg/your.cfg --weights runs/train/your_best.pt 

Besides, you can run images for not just one. In other words, the model can detect a folder full of images one time.

    python detect.py --source path/img_folder --cfg cfg/your.cfg --weights runs/train/your_best.pt