Model encryption method and device, storage medium and electronic equipment

By using the preset encryption algorithm and hook checker to encrypt the model files and encrypt the project code when deploying the deep learning model, the problems of high encryption difficulty and low security in the existing technology are solved, and the model files and sources are The double protection of the code ensures the security of the model.

CN118586018AInactive Publication Date: 2024-09-03WUHAN AI RES +1
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411064800.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-09-03
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the existing technology, the encryption of deep learning models is difficult and the security is not high. The underlying code needs to be modified and the project source code is not encrypted, which makes it easy to be cracked.

Method used

Use the preset encryption algorithm to encrypt the deep learning model file, and set up a hook-based checker in the project code. Choose whether to decrypt based on the file type. Use tools to encrypt the project code to avoid changes to the underlying library and improve security. .

Benefits of technology

It reduces the difficulty of encryption and improves the security of model files. Through file type judgment and decryption processing, it ensures the security of model files when reading, and further improves security through source code encryption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118586018A
    Figure CN118586018A
Patent Text Reader

Abstract

The invention discloses a model encryption method and device, a storage medium and electronic equipment, and the method comprises the steps: encrypting a model file of a target deep learning model through employing an encryption key of a preset encryption algorithm when the target deep learning model is deployed; and setting a hook-based inspection program in the project code for deploying the target deep learning model, and then encrypting a source code of the project code for setting the hook-based inspection program by using a preset tool. Through the method, the model encryption difficulty can be reduced, and the model security can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a model encryption method, device, storage medium and electronic device. Background Art

[0002] With the development of deep learning technology, various types of deep learning models have emerged, and the models are being used more and more widely in various industries. The deployment of deep learning models includes local deployment and non-local deployment. For non-local deployment, in order to obtain the results of model inference, users need to upload data to the model supplier first, which will lead to the risk of data leakage. For local deployment, since the model needs to be deployed on the user's device, how to deploy the deep learning model to ensure that the model file is not stolen is currently a difficult problem.

[0003] In the prior art, there is a solution that uses a model encryption method to ensure that the model file is not stolen. The solution is based on the python encryption library and uses the AES symmetric encryption algorithm to encrypt the pytorch model file.

[0004] During the model startup phase, the program reads the encrypted model file from the disk, decrypts it into the memory, and finally loads the model from the memory. However, this encryption method requires the transformation of the underlying code for model loading in the project. These underlying codes are part of the popular Python model deployment library (such as transformers, vllm). R&D personnel are not familiar with the code of the deployment library, which greatly increases the difficulty of transformation. On the other hand, the existing technology does not encrypt the project source code, making it easy to crack.

[0005] It can be seen from this that the existing technology has technical problems such as high encryption difficulty and low security. Summary of the invention

[0006] In view of the technical problems of high encryption difficulty and low security in the prior art, the present invention proposes a model encryption method, device, storage medium and electronic device.

[0007] The technical solution adopted by the present invention is as follows: A first aspect provides a model encryption method, comprising: When deploying the target deep learning model, encrypting the model file of the target deep learning model using an encryption key of a preset encryption algorithm; Setting a hook-based checker in the project code for deploying the target deep learning model, wherein the hook-based checker is triggered before a file reading operation is involved, and is used to select whether to decrypt the file and read the model file according to the type of the file to be read; Use the preset tool to encrypt the source code of the project code that sets up the hook-based checker.

[0008] In one embodiment, encrypting the model file of the target deep learning model using an encryption key of a preset encryption algorithm includes: Determine whether the size of the model file of the target deep learning model is greater than a preset value. If so, encrypt the model file of the target deep learning model in blocks using an encryption key of a preset encryption algorithm.

[0009] In one embodiment, the model file includes a data type model file and a code type model file, and a hook-based checker is set in the project code for deploying the target deep learning model, including: Designing a first program module for reading a data type model file in a project code for the target deep learning model; A second program module for loading a code type model file is designed in the project code for deploying the target deep learning model, and the first program module and the second program module constitute the hook-based inspection program.

