AlexeyAB / darknet

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

v3 model conversion problems - .weight file differences? #787

Open mate-cape opened 6 years ago

mate-cape commented 6 years ago

I'm trying to convert YOLO models to Keras with YAD2K (and finally to CoreML). With YOLOv2 I was able to parse the configs and load the weights. With v3 the config parsing is still working, however I ran into problems with loading the weights.

For YOLOv3 all weights are loaded, but the converted Keras model gives significantly different outputs. The recently released yolov3-tiny model on the other hand converts the model without using all the weights, and the outputs are all NaNs...

Are there differences in how v2 and v3 model parameters are saved to .weight files? Like in the ordering of some parameters?

AlexeyAB commented 6 years ago

Are there differences in how v2 and v3 model parameters are saved to .weight files? Like in the ordering of some parameters?

No, there is no differences in formats of weights-file.

Does Keras support Yolo v3 correctly?

mate-cape commented 6 years ago

I've just checked, and the original YOLOv3 gives NaNs, just like TinyYOLOv3. Before I tried a re-trained YOLOv3 with different categories, that gave valid numbers as outputs, but it was slightly different from Darknet outputs (detected boxes were close, confidences were significantly different).

Thanks for the info on the .weight file! I was suspecting that to be the problem, since the YAD2K conversion scrip did not use all weights from the file.

To summarize my findings so far:

Of course this is an issue of the conversion script and not YOLO, but I suspected some differences in the weight files. Anyway, let me know if you have any idea.

I was trying to find the differences between the architectures.

Here I uploaded the plotted architecture of the converted network, I think the graph has been built correctly.

AlexeyAB commented 6 years ago
  1. What implementation of Keras Yolo v3 do you use, can you give a link?

  2. Did you successfully convert using YAD2K it is this weights-file downloaded from this site? https://pjreddie.com/media/files/yolov2.weights not from other places? with this cfg-file: https://github.com/pjreddie/darknet/blob/master/cfg/yolov2.cfg


  1. Do you use this repository for training?

Try to change these 3 lines:

  1. https://github.com/AlexeyAB/darknet/blob/cda8171feb76bcb405350fd8341d42a0300e2f4b/src/parser.c#L957 to this: fwrite(net.seen, sizeof(uint64_t), 1, fp);

  2. https://github.com/AlexeyAB/darknet/blob/cda8171feb76bcb405350fd8341d42a0300e2f4b/src/network.h#L24 to this uint64_t *seen;

  3. https://github.com/AlexeyAB/darknet/blob/cda8171feb76bcb405350fd8341d42a0300e2f4b/src/network.c#L174 to this net.seen = calloc(1, sizeof(uint64_t));

And train 100 iterations, for saving weights-file, and try to convert it using YAD2K.


AlexeyAB commented 5 years ago

It can be related to this issue if you used ADAM optimizer: https://github.com/AlexeyAB/darknet/issues/2485#issuecomment-475656779