MEAN and STD values in TensorFlow Lite Micro for i.MXRT tutorial

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MEAN and STD values in TensorFlow Lite Micro for i.MXRT tutorial

Jump to solution
2,676 Views
MarcinChelminsk
Contributor IV

Hello!

question in regards to Getting Started with TensorFlow Lite for Microcontrollers on i.MX RT

there are two defines in section 4.1 (with camera version)

 

 

#define MODEL_INPUT_MEAN 127.5f
#define MODEL_INPUT_STD 127.5f

 

 

 however when you run flower_lab.py  (with small changes highlighted with "CHANGE", they aim to check what are mean/std values)

 

 

#Retrain model on new images
mobilenetv1_spec = model_spec.ImageModelSpec(uri='https://tfhub.dev/google/imagenet/mobilenet_v1_025_128/feature_vector/4')
print("MEAN", mobilenetv1_spec.mean_rgb) #CHANGE
print("STD", mobilenetv1_spec.stddev_rgb) #CHANGE 
mobilenetv1_spec.input_image_shape = [128, 128]
model = image_classifier.create(train_data, model_spec=mobilenetv1_spec, validation_data=validation_data)
model.summary()

 

 

 it prints out that during retraining the values took into account are:

 

 

MEAN [0.0]
STD [255.0]

 

 

Therefore, when I changed in MCUXpresso following defines to

 

 

#define MODEL_INPUT_MEAN 0.0f
#define MODEL_INPUT_STD 255.0f

 

 

results of inferencing are better, in my subjective opinion, it means model is more confident that sunflower or for example does not mixing dandelion with sunflower (when looking at dandelion)

What you think?

0 Kudos
1 Solution
2,539 Views
david_piskula
NXP Employee
NXP Employee

Hi @MarcinChelminsk, thanks for noticing this. The MEAN and STD used during training must equal the MEAN and STD used during inference. We'll need to fix the typo in the lab.

View solution in original post

2 Replies
2,479 Views
MarcinChelminsk
Contributor IV

@david_piskula, thanks for feedback! I see that Getting Started with TensorFlow Lite for Microcontrollers on i.MX RT has been updated already, great!

0 Kudos
2,540 Views
david_piskula
NXP Employee
NXP Employee

Hi @MarcinChelminsk, thanks for noticing this. The MEAN and STD used during training must equal the MEAN and STD used during inference. We'll need to fix the typo in the lab.