Files
FastDeploy/tutorials/encrypt_model

English | 中文

FastDeploy generates an encrypted model

This directory provides encrypt.py to quickly complete the encryption of the model and parameter files of ResNet50_vd

encryption

# Download deployment example code 
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd  FastDeploy/tutorials/encrypt_model

# Download the ResNet50_vd model file
wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz
tar -xvf ResNet50_vd_infer.tgz

python encrypt.py --model ResNet50_vd_infer

Note

After the encryption is completed, the ResNet50_vd_infer_encrypt folder will be generated, including __model__.encrypted, __params__.encrypted, encryption_key.txt three files, where encryption_key.txt contains the encrypted key. At the same time, you need to copy the inference_cls.yaml configuration file in the original folder to the ResNet50_vd_infer_encrypt folder for subsequent deployment

Python encryption interface

Use the encrypted interface through the following interface settings

import fastdeploy as fd
import os
# when key is not given, key will be automatically generated.
# otherwise, the file will be encrypted by specific key
encrypted_model, key = fd.encryption.encrypt(model_file.read())
encrypted_params, key= fd.encryption.encrypt(params_file.read(), key)

FastDeploy deployment encryption model (decryption)

Through the setting of the following interface, FastDeploy can deploy the encryption model

import fastdeploy as fd
option = fd.RuntimeOption()
option.set_encryption_key(key)
fastdeploy::RuntimeOption option;
option.SetEncryptionKey(key)

Note

For more details about RuntimeOption, please refer to RuntimeOption Python Documentation, RuntimeOption C++ Documentation