[0010] In one embodiment, a first program module for reading a data type model file is designed in a project code for the target deep learning model, including: Back up Python's built-in disk file reading function; A custom disk file reading function, wherein the custom disk file reading function is used to determine whether the type of the file to be read is a model file, decrypt the encrypted model file using a decryption key of a preset encryption algorithm when the file to be read is a model file, and jump to the disk file reading function built into Python when the file to be read is not a model file; Replace Python's built-in disk read function with a custom disk read function.

[0011] In one embodiment, a second program module for loading a code type model file is designed in the project code for deploying the target deep learning model, including: Back up the built-in module search class in Python; A custom module loading class, wherein the custom module loading class is used to read the encrypted code type model file, and decrypt the encrypted code type model file before loading it; A custom module search class, wherein the custom module search class is used to determine whether the type of the file to be read is a model file, and when the file to be read is a model file, specify to use the custom module loading class to load the model file; Replace the built-in module search class in Python with the custom module loading class.

[0012] Based on the same inventive concept, the second aspect of the present invention provides a model decryption method, comprising: In the process of starting the target deep learning model, when the model file needs to be read, the hook-based inspection program is executed, and the encrypted model file is decrypted by the hook-based inspection program using a decryption key of a preset encryption algorithm to obtain the decrypted model file.

[0013] Based on the same inventive concept, the third aspect of the present invention provides a model encryption device, comprising: A model file encryption module, used to encrypt the model file of the target deep learning model using an encryption key of a preset encryption algorithm when deploying the target deep learning model; A hook-based checker setting module, used to set a hook-based checker in the project code for deploying the target deep learning model, wherein the hook-based checker is triggered before a file reading operation is involved, and is used to select whether to decrypt the file and read the model file according to the type of the file to be read; The project code encryption module is used to encrypt the source code of the project code for setting the hook-based checker using a preset tool.

[0014] Based on the same inventive concept, the fourth aspect of the present invention provides a model decryption device, comprising: The decryption module is used to decrypt the encrypted model file by executing a hook-based check program when the model file needs to be read during the process of starting the target deep learning model, using the decryption key of the preset encryption algorithm to obtain the decrypted model file.

[0015] Based on the same inventive concept, the fifth aspect of the present invention provides a model encryption and decryption system, including the model encryption device described in the third aspect and the model decryption device described in the fourth aspect.

[0016] Based on the same inventive concept, the sixth aspect of the present invention provides a non-volatile storage medium, which stores multiple instructions, and the instructions are suitable for being loaded by a processor and executing the model encryption method described in the first aspect, or executing the model decryption method described in the second aspect.

[0017] Based on the same inventive concept, the seventh aspect of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the model encryption method described in the first aspect, or to execute the model decryption method of the second aspect.

[0018] Compared with the prior art, the advantages and beneficial technical effects of the present invention are as follows: In an embodiment of the present invention, when the target deep learning model is deployed, the model file of the target deep learning model is encrypted using an encryption key of a preset encryption algorithm, so that the model file is in an encrypted state and is not easy to obtain, and a hook-based checker is set in the project code used to deploy the target deep learning model. The hook-based checker can be implemented by only making a small modification to the project code for deploying the target deep learning model. There is no need to change the underlying library used for model loading, thereby avoiding intrusion into the underlying library of the model and reducing the difficulty of implementing encryption. In addition, the hook-based checker can determine the file type and perform corresponding decryption processing before reading the file, thereby ensuring the security of model file reading. Furthermore, the present invention also uses a preset tool to encrypt the source code of the project code for setting the hook-based checker, which can further improve the security of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 A flow chart of a model encryption method provided by an embodiment of the present invention; Figure 2 A schematic diagram of the structure of a model encryption device provided by an embodiment of the present invention; Figure 3 A schematic diagram of the structure of a model encryption and decryption system provided by an embodiment of the present invention; Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0022] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0023] The prior art discloses a method for encrypting a pytorch model. The inventor of the present application has found through extensive research and practice that the prior art mainly has the following two problems: First, the existing technology requires the transformation of the underlying code for model loading in the project. However, there are some practical Python model deployment libraries (such as transformers and vllm) on the market today. Using these libraries to deploy models can not only improve the model's reasoning performance, but also simplify deployment. R&D personnel are not familiar with the code of the model deployment library, and it is difficult and complex to encrypt and transform the underlying model code. This is mainly because the underlying model deployment library takes over the loading of the model, and R&D personnel cannot directly customize the model loading process, making encryption transformation difficult.

