cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
yokota06y
Visitor
Visitor
9,158 Views
Registered: ‎06-03-2019

How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

I tried darknet2caffemodel conversion tutorial (https://github.com/Xilinx/Edge-AI-Platform-Tutorials/tree/master/docs/Darknet-Caffe-Conversion).

I have converted default/example YOLOv3 darknet model to caffemodel, and it is successfully running on ZCU102 board.

The tutorial page mention that YOLOv3/tiny darknet is able to convert to caffemodel.
> The conversion from Darknet to Caffe supports YOLOv2/tiny, YOLOv2, YOLOv3/tiny, and YOLOv3 basic networks.

 

Next step, I try to convert YOLOv3-tiny darknet model which is downloaded from https://pjreddie.com/darknet/yolo/.

but when I convert yolov3-tiny.cfg and yolov3-tiny.weights, error reported as follows:

 

$ bash -v 0_convert.sh
#!/bin/bash

python ../yolo_convert.py \
0_model_darknet/yolov3-tiny.cfg \
0_model_darknet/yolov3-tiny.weights \
1_model_caffe/v3.prototxt \
1_model_caffe/v3.caffemodel
...

...

I0604 12:06:15.485395 4005 layer_factory.hpp:77] Creating layer layer20-concat
I0604 12:06:15.485421 4005 net.cpp:84] Creating Layer layer20-concat
I0604 12:06:15.485446 4005 net.cpp:406] layer20-concat <- layer19-upsample
I0604 12:06:15.485471 4005 net.cpp:406] layer20-concat <- layer8-conv_layer8-act_0_split_1
I0604 12:06:15.485497 4005 net.cpp:380] layer20-concat -> layer20-concat
F0604 12:06:15.485532 4005 concat_layer.cpp:42] Check failed: top_shape[j] == bottom[i]->shape(j) (24 vs. 26) All inputs must have the same shape, except at concat_axis.
*** Check failure stack trace: ***
0_convert.sh: line 7: 4005 Aborted (core dumped) python ../yolo_convert.py 0_model_darknet/yolov3-tiny.cfg 0_model_darknet/yolov3-tiny.weights 1_model_caffe/v3.prototxt 1_model_caffe/v3.caffemodel

 

Is there any way to solve this problem?

 

BRs

0 Kudos
1 Solution

Accepted Solutions
yokota06y
Visitor
Visitor
9,050 Views
Registered: ‎06-03-2019

Thanks reply.

I have solved YOLOv3-tiny darknet conversion problem and the converted YOLOv3-tiny is running on ZCU102 board (80class, 28fps).

That layer20 upsample was not problem bacause Deephi has prepared DeephiResize for upsamle layer.

> F0604 12:06:15.485532 4005 concat_layer.cpp:42] Check failed: top_shape[j] == bottom[i]->shape(j) (24 vs. 26) All inputs must have the same shape, except at concat_axis.

This mismatch 24 vs 26 error is caused in layer11-maxpool.
This is a critical issue of deephi darknet2caffe conversion program code.

I modified it and then I could convert YOLOv3-tiny model.

BRs

View solution in original post

24 Replies
kjgreenwood
Adventurer
Adventurer
9,113 Views
Registered: ‎04-10-2019

I would suspect your up_sample layer is not converted correctly. Are you upsampling using deconvolution. If you could include the prototxt for that layer, it might be something easy to spot.

0 Kudos
yokota06y
Visitor
Visitor
9,051 Views
Registered: ‎06-03-2019

Thanks reply.

I have solved YOLOv3-tiny darknet conversion problem and the converted YOLOv3-tiny is running on ZCU102 board (80class, 28fps).

That layer20 upsample was not problem bacause Deephi has prepared DeephiResize for upsamle layer.

> F0604 12:06:15.485532 4005 concat_layer.cpp:42] Check failed: top_shape[j] == bottom[i]->shape(j) (24 vs. 26) All inputs must have the same shape, except at concat_axis.

This mismatch 24 vs 26 error is caused in layer11-maxpool.
This is a critical issue of deephi darknet2caffe conversion program code.

