qqwweee / keras-yolo3

A Keras implementation of YOLOv3 (Tensorflow backend)
MIT License
7.14k stars 3.45k forks source link

about train own dataset question #353

Open HaiLongEmb opened 5 years ago

HaiLongEmb commented 5 years ago

I am training Yolov3 with my own dataset.... only one class,person。

Sometimes the following situations occur when predicting pictures:

1

2

What is the reason? Where should I start?

Please....Help....

OtiTantaoui commented 5 years ago

Hello, please I would like to ask you if you did your training using this repo. Did you change the anchors ? and what are the height and widths of your images ? About your problem. I m only a beginner but I think you can solve it using non minimal suppression NMS

OtiTantaoui commented 5 years ago

Also, I would like to know if you did the training if you didnt have a large loss function that stagnated during the training

ancientghost commented 5 years ago

This problem can be solved by non-maximum-supression. It has been already embedded, https://github.com/qqwweee/keras-yolo3/blob/e6598d13c703029b2686bc2eb8d5c09badf42992/yolo3/model.py#L218

Perhaps, what you need is to modify the threshold https://github.com/qqwweee/keras-yolo3/blob/e6598d13c703029b2686bc2eb8d5c09badf42992/yolo.py#L99

HaiLongEmb commented 5 years ago

@OtiTantaoui ,Thank you for your help. I didn't change the anchors. I dont't know how to to modify anchors. My image is 1920*1080. I finish the train of loss 14.5369 - val_loss 14.9757.

@ancientghost , I'm using this method now. Sometimes this happens. Is there any other way?

wtx8887 commented 5 years ago

Hello, please I would like to ask you if you did your training using this repo. Did you change the anchors ? and what are the height and widths of your images ? About your problem. I m only a beginner but I think you can solve it using non minimal suppression NMS

I use the anchors generated by kmeans.py, but I don't know use which one: Generated by origin image(19201080) OR Generated by input_shape image (416416) Have you solved this problem?

OtiTantaoui commented 5 years ago

@wtx8887 no couldn't solve the problem yet. I m using images with width = 1240 and height = 377 and also have crowded scenes, hence I have a stagnating loss at around 30. I m not sure how to solve the problem but if I find a work around I ll update u here

OtiTantaoui commented 5 years ago

@wtx8887 I think you need to use the one generqted by the origin image. In the code, a data generator is used to generate the expected outputs of the network and resizing of the boxes is taken into account during that step if I m not mistaken

ancientghost commented 5 years ago

@HaiLongEmb Firstly, I need to make your problem more clear.

Actually, non-maximum-supression is the best way to solve this problem. If you use your own anchors and set appropriate threshold, but the problem is still there. Try to use less anchors, e.g. 6 anchors (then it become to yolo-tiy).

If it still doesn't work, sadly, I cannot help you anymore :(

ancientghost commented 5 years ago

@wtx8887 The Anchors should be generated from original size.

OtiTantaoui commented 5 years ago

@ancientghost please do you have any idea about my problem or any suggestion. I am actually having a trouble to reduce my loss less than 30. it got stuck at a loss of 30. I tried changing the anchors, reducing the learning rate, and training the full network. I also did set the parameter of data augmentation to random = False so that my network is not generalized and I was even hopping to get some overfitting but still same problem. I am using kitti dataset. It has many objects in the images and I suspect the dataset to be more tricky than others but when I use pretrained model on Coco I get good detection. I only need to retrain cause I want only few classes and I changed a bit the Kitti dataset. if you have any guidance or any hint to give me I will be grateful. Thanks

ancientghost commented 5 years ago

@OtiTantaoui There are lots of possibilities to cause a big loss. So, I couldn't give you some suggestions.

OtiTantaoui commented 5 years ago

@ancientghost Okay, thanks any way for your help

wtx8887 commented 5 years ago

@OtiTantaoui @ancientghost Thanks for your help

WZMIAOMIAO commented 5 years ago

@HaiLongEmb @wtx8887 I suggest using default Anchor box. And If you want to use your Anchor from your dataset, you need to scale anchor produced by K-means in 416x416.

the get_random_data function in utils.py: image = image.resize((nw,nh), Image.BICUBIC)
new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 new_image.paste(image, (dx, dy)) image_data = np.array(new_image)/255.

your input image sizes were scaled and filled into 416x416 image. So you cannot use directly the Anchor produced by K-means.

And when you test your network, you need to modify some code. in the yolo.py file: change: self.anchors_path = 'model_data/yolo_anchors.txt' to: self.anchors_path = 'your_anchors_resulted_by_K-meas.txt'

LiaoLIDIP commented 5 years ago

Reduce "iou" value in yolo.py at line 27 might help!

fourth-archive commented 5 years ago

