UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor yokota06y
Visitor
2,962 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
Visitor yokota06y
Visitor
2,854 Views
Registered: ‎06-03-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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

19 Replies
Adventurer
Adventurer
2,917 Views
Registered: ‎04-10-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Visitor yokota06y
Visitor
2,855 Views
Registered: ‎06-03-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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

Contributor
Contributor
2,773 Views
Registered: ‎05-07-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Visitor yokota06y
Visitor
2,714 Views
Registered: ‎06-03-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
2,686 Views
Registered: ‎05-06-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

@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
Visitor pggsmiles
Visitor
2,529 Views
Registered: ‎07-11-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Observer stockerc
Observer
2,480 Views
Registered: ‎04-20-2019

回复: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

@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
Visitor bluesea2012
Visitor
2,397 Views
Registered: ‎06-02-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

@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
Contributor
Contributor
2,214 Views
Registered: ‎05-07-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

@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
Contributor
Contributor
2,025 Views
Registered: ‎11-23-2017

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Adventurer
Adventurer
2,010 Views
Registered: ‎06-09-2015

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Visitor yokota06y
Visitor
1,988 Views
Registered: ‎06-03-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Observer stockerc
Observer
1,973 Views
Registered: ‎04-20-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution
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
Observer stockerc
Observer
1,971 Views
Registered: ‎04-20-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution
The cfg file is below.
0 Kudos
Visitor hcyhanson
Visitor
1,839 Views
Registered: ‎11-08-2018

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

Thanks for your solution, it solved my problem!

0 Kudos
Visitor u3527884
Visitor
1,781 Views
Registered: ‎08-19-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Xilinx Employee
Xilinx Employee
1,725 Views
Registered: ‎03-21-2008

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
Observer messikou
Observer
1,444 Views
Registered: ‎11-20-2012

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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
476 Views
Registered: ‎03-14-2019

Re: How to convert YOLOv3-tiny darknet to caffemodel

Jump to solution

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

thanks!

0 Kudos