Model Obfuscation Tool
Overview
MindSpore Lite provides a lightweight offline model obfuscator to protect the confidentiality of model files deployed on the IoT devices. This tool obfuscates the network structure and operator type of the ms
model, making the computation logic of the model difficult to understand after the obfuscation. The model generated by the obfuscator is still in ms
format. You can directly perform inference through the runtime inference framework. (The MSLITE_ENABLE_MODEL_OBF
option in mindspore/mindspore/lite/CMakeLists.txt
must be enabled during build.) Obfuscation slightly increases the model loading latency, but does not affect the inference performance.
Usage in the Linux Environment
Environment Preparation
To use the MindSpore Lite model obfuscator, you need to prepare the environment as follows:
Build the x86_64 version by referring to Environment Requirements and Compilation Example.
Directory Structure
mindspore-lite-{version}-linux-x64
└── tools
└── obfuscator # Model obfuscator
└── msobfuscator # Executable program
Parameter Description
The MindSpore Lite model obfuscator provides multiple parameter settings. You can use them as required. In addition, you can enter ./msobfuscator --help
to obtain the help information in real time.
The following describes the parameters in detail.
Parameter |
Mandatory or Not |
Parameter Description |
Value Range |
Default Value |
---|---|---|---|---|
|
No |
Displays all help information. |
- |
- |
|
Yes |
Enters the path of the MindSpore Lite model. |
- |
- |
|
Yes |
Specifies the path of the output model. You do not need to add a suffix because the suffix |
- |
- |
|
No |
Sets the obfuscation degree of the model. A larger value indicates that more nodes and edges are added to the model. |
(0,1] |
0.2 |
The
.ms
model can be input.The parameter name and value are separated by an equal sign (=) and no space is allowed between them.
Model obfuscation increases the model scale. A larger value of obfDegree indicates a larger model scale.
The following examples describe how to use the obfuscation command.
Examples
Set the log display level to INFO.
set GLOG_v=1
Log levels: 0 indicates DEBUG, 1 indicates INFO, 2 indicates WARNING, and 3 indicates ERROR.
The following uses the MindSpore Lite model LeNet as an example to describe how to run the obfuscation command.
./msobfuscator --modelFile=lenet.ms --outputFile=lenet_obf --obfDegree=0.5
The command output is as follows:
OBFUSCATE MODEL lenet.ms SUCCESS!
This indicates that the MindSpore Lite model has been successfully obfuscated and the new file
lenet_obf.ms
is obtained.