Skip to content

ZouJiu1/Pytorch_YOLOV3

Repository files navigation

Pytorch_YOLOV3 from COCO scratch

upgrade version 7 2023-08-09

I found why the training before is slowly and can not merge finally, it is very simple to understand.

I used the torch.mean to calculate the loss of non_confidence before, so it loss decrease very slowly and the derivation or the gradient backpropagation is slowly, the non_confidence gradient backpropagation will multiply the $\frac{1}{numberofnon_confidence}$, the gradient will be very very small, the non_confidence loss work for nothing. using torch.mean need so many epoch to training and nonconf can not be trained, the real training epoch is little. so the negative confidence or non confidence can not be trained. the recall is low and precision is low.

but the training codes and model is correct.

Detection model

model_e30_map https://www.aliyundrive.com/s/xVYNAiaa19c 提取码: 16bn

model_e51_map https://www.aliyundrive.com/s/F7wRTcitbkB 提取码: gn85

Train

python allcodes/train_yolovkkn.py
python allcodes/train_yolovkkn_distribute.py

Predict

python allcodes/predict_yolovkkn.py
Things different

I write several different loss calculation function with torch.sum instead of mean and use yolov3-tiny network to training, it is training in gpu server with multi gpu cards, it needs much money for renting it, so I train very little epoch and use small batchsize to saving money without adjust hyper_params. The training result is very good compared with before.

those references are darknet_yolov3 https://github.com/AlexeyAB/darknet, darknet https://github.com/pjreddie/darknet, yolov* https://github.com/ultralytics. Considering the reference, those loss functions are:

the calculate_losses_darknet training is not stable so using the ciou loss to replace the coordinates loss for now. it is the calculate_losses_darknetRevise, the correspondding web is https://github.com/pjreddie/darknet.

the calculate_losses_Alexeydarknet is corresponding to https://github.com/pjreddie/darknet.

the calculate_losses_yolofive is corresponding to https://github.com/ultralytics

the calculate_losses_20230730 is writed by myself, it use iou to choose anchor and calculate the loss. I add the num_scale to balance different categories, and the iou scale to balance the difference anchor or prediction loss.

you can find those files in the models directory.

calculate_losses_darknetRevise(...)
calculate_losses_darknet(...)
calculate_losses_Alexeydarknet(...)
...
calculate_losses_yolofive(...)
calculate_losses_20230730(...)
...

the training result with yolov3-tiny alexeydarknet, 70 epoch, train from scratch without pretrained model and without data augmentation

the training result with yolov5s, 7 epoch mAP 16%, 10 epoch 21.2% in val2017, train from scratch without pretrained model and without data augmentation

the segmentation model is much better. it bbox mAP can reach to 33%

model_e46seg_map[0.50716__0.334552]_lnan_2023-09-01.pt https://www.aliyundrive.com/s/bLnC733gX5C 提取 nu63

dataset

the training datast is coco, which website is https://cocodataset.org/#download

Tracking

the tracking result is here: waiting for minutes

run command

Tracking

python tracking/tracking.py

tracking dataset download

MVI_39031.zip https://www.aliyundrive.com/s/PtnZBBf2E2V 提取码: e3q7

MOT16-06-raw.webm https://www.aliyundrive.com/s/tUwZH1H5gET 提取码: p50u

Model Segment

Train

python allcodes/train_yolovkkn_seg.py
python allcodes/train_yolovkkn_seg_distribute.py

Predict

python allcodes/predict_yolovkkn_seg.py

Model it bbox mAP can reach to 33% model_e46seg_map[0.50716__0.334552]_lnan_2023-09-01.pt

model_e60seg_map[0.485051__0.295817]_lnan_2023-09-03.pt https://www.aliyundrive.com/s/bLnC733gX5C 提取 nu63

Result





Model Segment+Pose Keypoint Person

the pose keypoint detection and segmentation in a model.

Train

python allcodes/train_yolovkkn_seg_keypoint.py
python allcodes/train_yolovkkn_seg_keypoint_distribute.py

Predict

python allcodes/predict_yolovkkn_seg_keypoint.py

Model it bbox mAP can reach to 50%

model_e39segkpt_map[0.502372__0.006359]_l155.764_2023-09-03.pt https://www.aliyundrive.com/s/bLnC733gX5C 提取 nu63

Result

the result including segment and person pose keypoint
















upgrade version 6 2022-11-13

Maybe I know the reason why the mAP of validation dataset is so slow in version3 2022-09

the first reason is that I used a big network yolov3, yolov3 is big, it has so many parameters and the training dataset is little just thousand, and I didn't used a pretrained model, and the train epoch <300. So it must be overfitted and not merged

another reason which is I used albumentations to augment images which old version is lower than 1.2.0 and the labels used in training and the labels used in validation is different. now I find it and upgrade the albumentations to version 1.3.0.

other reasons are the codes level ...

The solution

I don't have a computer which has a gpu, I rent a computer which has gpu before. I use a small network using pytorch from other person, which name is yolofastest and you can visit it from thisweb, yolofastest use the darknet to train.

The training result

this time, the network is merged and the mAP is higher than before, you can train your own dataset using command use allcodes\\preprocess.py or allcodes\\preprocess_v.py get data
python allcodes/train_yolofastest.py

--------------==================version 3 2022-09========------------------------------------

download voc data

https://pjreddie.com/projects/pascal-voc-dataset-mirror/

then use allcodes\\preprocess.py or allcodes\\preprocess_v.py get data
or you can download it from here https://pan.baidu.com/s/1nzUiAwUWD8J_lV7qkTdq4w?pwd=u2dn

models

https://pan.baidu.com/s/1lemOGC5zwJIcOcxWumCcRQ?pwd=9r22

use 3362 images with 2 classes person and car to train the model from scratch. the model is overfit, so the validation images is not so good.

#run
python allcodes/train_730.py
#predict
python allcodes/predict_730.py

train_overfit

validation

you can download yolov3 weight from here https://pan.baidu.com/s/1hWIxV2MggrzL_vlnbMbP_w?pwd=sugw

--------------==================version 2 2022-09========------------------------------------

data is same as version 3

models

https://pan.baidu.com/s/16FPm_aOxI3hoJoQ0exAmVQ?pwd=xj5k

train is not very good, maybe it is the yolohead coordinates problem

#run
python allcodes/train_717_730.py
#predict
python allcodes/predict_717_730.py

--------------==================version 1 2021-08========------------------------------------

dataset used is voc2007, processed dataset can download from processedvoc20072012, unzip it to datas directory,voc pretrained model
#run
python models/train.py
#predict
python predict.py

Reference

https://github.com/pjreddie/darknet
https://github.com/Peterisfar/YOLOV3
https://github.com/AlexeyAB/darknet
https://github.com/qqwweee/keras-yolo3
https://github.com/ultralytics
https://github.com/eriklindernoren/PyTorch-YOLOv3
https://github.com/YunYang1994/tensorflow-yolov3
https://github.com/mystic123/tensorflow-yolo-v3
https://github.com/Ray-Luo/YOLOV3-PyTorch
https://github.com/DeNA/PyTorch_YOLOv3

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages