ResNet-20 FHE Implementation
This page demonstrates the Basic ResNet 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 CIFAR-10 images using a ResNet-20 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 and serializes them for optimized FHE convolution operations.
Data Preparation
Reads and preprocesses CIFAR-10 images.
Encrypts the image data for inference.
ResNet-20 Blocks
Implements convolutional blocks, shortcut convolution blocks, double shortcut blocks, and fully connected layers.
Each block leverages optimized encoding and rotation strategies for FHE-friendly computation.
Uses the ANNController to perform secure ReLU and pooling operations on encrypted data.
Inference Loop
Iterates over all input images.
Applies the ResNet-20 layers sequentially.
Performs encrypted global average pooling and fully connected classification.
Decrypts the results and prints predicted labels.
Key Functions
The main functions used in the example include:
convolution_block() – Performs a single convolutional layer on encrypted data.
shortcut_convolution_block() – Handles the shortcut connections in ResNet.
double_shortcut_convolution_block() – Implements convolution with shortcut for downsampled layers.
resnet_block() – Combines convolution, ReLU, and shortcut operations to form a ResNet residual block.
fc_layer_block() – Implements the final fully connected layer for classification.
Full Example Source
You can view and download the full source code of this example: