Conflicting configuration cfg files for Yolov3

Hi,
I used following two different cfg with same weights for yolov3, first one is producing wrong results and the second one is correctly executed. The detail is given below, can you please help me out!

  1. CASE. A

cfg: darknet/yolov3.cfg at master · pjreddie/darknet · GitHub
weights: https://pjreddie.com/media/files/yolov3.weights

  1. CASE. B

cfg: models-zoo/yolov3.cfg at master · yan-wyb/models-zoo · GitHub
weights: https://pjreddie.com/media/files/yolov3.weights

Differnce between two cfg files:

diff ~/sajjad/darknet/cfg/yolov3.cfg ~/sajjad/models-zoo/darknet/yolov3/yolov3/yolov3.cfg
3,4c3,4
< # batch=1
< # subdivisions=1
---
> batch=1
> subdivisions=1
6,9c6,9
< batch=64
< subdivisions=16
< width=608
< height=608
---
> # batch=64
> # subdivisions=16
> width=416
> height=416
  1. For CASE A. SDK CONVERSION SCRIPTS ARE:

0_import_model_608A.sh

#!/bin/bash

NAME=yolov3
ACUITY_PATH=../bin/

pegasus=${ACUITY_PATH}pegasus
if [ ! -e "$pegasus" ]; then
    pegasus=${ACUITY_PATH}pegasus.py
fi
$pegasus import darknet\
    --model  /home/sajjad/sajjad/darknet/cfg/yolov3.cfg \
    --weights /home/sajjad/sajjad/darknet/yolov3.weights \
    --output-model ${NAME}.json \
    --output-data ${NAME}.data \

#generate inpumeta  --source-file dataset.txt
$pegasus generate inputmeta \
        --model ${NAME}.json \
        --input-meta-output ${NAME}_inputmeta.yml \
        --channel-mean-value "0 0 0 0.003906"  \
        --source-file data/validation_tf_608.txt

1_quantize_model_608_tiny.sh

#!/bin/bash

NAME=yolov3
ACUITY_PATH=../bin/

pegasus=${ACUITY_PATH}pegasus
if [ ! -e "$pegasus" ]; then
    pegasus=${ACUITY_PATH}pegasus.py
fi

$pegasus  quantize \
        --quantizer dynamic_fixed_point \
        --qtype int8 \
        --rebuild \
        --with-input-meta  ${NAME}_inputmeta.yml \
        --model  ${NAME}.json \
        --model-data  ${NAME}.data

2_export_case_code_608_tiny.sh

#!/bin/bash

NAME=yolov3
ACUITY_PATH=../bin/

pegasus=$ACUITY_PATH/pegasus
if [ ! -e "$pegasus" ]; then
    pegasus=$ACUITY_PATH/pegasus.py
fi

$pegasus export ovxlib\
    --model ${NAME}.json \
    --model-data ${NAME}.data \
    --model-quantize ${NAME}.quantize \
    --with-input-meta ${NAME}_inputmeta.yml \
    --dtype quantized \
    --optimize VIPNANOQI_PID0X88  \
    --viv-sdk ${ACUITY_PATH}vcmdtools \
    --pack-nbg-unify

rm -rf ${NAME}_nbg_unify

mv ../*_nbg_unify ${NAME}_nbg_unify

cd ${NAME}_nbg_unify

mv network_binary.nb ${NAME}_88.nb

cd ..

#save normal case demo export.data
mkdir -p ${NAME}_normal_case_demo
mv  *.h *.c .project .cproject *.vcxproj BUILD *.linux *.export.data ${NAME}_normal_case_demo

# delete normal_case demo source
#rm  *.h *.c .project .cproject *.vcxproj  BUILD *.linux *.export.data

#rm *.data *.quantize *.json *_inputmeta.yml
rm *.data *.json *_inputmeta.yml

validation_tf_608.txt

demo$ cat data/validation_tf_608.txt
./1080p-608x608.jpg
  1. For CASE B. SDK CONVERSION SCRIPTS ARE:

Only difference is in the first script actually.
0_import_model_416A.sh

#!/bin/bash

NAME=yolov3
ACUITY_PATH=../bin/

pegasus=${ACUITY_PATH}pegasus
if [ ! -e "$pegasus" ]; then
    pegasus=${ACUITY_PATH}pegasus.py
fi

$pegasus import darknet\
    --model  /home/sajjad/sajjad/models-zoo/darknet/yolov3/yolov3/yolov3.cfg \
    --weights /home/sajjad/sajjad/darknet/yolov3.weights \
    --output-model ${NAME}.json \
    --output-data ${NAME}.data \

#generate inpumeta  --source-file dataset.txt
$pegasus generate inputmeta \
        --model ${NAME}.json \
        --input-meta-output ${NAME}_inputmeta.yml \
        --channel-mean-value "0 0 0 0.003906"  \
        --source-file data/validation_tf_416.txt

1_quantize_model_416.sh

#!/bin/bash

NAME=yolov3
ACUITY_PATH=../bin/

pegasus=${ACUITY_PATH}pegasus
if [ ! -e "$pegasus" ]; then
    pegasus=${ACUITY_PATH}pegasus.py
fi

$pegasus  quantize \
        --quantizer dynamic_fixed_point \
        --qtype int8 \
        --rebuild \
        --with-input-meta  ${NAME}_inputmeta.yml \
        --model  ${NAME}.json \
        --model-data  ${NAME}.data

2_export_case_code_416.sh

#!/bin/bash

NAME=yolov3
ACUITY_PATH=../bin/

pegasus=$ACUITY_PATH/pegasus
if [ ! -e "$pegasus" ]; then
    pegasus=$ACUITY_PATH/pegasus.py
fi

$pegasus export ovxlib\
    --model ${NAME}.json \
    --model-data ${NAME}.data \
    --model-quantize ${NAME}.quantize \
    --with-input-meta ${NAME}_inputmeta.yml \
    --dtype quantized \
    --optimize VIPNANOQI_PID0X88  \
    --viv-sdk ${ACUITY_PATH}vcmdtools \
    --pack-nbg-unify

rm -rf ${NAME}_nbg_unify

mv ../*_nbg_unify ${NAME}_nbg_unify

cd ${NAME}_nbg_unify

mv network_binary.nb ${NAME}_88.nb

cd ..

#save normal case demo export.data
mkdir -p ${NAME}_normal_case_demo
mv  *.h *.c .project .cproject *.vcxproj BUILD *.linux *.export.data ${NAME}_normal_case_demo

# delete normal_case demo source
#rm  *.h *.c .project .cproject *.vcxproj  BUILD *.linux *.export.data

#rm *.data *.quantize *.json *_inputmeta.yml
rm *.data *.json *_inputmeta.yml

validation_tf_416.txt

demo$ cat data/validation_tf_416.txt
./1080p-416x416.jpg

Test using detect_demo_picture/detect_demo_x11 -m 2
I am following the instructions from convert and call your own model through NPU | Khadas Documentation to detect objects using yolov3 based on the converted models.

  • CASE. A: gives wrong results, I don’t know why?
  • CASE. B: gives correct results:

Can you please elaborate what is the difference here for darknet/yolov3.cfg at master · pjreddie/darknet · GitHub, what should be the correct parameters in the conversion scripts to perform conversion based on this configuration file.

NOTE: When i modified darknet/yolov3.cfg at master · pjreddie/darknet · GitHub to the following (changed width=416, height=416), it still works for me correctly.

[net]
# Testing
# batch=1
# subdivisions=1
# Training
batch=64
subdivisions=16
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1

I am really curious and confused what is the problem in these two configurations files while the three conversion scripts are similar.

@Frank @numbqq
Please guide, thanks for you time!

Regards,
Sajjad

@enggsajjad I think you should learn the meaning and usage of each parameter of the darknet framework. I have given you all the information I can provide.

1 Like

Sure, the basic question is that while setting width=608, height=608 in the cfg file means I should use a 608x608 images in validation and detection. That is the only difference. I don’t see any other difference in the parameteres while using (width=416, height=416) and (width=608, height=608) except the usage of respective dimensions in validation and in detection, and all other params should remain the same.
Nevertheless, thanks for the help. I will try, if I am still missing something.

@enggsajjad It is not recommended to use a size of 608, and your weights are fixed. If you modify the image size, you must retrain the model

1 Like

After debugging, I found that for 608 we have to change 416 to 608 at the following lines from main.cpp in sample_demo_x11:

	Line 125: 	amlge2d.ge2dinfo.dst_info.canvas_w = 416;
	Line 126: 	amlge2d.ge2dinfo.dst_info.canvas_h = 416;

to

	Line 125: 	amlge2d.ge2dinfo.dst_info.canvas_w = 608;
	Line 126: 	amlge2d.ge2dinfo.dst_info.canvas_h = 608;

And it works perfect. The results are also correct.

khadas@Khadas:~/hussain/sample_demo_x11_yolov3_608/bin_r_cv4$ ./detect_demo_x11 -m 2 -p ~/hussain/img/1920x1056/person_1920x1056.jpg
det_set_log_config Debug
det_set_model success!!

model.width:608
model.height:608
model.channel:3

Det_set_input START
Det_set_input END
Det_get_result START
Det_get_result END

resultData.detect_num=3
result type is 2
i:3 left:576.057 right:808.759 top:224.556 bottom:969.128
i:3 left:1189.88 right:1822.43 top:317.091 bottom:896.963
i:3 left:228.718 right:595.034 top:657.77 bottom:863.045
khadas@Khadas:~/hussain/sample_demo_x11_yolov3_608/bin_r_cv4$

output.bmp