AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.79k stars 7.96k forks source link

Cross-validation #4431

Open omarmaree opened 4 years ago

omarmaree commented 4 years ago

Hello @AlexeyAB , I trained my model but I got an overfitting problem and i want to solve it by doing cross-validation with 5 folds. can u help me please to do that?

AlexeyAB commented 4 years ago

So what is the problem?

Divide the dataset into 5 parts, combine 1-4 parts to train.txt and 5th part to valid.txt and set in obj.data train = train.txt valid = valid.txt

And train Detector with -map flag and Classifier with -topk flag at the end of training command.

omarmaree commented 4 years ago

So what is the problem?

Divide the dataset into 5 parts, combine 1-4 parts to train.txt and 5th part to valid.txt and set in obj.data train = train.txt valid = valid.txt

And train Detector with -map flag and Classifier with -topk flag at the end of training command.

so the training comand will be like this? "darknet.exe detector train data/obj.data yolo-obj.cfg darknet53.conv.74 -map -topk " without specify the number of folds and there is no modification in the codes?

AlexeyAB commented 4 years ago

If you train Detector then:

And train Detector with -map flag and Classifier with -topk flag at the end of training command.

so the training comand will be like this "darknet.exe detector train data/obj.data yolo-obj.cfg darknet53.conv.74 -map "


Cross-validation 5 folds

You should:

mAP_cross_val = (mAP1 + mAP2 + ... + mAP5) / 5

omarmaree commented 4 years ago

If you train Detector then:

And train Detector with -map flag and Classifier with -topk flag at the end of training command.

so the training comand will be like this "darknet.exe detector train data/obj.data yolo-obj.cfg darknet53.conv.74 -map "

Cross-validation 5 folds

You should:

  • create 5 files train1.txt - train5.txt
  • create 5 files valid1.txt-valid5.txt
  • create 5 obj.data with train=train1.txt valid=valid1.txt
  • And train 5 times with different obj1 ... obj5.data files "darknet.exe detector train data/obj1.data yolo-obj.cfg darknet53.conv.74 -map" ... then average the final values mAP

mAP_cross_val = (mAP1 + mAP2 + ... + mAP5) / 5

but the final weights will be for the last trained model! is that right? or i should use the last best weights for the next training ?

AlexeyAB commented 4 years ago

but the final weights will be for the last trained model! is that right?

You can use the best weights-file to check the mAP.


or i should use the last best weights for the next training ?

No. You should train from scratch, by using http://pjreddie.com/media/files/darknet53.conv.74

omarmaree commented 4 years ago

but the final weights will be for the last trained model! is that right?

You can use the best weights-file to check the mAP. yeah. but as i understand from you to do cross-validation with 5 folds I need to repeat the training 5 times with the different composite of data sets. and after each training, I will have weights of that training. and since each training is not affected by the previous training weights, how the validation will affect on the next training? Also, which weights file should i choose when implementing the trained model?

or i should use the last best weights for the next training ?

No. You should train from scratch, by using http://pjreddie.com/media/files/darknet53.conv.74

AlexeyAB commented 4 years ago

and since each training is not affected by the previous training weights, how the validation will affect on the next training?

It will not affect. This is the essence of cross validation.

Also, which weights file should i choose when implementing the trained model?

What does it mean "implementing the trained model" ?

omarmaree commented 4 years ago

and since each training is not affected by the previous training weights, how the validation will affect on the next training?

It will not affect. This is the essence of cross validation.

Also, which weights file should i choose when implementing the trained model?

What does it mean "implementing the trained model" ? when i using the trained model in my application, which weights file should i use from all training trials?!

AlexeyAB commented 4 years ago

You can use any of these 5 weights-file. Or you can train another one weights-file by using the whole dataset (all 5 parts) - preferably (unless the customer explicitly sets other restrictions).

omarmaree commented 4 years ago

You can use any of these 5 weights-file. Or you can train another one weights-file by using the whole dataset (all 5 parts) - preferably (unless the customer explicitly sets other restrictions).

ok thanks a lot