LeNet-5 FHE Implementation
This page demonstrates the LeNet-5 inference workflow using FHEON. It provides an example of how to set up the FHE context, configure the ANNController, and perform encrypted-domain inference on MNIST images using a LeNet-5 architecture.
Overview
The workflow includes:
Context and Key Generation
Initializes the FHEController with parameters such as ring degree, number of slots, circuit depth, and scaling factors.
Generates rotation keys for convolution, average pooling, and fully connected layers, then serializes them for optimized FHE operations.
Data Preparation
Read and encode all the model weights and baises.
Reads and preprocesses MNIST images.
Encrypts the image data for inference.
LeNet-5 Layers
Implements two convolutional layers (Conv1 and Conv2) followed by average pooling.
Implements three fully connected layers (FC1, FC2, FC3) for classification.
Applies encrypted-domain ReLU activations and bootstrapping where needed.
Inference Loop
Iterates over all input MNIST images.
Sequentially applies convolution, pooling, ReLU, and fully connected layers.
Decrypts results and writes predicted labels to a file.
Key Functions
The main functions used in this example include:
secure_convolution() – Performs a convolutional layer on encrypted data.
secure_optimzed_avgPool() – Applies average pooling on encrypted data.
secure_flinear() – Implements a fully connected layer on encrypted data.
secure_relu() – Secure ReLU activation.
bootstrap_function() – Optional CKKS bootstrapping to refresh ciphertext precision.
encode_kernel() and encode_inputData() – Encode plaintext weights and inputs for FHE operations.
Full Example Source
You can view and download the full source code of this example: