KSNN work with single-channel images

Hello I’m working with Vim3 Pro and I thought about one interesting thing, my dataset is consists of one-channel images. So is there a way to push KSNN this kind of images? It will be much faster + I wouldnt have to add 2 extra channels to my one channel images.

Thank you

Hello @Agent_kapo ,

Yes, KSNN support single-channel.

When you convert single-channel input model, the second and third parameter of mean-values should be 0, like ‘127 0 0 0.0078125’.

Inferring on VIM3 is the same.

the inference looks like this:

data = self.yolov3.nn_inference(cv_img, platform='ONNX', reorder='2 1 0', output_tensor=3, output_format=output_format.OUT_FORMAT_FLOAT32)

                input0_data = data[2]
                input1_data = data[1]
                input2_data = data[0]

                input0_data = input0_data.reshape(SPAN, LISTSIZE, GRID0, GRID0)
                input1_data = input1_data.reshape(SPAN, LISTSIZE, GRID1, GRID1)
                input2_data = input2_data.reshape(SPAN, LISTSIZE, GRID2, GRID2)
                
                input_data = list()
                input_data.append(np.transpose(input0_data, (2, 3, 0, 1)).astype(np.float32))
                input_data.append(np.transpose(input1_data, (2, 3, 0, 1)).astype(np.float32))
                input_data.append(np.transpose(input2_data, (2, 3, 0, 1)).astype(np.float32))

so where i have specify that it’s a single channel image?
Thank you)

Hello @Agent_kapo ,

Remember to add single-channel image instead of three-channel in cv
_img. Other is the same.

1 Like

So when I convert a model for a single channel images, I can use default parametrs from your example - 0,0,0,0…
Correct?

Hello @Agent_kapo ,

Like this.

./convert \
--model-name yolov8n \
--platform onnx \
--model ./yolov8n.onnx \
--mean-values 'means 0 0 scale' \
--quantized-dtype asymmetric_affine \
--source-files ./data/dataset/dataset0.txt \
--kboard VIM3 \
--print-level 0

If single-channel YOLOv8 model.

./convert \
--model-name yolov8n \
--platform onnx \
--model ./yolov8n.onnx \
--mean-values '0 0 0 0.00392156' \
--quantized-dtype asymmetric_affine \
--source-files ./data/dataset/dataset0.txt \
--kboard VIM3 \
--print-level 0
1 Like