[0024] Second, the source code (project code) is not encrypted. The existing technology does not encrypt the project source code, and professionals can easily crack the model by reading the source code. This is mainly because the Python project is an interpreted language and will not be directly compiled into machine code. The project source code can be directly executed on the target machine. If it is not encrypted, the project source code is easy to leak.

[0025] Embodiment 1 Based on the above technical problems, an embodiment of the present invention provides an embodiment of a model encryption method. The steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0026] Figure 1 is a flow chart of a model encryption method according to an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps: S101: When deploying a target deep learning model, encrypt a model file of the target deep learning model using an encryption key of a preset encryption algorithm; S102: Setting a hook-based checker in the project code for deploying the target deep learning model, wherein the hook-based checker is triggered before a file reading operation is involved, and is used to select whether to decrypt the file and read the model file according to the type of the file to be read; S103: Encrypt the source code of the project code for setting the hook-based inspection program using a preset tool.

[0027] First, the professional terms involved in the present invention are explained as follows: Hook: A checkpoint pre-set in the program execution process, used to perform specific processing. In the present invention, the automatic decryption of the model file is achieved by setting a hook during the model file loading process.

[0028] AES: Advanced Encryption Standard, a widely used symmetric encryption algorithm. In the present invention, the AES algorithm can be used to encrypt the model file.

[0029] Pytorch: An open source machine learning framework for developing deep learning models.

[0030] Transformers: A popular model deployment library that simplifies the deployment process of deep learning models.

[0031] Nuitka: A tool that compiles Python source code into binaries, thus protecting the source code.

[0032] Hook SDK: A software development kit that includes a custom open function, importlib's loader, and metapathfinder, etc., used to implement transparent encryption of model files and source code.

[0033] MetaPathFinder: A class used to find modules in Python. By customizing MetaPathFinder, you can implement custom processing when importing modules.

[0034] Loader: A class in Python used to load modules. By customizing Loader, you can implement custom processing when loading modules.

[0035] The above solution of the present invention mainly includes two main processes: model file encryption (S101, S102) and project source code encryption (S103).

[0036] Specifically, the preset encryption algorithms in S101 come from two Python encryption libraries: cryptography and pycryptodome, which can be symmetric encryption algorithms, asymmetric encryption algorithms, or other encryption algorithms. When encrypting model files, you can directly use the algorithms in the above two libraries for encryption. The target deep learning model is a Python-based model, such as a pytorch model, a Transformer model, etc.

[0037] In the startup phase of the model, files are usually read, including model files or other model files. S102 can perform specific processing before reading files by setting a hook-based checker. These specific processing can ensure the security of model files. Specific processing includes selecting whether to decrypt files and reading decrypted files according to the type of files to be read. Specifically, if it is reading other types of files, no decryption is performed and the files are read directly. If it is reading a model file, the encrypted model file is obtained and then decrypted before reading.

[0038] In S103, you can use Python's nuitka tool to encrypt the project source code. Nuitka can compile Python projects into binary bin or so format files, thereby effectively protecting the model provider's project source code.

[0039] In one embodiment, encrypting the model file of the target deep learning model using an encryption key of a preset encryption algorithm includes: Determine whether the size of the model file of the target deep learning model is greater than a preset value. If so, encrypt the model file of the target deep learning model in blocks using an encryption key of a preset encryption algorithm.

[0040] Specifically, the preset value can be set according to the actual situation, for example, it is set to 5GB. For larger model files, larger than 5GB, block encryption is used to avoid memory overflow errors caused by encrypting and decrypting the entire file in memory at one time.

[0041] In one embodiment, the model file includes a data type model file and a code type model file, and a hook-based checker is set in the project code for deploying the target deep learning model, including: Designing a first program module for reading a data type model file in a project code for the target deep learning model; A second program module for loading a code type model file is designed in the project code for deploying the target deep learning model, and the first program module and the second program module constitute the hook-based inspection program.

[0042] In actual application, different types of model files are included, that is, the model file can be regarded as a folder containing a group of files. It mainly includes data type model files and code type model files. The py model file belongs to the code type model file, which describes the network structure of the model. In addition to the py model file, the model file also contains parameter files (.bin suffix), configuration files (.json suffix) and other data type model files. For different types of model files, different program models are designed to facilitate the reading or loading of model files in the subsequent model loading process.

[0043] In one embodiment, a first program module for reading a data type model file is designed in a project code for the target deep learning model, including: Back up Python's built-in disk file reading function; A custom disk file reading function, wherein the custom disk file reading function is used to determine whether the type of the file to be read is a model file, decrypt the encrypted model file using a decryption key of a preset encryption algorithm when the file to be read is a model file, and jump to the disk file reading function built into Python when the file to be read is not a model file; Replace Python's built-in disk read function with a custom disk read function.

[0044] Specifically, the inventor of the present application has found through extensive research and practice that no matter what method the underlying library uses to load the model, it ultimately cannot circumvent the use of Python's open function to read the disk file. Therefore, this embodiment sets a hook point (hook-based checker) for the open function.

[0045] In specific implementation, you can introduce the hook SDK and configure the functions or classes in the hook SDK to implement the setting of the hook-based inspection program. The built-in disk file reading function of Python is the open function.

[0046] When determining the type of a file to be read, the path of the file may be used for determination, because model files are generally stored in a specific directory.

[0047] When the file to be read is a model file, the encrypted model file is decrypted using the decryption key of the preset encryption algorithm in the cryptography library.

[0048] In one embodiment, a second program module for loading a code type model file is designed in the project code for deploying the target deep learning model, including: Back up the built-in module search class in Python; A custom module loading class, wherein the custom module loading class is used to read the encrypted code type model file, and decrypt the encrypted code type model file before loading it; A custom module search class, wherein the custom module search class is used to determine whether the type of the file to be read is a model file, and when the file to be read is a model file, specify to use the custom module loading class to load the model file; Replace the built-in module search class in Python with the custom module loading class.

[0049] Specifically, when using the Transfomers library of HuggingFace to customize the model, the corresponding py model file will be defined in the model directory, so the py model file (code model file) also needs to be encrypted. The Transfomers library dynamically loads the py model file through importlib, so this implementation sets a hook point for the importlib library.

[0050] In the specific implementation, the built-in module search class in Python is the MetaPathFinder class, the custom module loading class is the Loader class of the custom importlib library, and the custom module search class is the MetaPathFinder class of the custom importlib library.

[0051] In this implementation, hook open and hook importlib belong to the scheme of setting the hook point to Python. The hook open scheme is more low-level and has the best versatility, because the framework's model reading function also reads the model through the Python language open function. In other implementations, the hook point can also be set to the framework's model reading function, such as torch.load.

[0052] Since most model frameworks are also in Python, the model reading by these frameworks will also be intercepted by the hook open set by this solution. The method implemented in this solution can be extended to other models.

[0053] Embodiment 2 Based on the same inventive concept, this embodiment discloses a model decryption method, which includes: In the process of starting the target deep learning model, when the model file needs to be read, the hook-based inspection program is executed, and the encrypted model file is decrypted by the hook-based inspection program using a decryption key of a preset encryption algorithm to obtain the decrypted model file.

[0054] In the specific implementation process, if it is a model file of a data type, after the hook-based inspection program, the decryption and reading of the model file of the data type can be achieved by executing the first program module therein.

[0055] If it is a code type model file, after the hook-based inspection program, the code type model file can be searched, decrypted and loaded by executing the second program module therein.

[0056] The setting of the hook-based inspection program has been described in detail in the first embodiment and will not be repeated here.

[0057] In general, the advantages and beneficial technical effects of the present invention are as follows: 1. Hook-based model encryption method: Modify the project code and introduce hooks during the model file loading process to achieve encrypted deployment of the model and avoid intrusion into the underlying model code.

