Skip to content

Instantly share code, notes, and snippets.

@jeremy-rutman
Last active January 30, 2020 10:50
Show Gist options
  • Select an option

  • Save jeremy-rutman/74c03f4c9a15492227ca22164890d68a to your computer and use it in GitHub Desktop.

Select an option

Save jeremy-rutman/74c03f4c9a15492227ca22164890d68a to your computer and use it in GitHub Desktop.
setting .cfg for yolov3
https://pjreddie.com/darknet/yolo/
https://gist.github.com/jeremy-rutman/74c03f4c9a15492227ca22164890d68a
https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects
also see https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects for opencv reading yolo dnn
1. make train.txt with paths to training jpgs
2. label files either in parallel dir or same dir (not sure ))
3. edit cfg/voc.data (locations of train/test files, class names etc)
4. set to train vs test in .cfg
5. n_filters in last conv. layer =
(classes+1+coords)*num_of_clusters , e.g it should be 30 if classes =1, coords=4, num_of_clusters=5
(2+1+4)* 5 = 35
or
3*(classes+5)
working examples:
classes 80
filters 255
3*(85)=255
or
filter size=(num/3)*(classes+5)
working examples:
classes=80
filters=255
num=9
9/3*85=255
classes=2
filters=21
num=9
9/3*(2+5)=21
6. set classes to right # in .cfg - 3 different places
7. gen anchors? https://github.com/AlexeyAB/darknet/blob/master/scripts/gen_anchors.py
8. train - eg
./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74
concerning output:: see https://github.com/AlexeyAB/darknet/issues/636
RAM 5846/7851MB (lfb 86x4MB) cpu [0%@345,0%@345,0%@345,0%@345,0%@345,49%@345]
My questions are:
from training log, why are some Avg IOU's value nan?
According to your instructions, you say yolo v3 requires 4GB GPU RAM. buy why does it take over 4GB on my environment?
Are there any configuration I could miss ?
Thanks.
@AlexeyAB
Owner
AlexeyAB commented on Apr 15, 2018 •
nan occurs when there isn't labels (box truth) for anchors in this [yolo]-layer (anchor= which are specified in mask= in cfg-file for the current one of three yolo-layers)
nan occurs when there isn't labels for this image at all (negative samples).
Only if nan occurs for avg loss for several dozen consecutive iterations, then training went wrong. Otherwise, the training goes well.
Yolo does in a loop for each Ground truth labels:
Yolo looking for the most suitable anchor for the current Ground truth labels (from all 9 anchors):
darknet/src/yolo_layer.c
Lines 243 to 245 in 5c1e8e3
if (iou > best_iou){
best_iou = iou;
best_n = n;
Then Yolo check is this the best anchors specified in mask= of this [yolo]-layers (in total there are 3 yolo-layers):
darknet/src/yolo_layer.c
Line 249 in 5c1e8e3
int mask_n = int_index(l.mask, best_n, l.n);
And if yes, then calculates these indicators - i.e. calculates sum and divide it on number of Ground truth labels which suitable for anchor from this [yolo]-layer:
Region 82 - index of current [yolo]-layer (in the default yolov3.cfg there are 3 yolo layers: 82, 94, 106)
Avg IOU - is average intersect of union between Detected objects and Ground truth from label-txt-file
Class: - is average of the probabilities of correctly classified objects
Obj: - is average of the objectness T0 (probabilities that there is an object in this box (anchor))
.5R: - is average true positives with (IoU > 0.5)
.75R: - is average true positives with (IoU > 0.75)
Conclusion: So if the best anchor isn't suitable for this [yolo]-layer, then count of Ground truth labels which suitable for this [yolo]-layer is equal to zero (count=0), then will be divide by zero
Avg IOU = <avg_iou>/count = <avg_iou>/0 = nan
Class = <avg_cat>/class_count = <avg_cat>/0 = nan
Obj = <avg_obj>/count = <avg_obj>/0 = nan
Region 82 Avg IOU: 0.093910, Class: 0.450770, Obj: 0.548225, No Obj: 0.489352, .5R: 0.000000, .75R: 0.000000, count: 1
Region 94 Avg IOU: nan, Class: nan, Obj: nan, No Obj: 0.558836, .5R: nan, .75R: nan, count: 0
Region 106 Avg IOU: 0.314969, Class: 0.234830, O
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment