Homomorphic Convolution Unit (hcunit), including homomorphic convolution layer, homomorphic average pooling layer, square activation layer and fully connected layer, uses the leveled homomorphic encryption (CKKS) to encrypt the data inputted into model. The whole computations in model are in ciphertext forms. The cloud service providers and model providers can not get any useful information about the input and the results. We will get the encrypted inference result and decrypt it to get the real result. By using this homomorphic convolution unit, we can construct more complex and deep neural networks to solve different tasks.
This implementation includes the following contents:
- cnpy.cpp and cnpy.h,
git clone
from Rogersce, are used to load.npz
datasets. - datasets.cpp and datasets.h implemented that load
.npz
data (images and labels) intotorch::Tensor
. In our implementation, we encapsulated API of loading MedMNIST datasets and MNIST dataset. - dataloader.cpp and dataloader.h files, according the batch size and data category (
DATA_CAT::TRIN
,DATA_CAT::VAL
andDATA_CAT::TEST
), load images and labels into atorch::Tensor
std::vector
; - train_model.cpp and train_model.h files are used to define the convolution neural networks. At same time, it includes the training, valuation and test processes. This two files mainly used to train the model to get the parameters of weights and bias.
- he_utils.cpp and he_utils.h files are used to encapsulate the leveled homomorphic encryption tools. And it also defines the
Cipher_Tensor
which looks like thetorch::Tensor
. But its element is the ciphertext polynomial of CKKS. - he_layer.cpp and he_layer.h files define the homomorphic layers, including homomorphic 2D convolution layer (
HEConv2dLayer
), homomorphic average layer (HEAverage2dLayer
), homomorphic square activation layer (HESquare
), and homomorphic fully connected layer (HELinear
). - conv_unit.cpp and conv_unit.h test the efficiency of each layers in our homomorphic convolution unit.
- LoLa-Dense.cpp and LoLa-Dense.h construct the homomorphic LoLa-Dense network and test the efficiency of each homomorphic layers.
- CryptoNets.cpp and CryptoNets.h construct the homomorphic CryptoNets network and test the efficiency of each homomorphic layers.
- lenet.cpp and lenet.h construct the homomorphic LeNet network and test the efficiency of it each homomorphic layers.
- ./experiment/conv_unit, ./experiment/loladense, ./experiment/cryptonets and ./experiment/lenet include the experimental results about conv_unit, LoLa-Dense, CryptoNets and LeNet separately.
To use the APIs in our homomorphic convolution unit, you need install Libtorch library and SEAL library (>3.7). In our implementation, we use CMake tools to compile. If you want to compile by CMake, you only add the library dependency statement in CMakeList.txt to your CMakeList.txt file.