[0058] 2. Runtime decryption: During the startup phase, a hook-based checker is used to decrypt the encrypted model file into memory, and then the model is loaded from memory. The decrypted model file is not saved to disk to prevent users from copying it, thereby ensuring that the model file is not stolen.

[0059] 3. Source code encryption: Use the nuitka tool to compile the Python source code into a binary file to effectively protect the source code from being easily obtained.

[0060] 4. Block encryption: For large model files, block encryption is used to avoid memory overflow caused by one-time encryption and decryption.

[0061] 5. Double encryption of model files and source codes: Through the dual protection of model file encryption and source code encryption, the model security is further improved.

[0062] Embodiment 3 Based on the same inventive concept, the embodiment of the present invention provides a model encryption device, see Figure 2 ,include: A model file encryption module 201 is used to encrypt the model file of the target deep learning model using an encryption key of a preset encryption algorithm when deploying the target deep learning model; A hook-based checker setting module 202, used to set a hook-based checker in the project code for deploying the target deep learning model, wherein the hook-based checker is triggered before a file reading operation is involved, and is used to select whether to decrypt the file and read the model file according to the type of the file to be read; The project code encryption module 203 is used to encrypt the source code of the project code for setting the hook-based inspection program using a preset tool.

[0063] Since the device introduced in the third embodiment of the present invention is a device used to implement the model encryption method in the first embodiment of the present invention, based on the method introduced in the first embodiment of the present invention, the person skilled in the art can understand the specific structure and deformation of the device, so it is not repeated here. All devices used in the method in the first embodiment of the present invention belong to the scope of protection of the present invention.

[0064] Embodiment 4 Based on the same inventive concept, an embodiment of the present invention provides a model decryption device, comprising: The decryption module is used to decrypt the encrypted model file by executing a hook-based check program when the model file needs to be read during the process of starting the target deep learning model, using the decryption key of the preset encryption algorithm to obtain the decrypted model file.

[0065] Since the device introduced in the fourth embodiment of the present invention is a device used to implement the model decryption method in the second embodiment of the present invention, based on the method introduced in the second embodiment of the present invention, the person skilled in the art can understand the specific structure and deformation of the device, so it is not repeated here. All devices used in the method in the second embodiment of the present invention belong to the scope of protection of the present invention.

[0066] Embodiment 5 Based on the same inventive concept, the present invention also provides a model encryption and decryption system 300, see Figure 3 , including the model encryption device 301 described in the third embodiment and the model decryption device 302 described in the fourth embodiment.

[0067] Embodiment 6 Based on the same inventive concept, the present invention also provides a non-volatile storage medium, which stores multiple instructions, and the instructions are suitable for being loaded by a processor and executing the model encryption method described in Example 1, or executing the model decryption method described in Example 2.

[0068] Since the non-volatile storage medium introduced in the sixth embodiment of the present invention is the storage medium used to implement the model encryption method in the first embodiment of the present invention or the model decryption method in the second embodiment, based on the method introduced in the first or second embodiment of the present invention, the person skilled in the art can understand the specific structure and deformation of the storage medium, so it is not repeated here. All storage media used in the methods of the first or second embodiments of the present invention belong to the scope of protection of the present invention.

[0069] Embodiment 7 The present invention also provides an electronic device, see Figure 4 , including a memory 401 and a processor 402, wherein the memory stores a computer program 403, and the processor is configured to run the computer program to execute the model encryption method described in the first embodiment, or to execute the model decryption method described in the second embodiment.

[0070] Since the electronic device introduced in the seventh embodiment of the present invention is an electronic device used to implement the model encryption method in the first embodiment of the present invention or the model decryption method in the second embodiment, based on the method introduced in the first or second embodiment of the present invention, the person skilled in the art can understand the specific structure and deformation of the electronic device, so it is not repeated here. All electronic devices used in the methods of the first or second embodiments of the present invention belong to the scope of protection of the present invention.

