Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6574 Discussions

creation of stat.txt for my own network

idata
Employee
1,599 Views

I am interested in running stream_infer after training with some new images. In the readme for stream_infer it states that more information can be found for creating the stat.txt file in Movidus Neural Compute Toolkit User's Manual. I cannot find any more information on this. I have figured out that the first set of data is just the mean of all the RGB values of the training data. The second set of 3 values are supposed to be some form of standard deviation for the network. I have not been able to figure out how these values are derived, especially since all three are the same for the stat.txt that comes with the example networks:

 

0.40787054 0.45752458 0.48109378 (means for RGB values of the input data)

 

0.00392157 0.00392157 0.00392157 (std dev?)

 

Thanks to anyone that can help out with this

0 Kudos
6 Replies
idata
Employee
1,361 Views

@nlannan You are correct. These values are the average RGB values and std dev for the training set of images used for the network.

0 Kudos
idata
Employee
1,361 Views

The weird thing is I did not get 0.00392157 as the standard deviation when I calculated it for the training set: ilsvrc12

 

the three std deviation values are all the same in the stat.txt file included with the example nets:

 

0.00392157 0.00392157 0.00392157

 

when I calculated the mean and std dev on the numpy gathered by using convert_mean.py on imagenet_mean.binaryproto I got the same mean values but not the same standard deviation values:

 

means: 0.40787054 0.45752458 0.48109378

 

std devs: 0.0264842429796 0.0213271232094 0.0142675012063

 

to get the standard deviations I hacked convert_mean.py and used:

 

np.std(out[0]/255)

 

np.std(out[1]/255)

 

np.std(out[2]/255)

 

am I doing something wrong to calculate it?

0 Kudos
idata
Employee
1,361 Views

@nlannan Some Neural Networks utilize normalization and this could explain why dividing by 255 gets you the right values.

0 Kudos
idata
Employee
1,361 Views

The mean values 0.40787054 0.45752458 0.48109378 and std deviation values 0.00392157 0.00392157 0.00392157 appear to be the same in all networks.

 

Note that 0.00392157 = 1/255.

 

Also 255*[0.40787054 0.45752458 0.48109378] gets us to [104 117 123] which match the mean values in BVLC/GoogleNet and SqueezeNet prototxt files.

 

This is then used in the API (c_examples/ncs-fullcheck.c) as follows

 

for(i = 0; i < 3; i++) { mean[i] = 255.0 * mean[i]; std[i] = 1.0 / (255.0 * std[i]); }

 

and then

 

imgfp32[3*i] = (imgfp32[3*i]-mean[0])*std[0]; imgfp32[3*i+1] = (imgfp32[3*i]-mean[1])*std[1]; imgfp32[3*i+2] = (imgfp32[3*i]-mean[2])*std[2];

 

so essentially, std deviation is not being used, as it leads to a multiply by 1 when it is used to transform the image data. Also, image data range of 0-255 is being assumed (quite reasonably, as this is the most common use case).

 

It looks like std dev has been included for future proofing (in cases where the image data does not range from 0-255, this may be useful, but it will require a change to the API examples and adding a third line for range of input values in stats.txt).

0 Kudos
idata
Employee
1,361 Views

@pashmina.bendale You are correct in regards to the std_dev not being factored into ncs-fullcheck.c. Thank you for clarification :smile:.

0 Kudos
idata
Employee
1,361 Views

That makes sense now. Thank you very much to you both.

0 Kudos
Reply