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: 
Highlighted
Observer zorz123
Observer
258 Views
Registered: ‎03-22-2013

Darknet 2 Caffe Quantize problem incorrect shape

How to convert YOLOv3-tiny darknet to caffemodel

Hi All

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.

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

1. Classe 80 -> 1

2. filters: 255 -> 18

I do teach base on 1 classe and 18 filters .

3 darknet training create weight file about 256 Mb (it is correct, i verify result is ok )

4. Try convert darknet 2 caffe base on xilinx tutorial as follow:

 

bash -v 0_convert.sh
# step 1: test Darknet and Caffe YOLOv3 models
bash -v 0_test_darknet.sh
bash -v 1_test_caffe.sh
# step 2: quantize YOLOv3 Caffe model
cp 1_model_caffe/v3.caffemodel  ./2_model_for_quantize/
bash -v 2_quantize.sh

0604 11:20:22.077857  1844 net.cpp:310] This network produces output layer93-conv
I0604 11:20:22.077980  1844 net.cpp:330] Network initialization done.
I0604 11:20:22.078330  1844 net.cpp:869] Ignoring source layer input
F0604 11:20:22.105778  1844 net.cpp:913] Cannot copy param 0 weights from layer 'layer81-conv'; shape mismatch.  Source param shape is 18 1024 1 1 (18432); target param shape is 255 1024 1 1 (261120). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.
*** Check failure stack trace: ***
2_quantize.sh: line 8:  1844 Aborted                 (core dumped) decent quantize -model 2_model_for_quantize/v3.prototxt -weights 2_model_for_quantize/v3.caffemodel -gpu 0 -sigmoided_layers layer81-conv,layer93-conv,layer105-conv -output_dir 3_model_after_quantize -method 1
# step 3: compile ELF file
cp 3_model_after_quantize/ref_deploy.prototxt 3_model_after_quantize/deploy.prototxt
bash -v 3_compile.sh
#!/bin/bash

#Assume the dnnc-dpu1.3.0 is installed in /usr/local/bin

dnnc-dpu1.3.0 --prototxt=3_model_after_quantize/deploy.prototxt \
             --caffemodel=3_model_after_quantize/deploy.caffemodel \
             --dpu=4096FA \
             --cpu_arch=arm64 --output_dir=4_model_elf \
             --net_name=yolo --mode=normal --save_kernel

DNNC Kernel Information

 

Is there any way to solve this problem?

0 Kudos
7 Replies
Xilinx Employee
Xilinx Employee
250 Views
Registered: ‎12-09-2015

Re: Darknet 2 Caffe Quantize problem incorrect shape

(^^)/

 

"F0604 11:20:22.105778 1844 net.cpp:913] Cannot copy param 0 weights from layer 'layer81-conv'; shape mismatch. Source param shape is 18 1024 1 1 (18432); target param shape is 255 1024 1 1 (261120)."

 

It seems that the parameters for layer81-conv may not have been properly modified.

 

Perhaps do a search for "filters=255" in the original cfg file and check if an edit was missed?

 

 

0 Kudos
Observer zorz123
Observer
224 Views
Registered: ‎03-22-2013

Re: Darknet 2 Caffe Quantize problem incorrect shape

I verify my yolov3.cfg everything is correct .
Any suggestion for me ?
0 Kudos
Observer zorz123
Observer
204 Views
Registered: ‎03-22-2013

Re: Darknet 2 Caffe Quantize problem incorrect shape

Hi All 

More details:

1. I train datknet on VOC base . (it is difference Xilinx use COCO)

2. When i change file yolov3.cfg (name [convolutional] -> [convolutional_my] : lines : 599, 685, 772 )

The problem not exist during quantize steps.

3. Now i hold no error:

 

cp 3_model_after_quantize/ref_deploy.prototxt 3_model_after_quantize/deploy.prototxt
bash -v 3_compile.sh
#!/bin/bash

#Assume the dnnc-dpu1.3.0 is installed in /usr/local/bin

