Use Cropper Tool To Reduce Library File Size
Linux
Environment Preparation
Static Library Cropping
Intermediate
Expert
Overview
MindSpore Lite provides the libmindspore-lite.a
static library cropping tool for runtime, which can filter out the operators in the ms
model, crop the static library files, and effectively reduce the size of the library files.
The operating environment of the library cutting tool is x86_64, and currently supports the cropping of CPU operators, the compilation command is bash build.sh -I arm64 -e cpu
, bash build.sh -I arm32 -e cpu
, and bash build.sh -I x86_64 -e cpu
.
Environment Preparation
To use the Cropper tool, you need to prepare the environment as follows:
Compilation: The code of the Cropper tool is stored in the
mindspore/lite/tools/cropper
directory of the MindSpore source code. For details about the build operations, see the Environment Requirements and Compilation Example in the build document to compile version x86_64.Run: Obtain the
cropper
tool and configure environment variables. For details, see Output Description in the build document.
Parameter Description
The command used for crop the static library based on Cropper is as follows:
./cropper [--packageFile=<PACKAGEFILE>] [--configFile=<CONFIGFILE>]
[--modelFile=<MODELFILE>] [--modelFolderPath=<MODELFOLDERPATH>]
[--outputFile=<MODELFILE>] [--help]
The following describes the parameters in detail.
Parameter |
Attribute |
Function |
Parameter Type |
Default Value |
Value Range |
---|---|---|---|---|---|
|
Mandatory |
The path of the |
String |
- |
- |
|
Mandatory |
The path of the configuration file of the cropper tool. The file path of |
String |
- |
- |
|
Optional |
The model folder path, according to all the |
String |
- |
- |
|
Optional |
The model file path is cut according to the specified |
String |
- |
- |
|
Optional |
The saved path of the cut library |
String |
- |
- |
|
Optional |
Displays the help information about the |
- |
- |
- |
The configuration file
cropper_mapping_cpu.cfg
exists in thecropper
directory in themindspore-lite-{version}-inference-linux-x64
package.
Example
The Cropper tool obtains the operator list by parsing the ms
model, and crop the libmindspore-lite.a
static library according to the mapping relationship in the configuration file configFile
.
Pass in the
ms
model through the folder, and pass the folder path where the model file is located to themodelFolderPath
parameter to crop thelibmindspore-lite.a
static library of arm64-cpu.
./cropper --packageFile=/mindspore-lite-{version}-inference-android-aarch64/lib/libmindspore-lite.a --configFile=./cropper_mapping_cpu.cfg --modelFolderPath=/model --outputFile=/mindspore-lite/lib/libmindspore-lite.a
This example will read all the ms
models contained in the /model
folder, crop the libmindspore-lite.a
static library of arm64-cpu, and the cropped libmindspore-lite.a
static library will be saved to /mindspore-lite/lib/
directory.
Pass in the
ms
model by file, pass the path where the model file is located to themodelFile
parameter, and crop thelibmindspore-lite.a
static library of arm64-cpu.
./cropper --packageFile=/mindspore-lite-{version}-inference-android-aarch64/lib/libmindspore-lite.a --configFile=./cropper_mapping_cpu.cfg --modelFile=/model/lenet.ms,/model/retinaface.ms --outputFile=/mindspore-lite/lib/libmindspore-lite.a
In this example, the libmindspore-lite.a
static library of arm64-cpu will be cropped according to the ms
model passed by modelFile
, and the cropped libmindspore-lite.a
static library will be saved to /mindspore-lite/lib/
directory.