If you need to do this process in the sample folder, you need to execute the 00_init.sh script in the folder first to get the corresponding original model and dataset.
When performing model calibration, 20~100 samples are required at the calibration stage, each is an independent data file. To ensure the accuracy of the calibrated models, these calibration samples better come from the training or validation dataset when training the models. In addition, please try NOT to use rare samples, e.g. single colored images or those images who don't contain any detection or classification targets in them.
You need to preprocess the samples from the training/verification sets (the preprocessing process is the same as the original floating-point model data preprocessing process),
and the calibrated samples after processing will have the same data type (input_type_train), size (input_shape) and layout (input_layout _train) with the original floating-point model.
You can save the data as an npy file with the numpy.save command, and the toolchain will read it based on the numpy.load command when it is calibrated.
For example, there is an ImageNet trained original classification floating-point model with only one input node, it should be described as below:
BGR.NCHW.1x3x224x224.The steps for data preprocessing of the original floating point model are as follows:
Uniformly scale the image and resize the shorter side to 256.
Get 224x224 image using the center_crop method.
Align the input layout to the NCHW required by the model.
Convert the color space to the BGR required by the model.
Adjust the range of image values to [0, 255] as required by the model.
Subtract mean value by the channel.
Data multiple by the scale factor.
The sample processing code for the above example model is as follows (to avoid excessive code length, some simple transformer implementation codes are ignored, the usage of transformer can be found in Image Processing).
Note that the input_shape parameter in the yaml file serves to specify the input data size of the original floating-point model. If it is a dynamic input model, you can use this parameter to set the converted input size, and the shape size of the calibration data should be consistent with input_shape.
For example, if the original floating-point model input node shape is ?x3x224x224 ("?" sign represents the placeholder, i.e., the first dimension of the model is dynamic input), and the input_shape: 8x3x224x224 is set in the conversion profile, then the size of each calibration data that you need to prepare is 8x3x224x224 (Please be aware that the input_batch parameter does not support modifying the model batch information for models with the first dimension of the input shape not equal to 1).