dnnc-dpu1.3.0 --prototxt=3_model_after_quantize/deploy.prototxt \
--caffemodel=3_model_after_quantize/deploy.caffemodel \
--dpu=4096FA \
--cpu_arch=arm64 --output_dir=4_model_elf \
--net_name=yolo --mode=normal --save_kernel
dnnc-dpu1.3.0: /tmp/DNNC_V010_Package/dnnc/submodules/asicv2com/src/SlNode/SlNodeConv.cpp:81: void SlNodeConv::generate_convinit_op(const Arch&, const LCONV&, const YAggregationType&, const YAggregationType&, const BlockSmf&, const BlockSmf&, uint32_t, uint32_t): Assertion `conv_param.get_shift_cut() >= 0' failed.
3_compile.sh: line 9: 424 Aborted (core dumped) dnnc-dpu1.3.0 --prototxt=3_model_after_quantize/deploy.prototxt --caffemodel=3_model_after_quantize/deploy.caffemodel --dpu=4096FA --cpu_arch=arm64 --output_dir=4_model_elf --net_name=yolo --mode=normal --save_kernel
# step 4: prepare the package for the ZCU102 board

0 Kudos
Observer zorz123
Observer
194 Views
Registered: ‎03-22-2013

Re: Darknet 2 Caffe Quantize problem incorrect shape

Hi ALL 

Suspect problemi is in caffe weights file. 

1. I compare network configuration file for caffe as below:

root@gd16:/mnt/data/test_darknet/Edge-AI-Platform-Tutorials/docs/Darknet-Caffe-Conversion/example_yolov3/1_model_caffe# diff v3_class80.prototxt v3_calss1.prototxt
diff v3_class80.prototxt v3_class1.prototxt
2564c2564
< num_output: 255
---
> num_output: 18
2874c2874
< num_output: 255
---
> num_output: 18
3184c3184
< num_output: 255
---
> num_output: 18

Conclusion :

All changes was convert corret. 

for classe = 1 , num_output: 18 

for classe = 80, num_output: 255

The problem exist in weights file .

Any suggestion how edit weights file ? (too big 250 Mb)

0 Kudos
Observer zorz123
Observer
162 Views
Registered: ‎03-22-2013

Re: Darknet 2 Caffe Quantize problem incorrect shape

Update
1. I've check on coco base the same problem as voc base.
2. Training on one classe and coco base + Xilinx weights for 80 classes as initial. Incorrect results past 20000 iterations, error during conversion darknet2caffe
Source param shape is 18 1024 1 1 (18432); target param shape is 255 1024 1 1
3. Training one classe and coco base + "0" weights as initial. Correct results past 2000 iterations, error during conversion darknet2caffe
Source param shape is 18 1024 1 1 (18432); target param shape is 255 1024 1 1

Any suggestion for me ?
0 Kudos
Observer zorz123
Observer
133 Views
Registered: ‎03-22-2013

Re: Darknet 2 Caffe Quantize problem incorrect shape

Update.

1. Traing assume classes=2 filters=21 , base : coco  modify base to 1 classe the second class without images .

1.1 Verify past 3000 iteration , object detected 76 %

1.2 Convert darknet2caffe , I've get error as below:

1. F0612 06:22:16.884925 653 net.cpp:913] Cannot copy param 0 weights from layer 'layer81-conv'; shape mismatch. Source param shape is 21 1024 1 1 (21504); target param shape is 255 1024 1 1 (261120). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.
*** Check failure stack trace: ***
2_quantize.sh: line 8: 653 Aborted (core dumped) decent quantize -model 2_model_for_quantize/v3.prototxt -weights 2_model_for_quantize/v3.caffemodel -gpu 0 -sigmoided_layers layer81-conv,layer93-conv,layer105-conv -output_dir 3_model_after_quantize -method 1
# step 3: compile ELF file

2. Traing assume classes=80 filters=255 , base : coco  modify base to 1 class the rest classes without images .

Under test

 

0 Kudos
Observer zorz123
Observer
102 Views
Registered: ‎03-22-2013

Re: Darknet 2 Caffe Quantize problem incorrect shape

2. Traing assume classes=80 filters=255 , base : coco  modify base to 1 class the rest classes without images .

2.1 Test  on darknet result correct (person detected, label size ok , label name ok )

2.2 Test  on xilinx caffe + DPU  result correct (person detected, label size ok , label name not exist).

Next step is to check create new base , user defined objects

0 Kudos