MobileNetV2 offline conversion

Hi all,

I am currently using Tensorflow v2.14.1 and Keras to train my model with MobileNetV2 as the base model. The model is as shown:

`_________________________________________________________________
Layer (type)                Output Shape              Param #

lambda_3 (Lambda)           (None, 224, 224, 3)       0

mobilenetv2_0.35_224 (Func  (None, 7, 7, 1280)        410208
tional)

global_average_pooling2d_1  (None, 1280)              0
2 (GlobalAveragePooling2D)

dropout_12 (Dropout)        (None, 1280)              0

dense_12 (Dense)            (None, 3)                 3843

=================================================================
Total params: 414051 (1.58 MB)
Trainable params: 3843 (15.01 KB)
Non-trainable params: 410208 (1.56 MB)
_________________________________________________________________`

After training, I have encountered issues importing the .h5 output using the pegasus_import script with the following line:

I Try match mobilenetv2_0.35_224
W Unsupport layer type Functional need add
I Try match rescaling
W Unsupport layer type Rescaling need add.

The issue is solved by converting the .h5 Keras model to .tflite and the import succeeds but with the following warning:

I Start importing tflite…
W Unsupport attribute fold_const_inputs

Since there is a warning, I would like to ask whether this is the proper way to import a model with MobileNetV2 as the base model.

Other than that, I would like to ask what do the fields in the xxx_inputmeta.yml mean and what should I configure since I see there are different configurations for different model types. The link for the guide to change the fields according to the imported model is also missing ( NN Model Conversion Steps using Acuity Toolkit on Docker — AmebaPro2's Documentation v0.1 documentation )

Once import is successful, kindly refer to this page to modify the inputmeta.yml according to the type of imported model.

Therefore, do I need to change the scale if I already have a lambda layer to scale pixel values between -1 and 1?

Finally, I see that there is a cropping option in the xxx_inputmeta.yml and a ROI option (void NNImageClassification::configRegionOfInterest(int xmin, int xmax, int ymin, int ymax)) in the ArduinoSDK. Which one should I use to first center crop 640 x 640 and then resize to 224 x 224?

I’m quite new to all of this so thanks for all the help in advance!

Hi @PingTKP ,

Thank you for your question. Currently the SDK only supports PyTorch trained MobileNetV2 as the input image will be normalized according to the preset mean and std. Apologize for the inconvenience caused. Kindly follow the input settings below for MobileNetV2, you might not need to change the scale as it will be handled in the preprocess function.

Regarding the image crop, kindly re-configure the video_v4 ROI Xmin, Ymin, Xmax, Ymax in line 217-221 of video_drv.c, with (xmin,ymin) correspond to the top left corner and (xmax,ymax) to the bottom right corner.

Thank you.

Alright, after changing to PyTorch and using the modified changes in the xxx_inputmeta.yml. The model now works correctly in the board now.

Thanks for the help!