AlexeyAB / darknet

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

Custom base network #391

Closed groot-1313 closed 6 years ago

groot-1313 commented 6 years ago

I have modified the cfg file to have a custom base network, followed by the last convolution layer(with linear activation) and the region layer. My base network returns an output of the same size as the image i.e., 416.

  1. How do I change the anchor values in this respect? Is the below equation doing the right job? anchor_val = anchor_val*32

  2. Will this command without the darknet19_448.conv.23 file as pretrained weights work? ./darknet detector train cfg/obj.data cfg/yolo.cfg

AlexeyAB commented 6 years ago
  1. In general yes.
  2. Yes.

What is the type of network do you try to use, is your network based on Semantic Segmentation network?

groot-1313 commented 6 years ago

I am using the densely connected neural network as the base network. It worked well to give an object segmentation output upon removing the fully connected layers and placing a sigmoid activation function on the final convolution layer. I want to use this network to also predict bounding boxes without having to take the sliding window approach for multiple objects within an image. But I observed darknet doesn't have a sigmoid layer, but only a softmax layer. Thanks for the quick reply!!

AlexeyAB commented 6 years ago
groot-1313 commented 6 years ago

Oh thanks for the input! Will look into DSOD.

I actually wanted to use densenet201.cfg but I could not find the appropriate pretrained file. Thanks for pointing that out!

groot-1313 commented 6 years ago

Are the deconvolutional layers not supported? networks.c has it defined and upon checking deconvolutional_layer.c has the same fields as the convolutional layer. This error did not show in the original repository.

[deconvolutional]
filters=1
size=3
stride=2
activation=linear

Gives me the following error:

Type not recognized: [deconvolutional] Unused field: 'filters = 1' Unused field: 'size = 3' Unused field: 'stride = 2' Unused field: 'activation = linear'

groot-1313 commented 6 years ago

I am also getting nan values upon using densenet201_yolo.cfg with densenet201.300

AlexeyAB commented 6 years ago
groot-1313 commented 6 years ago

I got NAN on all iteration number lines. I got the first NAN on the first iteration. I will try it upon changing batch and subdivision values. Can you please shed some light upon the cause of such values?

I could give stopbackward=1 an attempt because YOLO network as it is gave better results with the pretrained weights than it did after training for 50k iterations.

sivagnanamn commented 6 years ago

@groot-1313 If you're attempting transfer learning, you can try with even smaller learning rate. I've experienced similar issue when my learning rate was high (in the order ^-2 or sometime with ^-3). Usually occurs when the gradients are too big.

groot-1313 commented 6 years ago

I changed the learning rate to order of ^-3 from ^-2 after 40k iterations. Continued training for 30k iterations more, but saw no improvement. The performance of the network actually deteriorated in comparison to the weights after 8k iterations.

sivagnanamn commented 6 years ago

The performance of the network actually deteriorated in comparison to the weights after 8k iterations.

Appears to be overfitting. You can try adding dropouts.

groot-1313 commented 6 years ago

@sivagnanamn , it is not really over fitting because it performs poorly on the training data as well!

groot-1313 commented 6 years ago

hi @AlexeyAB, finetuning the network worked out well, better than any of my previous attempts. Though I am still not highly satisfied with the model. Could be due to 2 reasons.

  1. The dataset I am using is a highly challenging one.
  2. The loss doesn't reduce below 13. It oscillates between 11 and 14. I reduced the learning rate to the order 10^-4 as well. Trained for 22000 iterations. And the loss has been an avg of 13 since the 10000th iteration.

Any more suggestions to improve the learning?

AlexeyAB commented 6 years ago

@groot-1313 Hi,

learning_rate=0.0001 max_batches = 45000 policy=steps steps=100,25000,35000 scales=10,.1,.1



* Also if you have small objects, you can try to increase `width=608 height=608` or try to use `random=1` if you have enought GPU-RAM (if error out-of-memory occurs, then try to increase subdivision=64)
groot-1313 commented 6 years ago

@AlexeyAB , I will try with the suggestions you have mentioned. I do have small objects, so setting small_object=1 should definitely help. I was also wondering if its possible to visualize the outputs of the intermediate layers, for example , I would like to visualize the output of say, the 13th convolutional layer.

ghost commented 6 years ago

i tried to used resnet50 as cnn in yolo2, but bbox_loss becomes to nan. with smaller learning rate, loss becomes nan after more epochs. i tested with 1e-3, 1e-5, 1e-6 with 200k iteration. i tried with vgg16, it worked. what things need to change to finetune resnet? thanks!

AlexeyAB commented 6 years ago

@txdat Did you use this command for training? darknet.exe detector train data/obj.data resnet50_obj.cfg resnet50.65

To fine-tune just un-comment this line (remove #): https://github.com/AlexeyAB/darknet/blob/726cebd3fb67d65ec6d2d49fa6bfba4c053085df/build/darknet/x64/resnet50_yolo.cfg#L482

bit-scientist commented 6 years ago

@groot-1313 Any updates on that so far?