I modified it and then I could convert YOLOv3-tiny model.

BRs

View solution in original post

multierection
Contributor
Contributor
8,969 Views
Registered: ‎05-07-2019

Have you meet the "caffe.LayerParameter" has no field named "upsample_param" problem, and How sloved it?
can you share me your caffemodel and prototxt?

0 Kudos
yokota06y
Visitor
Visitor
8,910 Views
Registered: ‎06-03-2019

I have not met "upsample_param" problem.

Have you tried darknet2caffe conversion tutorial ?

 

I seem your yolov3-caffemodel is not generated by Deephi darknet2caffe conversion tool. 

 

0 Kudos
8,882 Views
Registered: ‎05-06-2019

@yokota06y 

Hi, I'm also trying to convert the tiny yolo weights to caffe using the Xilinx tutorial but I get the same error.

Can you tell me how to fix it?

Thanks

0 Kudos
pggsmiles
Visitor
Visitor
8,725 Views
Registered: ‎07-11-2019

Hi, I'm trying to convert the YOLOv3 darknet weights to caffemodel using the "darknet2caffe.py" code.

Unfortunately, I Could get the prototxt file but not  the caffemodel file that is similar to weights.

Can you tell me how to fix it?

Thanks a lot.

0 Kudos
stockerc
Observer
Observer
8,676 Views
Registered: ‎04-20-2019

@yokota06y 

I meet the same problem.

F0713 21:48:05.792819 9621 concat_layer.cpp:42] Check failed: top_shape[j] == bottom[i]->shape(j) (24 vs. 26) All inputs must have the same shape, except at concat_axis.

Can you send your yolo_convert.py to me?Email:1845959584@qq.com,Thanks!

0 Kudos
bluesea2012
Visitor
Visitor
8,593 Views
Registered: ‎06-02-2019

@yokota06y 

I meet the same problem.concat_layer.cpp:42] Check failed: top_shape[j] == bottom[i]->shape(j) (24 vs. 26)

Can you send your yolo_convert.py to me?

Email:aaaa942124@126.com

Thanks!

0 Kudos
multierection
Contributor
Contributor
8,410 Views
Registered: ‎05-07-2019

@yokota06y 

I meet the same problem. bottom[i]->shape(j) (24 vs. 26)

Can you tell me how to fix the issue of deephi darknet2caffe conversion program code?

or share your yolo_convert.py with me?

Email:272132922@qq.com

Thanks!

0 Kudos
haroonrl123
Contributor
Contributor
8,221 Views
Registered: ‎11-23-2017

1.  find concat_layer.cpp in the caffe-master folder .

2. Go to line 42 (in my case) and comment the equality check 

//CHECK_EQ(top_shape[j], bottom[i]-> shape(j))

// <<"All inputs must have the same shape , except at concat axis.";

 

3. Go to line 49 (in my case) and comment the equality check

//CHECK_EQ(bottom_count_sum, top[0]->count());

 

Run make clean for caffe-master.

Build caffe again 

make pycaffe

make all

and finally run

0_bash_convert.sh 

you will able convert the Yolo-tinyv3 to caffe successfully.

 

0 Kudos
krishnagaihre
Explorer
Explorer
8,206 Views
Registered: ‎06-09-2015

We also have published complete tutorial [with demo output] on "YoloV3 Tiny Darknet to Caffe with DNNDK and Ultra96 FPGA". If anyone interested then here is the complete tutorial link: YoloV3-tiny Darknet to Caffe with Ultra96.

Regards,
krishna@logictronix.com
0 Kudos
yokota06y
Visitor
Visitor
8,184 Views
Registered: ‎06-03-2019

Thank you for good information. 

 

(1) In my environment, layer11 with maxpooling size=1 causes performance degradation.

However your tutorial page output picture is no performance degration. 

Is it correct ? In my case, I have  

re-trained yolov3-tiny with maxpool size=1.

 

(2) In your tutorial, I  seem anchor box  is not change from yolov3 to yolov3-tiny (main.cc or utils.h).