@HaiLongEmb @OtiTantaoui @ancientghost @wtx8887 @WZMIAOMIAO this YOLOv3 tutorial may help you: https://github.com/ultralytics/yolov3/wiki/Train-Custom-Data

The accompanying repository works on MacOS, Windows and Linux, includes multigpu and multithreading, performs inference on images, videos, webcams, and an iOS app. It also tests to slightly higher mAPs than darknet, including on the latest YOLOv3-SPP.weights (60.7 COCO mAP), and offers the ability to train custom datasets from scratch to darknet performance, all using PyTorch :) https://github.com/ultralytics/yolov3



ZooZoo-tc commented 5 years ago

@HaiLongEmb @wtx8887 I suggest using default Anchor box. And If you want to use your Anchor from your dataset, you need to scale anchor produced by K-means in 416x416.

the get_random_data function in utils.py: image = image.resize((nw,nh), Image.BICUBIC) new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 new_image.paste(image, (dx, dy)) image_data = np.array(new_image)/255.

your input image sizes were scaled and filled into 416x416 image. So you cannot use directly the Anchor produced by K-means.

And when you test your network, you need to modify some code. in the yolo.py file: change: self.anchors_path = 'model_data/yolo_anchors.txt' to: self.anchors_path = 'your_anchors_resulted_by_K-meas.txt'

new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 what is (128,128,128)) ? could you give some info how it will effect when i use custom anchors?

HaiLongEmb commented 5 years ago

@HaiLongEmb @wtx8887 I suggest using default Anchor box. And If you want to use your Anchor from your dataset, you need to scale anchor produced by K-means in 416x416. the get_random_data function in utils.py: image = image.resize((nw,nh), Image.BICUBIC) new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 new_image.paste(image, (dx, dy)) image_data = np.array(new_image)/255. your input image sizes were scaled and filled into 416x416 image. So you cannot use directly the Anchor produced by K-means. And when you test your network, you need to modify some code. in the yolo.py file: change: self.anchors_path = 'model_data/yolo_anchors.txt' to: self.anchors_path = 'your_anchors_resulted_by_K-meas.txt'

new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 what is (128,128,128)) ? could you give some info how it will effect when i use custom anchors?

(128,128,128) is colour of grey。It has nothing to do with custom anchors.

ZooZoo-tc commented 5 years ago

@HaiLongEmb @wtx8887 I suggest using default Anchor box. And If you want to use your Anchor from your dataset, you need to scale anchor produced by K-means in 416x416. the get_random_data function in utils.py: image = image.resize((nw,nh), Image.BICUBIC) new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 new_image.paste(image, (dx, dy)) image_data = np.array(new_image)/255. your input image sizes were scaled and filled into 416x416 image. So you cannot use directly the Anchor produced by K-means. And when you test your network, you need to modify some code. in the yolo.py file: change: self.anchors_path = 'model_data/yolo_anchors.txt' to: self.anchors_path = 'your_anchors_resulted_by_K-meas.txt'

new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 what is (128,128,128)) ? could you give some info how it will effect when i use custom anchors?

(128,128,128) is colour of grey。It has nothing to do with custom anchors.

Thank you ... Any idea what is the input_shape means? is it object size or image size? Any idea how to train model with whole image(32x32 size) as object?

HaiLongEmb commented 5 years ago

@HaiLongEmb @wtx8887 I suggest using default Anchor box. And If you want to use your Anchor from your dataset, you need to scale anchor produced by K-means in 416x416. the get_random_data function in utils.py: image = image.resize((nw,nh), Image.BICUBIC) new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 new_image.paste(image, (dx, dy)) image_data = np.array(new_image)/255. your input image sizes were scaled and filled into 416x416 image. So you cannot use directly the Anchor produced by K-means. And when you test your network, you need to modify some code. in the yolo.py file: change: self.anchors_path = 'model_data/yolo_anchors.txt' to: self.anchors_path = 'your_anchors_resulted_by_K-meas.txt'

new_image = Image.new('RGB', (w,h), (128,128,128)) # w=h=416 what is (128,128,128)) ? could you give some info how it will effect when i use custom anchors?

(128,128,128) is colour of grey。It has nothing to do with custom anchors.

Thank you ... Any idea what is the input_shape means? is it object size or image size? Any idea how to train model with whole image(32x32 size) as object?

Input_shape is object size, The yolov3 input_shape is 4164163. For example, 3232 image need resize 416416 to yolov3.

ZooZoo-tc commented 5 years ago

Hi All, I am getting always accuracy like below... any idea about this.... how to fix this issue... i am not having any clue.... could someone help me understand this....

89/89 [==============================] - 299s 3s/step - loss: 24.7013 - acc: 0.0000e+00 - val_loss: 28.5394 - val_acc: 0.0000e+00