VGG-16 Optimized Implementation

This page demonstrates the optimized VGG-16 inference workflow using FHEON. It highlights improvements in bootstrapping management, rotation key organization, and memory efficiency for encrypted CIFAR-10 inference.

Overview

The workflow consists of:

  1. Context and Key Generation - Initializes FHEONHEController with parameters such as ring degree, slots, depth, and modulus chain. - Generates rotation and bootstrapping keys for convolution, average pooling, and fully connected layers. - Keys are serialized per layer, cleared after use, and reloaded during inference to optimize memory usage.

  2. Data Preparation - Loads CIFAR-10 test images from binary format. - Normalizes pixel values and encrypts them into ciphertext vectors.

  3. Optimized VGG-16 Layers - Implements convolution + ReLU blocks with optional bootstrapping. - Average pooling reduces spatial dimensions between stages. - Global average pooling before fully connected layers. - Fully connected layers finalize classification. - Bootstrapping is applied selectively to refresh ciphertext precision while minimizing overhead.

  4. Inference Loop - Iterates over encrypted CIFAR-10 images. - Loads layer-specific bootstrapping and rotation keys on-demand. - Sequentially applies convolution blocks, pooling, bootstrapping, and fully connected layers. - Decrypts outputs and writes predicted labels to file.

Key Functions

Controller functions used in this example:

  • he_convolution_optimized() – 3x3 “same” convolution with hoisted rotations.

  • he_avgpool_optimzed_with_multiple_channels() – Average pooling that also compacts the channels for the next stage.

  • he_globalavgpool() – Global average pooling.

  • he_linear() – Fully connected layer.

  • he_relu() – Chebyshev approximation of ReLU.

  • bootstrap_function() – CKKS bootstrapping to refresh the ciphertext levels.

  • encode_kernel_optimized() – Encodes the 3x3 kernels with their padding masks.

Functions of the example:

  • convolution_relu_block() – Convolution followed by ReLU (and bootstrapping).

  • FClayer_relu_block() – Fully connected layer followed by ReLU.

Full Example Source

You can view the full optimized VGG-16 implementation here:

VGG16Optimized.cpp