AlexeyAB / darknet

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

imbalanced training data #1935

Open yingzhec opened 5 years ago

yingzhec commented 5 years ago

Hi, I'm working on a multiple class detection with imbalanced training data, which means the distribution of images on each class is far from uniform. Any part of code in AlexeyAB repository could solve the problem? Thanks in advance.

holger-prause commented 5 years ago

On 14.11.2018 22:49, yingzhec wrote:

Hi, I'm working on a multiple class detection with imbalanced training data, which means the distribution of images on each class is far from uniform. Any part of code in AlexeyAB repository could solve the problem? Thanks in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AlexeyAB/darknet/issues/1935, or mute the thread https://github.com/notifications/unsubscribe-auth/AHjhQ8B2SAIRphIvcW5rpTSaYON2x2hZks5uvI_egaJpZM4YepVw.

Yolov3 allows multiclass labeling/prediction. Depending what you consider unbalanced(count nr of object(bboxes) not only nr of images) this could solve your "unbalanced" classes problem.

I personally also prefer alexs repo but this is not exclusive to that repo but a feature of yolov3(no plain softmax anymore).

yingzhec commented 5 years ago

I worry about the imbalanced training data could affect the weights generated from training. I have an idea of modifying the loss function in yolo but haven't know where to start

AlexeyAB commented 5 years ago

Hi, Just train as usual.

There are some features for imbalanced training - but both work poorly:

But even imbalance training will work better without these features ) May be we should check implementations again.

lvshuaigg commented 5 years ago

@AlexeyAB Hello, if adding focal_loss=1 is added in 3 [yolo] layers? Can you add the focal_loss function? Thank you very much!

AlexeyAB commented 5 years ago

@lvshuaigg

Can you add the focal_loss function?

It is already added: https://github.com/AlexeyAB/darknet/blob/14ed6fcb6e31dd111fc5c35c31ffa6e45fe52737/src/yolo_layer.c#L121-L139

You can use focal_loss=1 in the [yolo] layers in cfg-file. And you can use adam=1 in the [net] section in cfg-file.

lvshuaigg commented 5 years ago

@AlexeyAB Thank you very much!

arkjiang commented 5 years ago

@AlexeyAB would manually duplicating certain minority class work for rebalancing classes? for example replicating the same line multiple times in a file 15 x x x x (org) 15 x x x x (rep1) 15 x x x x (rep2) 0 x x x x 1 x x x x 2 x x x x

AlexeyAB commented 5 years ago

@arkjiang

No, multiple identical lines will not solve imbalancig problem, and willn't have any influence at all.

You can duplicate lines with image-path in train.txt - it can solve imbalancing problem.

arkjiang commented 5 years ago

@AlexeyAB what if the class imblance is embedded in each image ? For example, all images has 5 timese more Class A object than Class B. Is there a way to balance up class B

AlexeyAB commented 5 years ago

@arkjiang

what if the class imblance is embedded in each image ? For example, all images has 5 timese more Class A object than Class B. Is there a way to balance up class B

There is no simple way to balance it. You should add images with class B.

But any imbalance partially will be solved automatically, since there is used decay https://github.com/AlexeyAB/darknet/issues/1943#issuecomment-439560675