Is it ok ?

 

Now I don't have pc and confirm it.

Sorry, if there were some mistakes

.

 

 

 

0 Kudos
stockerc
Observer
Observer
8,169 Views
Registered: ‎04-20-2019
I success to run yolov3-tiny under ZCU102.The new version yolo_convert.py and the cfg file is below. The reason maybe is the oringe darknet's maxpool is not compatible with the caffe's maxpool. It makes concat run mistake. To solve it, I add ''pad=1" in yolov3-tiny.cfg(about 84 line),and rewrite part of yolo_convert.py(about 411 line ,oringe is: "if block.has_key('pad') and int(block['pad']) == 1: pooling_param['pad'] = str((int(block['size'])-1)/2)" ,now is "if block.has_key('pad'): pooling_param['pad'] = '1' " ). The model trained by the oringe yolov3-tiny ,can be converted to the DNNDK success, and run perfectly. enjoy it! 1845959584@qq.com
0 Kudos
stockerc
Observer
Observer
8,167 Views
Registered: ‎04-20-2019
The cfg file is below.
0 Kudos
hcyhanson
Visitor
Visitor
8,035 Views
Registered: ‎11-08-2018

Thanks for your solution, it solved my problem!

0 Kudos
u3527884
Visitor
Visitor
7,977 Views
Registered: ‎08-19-2019

Thanks for your workaround. Can you also explain why the you modify that line? So that I can also apply this to other networks. There are many other maxpool layers and they dont need to be padded?

My assumption is that layer8 is 26 in width and layer19 is 24, so we have to pad layer9 to widen all subsequent layers upto layer19. At the end layer8 and layer19 will have the same width and can be processed in layer20(the concat layer). Is that right?

0 Kudos
jheaton
Xilinx Employee
Xilinx Employee
7,921 Views
Registered: ‎03-21-2008

There is a mismatch between Caffe and Darknet for max pool layers with stride of one. This creates a blob mismatch in Caffe and will cause an error.

The other max pooling layers are not effected, since their stride is not one.

The easiet solition is to just comment the layer in the .cfg file and retrain:

Capture.JPG

0 Kudos
messikou
Observer
Observer
7,640 Views
Registered: ‎11-20-2012

hello ,i tried to convert my own yolov3-tiny model,after i fixed the maxpool problem i tried to test the caffe model using the 1_test_caffe.sh. the result is very confused. it seemed that the banding box are not right. there will be several BB on one target ,but none of that can occupy the whole target. seemed like the no maxmium supress function dose not working correctlly. do i need to modify anywhere else? TKS!

0 Kudos
6,672 Views
Registered: ‎03-14-2019

hello,I have the same problem,Have you found a solution to the problem?Can you share with me?

thanks!

0 Kudos
xh
Visitor
Visitor
3,717 Views
Registered: ‎06-01-2020

Hi,

The darknet to caffe tutorial link no longer works.

Does anyone know where Xilinx move this repository to????

Many thanks!!

 

0 Kudos
prymasss1
Observer
Observer
3,684 Views
Registered: ‎02-11-2019
0 Kudos
xh
Visitor
Visitor
3,660 Views
Registered: ‎06-01-2020

Thank you!!!!!!

0 Kudos
jheaton
Xilinx Employee
Xilinx Employee
3,644 Views
Registered: ‎03-21-2008

You can also use the following flow for TensorFlow. The advantage of this is that you dont have to retrain the model to be compatible with Caffe:

You can try use the following flow

One disclaimer: I did see some differences between Darknet and the Keras detecions: I did open up the following issue on the githib repo site but have not had time to test out the recommendation:https://github.com/qqwweee/keras-yolo3/issues/625#issuecomment-636373390

0 Kudos
xh
Visitor
Visitor
3,632 Views
Registered: ‎06-01-2020

Thank you!

I'm trying with caffe now (someone was nice enough to shared a link to his/her saved tutorial with me). But still curious about how to handle it with keras… Will definitely check it later!:)

0 Kudos