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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
3,376 次查看
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 项奖励
1 解答
3,239 次查看
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.

在原帖中查看解决方案

2 回复数
3,179 次查看
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 项奖励
3,240 次查看
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.