ML-examples icon indicating copy to clipboard operation
ML-examples copied to clipboard

Image Data pre-processing.

Open mansiag05 opened this issue 6 years ago • 2 comments

Hi, I would like to know what is the expected way to pre-process the image data before sending it to the conv1 layer for processing?

  1. Is it simple mean subtraction like: for (int i=0;i<32323; i+=3) { img_buffer2[i] = (q7_t)((int)image_data[i] - mean_data[0]); img_buffer2[i+1] = (q7_t)((int)image_data[i+1] - mean_data[1]); img_buffer2[i+2] = (q7_t)((int)image_data[i+2] - mean_data[2]); }

  2. Or As given in https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/NN/Examples/IAR/iar_nn_examples/NN-example-cifar10/arm_nnexamples_cifar10.cpp for (int i=0;i<32323; i+=3) { img_buffer2[i] = (q7_t)__SSAT( ((((int)image_data[i] - mean_data[0])<<7) + (0x1<<(scale_data[0]-1))) >> scale_data[0], 8); img_buffer2[i+1] = (q7_t)__SSAT( ((((int)image_data[i+1] - mean_data[1])<<7) + (0x1<<(scale_data[1]-1))) >> scale_data[1], 8); img_buffer2[i+2] = (q7_t)__SSAT( ((((int)image_data[i+2] - mean_data[2])<<7) + (0x1<<(scale_data[2]-1))) >> scale_data[2], 8); }

mansiag05 avatar Nov 21 '18 11:11 mansiag05

@mansiag05, It would be simple mean subtraction (i.e. 1). If you use mean.binaryproto (e.g. here), that would be pixel-wise subtraction (i.e. image_data[i]-mean_data[i]). If you use channel-wise mean transform (e.g. here, then you can do image_data[i]-mean_data[0].

navsuda avatar Nov 29 '18 06:11 navsuda

Thank you for your response @navsuda

The doubt that I have now is, if we quantize the given caffe model cifar10_m7_train_test.prototxt using the given script nn_quantizer, the output says that the input will be of the form

Input: data Q8.-1(scaling factor:0.5)

According to this line, would it not be required to do mean subtraction (i.e. image_data[i] - mean_data[i]) * power(2,-1),

to make the input of the form Q(8,-1) rather than the original Q(7,0)?

mansiag05 avatar Nov 30 '18 11:11 mansiag05