How to get metrics during yolov4 detector training process and how to solve data overfitting?

5 次查看(过去 30 天)
When i use yolov4 detector to achieve a single-class target detection tasks, i can only get training-loss and validation-loss after training process.I have tried to use "options" to get metrics ,but it made Errow, wrong use " nnet.cnn.TrainingOptions/validateDataFormatsAndMetricsAreEmpty ,trainYOLOv4ObjectDetector can't support 'Metrics' training options",my code and errow are below:
Then how to get metrics during yolov4 detector training process?
----------------------------------------------------------------------------------------------
Meanwhile, after fine-tuning options parameters,I have trained the detector many times, the final training loss maintains 0.1 while validation loss can only get 2.0, how can I avoid this data overfitting?I've tried many methods , if you can give me some suggestions , it will be very helpful .

采纳的回答

Gayathri
Gayathri 2024-8-13
Hi @xinru,
As the error suggests, its not possible to pass “metrics” option in “trainingOptions” for “YOLOv4ObjectDetector”. Instead I can suggest you to use “evaluateObjectDetection” function to obtain the metrics Precision, Recall and Accuracy. This function also provides the confusion matrix through which all metrics could be calculated.
detectionresults=detect(trainedDetector,imds)
%%%%%%%%%%%%%Calculate metrics
metrics = evaluateObjectDetection(detectionresults, blds)
%%To obtain confusion matrix
cm=metrics.ConfusionMatrix
%%To obtain Precision,recall and AP
recall = metrics.ClassMetrics{"vehicle","Recall"}
precision = metrics.ClassMetrics{"vehicle","Precision"}
ap = metrics.ClassMetrics{"vehicle","AP"}
For additional information and example about “evaluateObjectDetection” please refer to https://www.mathworks.com/help/vision/ref/evaluateobjectdetection.html
To avoid overfitting, you can try training with more data. That would help mitigate overfitting.
Hope you find this information helpful.
  2 个评论
xinru
xinru 2024-8-14
Very thanks for your answer! However I think your code should use testdata to test detector precision instead of training data ,which cannot reflect real training situations.I've tried augmented data to increase amount of data, however the training loss is 0.01 and validation loss maintains 1.0,still overfitting.
Gayathri
Gayathri 2024-8-16
编辑:Gayathri 2024-8-16
Hi, yes we should be using test data. The code provided was just for illustrating the function usage. For overfitting, you can also try reducing the learning rate from 0.01 to 0.001 or lesser, if you have not tried this earlier. A learning rate that is high might cause the model to converge too quickly on the training data, leading to overfitting.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by