[0071] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0072] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0073] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic creative concepts are known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the embodiments of the present invention without departing from the spirit and scope of the embodiments of the present invention. Thus, if these modifications and variations of the embodiments of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A model encryption method, characterized in that: include: When deploying the target deep learning model, encrypting the model file of the target deep learning model using an encryption key of a preset encryption algorithm; Setting a hook-based checker in the project code for deploying the target deep learning model, wherein the hook-based checker is triggered before a file reading operation is involved, and is used to select whether to decrypt the file and read the model file according to the type of the file to be read; Use the preset tool to encrypt the source code of the project code that sets up the hook-based checker.

2. The model encryption method according to claim 1, characterized in that: Encrypting the model file of the target deep learning model using an encryption key of a preset encryption algorithm includes: Determine whether the size of the model file of the target deep learning model is greater than a preset value. If so, encrypt the model file of the target deep learning model in blocks using an encryption key of a preset encryption algorithm.

3. The model encryption method according to claim 1, characterized in that: The model file includes a data type model file and a code type model file, and a hook-based checker is set in the project code for deploying the target deep learning model, including: Designing a first program module for reading a data type model file in a project code for the target deep learning model; A second program module for loading a code type model file is designed in the project code for deploying the target deep learning model, and the first program module and the second program module constitute the hook-based inspection program.

4. The model encryption method according to claim 3, characterized in that: A first program module for reading a data type model file is designed in the project code for the target deep learning model, including: Back up Python's built-in disk file reading function; A custom disk file reading function, wherein the custom disk file reading function is used to determine whether the type of the file to be read is a model file, decrypt the encrypted model file using a decryption key of a preset encryption algorithm when the file to be read is a model file, and jump to the disk file reading function built into Python when the file to be read is not a model file; Replace Python's built-in disk read function with a custom disk read function.

5. The model encryption method according to claim 3, characterized in that: A second program module for loading a code type model file is designed in the project code for deploying the target deep learning model, including: Back up the built-in module search class in Python; A custom module loading class, wherein the custom module loading class is used to read the encrypted code type model file, and decrypt the encrypted code type model file before loading it; A custom module search class, wherein the custom module search class is used to determine whether the type of the file to be read is a model file, and when the file to be read is a model file, specify to use the custom module loading class to load the model file; Replace the built-in module search class in Python with the custom module loading class.

6. A model decryption method, characterized in that: include: In the process of starting the target deep learning model, when the model file needs to be read, the hook-based inspection program is executed, and the encrypted model file is decrypted by the hook-based inspection program using a decryption key of a preset encryption algorithm to obtain the decrypted model file.

7. A model encryption device, characterized in that: include: A model file encryption module, used to encrypt the model file of the target deep learning model using an encryption key of a preset encryption algorithm when deploying the target deep learning model; A hook-based checker setting module, used to set a hook-based checker in the project code for deploying the target deep learning model, wherein the hook-based checker is triggered before a file reading operation is involved, and is used to select whether to decrypt the file and read the model file according to the type of the file to be read; The project code encryption module is used to encrypt the source code of the project code for setting the hook-based checker using a preset tool.

8. A model decryption device, characterized in that: include: The decryption module is used to decrypt the encrypted model file by executing a hook-based check program when the model file needs to be read during the process of starting the target deep learning model, using the decryption key of the preset encryption algorithm to obtain the decrypted model file.

9. A model encryption and decryption system, characterized in that: It includes the model encryption device described in claim 7 and the model decryption device described in claim 8.

10. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the model encryption method described in any one of claims 1 to 5, or executing the model decryption method described in claim 6.

11. An electronic device comprising a memory and a processor, characterized in that: The memory stores a computer program, and the processor is configured to run the computer program to execute the model encryption method according to any one of claims 1 to 5, or to execute the model decryption method according to claim 6.

Citation Information

Patent Citations

  • File encryption method, device and equipment

    CN105893857A

  • A method and equipment for security assessment of encryption model

    CN110113203A

  • Encryption method and device of target detection model, equipment and storage medium

    CN113407968A

  • Model processing method, device and equipment

    CN114969784A

  • Model encryption method and device, storage medium and electronic equipment

    CN115051788A